FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make syntax error display optional · wave2future/node@1c7cd4a · GitHub

Repository navigation

Commit 1c7cd4a

Browse files
committed
Make syntax error display optional
Fixes nodejsGH-543
1 parent 40f29dd commit 1c7cd4a

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎src/node.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
if (!x) throw new Error(msg || 'assertion error');
3636
};
3737

38-
var evals = process.binding('evals');
38+
var Script = process.binding('evals').Script;
39+
var runInThisContext = Script.runInThisContext;
40+
var runInNewContext = Script.runInNewContext;
3941

4042
// lazy loaded.
4143
var constants;
@@ -86,7 +88,7 @@
8688
if (internalModuleCache[id]) return internalModuleCache[id].exports;
8789
if (!natives[id]) throw new Error('No such native module ' + id);
8890

89-
var fn = evals.Script.runInThisContext(
91+
var fn = runInThisContext(
9092
'(function (module, exports, require) {' + natives[id] + '\n})',
9193
id + '.js');
9294
var m = {id: id, exports: {}};
@@ -332,7 +334,7 @@
332334
sandbox.global = sandbox;
333335
sandbox.root = root;
334336

335-
return evals.Script.runInNewContext(content, sandbox, filename);
337+
return runInNewContext(content, sandbox, filename);
336338
} else {
337339
debug('load root module');
338340
// root module
@@ -342,7 +344,7 @@
342344
global.__dirname = dirname;
343345
global.module = self;
344346

345-
return evals.Script.runInThisContext(content, filename);
347+
return runInThisContext(content, filename);
346348
}
347349

348350
} else {
@@ -352,7 +354,7 @@
352354
content +
353355
'\n});';
354356

355-
var compiledWrapper = evals.Script.runInThisContext(wrapper, filename);
357+
var compiledWrapper = runInThisContext(wrapper, filename);
356358
if (filename === process.argv[1] && global.v8debug) {
357359
global.v8debug.Debug.setBreakPoint(compiledWrapper, 0, 0);
358360
}

‎src/node_script.cc‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
280280
? args[filename_index]->ToString()
281281
: String::New("evalmachine.<anonymous>");
282282

283+
const int display_error_index = args.Length() - 1;
284+
bool display_error = false;
285+
if (args.Length() > display_error_index &&
286+
args[display_error_index]->IsBoolean() &&
287+
args[display_error_index]->BooleanValue() == true) {
288+
display_error = true;
289+
}
290+
283291
Persistent<Context> context;
284292

285293
Local<Array> keys;
@@ -325,7 +333,7 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
325333
: Script::New(code, filename);
326334
if (script.IsEmpty()) {
327335
// FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
328-
DisplayExceptionLine(try_catch);
336+
if (display_error) DisplayExceptionLine(try_catch);
329337

330338
// Hack because I can't get a proper stacktrace on SyntaxError
331339
return try_catch.ReThrow();

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL