UNPKG

prepack

Version:

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

82 lines (54 loc) 3.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; var _index = require("../../values/index.js"); var _singletons = require("../../singletons.js"); var _proxy = require("../../methods/proxy.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. */ /* strict-local */ function _default(realm) { // ECMA262 26.2.1.1 let func = new _index.NativeFunctionValue(realm, "Proxy", "Proxy", 2, (context, [target, handler], argCount, NewTarget) => { // 1. If NewTarget is undefined, throw a TypeError exception. if (!NewTarget) { throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError); } // 2. Return ? ProxyCreate(target, handler). return (0, _proxy.ProxyCreate)(realm, target, handler); }); // ECMA262 26.2.2.1 func.defineNativeMethod("revocable", 2, (context, [target, handler]) => { // 1. Let p be ? ProxyCreate(target, handler). let p = (0, _proxy.ProxyCreate)(realm, target, handler); // 2. Let revoker be a new built-in function object as defined in 26.2.2.1.1. let revoker = createRevoker(); // 3. Set the [[RevocableProxy]] internal slot of revoker to p. revoker.$RevocableProxy = p; // 4. Let result be ObjectCreate(%ObjectPrototype%). let result = _singletons.Create.ObjectCreate(realm, realm.intrinsics.ObjectPrototype); // 5. Perform CreateDataProperty(result, "proxy", p). _singletons.Create.CreateDataProperty(realm, result, "proxy", p); // 6. Perform CreateDataProperty(result, "revoke", revoker). _singletons.Create.CreateDataProperty(realm, result, "revoke", revoker); // 7. Return result. return result; }); function createRevoker() { let F = new _index.NativeFunctionValue(realm, undefined, undefined, 0, (context, [target, handler], argCount, NewTarget) => { // 1. Let p be the value of F's [[RevocableProxy]] internal slot. let p = F.$RevocableProxy; // 2. If p is null, return undefined. if (p instanceof _index.NullValue) return realm.intrinsics.undefined; // 3. Set the value of F's [[RevocableProxy]] internal slot to null. F.$RevocableProxy = realm.intrinsics.null; // 4. Assert: p is a Proxy object. (0, _invariant.default)(p instanceof _index.ProxyValue, "expected proxy"); // 5. Set the [[ProxyTarget]] internal slot of p to null. p.$ProxyTarget = realm.intrinsics.null; // 6. Set the [[ProxyHandler]] internal slot of p to null. p.$ProxyHandler = realm.intrinsics.null; // 7. Return undefined. return realm.intrinsics.undefined; }, false); return F; } return func; } //# sourceMappingURL=Proxy.js.map