prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
56 lines (49 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = function (realm) {
let global = realm.$GlobalObject;
global.$DefineOwnProperty("global", {
value: global,
writable: true,
enumerable: false,
configurable: true
});
for (let name of ["undefined", "NaN", "Infinity"]) {
global.$DefineOwnProperty(name, {
value: realm.intrinsics[name],
writable: false,
enumerable: false,
configurable: false
});
}
let typeNames = ["String", "Object", "Function", "Array", "Number", "RegExp", "Date", "Math", "Error", "Function", "TypeError", "RangeError", "ReferenceError", "SyntaxError", "URIError", "EvalError", "Boolean", "DataView", "Float32Array", "Float64Array", "Int8Array", "Int16Array", "Int32Array", "Map", "Set", "WeakMap", "Uint8Array", "Uint8ClampedArray", "Uint16Array", "Uint32Array", "ArrayBuffer", "JSON"];
if (!realm.isCompatibleWith(realm.MOBILE_JSC_VERSION) && !realm.isCompatibleWith("mobile")) typeNames = typeNames.concat("Symbol", "Promise", "WeakSet", "Proxy", "Reflect");
for (let name of typeNames) {
// need to check if the property exists (it may not due to --compatibility)
if (realm.intrinsics[name]) {
global.$DefineOwnProperty(name, {
value: realm.intrinsics[name],
writable: true,
enumerable: false,
configurable: true
});
} else {
(0, _invariant2.default)(name === "Symbol" || name === "Promise" || name === "WeakSet" || name === "Proxy" || name === "Reflect");
(0, _invariant2.default)(realm.isCompatibleWith(realm.MOBILE_JSC_VERSION) || realm.isCompatibleWith("mobile"));
}
}
for (let name of ["parseFloat", "parseInt", "console", "isNaN", "eval", "isFinite", "encodeURI", "decodeURI", "encodeURIComponent", "decodeURIComponent"]) {
global.$DefineOwnProperty(name, {
value: realm.intrinsics[name],
writable: true,
enumerable: false,
configurable: true
});
}
};
var _invariant = require("../../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=global.js.map