Make syntax error display optional

Fixes GH-543
This commit is contained in:
Ryan Dahl 2011-01-01 14:24:16 -08:00
parent 40f29dd48a
commit 1c7cd4aac3
2 changed files with 16 additions and 6 deletions

View File

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

View File

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