prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
96 lines (73 loc) • 2.9 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _index = require("./index.js");
var _completions = require("../completions.js");
var _singletons = require("../singletons.js");
var _descriptors = require("../descriptors.js");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/* Built-in Function Objects */
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", new _descriptors.PropertyDescriptor({
value: new _index.NumberValue(realm, length),
writable: false,
configurable: true,
enumerable: false
}));
if (name !== undefined && name !== "") {
if (name instanceof _index.SymbolValue) {
this.name = name.$Description ? `[${name.$Description.throwIfNotConcreteString().value}]` : "[native]";
} else {
this.name = name;
}
this.$DefineOwnProperty("name", new _descriptors.PropertyDescriptor({
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, originalArgsList, newTarget) {
let originalLength = originalArgsList.length;
let argsList = originalArgsList.slice();
for (let i = 0; i < this.length; i++) {
argsList[i] = originalArgsList[i] || this.$Realm.intrinsics.undefined;
}
return new _completions.ReturnCompletion(this.callback(context, argsList, originalLength, newTarget), this.$Realm.currentLocation);
} // for Proxy
}
exports.default = NativeFunctionValue;
_defineProperty(NativeFunctionValue, "trackedPropertyNames", _index.ObjectValue.trackedPropertyNames.concat("$RevocableProxy"));
//# sourceMappingURL=NativeFunctionValue.js.map