worker: hide MessagePort init function behind symbol
This reduces unintended exposure of internals. PR-URL: https://github.com/nodejs/node/pull/23037 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
d102a85cd9
commit
2d65e67305
@ -24,7 +24,8 @@ util.inherits(MessagePort, EventEmitter);
|
|||||||
const {
|
const {
|
||||||
Worker: WorkerImpl,
|
Worker: WorkerImpl,
|
||||||
getEnvMessagePort,
|
getEnvMessagePort,
|
||||||
threadId
|
threadId,
|
||||||
|
oninit: oninit_symbol
|
||||||
} = internalBinding('worker');
|
} = internalBinding('worker');
|
||||||
|
|
||||||
const isMainThread = threadId === 0;
|
const isMainThread = threadId === 0;
|
||||||
@ -93,7 +94,7 @@ function oninit() {
|
|||||||
setupPortReferencing(this, this, 'message');
|
setupPortReferencing(this, this, 'message');
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(MessagePort.prototype, 'oninit', {
|
Object.defineProperty(MessagePort.prototype, oninit_symbol, {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
writable: false,
|
writable: false,
|
||||||
value: oninit
|
value: oninit
|
||||||
|
@ -113,6 +113,7 @@ struct PackageConfig {
|
|||||||
#define PER_ISOLATE_SYMBOL_PROPERTIES(V) \
|
#define PER_ISOLATE_SYMBOL_PROPERTIES(V) \
|
||||||
V(handle_onclose_symbol, "handle_onclose") \
|
V(handle_onclose_symbol, "handle_onclose") \
|
||||||
V(owner_symbol, "owner") \
|
V(owner_symbol, "owner") \
|
||||||
|
V(oninit_symbol, "oninit") \
|
||||||
|
|
||||||
// Strings are per-isolate primitives but Environment proxies them
|
// Strings are per-isolate primitives but Environment proxies them
|
||||||
// for the sake of convenience. Strings should be ASCII-only.
|
// for the sake of convenience. Strings should be ASCII-only.
|
||||||
@ -219,7 +220,6 @@ struct PackageConfig {
|
|||||||
V(onhandshakedone_string, "onhandshakedone") \
|
V(onhandshakedone_string, "onhandshakedone") \
|
||||||
V(onhandshakestart_string, "onhandshakestart") \
|
V(onhandshakestart_string, "onhandshakestart") \
|
||||||
V(onheaders_string, "onheaders") \
|
V(onheaders_string, "onheaders") \
|
||||||
V(oninit_string, "oninit") \
|
|
||||||
V(onmessage_string, "onmessage") \
|
V(onmessage_string, "onmessage") \
|
||||||
V(onnewsession_string, "onnewsession") \
|
V(onnewsession_string, "onnewsession") \
|
||||||
V(onocspresponse_string, "onocspresponse") \
|
V(onocspresponse_string, "onocspresponse") \
|
||||||
|
@ -421,7 +421,7 @@ MessagePort::MessagePort(Environment* env,
|
|||||||
async()->data = static_cast<void*>(this);
|
async()->data = static_cast<void*>(this);
|
||||||
|
|
||||||
Local<Value> fn;
|
Local<Value> fn;
|
||||||
if (!wrap->Get(context, env->oninit_string()).ToLocal(&fn))
|
if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fn->IsFunction()) {
|
if (fn->IsFunction()) {
|
||||||
|
@ -502,6 +502,10 @@ void InitWorker(Local<Object> target,
|
|||||||
thread_id_string,
|
thread_id_string,
|
||||||
Number::New(env->isolate(),
|
Number::New(env->isolate(),
|
||||||
static_cast<double>(env->thread_id()))).FromJust();
|
static_cast<double>(env->thread_id()))).FromJust();
|
||||||
|
Local<String> oninit_string = FIXED_ONE_BYTE_STRING(env->isolate(), "oninit");
|
||||||
|
target->Set(env->context(),
|
||||||
|
oninit_string,
|
||||||
|
env->oninit_symbol()).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user