Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: reduce MessagePort prototype to documented API #23037

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/internal/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ util.inherits(MessagePort, EventEmitter);
const {
Worker: WorkerImpl,
getEnvMessagePort,
threadId
threadId,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this triggers my OCD, can we make this consistent with the above destructuring assignment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this was leftover from addressing the previous review comment … the comma is gone now :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

oninit: oninit_symbol
} = internalBinding('worker');

const isMainThread = threadId === 0;
Expand Down Expand Up @@ -93,7 +94,7 @@ function oninit() {
setupPortReferencing(this, this, 'message');
}

Object.defineProperty(MessagePort.prototype, 'oninit', {
Object.defineProperty(MessagePort.prototype, oninit_symbol, {
enumerable: true,
writable: false,
value: oninit
Expand Down
2 changes: 1 addition & 1 deletion src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct PackageConfig {
#define PER_ISOLATE_SYMBOL_PROPERTIES(V) \
V(handle_onclose_symbol, "handle_onclose") \
V(owner_symbol, "owner") \
V(oninit_symbol, "oninit") \

// Strings are per-isolate primitives but Environment proxies them
// for the sake of convenience. Strings should be ASCII-only.
Expand Down Expand Up @@ -219,7 +220,6 @@ struct PackageConfig {
V(onhandshakedone_string, "onhandshakedone") \
V(onhandshakestart_string, "onhandshakestart") \
V(onheaders_string, "onheaders") \
V(oninit_string, "oninit") \
V(onmessage_string, "onmessage") \
V(onnewsession_string, "onnewsession") \
V(onocspresponse_string, "onocspresponse") \
Expand Down
2 changes: 1 addition & 1 deletion src/node_messaging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ MessagePort::MessagePort(Environment* env,
async()->data = static_cast<void*>(this);

Local<Value> fn;
if (!wrap->Get(context, env->oninit_string()).ToLocal(&fn))
if (!wrap->Get(context, env->oninit_symbol()).ToLocal(&fn))
return;

if (fn->IsFunction()) {
Expand Down
4 changes: 4 additions & 0 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ void InitWorker(Local<Object> target,
thread_id_string,
Number::New(env->isolate(),
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
Expand Down