diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2011-01-02 01:24:16 +0300 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-01-02 03:38:31 +0300 |
commit | 1c7cd4aac34f98953b81a1af46ddda5b62f87899 (patch) | |
tree | d191833891133a4a8b8c165a2389494649ce8820 /src | |
parent | 40f29dd48a52699c82af8b844a2e6f2832f23a6a (diff) |
Make syntax error display optional
Fixes GH-543
Diffstat (limited to 'src')
-rw-r--r-- | src/node.js | 12 | ||||
-rw-r--r-- | src/node_script.cc | 10 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/node.js b/src/node.js index 43ccdb03258..7bb85cc4f59 100644 --- a/src/node.js +++ b/src/node.js @@ -35,7 +35,9 @@ if (!x) throw new Error(msg || 'assertion error'); }; - var evals = process.binding('evals'); + var Script = process.binding('evals').Script; + var runInThisContext = Script.runInThisContext; + var runInNewContext = Script.runInNewContext; // lazy loaded. var constants; @@ -86,7 +88,7 @@ if (internalModuleCache[id]) return internalModuleCache[id].exports; if (!natives[id]) throw new Error('No such native module ' + id); - var fn = evals.Script.runInThisContext( + var fn = runInThisContext( '(function (module, exports, require) {' + natives[id] + '\n})', id + '.js'); var m = {id: id, exports: {}}; @@ -332,7 +334,7 @@ sandbox.global = sandbox; sandbox.root = root; - return evals.Script.runInNewContext(content, sandbox, filename); + return runInNewContext(content, sandbox, filename); } else { debug('load root module'); // root module @@ -342,7 +344,7 @@ global.__dirname = dirname; global.module = self; - return evals.Script.runInThisContext(content, filename); + return runInThisContext(content, filename); } } else { @@ -352,7 +354,7 @@ content + '\n});'; - var compiledWrapper = evals.Script.runInThisContext(wrapper, filename); + var compiledWrapper = runInThisContext(wrapper, filename); if (filename === process.argv[1] && global.v8debug) { global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0); } diff --git a/src/node_script.cc b/src/node_script.cc index 81d10958184..3057a3429f6 100644 --- a/src/node_script.cc +++ b/src/node_script.cc @@ -280,6 +280,14 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) { ? args[filename_index]->ToString() : String::New("evalmachine.<anonymous>"); + const int display_error_index = args.Length() - 1; + bool display_error = false; + if (args.Length() > display_error_index && + args[display_error_index]->IsBoolean() && + args[display_error_index]->BooleanValue() == true) { + display_error = true; + } + Persistent<Context> context; Local<Array> keys; @@ -325,7 +333,7 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) { : Script::New(code, filename); if (script.IsEmpty()) { // FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS. - DisplayExceptionLine(try_catch); + if (display_error) DisplayExceptionLine(try_catch); // Hack because I can't get a proper stacktrace on SyntaxError return try_catch.ReThrow(); |