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

Commit 1ebae5c

Browse files
committed
fixup! code cleanup
Fixed issues pointed out in the code review.
1 parent 218d4c5 commit 1ebae5c

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

src/node.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ ssize_t DecodeWrite(char *buf,
11271127
return StringBytes::Write(buf, buflen, val, encoding, NULL);
11281128
}
11291129

1130-
void DisplayExceptionLine (Handle<Message> message) {
1130+
void DisplayExceptionLine(Handle<Message> message) {
11311131
// Prevent re-entry into this function. For example, if there is
11321132
// a throw from a program in vm.runInThisContext(code, filename, true),
11331133
// then we want to show the original failure, not the secondary one.
@@ -1194,11 +1194,11 @@ static void ReportException(Handle<Value> er, Handle<Message> message) {
11941194

11951195
DisplayExceptionLine(message);
11961196

1197-
Local<Value> traceValue(er->ToObject()->Get(String::New("stack")));
1198-
String::Utf8Value trace(traceValue);
1197+
Local<Value> trace_value(er->ToObject()->Get(String::New("stack")));
1198+
String::Utf8Value trace(trace_value);
11991199

12001200
// range errors have a trace member set to undefined
1201-
if (trace.length() > 0 && !traceValue->IsUndefined()) {
1201+
if (trace.length() > 0 && !trace_value->IsUndefined()) {
12021202
fprintf(stderr, "%s\n", *trace);
12031203
} else {
12041204
// this really only happens for RangeErrors, since they're the only
@@ -1889,15 +1889,13 @@ void FatalException(Handle<Value> error, Handle<Message> message) {
18891889

18901890
Local<Function> fatal_f = Local<Function>::Cast(fatal_v);
18911891

1892-
Handle<Value> argv[] = { error };
1893-
18941892
TryCatch fatal_try_catch;
18951893

18961894
// Do not call FatalException when _fatalException handler throws
18971895
fatal_try_catch.SetVerbose(false);
18981896

18991897
// this will return true if the JS layer handled it, false otherwise
1900-
Local<Value> caught = fatal_f->Call(process, ARRAY_SIZE(argv), argv);
1898+
Local<Value> caught = fatal_f->Call(process, 1, &error);
19011899

19021900
if (fatal_try_catch.HasCaught()) {
19031901
// the fatal exception function threw, so we must exit
@@ -1912,15 +1910,17 @@ void FatalException(Handle<Value> error, Handle<Message> message) {
19121910
}
19131911

19141912

1915-
void FatalException(TryCatch &try_catch) {
1913+
void FatalException(TryCatch& try_catch) {
19161914
HandleScope scope(node_isolate);
19171915
// TODO do not call FatalException if try_catch is verbose
1916+
// (requires V8 API to expose getter for try_catch.is_verbose_)
19181917
FatalException(try_catch.Exception(), try_catch.Message());
19191918
}
19201919

19211920

19221921
void OnMessage(Handle<Message> message, Handle<Value> error) {
1923-
// TODO - check if exception is set?
1922+
// The current version of V8 sends messages for errors only
1923+
// (thus `error` is always set).
19241924
FatalException(error, message);
19251925
}
19261926

@@ -2434,8 +2434,9 @@ void Load(Handle<Object> process_l) {
24342434

24352435
TryCatch try_catch;
24362436

2437-
// try_catch must be not verbose to disable FatalException() handler
2438-
// Load exceptions cannot be ignored (handled) by _fatalException
2437+
// Disable verbose mode to stop FatalException() handler from trying
2438+
// to handle the exception. Errors this early in the start-up phase
2439+
// are not safe to ignore.
24392440
try_catch.SetVerbose(false);
24402441

24412442
Local<Value> f_value = ExecuteString(MainSource(),
@@ -2471,7 +2472,7 @@ void Load(Handle<Object> process_l) {
24712472
// (FatalException(), break on uncaught exception in debugger)
24722473
//
24732474
// This is not strictly necessary since it's almost impossible
2474-
// to attach debugger fast enought to break on exception
2475+
// to attach the debugger fast enought to break on exception
24752476
// thrown during process startup.
24762477
try_catch.SetVerbose(true);
24772478

src/node_script.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,7 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
415415
: Script::New(code, filename);
416416
if (script.IsEmpty()) {
417417
// FIXME UGLY HACK TO DISPLAY SYNTAX ERRORS.
418-
if (display_error) {
419-
HandleScope scope(node_isolate);
420-
DisplayExceptionLine(try_catch.Message());
421-
}
418+
if (display_error) DisplayExceptionLine(try_catch.Message());
422419

423420
// Hack because I can't get a proper stacktrace on SyntaxError
424421
return try_catch.ReThrow();
@@ -451,10 +448,7 @@ Handle<Value> WrappedScript::EvalMachine(const Arguments& args) {
451448
String::New("Script execution timed out.")));
452449
}
453450
if (result.IsEmpty()) {
454-
if (display_error) {
455-
HandleScope scope(node_isolate);
456-
DisplayExceptionLine(try_catch.Message());
457-
}
451+
if (display_error) DisplayExceptionLine(try_catch.Message());
458452
return try_catch.ReThrow();
459453
}
460454
} else {

test/fixtures/uncaught-exceptions/domain.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ d.run(function() {
1010
throw new Error('in domain');
1111
});
1212
});
13-

0 commit comments

Comments
 (0)