-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
worker: implement worker.moveMessagePortToContext() #26497
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,14 +15,17 @@ | |
|
||
namespace node { | ||
using v8::Context; | ||
using v8::EscapableHandleScope; | ||
using v8::Function; | ||
using v8::HandleScope; | ||
using v8::Isolate; | ||
using v8::Local; | ||
using v8::MaybeLocal; | ||
using v8::Message; | ||
using v8::MicrotasksPolicy; | ||
using v8::Object; | ||
using v8::ObjectTemplate; | ||
using v8::Private; | ||
using v8::String; | ||
using v8::Value; | ||
|
||
|
@@ -279,6 +282,26 @@ void FreePlatform(MultiIsolatePlatform* platform) { | |
delete platform; | ||
} | ||
|
||
MaybeLocal<Object> GetPerContextExports(Local<Context> context) { | ||
Isolate* isolate = context->GetIsolate(); | ||
EscapableHandleScope handle_scope(isolate); | ||
|
||
Local<Object> global = context->Global(); | ||
Local<Private> key = Private::ForApi(isolate, | ||
FIXED_ONE_BYTE_STRING(isolate, "node:per_context_binding_exports")); | ||
|
||
Local<Value> existing_value; | ||
if (!global->GetPrivate(context, key).ToLocal(&existing_value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We’ve been using V8 privates extensively for a while, I don’t think they’re going away (and if they did we’d have bigger problems, e.g. N-API relies on them as well). But yes, if you prefer, we could use the extras binding object for that … I feel like that’s mostly intended for actual v8-extras, but in theory nothing stops us, and I don’t mind making the switch if you prefer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @addaleax I don't have very strong opinions about the choices here...although I wonder what does this look like in the heap snapshot? Do they show up? BTW, we probably need to do something similar for the Environment persistent handles (save them temporarily to the global proxy) when we implement snapshots... |
||
return MaybeLocal<Object>(); | ||
if (existing_value->IsObject()) | ||
return handle_scope.Escape(existing_value.As<Object>()); | ||
|
||
Local<Object> exports = Object::New(isolate); | ||
if (context->Global()->SetPrivate(context, key, exports).IsNothing()) | ||
return MaybeLocal<Object>(); | ||
return handle_scope.Escape(exports); | ||
} | ||
|
||
Local<Context> NewContext(Isolate* isolate, | ||
Local<ObjectTemplate> object_template) { | ||
auto context = Context::New(isolate, nullptr, object_template); | ||
|
@@ -289,25 +312,42 @@ Local<Context> NewContext(Isolate* isolate, | |
True(isolate)); | ||
|
||
{ | ||
// Run lib/internal/bootstrap/context.js | ||
// Run per-context JS files. | ||
Context::Scope context_scope(context); | ||
|
||
std::vector<Local<String>> parameters = { | ||
FIXED_ONE_BYTE_STRING(isolate, "global")}; | ||
Local<Value> arguments[] = {context->Global()}; | ||
MaybeLocal<Function> maybe_fn = | ||
per_process::native_module_loader.LookupAndCompile( | ||
context, "internal/bootstrap/context", ¶meters, nullptr); | ||
if (maybe_fn.IsEmpty()) { | ||
return Local<Context>(); | ||
} | ||
Local<Function> fn = maybe_fn.ToLocalChecked(); | ||
MaybeLocal<Value> result = | ||
fn->Call(context, Undefined(isolate), arraysize(arguments), arguments); | ||
// Execution failed during context creation. | ||
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal. | ||
if (result.IsEmpty()) { | ||
Local<Object> exports; | ||
if (!GetPerContextExports(context).ToLocal(&exports)) | ||
return Local<Context>(); | ||
|
||
Local<String> global_string = FIXED_ONE_BYTE_STRING(isolate, "global"); | ||
Local<String> exports_string = FIXED_ONE_BYTE_STRING(isolate, "exports"); | ||
|
||
static const char* context_files[] = { | ||
"internal/per_context/setup", | ||
joyeecheung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"internal/per_context/domexception", | ||
nullptr | ||
}; | ||
|
||
for (const char** module = context_files; *module != nullptr; module++) { | ||
std::vector<Local<String>> parameters = { | ||
global_string, | ||
exports_string | ||
}; | ||
Local<Value> arguments[] = {context->Global(), exports}; | ||
MaybeLocal<Function> maybe_fn = | ||
per_process::native_module_loader.LookupAndCompile( | ||
context, *module, ¶meters, nullptr); | ||
if (maybe_fn.IsEmpty()) { | ||
return Local<Context>(); | ||
} | ||
Local<Function> fn = maybe_fn.ToLocalChecked(); | ||
MaybeLocal<Value> result = | ||
fn->Call(context, Undefined(isolate), | ||
arraysize(arguments), arguments); | ||
// Execution failed during context creation. | ||
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal. | ||
if (result.IsEmpty()) { | ||
return Local<Context>(); | ||
} | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.