Browse Source

src: wrap source before doing syntax check

This is to ensure that it is evaluated the same way it would be if it
were to be run by node or required.

Before, the following would pass if run by node, but fail if run via
the syntax check flag:

    if (true) {
      return;
    }

Now, this will pass the syntax check

PR-URL: https://github.com/nodejs/node/pull/3587
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
process-exit-stdio-flushing
Evan Lucas 9 years ago
parent
commit
08166cb99a
  1. 2
      src/node.js
  2. 3
      test/fixtures/syntax/illegal_if_not_wrapped.js
  3. 1
      test/parallel/test-cli-syntax.js

2
src/node.js

@ -106,6 +106,8 @@
var source = fs.readFileSync(filename, 'utf-8'); var source = fs.readFileSync(filename, 'utf-8');
// remove shebang and BOM // remove shebang and BOM
source = internalModule.stripBOM(source.replace(/^\#\!.*/, '')); source = internalModule.stripBOM(source.replace(/^\#\!.*/, ''));
// wrap it
source = Module.wrap(source);
// compile the script, this will throw if it fails // compile the script, this will throw if it fails
new vm.Script(source, {filename: filename, displayErrors: true}); new vm.Script(source, {filename: filename, displayErrors: true});
process.exit(0); process.exit(0);

3
test/fixtures/syntax/illegal_if_not_wrapped.js

@ -0,0 +1,3 @@
if (true) {
return;
}

1
test/parallel/test-cli-syntax.js

@ -20,6 +20,7 @@ var syntaxArgs = [
'syntax/good_syntax', 'syntax/good_syntax',
'syntax/good_syntax_shebang.js', 'syntax/good_syntax_shebang.js',
'syntax/good_syntax_shebang', 'syntax/good_syntax_shebang',
'syntax/illegal_if_not_wrapped.js'
].forEach(function(file) { ].forEach(function(file) {
file = path.join(common.fixturesDir, file); file = path.join(common.fixturesDir, file);

Loading…
Cancel
Save