joyent/node — pull request #3502 by itaylor (2012-06-21 09:49:59+00:00)
Title: Partial fix for issue 3452, missing filename and error location on syntax error in vm functions

I was unable to completely fix #3452 due to a bug with V8's TryCatch::ReThrow where the rethrown exceptions have their stack trace reset. I was, however able to make it so that the DisplayErrorLine is able to display the correct error line when a script is not a wrapped module. This makes it so that the undocumented display_errors argument works correctly.

To do this, I moved the declaration of the wrapper out of node.js and into node.h, and I then pass it to node.js via the process variable when the node.js script has it's constructor called. This seemed to fit with the pattern of how other things are being inited in the node.js file.

I'm also working on a pure V8 test of ReThrow's broken behavior that I'll submit to the V8 project, which, if fixed, would eliminate the need for the display_errors argument and fix this bug entirely.

Test:
```
var myFileName = "/path/to/some/file";
require("vm").createScript('invalidJsHere ?= 1;', myFileName, true); //using display_errors = true
```
Output before this patch:
```
/path/to/some/file:1

^

vm.js:32
var ns = new binding.NodeScript(code, ctx, filename);
^
SyntaxError: Unexpected token =
at new Script (vm.js:32:12)
at Function.Script.createScript (vm.js:48:10)
at Object. (/Users/itaylor/temp/test.js:2:15)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:487:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
```

After this change:
```
/path/to/some/file:1
invalidJsHere ?= 1;
^

vm.js:32
var ns = new binding.NodeScript(code, ctx, filename);
^
SyntaxError: Unexpected token =
at new Script (vm.js:32:12)
at Function.Script.createScript (vm.js:48:10)
at Object. (/Users/itaylor/temp/test.js:2:15)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:487:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
```