prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
111 lines (100 loc) • 4.66 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _index = require("../../values/index.js");
var _document = _interopRequireDefault(require("./document.js"));
var _console = _interopRequireDefault(require("../common/console.js"));
var _errors = require("../../errors.js");
var _invariant = _interopRequireDefault(require("../../invariant.js"));
var _index2 = require("../../domains/index.js");
var _descriptors = require("../../descriptors.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/* strict-local */
function _default(realm) {
let global = realm.$GlobalObject;
if (!realm.isCompatibleWith(realm.MOBILE_JSC_VERSION) && !realm.isCompatibleWith("mobile")) global.$DefineOwnProperty("console", new _descriptors.PropertyDescriptor({
value: (0, _console.default)(realm),
writable: true,
enumerable: false,
configurable: true
}));
global.$DefineOwnProperty("self", new _descriptors.PropertyDescriptor({
value: global,
writable: true,
enumerable: true,
configurable: true
}));
global.$DefineOwnProperty("window", new _descriptors.PropertyDescriptor({
value: global,
writable: true,
enumerable: true,
configurable: true
}));
global.$DefineOwnProperty("document", new _descriptors.PropertyDescriptor({
value: (0, _document.default)(realm),
writable: true,
enumerable: false,
configurable: true
}));
global.$DefineOwnProperty("setTimeout", new _descriptors.PropertyDescriptor({
value: new _index.NativeFunctionValue(realm, "global.setTimeout", "", 2, (context, args) => {
let callback = args[0].throwIfNotConcrete();
if (!(callback instanceof _index.FunctionValue)) throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "callback arguments must be function");
if (!realm.useAbstractInterpretation) throw new _errors.FatalError("TODO #1003: implement global.setTimeout");
(0, _invariant.default)(realm.generator !== undefined);
let generator = realm.generator;
return generator.emitCallAndCaptureResult(_index2.TypesDomain.topVal, _index2.ValuesDomain.topVal, "global.setTimeout", args);
}),
writable: true,
enumerable: true,
configurable: true
}));
global.$DefineOwnProperty("clearTimeout", new _descriptors.PropertyDescriptor({
value: new _index.NativeFunctionValue(realm, "global.clearTimeout", "", 2, (context, args) => {
if (!realm.useAbstractInterpretation) throw new _errors.FatalError("TODO #1003: implement global.clearTimeout");
(0, _invariant.default)(realm.generator !== undefined);
let generator = realm.generator;
generator.emitCall("global.clearTimeout", args);
return realm.intrinsics.undefined;
}),
writable: true,
enumerable: true,
configurable: true
}));
global.$DefineOwnProperty("setInterval", new _descriptors.PropertyDescriptor({
value: new _index.NativeFunctionValue(realm, "global.setInterval", "", 2, (context, args) => {
if (!realm.useAbstractInterpretation) throw new _errors.FatalError("TODO #1003: implement global.setInterval");
let callback = args[0].throwIfNotConcrete();
if (!(callback instanceof _index.FunctionValue)) throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "callback arguments must be function");
(0, _invariant.default)(realm.generator !== undefined);
let generator = realm.generator;
return generator.emitCallAndCaptureResult(_index2.TypesDomain.topVal, _index2.ValuesDomain.topVal, "global.setInterval", args);
}),
writable: true,
enumerable: true,
configurable: true
}));
global.$DefineOwnProperty("clearInterval", new _descriptors.PropertyDescriptor({
value: new _index.NativeFunctionValue(realm, "global.clearInterval", "", 2, (context, args) => {
if (!realm.useAbstractInterpretation) throw new _errors.FatalError("TODO #1003: implement global.clearInterval");
(0, _invariant.default)(realm.generator !== undefined);
let generator = realm.generator;
generator.emitCall("global.clearInterval", args);
return realm.intrinsics.undefined;
}),
writable: true,
enumerable: true,
configurable: true
}));
}
//# sourceMappingURL=global.js.map