prepack
Version:
Execute a JS bundle, serialize global state and side effects to a snapshot that can be quickly restored.
51 lines (36 loc) • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
var _index = require("../../values/index.js");
var _singletons = require("../../singletons.js");
var _get = require("../../methods/get.js");
var _call = require("../../methods/call.js");
var _is = require("../../methods/is.js");
var _generator = require("../../utils/generator.js");
/**
* 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 22.1.3.30
return new _index.NativeFunctionValue(realm, "Array.prototype.toString", "toString", 0, context => {
// 1. Let array be ? ToObject(this value).
let array = _singletons.To.ToObject(realm, context); // If we have an object that is an array with widened numeric properties, then
// we can return a temporal here as we know nothing of the array's properties.
// This should be safe to do, as we never expose the internals of the array.
if (_index.ArrayValue.isIntrinsicAndHasWidenedNumericProperty(array) && realm.isInPureScope() && array.$GetOwnProperty("toString") === undefined) {
return _index.AbstractValue.createTemporalFromBuildFunction(realm, _index.StringValue, [array, new _index.StringValue(realm, "toString")], (0, _generator.createOperationDescriptor)("UNKNOWN_ARRAY_METHOD_PROPERTY_CALL"));
} // 2. Let func be ? Get(array, "join").
let func = (0, _get.Get)(realm, array, "join"); // 3. If IsCallable(func) is false, let func be the intrinsic function %ObjProto_toString%.
if (!(0, _is.IsCallable)(realm, func)) func = realm.intrinsics.ObjectProto_toString; // 4. Return ? Call(func, array).
return (0, _call.Call)(realm, func, array);
}, false);
}
//# sourceMappingURL=ArrayProto_toString.js.map