Skip to content

Commit

Permalink
fix: preserve eval identity to support direct eval
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 13, 2020
1 parent ef7bf84 commit d263118
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/tame-metering/src/tame.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let replaceGlobalMeter;

// When using this function's text in a SES-1.0 shim, we redefine this
// constant to be Error.
const SES1ErrorConstructor = Error;
const SES1ErrorConstructor = null;

export function tameMetering() {
if (replaceGlobalMeter) {
Expand Down Expand Up @@ -34,6 +34,9 @@ export function tameMetering() {
const setWrapped = (...args) => apply(wmSet, wrapped, args);
const getWrapped = (...args) => apply(wmGet, wrapped, args);

// eslint-disable-next-line no-new-func
const globalEval = Function('return eval')();

// How to test for a constructor: https://stackoverflow.com/a/48036194
const isConstructorHandler = {
construct() {
Expand Down Expand Up @@ -76,7 +79,8 @@ export function tameMetering() {
if (
typeof target !== 'function' ||
target === FunctionPrototype ||
target === SES1ErrorConstructor
target === SES1ErrorConstructor ||
target === globalEval
) {
// Preserve identity and mutate in place.
wrapper = target;
Expand Down Expand Up @@ -142,6 +146,9 @@ export function tameMetering() {
({ [name]: wrapper } = {
[name](...args) {
// Fast path:
if (name === 'eval') {
console.log('eval escaped', target);
}
if (!globalMeter) {
return apply(target, this, args);
}
Expand Down

0 comments on commit d263118

Please sign in to comment.