-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
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)) | ||
|
||
| 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.
Outdated
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.