Browse Source

script.runIn*Context not throwing errors properly.

v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
f1a4f17897
  1. 2
      src/node_script.cc
  2. 2
      test/message/testcfg.py
  3. 11
      test/message/undefined_reference_in_new_context.js
  4. 14
      test/message/undefined_reference_in_new_context.out
  5. 16
      test/simple/test-script-new.js

2
src/node_script.cc

@ -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();

2
test/message/testcfg.py

@ -63,7 +63,7 @@ class MessageTestCase(test.TestCase):
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

11
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
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
test/simple/test-script-new.js

@ -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();

Loading…
Cancel
Save