-
-
Notifications
You must be signed in to change notification settings - Fork 36.5k
module: change return type for ModuleWrap::SyntheticModuleEvaluationStepsCallback #65375
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -280,7 +280,7 @@ class V8_EXPORT Module : public Data { | |
| * | ||
| * If IsGraphAsync() is false, the returned Promise is settled. | ||
| */ | ||
| V8_WARN_UNUSED_RESULT MaybeLocal<Value> Evaluate(Local<Context> context); | ||
| V8_WARN_UNUSED_RESULT MaybeLocal<Promise> Evaluate(Local<Context> context); | ||
|
|
||
| /** | ||
| * Returns the namespace object of this module. | ||
|
|
@@ -337,6 +337,15 @@ class V8_EXPORT Module : public Data { | |
| * (where an exception was thrown). | ||
| */ | ||
| using SyntheticModuleEvaluationSteps = | ||
| MaybeLocal<Promise> (*)(Local<Context> context, Local<Module> module); | ||
|
|
||
| /* | ||
| * Deprecated version of SyntheticModuleEvaluationSteps: the returned value is | ||
| * still required to be a Promise, but that is only enforced at runtime. | ||
| */ | ||
| // TODO(https://crbug.com/545375591): Remove once all embedders return a | ||
| // MaybeLocal<Promise>. | ||
| using LegacySyntheticModuleEvaluationSteps = | ||
| MaybeLocal<Value> (*)(Local<Context> context, Local<Module> module); | ||
|
|
||
| /** | ||
|
|
@@ -351,6 +360,16 @@ class V8_EXPORT Module : public Data { | |
| const MemorySpan<const Local<String>>& export_names, | ||
| SyntheticModuleEvaluationSteps evaluation_steps); | ||
|
|
||
| // TODO(https://crbug.com/545375591): Advance to V8_DEPRECATED and then remove | ||
| // this overload once all embedders have been migrated to the one above. | ||
| V8_DEPRECATE_SOON( | ||
| "Use the CreateSyntheticModule overload whose evaluation_steps return a " | ||
| "MaybeLocal<Promise>") | ||
| static Local<Module> CreateSyntheticModule( | ||
|
Contributor
Author
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. This becomes dead-code here once we migrate |
||
| Isolate* isolate, Local<String> module_name, | ||
| const MemorySpan<const Local<String>>& export_names, | ||
| LegacySyntheticModuleEvaluationSteps evaluation_steps); | ||
|
|
||
| /** | ||
| * Set this module's exported value for the name export_name to the specified | ||
| * export_value. This method must be called only on Modules created via | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2398,7 +2398,7 @@ Maybe<bool> Module::InstantiateModule(Local<Context> context, | |
| return Just(true); | ||
| } | ||
|
|
||
| MaybeLocal<Value> Module::Evaluate(Local<Context> context) { | ||
| MaybeLocal<Promise> Module::Evaluate(Local<Context> context) { | ||
| auto i_isolate = i::Isolate::Current(); | ||
| TRACE_EVENT_CALL_STATS_SCOPED(i_isolate, "v8", "V8.Execute"); | ||
| EnterV8Scope<InternalEscapableScope> api_scope{i_isolate, context, | ||
|
|
@@ -2436,6 +2436,33 @@ Local<Module> Module::CreateSyntheticModule( | |
| i_module_name, i_export_names, evaluation_steps))); | ||
| } | ||
|
|
||
| START_ALLOW_USE_DEPRECATED() | ||
| Local<Module> Module::CreateSyntheticModule( | ||
|
Contributor
Author
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. ditto about dead-code. |
||
| Isolate* v8_isolate, Local<String> module_name, | ||
| const MemorySpan<const Local<String>>& export_names, | ||
| v8::Module::LegacySyntheticModuleEvaluationSteps evaluation_steps) { | ||
| // TODO(https://crbug.com/545375591): Remove once | ||
| // LegacySyntheticModuleEvaluationSteps is gone. | ||
| #if (__GNUC__ >= 8) || defined(__clang__) | ||
| #pragma GCC diagnostic push | ||
| #pragma GCC diagnostic ignored "-Wcast-function-type" | ||
| #endif | ||
| // Cast from 'v8::MaybeLocal<v8::Value> (*)(v8::Local<v8::Context>, | ||
| // v8::Local<v8::Module>)' to 'v8::MaybeLocal<v8::Promise> | ||
| // (*)(v8::Local<v8::Context>, v8::Local<v8::Module>)'. Both return types are | ||
| // pointer-sized, trivially copyable handle wrappers, so they share the same | ||
| // representation. SyntheticModule::Evaluate() checks at runtime that the | ||
| // returned value really is a Promise. | ||
| auto promise_returning_steps = | ||
| reinterpret_cast<SyntheticModuleEvaluationSteps>(evaluation_steps); | ||
| #if (__GNUC__ >= 8) || defined(__clang__) | ||
| #pragma GCC diagnostic pop | ||
| #endif | ||
| return CreateSyntheticModule(v8_isolate, module_name, export_names, | ||
| promise_returning_steps); | ||
| } | ||
| END_ALLOW_USE_DEPRECATED() | ||
|
|
||
| Maybe<bool> Module::SetSyntheticModuleExport(Isolate* v8_isolate, | ||
| Local<String> export_name, | ||
| Local<v8::Value> export_value) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would break the ABI - I think if we want to backport to 22-26, this would need to be a duplicate method with a different name. Otherwise this needs to be dont-land-on-v26.x etc. and mostly just expediting things a bit more over #65161
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not planning to backport, given it doesn't change pretty much anything in practice. The goal here is to make sure that we will be able to remove the callback that returns
MaybeLocal<Value>eventually.