Skip to content

Commit eafb36c

Browse files
committed
esm: Source Phase Imports for WebAssembly
nodejs/node#56919
1 parent a2b14a9 commit eafb36c

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

patches/node/chore_expose_importmoduledynamically_and.patch

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ its own blended handler between Node and Blink.
1111
Not upstreamable.
1212

1313
diff --git a/lib/internal/modules/esm/utils.js b/lib/internal/modules/esm/utils.js
14-
index 9b41db8b0714b7408f79cbd5b4c460d9bc08f239..35ecfb9bbaf2c8e7351e1c69da84c82a4a7cb049 100644
14+
index 4a427945934..88d84786e72 100644
1515
--- a/lib/internal/modules/esm/utils.js
1616
+++ b/lib/internal/modules/esm/utils.js
17-
@@ -30,7 +30,7 @@ const {
17+
@@ -34,7 +34,7 @@ const {
1818
ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING,
1919
ERR_INVALID_ARG_VALUE,
2020
} = require('internal/errors').codes;
@@ -23,8 +23,8 @@ index 9b41db8b0714b7408f79cbd5b4c460d9bc08f239..35ecfb9bbaf2c8e7351e1c69da84c82a
2323
const {
2424
loadPreloadModules,
2525
initializeFrozenIntrinsics,
26-
@@ -281,12 +281,13 @@ let _forceDefaultLoader = false;
27-
* @param {boolean} [forceDefaultLoader=false] - A boolean indicating disabling custom loaders.
26+
@@ -291,12 +291,13 @@ let _forceDefaultLoader = false;
27+
* @param {boolean} [forceDefaultLoader] - A boolean indicating disabling custom loaders.
2828
*/
2929
function initializeESM(forceDefaultLoader = false) {
3030
+ const shouldSetOnIsolate = !getEmbedderOptions().shouldNotRegisterESMLoader;
@@ -40,19 +40,19 @@ index 9b41db8b0714b7408f79cbd5b4c460d9bc08f239..35ecfb9bbaf2c8e7351e1c69da84c82a
4040

4141
/**
4242
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
43-
index c52e20d742942667f43ea3e151fc6702260b176b..cbb3e7f4df72f83cb8a1afc25a7429218792e964 100644
43+
index 5783728da28..9c75d351f51 100644
4444
--- a/src/module_wrap.cc
4545
+++ b/src/module_wrap.cc
46-
@@ -901,7 +901,7 @@ MaybeLocal<Module> ModuleWrap::ResolveModuleCallback(
47-
return module->module_.Get(isolate);
46+
@@ -1165,7 +1165,7 @@ static MaybeLocal<Promise> ImportModuleDynamicallyWithPhase(
47+
return handle_scope.Escape(resolver->GetPromise());
4848
}
4949

5050
-static MaybeLocal<Promise> ImportModuleDynamically(
5151
+MaybeLocal<Promise> ImportModuleDynamically(
5252
Local<Context> context,
5353
Local<Data> host_defined_options,
5454
Local<Value> resource_name,
55-
@@ -973,12 +973,13 @@ void ModuleWrap::SetImportModuleDynamicallyCallback(
55+
@@ -1185,14 +1185,16 @@ void ModuleWrap::SetImportModuleDynamicallyCallback(
5656
Realm* realm = Realm::GetCurrent(args);
5757
HandleScope handle_scope(isolate);
5858

@@ -63,12 +63,16 @@ index c52e20d742942667f43ea3e151fc6702260b176b..cbb3e7f4df72f83cb8a1afc25a742921
6363
realm->set_host_import_module_dynamically_callback(import_callback);
6464

6565
- isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically);
66-
+ if (args[1]->IsBoolean() && args[1]->BooleanValue(isolate))
66+
- isolate->SetHostImportModuleWithPhaseDynamicallyCallback(
67+
+ if (args[1]->IsBoolean() && args[1]->BooleanValue(isolate)) {
6768
+ isolate->SetHostImportModuleDynamicallyCallback(ImportModuleDynamically);
69+
+ isolate->SetHostImportModuleWithPhaseDynamicallyCallback(
70+
ImportModuleDynamicallyWithPhase);
71+
+ }
6872
}
6973

7074
void ModuleWrap::HostInitializeImportMetaObjectCallback(
71-
@@ -1020,13 +1021,14 @@ void ModuleWrap::SetInitializeImportMetaObjectCallback(
75+
@@ -1234,13 +1236,14 @@ void ModuleWrap::SetInitializeImportMetaObjectCallback(
7276
Realm* realm = Realm::GetCurrent(args);
7377
Isolate* isolate = realm->isolate();
7478

@@ -87,7 +91,7 @@ index c52e20d742942667f43ea3e151fc6702260b176b..cbb3e7f4df72f83cb8a1afc25a742921
8791

8892
MaybeLocal<Value> ModuleWrap::SyntheticModuleEvaluationStepsCallback(
8993
diff --git a/src/module_wrap.h b/src/module_wrap.h
90-
index 9363ce73e51cde3d3a94f9912f072d532d0f8560..c0e972ed293157726efc5fa76dfa62d3da51c22a 100644
94+
index 03cf8d0e91d..9947191fca6 100644
9195
--- a/src/module_wrap.h
9296
+++ b/src/module_wrap.h
9397
@@ -8,6 +8,7 @@
@@ -98,8 +102,8 @@ index 9363ce73e51cde3d3a94f9912f072d532d0f8560..c0e972ed293157726efc5fa76dfa62d3
98102
#include "v8-script.h"
99103

100104
namespace node {
101-
@@ -33,7 +34,14 @@ enum HostDefinedOptions : int {
102-
kLength = 9,
105+
@@ -92,7 +93,14 @@ struct ModuleCacheKey : public MemoryRetainer {
106+
hash(hash) {}
103107
};
104108

105109
-class ModuleWrap : public BaseObject {
@@ -111,10 +115,10 @@ index 9363ce73e51cde3d3a94f9912f072d532d0f8560..c0e972ed293157726efc5fa76dfa62d3
111115
+ v8::Local<v8::FixedArray> import_assertions);
112116
+
113117
+class NODE_EXTERN ModuleWrap : public BaseObject {
114-
public:
115-
enum InternalFields {
116-
kModuleSlot = BaseObject::kInternalFieldCount,
117-
@@ -92,6 +100,8 @@ class ModuleWrap : public BaseObject {
118+
using ResolveCache =
119+
std::unordered_map<ModuleCacheKey, uint32_t, ModuleCacheKey::Hash>;
120+
121+
@@ -157,6 +165,8 @@ class ModuleWrap : public BaseObject {
118122
static void CreateRequiredModuleFacade(
119123
const v8::FunctionCallbackInfo<v8::Value>& args);
120124

@@ -123,11 +127,11 @@ index 9363ce73e51cde3d3a94f9912f072d532d0f8560..c0e972ed293157726efc5fa76dfa62d3
123127
private:
124128
ModuleWrap(Realm* realm,
125129
v8::Local<v8::Object> object,
126-
@@ -131,7 +141,6 @@ class ModuleWrap : public BaseObject {
130+
@@ -205,7 +215,6 @@ class ModuleWrap : public BaseObject {
127131
v8::Local<v8::String> specifier,
128132
v8::Local<v8::FixedArray> import_attributes,
129133
v8::Local<v8::Module> referrer);
130134
- static ModuleWrap* GetFromModule(node::Environment*, v8::Local<v8::Module>);
131135

132-
v8::Global<v8::Module> module_;
133-
std::unordered_map<std::string, v8::Global<v8::Object>> resolve_cache_;
136+
// This method may throw a JavaScript exception, so the return type is
137+
// wrapped in a Maybe.

0 commit comments

Comments
 (0)