Skip to content

Commit f1a4f17

Browse files
committed
script.runIn*Context not throwing errors properly.
1 parent 7d0252e commit f1a4f17

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

src/node_script.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Handle<Value> node::Script::EvalMachine(const Arguments& args) {
166166
}
167167
}
168168
if (result.IsEmpty()) {
169-
result = ThrowException(try_catch.Exception());
169+
return try_catch.ReThrow();
170170
} else if (cFlag == newContext) {
171171
// success! copy changes back onto the sandbox object.
172172
keys = context->Global()->GetPropertyNames();

test/message/testcfg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def IsFailureOutput(self, output):
6363
pattern = '^%s$' % pattern
6464
patterns.append(pattern)
6565
# Compare actual output with the expected
66-
raw_lines = output.stdout.split('\n')
66+
raw_lines = (output.stdout + output.stderr).split('\n')
6767
outlines = [ s for s in raw_lines if not self.IgnoreLine(s) ]
6868
if len(outlines) != len(patterns):
6969
return True
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require('../common');
2+
3+
error('before');
4+
5+
var Script = process.binding('evals').Script;
6+
7+
// undefined reference
8+
script = new Script('foo.bar = 5;');
9+
script.runInNewContext();
10+
11+
error('after');
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
before
2+
3+
4+
/Users/ryan/projects/node/test/message/undefined_reference_in_new_context.js:9
5+
script.runInNewContext();
6+
^
7+
ReferenceError: foo is not defined
8+
at evalmachine.<anonymous>:1:1
9+
at Object.<anonymous> (/Users/ryan/projects/node/test/message/undefined_reference_in_new_context.js:9:8)
10+
at Module._compile (module:384:23)
11+
at Module._loadScriptSync (module:393:8)
12+
at Module.loadSync (module:296:10)
13+
at Object.runMain (module:447:22)
14+
at node.js:208:10

test/simple/test-script-new.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ assert.throws(function() {
1515
script.runInNewContext();
1616
});
1717

18+
19+
20+
debug('undefined reference');
21+
var error;
22+
script = new Script('foo.bar = 5;');
23+
try {
24+
script.runInNewContext();
25+
} catch (e) {
26+
error = e;
27+
}
28+
assert.ok(error);
29+
assert.ok(error.message.indexOf('not defined') >= 0);
30+
31+
debug('error.message: ' + error.message);
32+
33+
1834
hello = 5;
1935
script = new Script('hello = 2');
2036
script.runInNewContext();

0 commit comments

Comments
 (0)