Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Make syntax error display optional
Browse files Browse the repository at this point in the history
Fixes GH-543
  • Loading branch information
ry committed Jan 2, 2011
1 parent 40f29dd commit 1c7cd4a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {}};
Expand Down Expand Up @@ -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
Expand All @@ -342,7 +344,7 @@
global.__dirname = dirname;
global.module = self;

return evals.Script.runInThisContext(content, filename);
return runInThisContext(content, filename);
}

} else {
Expand All @@ -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);
}
Expand Down
10 changes: 9 additions & 1 deletion src/node_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1c7cd4a

Please sign in to comment.