summaryrefslogtreecommitdiff
path: root/src/module_wrap.cc
diff options
context:
space:
mode:
authorGus Caplan <me@gus.host>2018-01-26 09:38:31 -0600
committerRuben Bridgewater <ruben@bridgewater.de>2018-02-01 09:33:05 +0100
commitedbcf7c8442d96aabeb564ba1121dad2ff4321a0 (patch)
tree994c471689a33aac08a1565c23c14123c412dde3 /src/module_wrap.cc
parent3cd7977a425d4ef6d2e9b6d535763bc5633789bf (diff)
downloadandroid-node-v8-edbcf7c8442d96aabeb564ba1121dad2ff4321a0.tar.gz
android-node-v8-edbcf7c8442d96aabeb564ba1121dad2ff4321a0.tar.bz2
android-node-v8-edbcf7c8442d96aabeb564ba1121dad2ff4321a0.zip
src, lib: return promises from link
Returns the promises created by link so that they can be awaited to get rid of race conditions while resolving and loading modules. PR-URL: https://github.com/nodejs/node/pull/18394 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/module_wrap.cc')
-rw-r--r--src/module_wrap.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/module_wrap.cc b/src/module_wrap.cc
index ba07fcdc79..daa7f9036a 100644
--- a/src/module_wrap.cc
+++ b/src/module_wrap.cc
@@ -171,6 +171,9 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
Local<Context> mod_context = obj->context_.Get(isolate);
Local<Module> module = obj->module_.Get(isolate);
+ Local<Array> promises = Array::New(isolate,
+ module->GetModuleRequestsLength());
+
// call the dependency resolve callbacks
for (int i = 0; i < module->GetModuleRequestsLength(); i++) {
Local<String> specifier = module->GetModuleRequest(i);
@@ -193,9 +196,11 @@ void ModuleWrap::Link(const FunctionCallbackInfo<Value>& args) {
}
Local<Promise> resolve_promise = resolve_return_value.As<Promise>();
obj->resolve_cache_[specifier_std].Reset(env->isolate(), resolve_promise);
+
+ promises->Set(mod_context, specifier, resolve_promise).FromJust();
}
- args.GetReturnValue().Set(that);
+ args.GetReturnValue().Set(promises);
}
void ModuleWrap::Instantiate(const FunctionCallbackInfo<Value>& args) {