GeezerVison is showing github.com — worker: hide MessagePort init function behind symbol · nodejs/node@2e30a68
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/worker.js +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,7 +24,8 @@ util.inherits(MessagePort, EventEmitter); | 24 | 24 | const { | 25 | 25 | Worker: WorkerImpl, | 26 | 26 | getEnvMessagePort, | 27 | | - threadId | | 27 | + threadId, | | 28 | + oninit: oninit_symbol | 28 | 29 | } = internalBinding('worker'); | 29 | 30 |
| 30 | 31 | const isMainThread = threadId === 0; | @@ -93,7 +94,7 @@ function oninit() { | 93 | 94 | setupPortReferencing(this, this, 'message'); | 94 | 95 | } | 95 | 96 |
| 96 | | -Object.defineProperty(MessagePort.prototype, 'oninit', { | | 97 | +Object.defineProperty(MessagePort.prototype, oninit_symbol, { | 97 | 98 | enumerable: true, | 98 | 99 | writable: false, | 99 | 100 | value: oninit | |
Collapse file Copy file name to clipboardExpand all lines: src/env.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -113,6 +113,7 @@ struct PackageConfig { | 113 | 113 | #define PER_ISOLATE_SYMBOL_PROPERTIES(V) \ | 114 | 114 | V(handle_onclose_symbol, "handle_onclose") \ | 115 | 115 | V(owner_symbol, "owner") \ | | 116 | + V(oninit_symbol, "oninit") \ | 116 | 117 |
| 117 | 118 | // Strings are per-isolate primitives but Environment proxies them | 118 | 119 | // for the sake of convenience. Strings should be ASCII-only. | @@ -219,7 +220,6 @@ struct PackageConfig { | 219 | 220 | V(onhandshakedone_string, "onhandshakedone") \ | 220 | 221 | V(onhandshakestart_string, "onhandshakestart") \ | 221 | 222 | V(onheaders_string, "onheaders") \ | 222 | | - V(oninit_string, "oninit") \ | 223 | 223 | V(onmessage_string, "onmessage") \ | 224 | 224 | V(onnewsession_string, "onnewsession") \ | 225 | 225 | V(onocspresponse_string, "onocspresponse") \ | |
Collapse file Copy file name to clipboardExpand all lines: src/node_messaging.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -421,7 +421,7 @@ MessagePort::MessagePort(Environment* env, | 421 | 421 | async()->data = static_cast<void*>(this); | 422 | 422 |
| 423 | 423 | Local<Value> fn; | 424 | | - if (!wrap->Get(context, env->oninit_string()).ToLocal(&fn)) | | 424 | + if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn)) | 425 | 425 | return; | 426 | 426 |
| 427 | 427 | if (fn->IsFunction()) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_worker.cc +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -501,6 +501,10 @@ void InitWorker(Local<Object> target, | 501 | 501 | thread_id_string, | 502 | 502 | Number::New(env->isolate(), | 503 | 503 | static_cast<double>(env->thread_id()))).FromJust(); | | 504 | + Local<String> oninit_string = FIXED_ONE_BYTE_STRING(env->isolate(), "oninit"); | | 505 | + target->Set(env->context(), | | 506 | + oninit_string, | | 507 | + env->oninit_symbol()).FromJust(); | 504 | 508 | } | 505 | 509 |
| 506 | 510 | } // anonymous namespace | |
|