Skip to content

Commit 2e0bb64

Browse files
committed
Adopt latest loader
1 parent 073a3d9 commit 2e0bb64

File tree

1 file changed

+59
-34
lines changed

1 file changed

+59
-34
lines changed

src/vs/loader.js

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var AMDLoader;
3030
this._isNode = false;
3131
this._isElectronRenderer = false;
3232
this._isWebWorker = false;
33+
this._isElectronNodeIntegrationWebWorker = false;
3334
}
3435
Object.defineProperty(Environment.prototype, "isWindows", {
3536
get: function () {
@@ -63,6 +64,14 @@ var AMDLoader;
6364
enumerable: false,
6465
configurable: true
6566
});
67+
Object.defineProperty(Environment.prototype, "isElectronNodeIntegrationWebWorker", {
68+
get: function () {
69+
this._detect();
70+
return this._isElectronNodeIntegrationWebWorker;
71+
},
72+
enumerable: false,
73+
configurable: true
74+
});
6675
Environment.prototype._detect = function () {
6776
if (this._detected) {
6877
return;
@@ -72,6 +81,7 @@ var AMDLoader;
7281
this._isNode = (typeof module !== 'undefined' && !!module.exports);
7382
this._isElectronRenderer = (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'renderer');
7483
this._isWebWorker = (typeof AMDLoader.global.importScripts === 'function');
84+
this._isElectronNodeIntegrationWebWorker = this._isWebWorker && (typeof process !== 'undefined' && typeof process.versions !== 'undefined' && typeof process.versions.electron !== 'undefined' && process.type === 'worker');
7585
};
7686
Environment._isWindows = function () {
7787
if (typeof navigator !== 'undefined') {
@@ -705,35 +715,52 @@ var AMDLoader;
705715
return this._cachedCanUseEval;
706716
};
707717
WorkerScriptLoader.prototype.load = function (moduleManager, scriptSrc, callback, errorback) {
708-
var trustedTypesPolicy = moduleManager.getConfig().getOptionsLiteral().trustedTypesPolicy;
709-
var isCrossOrigin = (/^((http:)|(https:)|(file:))/.test(scriptSrc) && scriptSrc.substring(0, self.origin.length) !== self.origin);
710-
if (!isCrossOrigin && this._canUseEval(moduleManager)) {
711-
// use `fetch` if possible because `importScripts`
712-
// is synchronous and can lead to deadlocks on Safari
713-
fetch(scriptSrc).then(function (response) {
714-
if (response.status !== 200) {
715-
throw new Error(response.statusText);
716-
}
717-
return response.text();
718-
}).then(function (text) {
719-
text = text + "\n//# sourceURL=" + scriptSrc;
720-
var func = (trustedTypesPolicy
721-
? self.eval(trustedTypesPolicy.createScript('', text))
722-
: new Function(text));
723-
func.call(self);
724-
callback();
725-
}).then(undefined, errorback);
726-
return;
727-
}
728-
try {
729-
if (trustedTypesPolicy) {
730-
scriptSrc = trustedTypesPolicy.createScriptURL(scriptSrc);
718+
if (/^node\|/.test(scriptSrc)) {
719+
var opts = moduleManager.getConfig().getOptionsLiteral();
720+
var nodeRequire = ensureRecordedNodeRequire(moduleManager.getRecorder(), (opts.nodeRequire || AMDLoader.global.nodeRequire));
721+
var pieces = scriptSrc.split('|');
722+
var moduleExports_2 = null;
723+
try {
724+
moduleExports_2 = nodeRequire(pieces[1]);
731725
}
732-
importScripts(scriptSrc);
726+
catch (err) {
727+
errorback(err);
728+
return;
729+
}
730+
moduleManager.enqueueDefineAnonymousModule([], function () { return moduleExports_2; });
733731
callback();
734732
}
735-
catch (e) {
736-
errorback(e);
733+
else {
734+
var trustedTypesPolicy_1 = moduleManager.getConfig().getOptionsLiteral().trustedTypesPolicy;
735+
var isCrossOrigin = (/^((http:)|(https:)|(file:))/.test(scriptSrc) && scriptSrc.substring(0, self.origin.length) !== self.origin);
736+
if (!isCrossOrigin && this._canUseEval(moduleManager)) {
737+
// use `fetch` if possible because `importScripts`
738+
// is synchronous and can lead to deadlocks on Safari
739+
fetch(scriptSrc).then(function (response) {
740+
if (response.status !== 200) {
741+
throw new Error(response.statusText);
742+
}
743+
return response.text();
744+
}).then(function (text) {
745+
text = text + "\n//# sourceURL=" + scriptSrc;
746+
var func = (trustedTypesPolicy_1
747+
? self.eval(trustedTypesPolicy_1.createScript('', text))
748+
: new Function(text));
749+
func.call(self);
750+
callback();
751+
}).then(undefined, errorback);
752+
return;
753+
}
754+
try {
755+
if (trustedTypesPolicy_1) {
756+
scriptSrc = trustedTypesPolicy_1.createScriptURL(scriptSrc);
757+
}
758+
importScripts(scriptSrc);
759+
callback();
760+
}
761+
catch (e) {
762+
errorback(e);
763+
}
737764
}
738765
};
739766
return WorkerScriptLoader;
@@ -831,15 +858,15 @@ var AMDLoader;
831858
var recorder = moduleManager.getRecorder();
832859
if (/^node\|/.test(scriptSrc)) {
833860
var pieces = scriptSrc.split('|');
834-
var moduleExports_2 = null;
861+
var moduleExports_3 = null;
835862
try {
836-
moduleExports_2 = nodeRequire(pieces[1]);
863+
moduleExports_3 = nodeRequire(pieces[1]);
837864
}
838865
catch (err) {
839866
errorback(err);
840867
return;
841868
}
842-
moduleManager.enqueueDefineAnonymousModule([], function () { return moduleExports_2; });
869+
moduleManager.enqueueDefineAnonymousModule([], function () { return moduleExports_3; });
843870
callback();
844871
}
845872
else {
@@ -1489,7 +1516,7 @@ var AMDLoader;
14891516
ModuleManager.prototype._onLoadError = function (moduleId, err) {
14901517
var error = this._createLoadError(moduleId, err);
14911518
if (!this._modules2[moduleId]) {
1492-
this._modules2[moduleId] = new Module(moduleId, this._moduleIdProvider.getStrModuleId(moduleId), [], function () { }, function () { }, null);
1519+
this._modules2[moduleId] = new Module(moduleId, this._moduleIdProvider.getStrModuleId(moduleId), [], function () { }, null, null);
14931520
}
14941521
// Find any 'local' error handlers, walk the entire chain of inverse dependencies if necessary.
14951522
var seenModuleId = [];
@@ -1880,9 +1907,7 @@ var AMDLoader;
18801907
RequireFunc.getStats = function () {
18811908
return moduleManager.getLoaderEvents();
18821909
};
1883-
RequireFunc.define = function () {
1884-
return DefineFunc.apply(null, arguments);
1885-
};
1910+
RequireFunc.define = DefineFunc;
18861911
function init() {
18871912
if (typeof AMDLoader.global.require !== 'undefined' || typeof require !== 'undefined') {
18881913
var _nodeRequire = (AMDLoader.global.require || require);
@@ -1894,7 +1919,7 @@ var AMDLoader;
18941919
RequireFunc.__$__nodeRequire = nodeRequire;
18951920
}
18961921
}
1897-
if (env.isNode && !env.isElectronRenderer) {
1922+
if (env.isNode && !env.isElectronRenderer && !env.isElectronNodeIntegrationWebWorker) {
18981923
module.exports = RequireFunc;
18991924
require = RequireFunc;
19001925
}

0 commit comments

Comments
 (0)