UNPKG

prepack

Version:

Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.

62 lines (53 loc) 2.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateIntrinsicNames = updateIntrinsicNames; exports.addMockFunctionToObject = addMockFunctionToObject; var _index = require("../../values/index.js"); var _index2 = require("../../methods/index.js"); var _invariant = _interopRequireDefault(require("../../invariant.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. */ function updateIntrinsicNames(realm, obj, requireName, properties) { obj.intrinsicName = `require("${requireName}")`; if (properties) { for (let property of properties) { if (typeof property === "string") { let val = (0, _index2.Get)(realm, obj, property); (0, _invariant.default)(val instanceof _index.Value); val.intrinsicName = `require("${requireName}").${property}`; } else if (typeof property === "object" && property !== null) { let { name, updatePrototype } = property; let val = (0, _index2.Get)(realm, obj, name); (0, _invariant.default)(val instanceof _index.Value); val.intrinsicName = `require("${requireName}").${name}`; if (updatePrototype) { (0, _invariant.default)(val instanceof _index.ObjectValue); let proto = (0, _index2.Get)(realm, val, "prototype"); proto.intrinsicName = `require("${requireName}").${name}.prototype`; } } } } } function addMockFunctionToObject(realm, obj, requireName, funcName, func) { let funcValue = new _index.NativeFunctionValue(realm, undefined, funcName, 0, (context, args) => func(funcValue, args)); obj.defineNativeProperty(funcName, funcValue, { writable: false, enumerable: false, configurable: true }); funcValue.intrinsicName = `require("${requireName}").${funcName}`; } //# sourceMappingURL=utils.js.map