Skip to content

Commit

Permalink
script.runIn*Context not throwing errors properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 20, 2010
1 parent 7d0252e commit f1a4f17
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/node_script.cc
Expand Up @@ -166,7 +166,7 @@ Handle<Value> node::Script::EvalMachine(const Arguments& args) {
}
}
if (result.IsEmpty()) {
result = ThrowException(try_catch.Exception());
return try_catch.ReThrow();
} else if (cFlag == newContext) {
// success! copy changes back onto the sandbox object.
keys = context->Global()->GetPropertyNames();
Expand Down
2 changes: 1 addition & 1 deletion test/message/testcfg.py
Expand Up @@ -63,7 +63,7 @@ def IsFailureOutput(self, output):
pattern = '^%s$' % pattern
patterns.append(pattern)
# Compare actual output with the expected
raw_lines = output.stdout.split('\n')
raw_lines = (output.stdout + output.stderr).split('\n')
outlines = [ s for s in raw_lines if not self.IgnoreLine(s) ]
if len(outlines) != len(patterns):
return True
Expand Down
11 changes: 11 additions & 0 deletions test/message/undefined_reference_in_new_context.js
@@ -0,0 +1,11 @@
require('../common');

error('before');

var Script = process.binding('evals').Script;

// undefined reference
script = new Script('foo.bar = 5;');
script.runInNewContext();

error('after');
14 changes: 14 additions & 0 deletions test/message/undefined_reference_in_new_context.out
@@ -0,0 +1,14 @@
before


/Users/ryan/projects/node/test/message/undefined_reference_in_new_context.js:9
script.runInNewContext();
^
ReferenceError: foo is not defined
at evalmachine.<anonymous>:1:1
at Object.<anonymous> (/Users/ryan/projects/node/test/message/undefined_reference_in_new_context.js:9:8)
at Module._compile (module:384:23)
at Module._loadScriptSync (module:393:8)
at Module.loadSync (module:296:10)
at Object.runMain (module:447:22)
at node.js:208:10
16 changes: 16 additions & 0 deletions test/simple/test-script-new.js
Expand Up @@ -15,6 +15,22 @@ assert.throws(function() {
script.runInNewContext();
});



debug('undefined reference');
var error;
script = new Script('foo.bar = 5;');
try {
script.runInNewContext();
} catch (e) {
error = e;
}
assert.ok(error);
assert.ok(error.message.indexOf('not defined') >= 0);

debug('error.message: ' + error.message);


hello = 5;
script = new Script('hello = 2');
script.runInNewContext();
Expand Down

0 comments on commit f1a4f17

Please sign in to comment.