114 lines
3.5 KiB
JavaScript
114 lines
3.5 KiB
JavaScript
// we define a __exec for globally-scoped execution
|
|
// used by module format implementations
|
|
var __exec;
|
|
|
|
(function() {
|
|
|
|
var hasBtoa = typeof btoa != 'undefined';
|
|
|
|
function getSource(load) {
|
|
var lastLineIndex = load.source.lastIndexOf('\n');
|
|
|
|
// wrap ES formats with a System closure for System global encapsulation
|
|
var wrap = load.metadata.format != 'global';
|
|
|
|
var sourceMap = load.metadata.sourceMap;
|
|
if (sourceMap) {
|
|
if (typeof sourceMap != 'object')
|
|
throw new TypeError('load.metadata.sourceMap must be set to an object.');
|
|
|
|
sourceMap = JSON.stringify(sourceMap);
|
|
}
|
|
|
|
return (wrap ? '(function(System, SystemJS, require) {' : '') + load.source + (wrap ? '\n})(System, System);' : '')
|
|
// adds the sourceURL comment if not already present
|
|
+ (load.source.substr(lastLineIndex, 15) != '\n//# sourceURL='
|
|
? '\n//# sourceURL=' + load.address + (sourceMap ? '!transpiled' : '') : '')
|
|
// add sourceMappingURL if load.metadata.sourceMap is set
|
|
+ (sourceMap && hasBtoa && '\n//# sourceMappingURL=data:application/json;base64,' + btoa(unescape(encodeURIComponent(sourceMap))) || '');
|
|
}
|
|
|
|
var curLoad;
|
|
|
|
// System.register, System.registerDynamic, AMD define pipeline
|
|
// if currently evalling code here, immediately reduce the registered entry against the load record
|
|
hook('pushRegister_', function() {
|
|
return function(register) {
|
|
if (!curLoad)
|
|
return false;
|
|
|
|
this.reduceRegister_(curLoad, register);
|
|
return true;
|
|
};
|
|
});
|
|
|
|
// System clobbering protection (mostly for Traceur)
|
|
var curSystem;
|
|
var callCounter = 0;
|
|
function preExec(loader, load) {
|
|
curLoad = load;
|
|
if (callCounter++ == 0)
|
|
curSystem = __global.System;
|
|
__global.System = __global.SystemJS = loader;
|
|
}
|
|
function postExec() {
|
|
if (--callCounter == 0)
|
|
__global.System = __global.SystemJS = curSystem;
|
|
curLoad = undefined;
|
|
}
|
|
|
|
__exec = function(load) {
|
|
if ((load.metadata.integrity || load.metadata.nonce) && supportsScriptExec)
|
|
return scriptExec.call(this, load);
|
|
try {
|
|
preExec(this, load);
|
|
curLoad = load;
|
|
(0, eval)(getSource(load));
|
|
postExec();
|
|
}
|
|
catch(e) {
|
|
postExec();
|
|
throw addToError(e, 'Evaluating ' + load.address);
|
|
}
|
|
};
|
|
|
|
var supportsScriptExec = false;
|
|
if (isBrowser && typeof document != 'undefined' && document.getElementsByTagName) {
|
|
var scripts = document.getElementsByTagName('script');
|
|
$__curScript = scripts[scripts.length - 1];
|
|
|
|
if (!(window.chrome && window.chrome.extension || navigator.userAgent.match(/^Node\.js/)))
|
|
supportsScriptExec = true;
|
|
}
|
|
|
|
// script execution via injecting a script tag into the page
|
|
// this allows CSP integrity and nonce to be set for CSP environments
|
|
var head;
|
|
function scriptExec(load) {
|
|
if (!head)
|
|
head = document.head || document.body || document.documentElement;
|
|
|
|
var script = document.createElement('script');
|
|
script.text = getSource(load, false);
|
|
var onerror = window.onerror;
|
|
var e;
|
|
window.onerror = function(_e) {
|
|
e = addToError(_e, 'Evaluating ' + load.address);
|
|
}
|
|
preExec(this, load);
|
|
|
|
if (load.metadata.integrity)
|
|
script.setAttribute('integrity', load.metadata.integrity);
|
|
if (load.metadata.nonce)
|
|
script.setAttribute('nonce', load.metadata.nonce);
|
|
|
|
head.appendChild(script);
|
|
head.removeChild(script);
|
|
postExec();
|
|
window.onerror = onerror;
|
|
if (e)
|
|
throw e;
|
|
}
|
|
|
|
})();
|