UNPKG

prepack

Version:

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

102 lines (80 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _index = require("./index.js"); var _completions = require("../completions.js"); var _singletons = require("../singletons.js"); /* Built-in Function Objects */ /** * 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. */ class NativeFunctionValue extends _index.ECMAScriptFunctionValue { constructor(realm, intrinsicName, name, length, callback, constructor = true) { super(realm, intrinsicName); this.$ThisMode = "strict"; this.$HomeObject = undefined; this.$FunctionKind = "normal"; this.$Call = (thisArgument, argsList) => { return _singletons.Functions.$Call(this.$Realm, this, thisArgument, argsList); }; if (constructor) { this.$ConstructorKind = "base"; this.$Construct = (argumentsList, newTarget) => { return _singletons.Functions.$Construct(this.$Realm, this, argumentsList, newTarget); }; } this.$Environment = realm.$GlobalEnv; this.callback = callback; this.length = length; this.$DefineOwnProperty("length", { value: new _index.NumberValue(realm, length), writable: false, configurable: true, enumerable: false }); if (name) { if (name instanceof _index.SymbolValue) { this.name = name.$Description ? `[${name.$Description.throwIfNotConcreteString().value}]` : "[native]"; } else { this.name = name; } this.$DefineOwnProperty("name", { value: new _index.StringValue(realm, this.name), writable: false, configurable: true, enumerable: false }); } else { this.name = "native"; } } getTrackedPropertyNames() { return NativeFunctionValue.trackedPropertyNames; } hasDefaultLength() { return this.getLength() === this.length; } // Override. getName() { return this.name; } callCallback(context, argsList, newTarget) { let originalLength = argsList.length; for (let i = 0; i < this.length; i++) { argsList[i] = argsList[i] || this.$Realm.intrinsics.undefined; } return new _completions.ReturnCompletion(this.callback(context, argsList, originalLength, newTarget), this.$Realm.currentLocation); } // for Proxy // for Promise resolve/reject functions // for Promise resolve functions } exports.default = NativeFunctionValue; NativeFunctionValue.trackedPropertyNames = _index.ObjectValue.trackedPropertyNames.concat("$RevocableProxy"); //# sourceMappingURL=NativeFunctionValue.js.map