node/test/parallel/test-eval-strict-referenceerror.js
Rich Trott 330f25ef82 test: prepare for consistent comma-dangle lint rule
Make changes so that tests will pass when the comma-dangle settings
applied to the rest of the code base are also applied to tests.

PR-URL: https://github.com/nodejs/node/pull/37930
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Derek Lewis <DerekNonGeneric@inf.is>
2021-04-01 23:14:29 -07:00

28 lines
624 B
JavaScript

/* eslint-disable strict */
require('../common');
// In Node.js 0.10, a bug existed that caused strict functions to not capture
// their environment when evaluated. When run in 0.10 `test()` fails with a
// `ReferenceError`. See https://github.com/nodejs/node/issues/2245 for details.
const assert = require('assert');
function test() {
const code = [
'var foo = {m: 1};',
'',
'function bar() {',
'\'use strict\';',
'return foo; // foo isn\'t captured in 0.10',
'};',
].join('\n');
eval(code);
return bar(); // eslint-disable-line no-undef
}
assert.deepStrictEqual(test(), { m: 1 });