Skip to content

Commit d263118

Browse files
committed
fix: preserve eval identity to support direct eval
1 parent ef7bf84 commit d263118

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/tame-metering/src/tame.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let replaceGlobalMeter;
55

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

1010
export function tameMetering() {
1111
if (replaceGlobalMeter) {
@@ -34,6 +34,9 @@ export function tameMetering() {
3434
const setWrapped = (...args) => apply(wmSet, wrapped, args);
3535
const getWrapped = (...args) => apply(wmGet, wrapped, args);
3636

37+
// eslint-disable-next-line no-new-func
38+
const globalEval = Function('return eval')();
39+
3740
// How to test for a constructor: https://stackoverflow.com/a/48036194
3841
const isConstructorHandler = {
3942
construct() {
@@ -76,7 +79,8 @@ export function tameMetering() {
7679
if (
7780
typeof target !== 'function' ||
7881
target === FunctionPrototype ||
79-
target === SES1ErrorConstructor
82+
target === SES1ErrorConstructor ||
83+
target === globalEval
8084
) {
8185
// Preserve identity and mutate in place.
8286
wrapper = target;
@@ -142,6 +146,9 @@ export function tameMetering() {
142146
({ [name]: wrapper } = {
143147
[name](...args) {
144148
// Fast path:
149+
if (name === 'eval') {
150+
console.log('eval escaped', target);
151+
}
145152
if (!globalMeter) {
146153
return apply(target, this, args);
147154
}

0 commit comments

Comments
 (0)