Skip to content

Commit 3ff001f

Browse files
committed
worker: handle exception when creating execArgv errors
Handle possible JS exceptions that can occur by returning to JS land immediately. The motivation for this change is that `USE(….FromJust());` is an anti-pattern, and `.FromJust()` with an unused return value is superseded by `.Check()`. However, in this case, checking that the operation succeeded is not necessary. Refs: nodejs#27162
1 parent 7938238 commit 3ff001f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/node_worker.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,15 @@ void Worker::New(const FunctionCallbackInfo<Value>& args) {
459459
// The first argument is program name.
460460
invalid_args.erase(invalid_args.begin());
461461
if (errors.size() > 0 || invalid_args.size() > 0) {
462-
v8::Local<v8::Value> error =
463-
ToV8Value(env->context(),
464-
errors.size() > 0 ? errors : invalid_args)
465-
.ToLocalChecked();
462+
v8::Local<v8::Value> error;
463+
if (!ToV8Value(env->context(),
464+
errors.size() > 0 ? errors : invalid_args)
465+
.ToLocal(&error)) {
466+
return;
467+
}
466468
Local<String> key =
467469
FIXED_ONE_BYTE_STRING(env->isolate(), "invalidExecArgv");
468-
USE(args.This()->Set(env->context(), key, error).FromJust());
470+
USE(args.This()->Set(env->context(), key, error));
469471
return;
470472
}
471473
}

0 commit comments

Comments
 (0)