Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

Commit e34a1d0

Browse files
committed
fix up loader error caching
1 parent a9b1275 commit e34a1d0

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

core/loader-polyfill.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { addToError, createSymbol } from './common.js';
22

3-
export { Loader, ModuleNamespace }
3+
export { Loader, ModuleNamespace, REGISTRY }
44

55
var resolvedPromise = Promise.resolve();
66

@@ -136,7 +136,6 @@ var iteratorSupport = typeof Symbol !== 'undefined' && Symbol.iterator;
136136
var REGISTRY = createSymbol('registry');
137137
function Registry() {
138138
this[REGISTRY] = {};
139-
this._registry = REGISTRY;
140139
}
141140
// 4.4.1
142141
if (iteratorSupport) {

core/register-loader.js

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Loader, ModuleNamespace } from './loader-polyfill.js';
1+
import { Loader, ModuleNamespace, REGISTRY } from './loader-polyfill.js';
22
import { resolveIfNotPlain } from './resolve.js';
33
import { addToError, global, createSymbol, baseURI } from './common.js';
44

@@ -116,18 +116,23 @@ function createLoadRecord (state, key, registration) {
116116
RegisterLoader.prototype[Loader.resolveInstantiate] = function (key, parentKey) {
117117
var loader = this;
118118
var state = this[REGISTER_INTERNAL];
119-
var registry = loader.registry[loader.registry._registry];
119+
var registry = this.registry[REGISTRY];
120120

121121
return resolveInstantiate(loader, key, parentKey, registry, state)
122122
.then(function (instantiated) {
123123
if (instantiated instanceof ModuleNamespace)
124124
return instantiated;
125125

126-
// if already beaten to linked, return
127-
if (instantiated.module)
128-
return instantiated.module;
129-
130126
// resolveInstantiate always returns a load record with a link record and no module value
127+
let link = instantiated.linkRecord;
128+
129+
// if already beaten to done, return
130+
if (!link) {
131+
if (instantiated.module)
132+
return instantiated.module;
133+
throw instantiated.evalError;
134+
}
135+
131136
if (instantiated.linkRecord.linked)
132137
return ensureEvaluate(loader, instantiated, instantiated.linkRecord, registry, state, undefined);
133138

@@ -148,8 +153,11 @@ function resolveInstantiate (loader, key, parentKey, registry, state) {
148153
var load = state.records[key];
149154

150155
// already linked but not in main registry is ignored
151-
if (load && !load.module)
156+
if (load && !load.module) {
157+
if (load.loadError)
158+
return Promise.reject(load.loadError);
152159
return instantiate(loader, load, load.linkRecord, registry, state);
160+
}
153161

154162
return loader.resolve(key, parentKey)
155163
.then(function (resolvedKey) {
@@ -167,6 +175,9 @@ function resolveInstantiate (loader, key, parentKey, registry, state) {
167175
if (!load || load.module)
168176
load = createLoadRecord(state, resolvedKey, load && load.registration);
169177

178+
if (load.loadError)
179+
return Promise.reject(load.loadError);
180+
170181
var link = load.linkRecord;
171182
if (!link)
172183
return load;
@@ -286,6 +297,9 @@ function resolveInstantiateDep (loader, key, parentKey, registry, state, traceDe
286297
if (module && (!load || load.module && module !== load.module))
287298
return module;
288299

300+
if (load && load.loadError)
301+
throw load.loadError;
302+
289303
// already has a module value but not already in the registry (load.module)
290304
// means it was removed by registry.delete, so we should
291305
// disgard the current load record creating a new one over it
@@ -401,9 +415,6 @@ function instantiateDeps (loader, load, link, registry, state, seen) {
401415
var depLoad = link.dependencyInstantiations[i];
402416
var depLink = depLoad.linkRecord;
403417

404-
if (depLoad.loadError)
405-
throw depLoad.loadError;
406-
407418
if (!depLink || depLink.linked)
408419
continue;
409420

0 commit comments

Comments
 (0)