Skip to content

Commit 002dacb

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: #27162 PR-URL: #27245 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 652877e commit 002dacb

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/node_worker.cc

+9-5
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,17 @@ 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+
// Ignore the return value of Set() because exceptions bubble up to JS
471+
// when we return anyway.
472+
USE(args.This()->Set(env->context(), key, error));
469473
return;
470474
}
471475
}

0 commit comments

Comments
 (0)