Skip to content

Commit

Permalink
Tests WIP 4
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Nov 23, 2023
1 parent e4e8b24 commit b3221d0
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions test/eval.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,172 @@ describe('eval', () => {
});
});

describe('where var frozen by eval also used in const violation', () => {
describe('where const violation in body of function', () => {
describe('no other bindings with same name', () => {
itSerializes('direct assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
x = 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");x=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});

itSerializes('read-write assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
x += 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");x+=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});
});

describe('other bindings with same name', () => {
itSerializes('direct assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
{
let x = 3;
}
x = 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");{let a=3}x=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});

itSerializes('read-write assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
{
let x = 4;
}
x += 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");{let a=4}x+=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
expect(fn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});
});
});

describe('where const violation in nested function', () => {
describe('no other bindings with same name', () => {
itSerializes('direct assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
return () => x = 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");return()=>x=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
const innerFn = fn();
expect(innerFn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});

itSerializes('read-write assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
return () => x += 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");return()=>x+=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
const innerFn = fn();
expect(innerFn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});
});

describe('other bindings with same name', () => {
itSerializes('direct assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
{
let x = 3;
}
return () => x = 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");{let a=3}return()=>x=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
const innerFn = fn();
expect(innerFn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});

itSerializes('read-write assignment', {
in: `
module.exports = function(module, exports) {
const x = 1;
eval('x');
{
let x = 4;
}
return () => x += 2;
};
`,
out: `(0,eval)("
(function(module,exports){const x=1;eval(\\"x\\");{let a=4}return()=>x+=2;})
")`,
validate(fn) {
expect(fn).toBeFunction();
const innerFn = fn();
expect(innerFn).toThrowWithMessage(TypeError, 'Assignment to constant variable.');
}
});
});
});
});

itSerializes('eval expression contains function', {
in: `module.exports = function(module, exports) {
return eval((() => '123')());
Expand Down

0 comments on commit b3221d0

Please sign in to comment.