first commit
This commit is contained in:
545
build/node_modules/prepack/lib/methods/abstract.js
generated
vendored
Normal file
545
build/node_modules/prepack/lib/methods/abstract.js
generated
vendored
Normal file
@@ -0,0 +1,545 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.URIUnescaped = exports.URIMark = exports.DecimalDigit = exports.URIAlpha = exports.URIReserved = undefined;
|
||||
exports.SplitMatch = SplitMatch;
|
||||
exports.RequireObjectCoercible = RequireObjectCoercible;
|
||||
exports.AbstractRelationalComparison = AbstractRelationalComparison;
|
||||
exports.AbstractEqualityComparison = AbstractEqualityComparison;
|
||||
exports.StrictEqualityComparison = StrictEqualityComparison;
|
||||
exports.StrictEqualityComparisonPartial = StrictEqualityComparisonPartial;
|
||||
exports.SameValueZero = SameValueZero;
|
||||
exports.SameValueZeroPartial = SameValueZeroPartial;
|
||||
exports.SameValue = SameValue;
|
||||
exports.SameValuePartial = SameValuePartial;
|
||||
exports.SameValueNonNumber = SameValueNonNumber;
|
||||
exports.SamePropertyKey = SamePropertyKey;
|
||||
exports.Add = Add;
|
||||
exports.InstanceofOperator = InstanceofOperator;
|
||||
exports.OrdinaryHasInstance = OrdinaryHasInstance;
|
||||
exports.Type = Type;
|
||||
exports.SymbolDescriptiveString = SymbolDescriptiveString;
|
||||
exports.UpdateEmpty = UpdateEmpty;
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _call = require("./call.js");
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var URIReserved = exports.URIReserved = ";/?:@&=+$,"; /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var URIAlpha = exports.URIAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
var DecimalDigit = exports.DecimalDigit = "0123456789";
|
||||
var URIMark = exports.URIMark = "-_.!~*'()";
|
||||
var URIUnescaped = exports.URIUnescaped = URIAlpha + DecimalDigit + URIMark;
|
||||
|
||||
// ECMA262 21.1.3.17.1
|
||||
function SplitMatch(realm, S, q, R) {
|
||||
// 1. Assert: Type(R) is String.
|
||||
(0, _invariant2.default)(typeof R === "string", "expected a string");
|
||||
|
||||
// 2. Let r be the number of code units in R.
|
||||
var r = R.length;
|
||||
|
||||
// 3. Let s be the number of code units in S.
|
||||
var s = S.length;
|
||||
|
||||
// 4. If q+r > s, return false.
|
||||
if (q + r > s) return false;
|
||||
|
||||
// 5. If there exists an integer i between 0 (inclusive) and r (exclusive) such that the code unit at index
|
||||
// q+i of S is different from the code unit at index i of R, return false.
|
||||
for (var i = 0; i < r; i++) {
|
||||
if (S[q + i] !== R[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Return q+r.
|
||||
return q + r;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.1
|
||||
function RequireObjectCoercible(realm, arg, argLoc) {
|
||||
if (arg instanceof _index.AbstractValue && (arg.mightBeNull() || arg.mightBeUndefined())) {
|
||||
if (argLoc) {
|
||||
var error = new _errors.CompilerDiagnostic("member expression object is unknown", argLoc, "PP0012", "FatalError");
|
||||
realm.handleError(error);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
arg.throwIfNotConcrete();
|
||||
}
|
||||
if (arg instanceof _index.NullValue || arg instanceof _index.UndefinedValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "null or undefined");
|
||||
} else {
|
||||
return arg;
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 7.2.12 Abstract Relational Comparison
|
||||
function AbstractRelationalComparison(realm, x, y, LeftFirst) {
|
||||
var px = void 0,
|
||||
py = void 0;
|
||||
|
||||
// 1. If the LeftFirst flag is true, then
|
||||
if (LeftFirst) {
|
||||
// a. Let px be ? ToPrimitive(x, hint Number).
|
||||
px = _singletons.To.ToPrimitive(realm, x, "number");
|
||||
|
||||
// b. Let py be ? ToPrimitive(y, hint Number).
|
||||
py = _singletons.To.ToPrimitive(realm, y, "number");
|
||||
} else {
|
||||
// 2. Else the order of evaluation needs to be reversed to preserve left to right evaluation
|
||||
// a. Let py be ? ToPrimitive(y, hint Number).
|
||||
py = _singletons.To.ToPrimitive(realm, y, "number");
|
||||
|
||||
// b. Let px be ? ToPrimitive(x, hint Number).
|
||||
px = _singletons.To.ToPrimitive(realm, x, "number");
|
||||
}
|
||||
|
||||
// 3. If both px and py are Strings, then
|
||||
if (px instanceof _index.StringValue && py instanceof _index.StringValue) {
|
||||
// a. If py is a prefix of px, return false. (A String value p is a prefix of String value q if q can be the result of concatenating p and some other String r. Note that any String is a prefix of itself, because r may be the empty String.)
|
||||
if (px.value.startsWith(py.value)) return realm.intrinsics.false;
|
||||
|
||||
// b. If px is a prefix of py, return true.
|
||||
if (py.value.startsWith(px.value)) return realm.intrinsics.true;
|
||||
|
||||
// c. Let k be the smallest nonnegative integer such that the code unit at index k within px is different from the code unit at index k within py. (There must be such a k, for neither String is a prefix of the other.)
|
||||
var k = 0;
|
||||
while (px.value.charCodeAt(k) === py.value.charCodeAt(k)) {
|
||||
k += 1;
|
||||
}
|
||||
|
||||
// d. Let m be the integer that is the code unit value at index k within px.
|
||||
var m = px.value.charCodeAt(k);
|
||||
|
||||
// e. Let n be the integer that is the code unit value at index k within py.
|
||||
var n = py.value.charCodeAt(k);
|
||||
|
||||
// f. If m < n, return true. Otherwise, return false.
|
||||
return m < n ? realm.intrinsics.true : realm.intrinsics.false;
|
||||
} else {
|
||||
// 4. Else,
|
||||
// a. Let nx be ? ToNumber(px). Because px and py are primitive values evaluation order is not important.
|
||||
var nx = _singletons.To.ToNumber(realm, px);
|
||||
|
||||
// b. Let ny be ? ToNumber(py).
|
||||
var ny = _singletons.To.ToNumber(realm, py);
|
||||
|
||||
// c. If nx is NaN, return undefined.
|
||||
if (isNaN(nx)) return realm.intrinsics.undefined;
|
||||
|
||||
// d. If ny is NaN, return undefined.
|
||||
if (isNaN(ny)) return realm.intrinsics.undefined;
|
||||
|
||||
// e. If nx and ny are the same Number value, return false.
|
||||
if (Object.is(nx, ny)) {
|
||||
return realm.intrinsics.false;
|
||||
}
|
||||
|
||||
// f. If nx is +0 and ny is -0, return false.
|
||||
if (Object.is(nx, +0) && Object.is(ny, -0)) {
|
||||
return realm.intrinsics.false;
|
||||
}
|
||||
|
||||
// g. If nx is -0 and ny is +0, return false.
|
||||
if (Object.is(nx, -0) && Object.is(ny, +0)) {
|
||||
return realm.intrinsics.false;
|
||||
}
|
||||
|
||||
// h. If nx is +∞, return false.
|
||||
// i. If ny is +∞, return true.
|
||||
// j. If ny is -∞, return false.
|
||||
// k. If nx is -∞, return true.
|
||||
|
||||
// i. If the mathematical value of nx is less than the mathematical value of ny —note that these
|
||||
// mathematical values are both finite and not both zero—return true. Otherwise, return false.
|
||||
if (nx < ny) {
|
||||
return realm.intrinsics.true;
|
||||
} else {
|
||||
return realm.intrinsics.false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 7.2.13
|
||||
function AbstractEqualityComparison(realm, x, y) {
|
||||
// 1. If Type(x) is the same as Type(y), then
|
||||
if (x.getType() === y.getType()) {
|
||||
// a. Return the result of performing Strict Equality Comparison x === y.
|
||||
return StrictEqualityComparison(realm, x, y);
|
||||
}
|
||||
|
||||
// 2. If x is null and y is undefined, return true.
|
||||
if (x instanceof _index.NullValue && y instanceof _index.UndefinedValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. If x is undefined and y is null, return true.
|
||||
if (x instanceof _index.UndefinedValue && y instanceof _index.NullValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
|
||||
if (x instanceof _index.NumberValue && y instanceof _index.StringValue) {
|
||||
return AbstractEqualityComparison(realm, x, new _index.NumberValue(realm, _singletons.To.ToNumber(realm, y)));
|
||||
}
|
||||
|
||||
// 5. If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
|
||||
if (x instanceof _index.StringValue && y instanceof _index.NumberValue) {
|
||||
return AbstractEqualityComparison(realm, new _index.NumberValue(realm, _singletons.To.ToNumber(realm, x)), y);
|
||||
}
|
||||
|
||||
// 6. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
|
||||
if (x instanceof _index.BooleanValue) {
|
||||
return AbstractEqualityComparison(realm, new _index.NumberValue(realm, _singletons.To.ToNumber(realm, x)), y);
|
||||
}
|
||||
|
||||
// 7. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
|
||||
if (y instanceof _index.BooleanValue) {
|
||||
return AbstractEqualityComparison(realm, x, new _index.NumberValue(realm, _singletons.To.ToNumber(realm, y)));
|
||||
}
|
||||
|
||||
// 8. If Type(x) is either String, Number, or Symbol and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
|
||||
if ((x instanceof _index.StringValue || x instanceof _index.NumberValue || x instanceof _index.SymbolValue) && y instanceof _index.ObjectValue) {
|
||||
return AbstractEqualityComparison(realm, x, _singletons.To.ToPrimitive(realm, y));
|
||||
}
|
||||
|
||||
// 9. If Type(x) is Object and Type(y) is either String, Number, or Symbol, return the result of the comparison ToPrimitive(x) == y.
|
||||
if (x instanceof _index.ObjectValue && (y instanceof _index.StringValue || y instanceof _index.NumberValue || y instanceof _index.SymbolValue)) {
|
||||
return AbstractEqualityComparison(realm, _singletons.To.ToPrimitive(realm, x), y);
|
||||
}
|
||||
|
||||
// 10. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.14 Strict Equality Comparison
|
||||
function StrictEqualityComparison(realm, x, y) {
|
||||
// 1. If Type(x) is different from Type(y), return false.
|
||||
if (x.getType() !== y.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. If Type(x) is Number, then
|
||||
if (x instanceof _index.NumberValue && y instanceof _index.NumberValue) {
|
||||
// a. If x is NaN, return false.
|
||||
if (isNaN(x.value)) return false;
|
||||
|
||||
// b. If y is NaN, return false.
|
||||
if (isNaN(y.value)) return false;
|
||||
|
||||
// c. If x is the same Number value as y, return true.
|
||||
// d. If x is +0 and y is -0, return true. (handled by c)
|
||||
// e. If x is -0 and y is +0, return true. (handled by c)
|
||||
if (x.value === y.value) return true;
|
||||
|
||||
// f. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Return SameValueNonNumber(x, y).
|
||||
return SameValueNonNumber(realm, x, y);
|
||||
}
|
||||
|
||||
function StrictEqualityComparisonPartial(realm, x, y) {
|
||||
return StrictEqualityComparison(realm, x.throwIfNotConcrete(), y.throwIfNotConcrete());
|
||||
}
|
||||
|
||||
// ECMA262 7.2.10
|
||||
function SameValueZero(realm, x, y) {
|
||||
// 1. If Type(x) is different from Type(y), return false.
|
||||
if (x.getType() !== y.getType()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 2. If Type(x) is Number, then
|
||||
if (x instanceof _index.NumberValue) {
|
||||
(0, _invariant2.default)(y instanceof _index.NumberValue);
|
||||
|
||||
// a. If x is NaN and y is NaN, return true.
|
||||
if (isNaN(x.value) && isNaN(y.value)) return true;
|
||||
|
||||
// b. If x is +0 and y is -0, return true.
|
||||
if (Object.is(x.value, +0) && Object.is(y.value, -0)) return true;
|
||||
|
||||
// c. If x is -0 and y is +0, return true.
|
||||
if (Object.is(x.value, -0) && Object.is(y.value, +0)) return true;
|
||||
|
||||
// d. If x is the same Number value as y, return true.
|
||||
if (x.value === y.value) return true;
|
||||
|
||||
// e. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Return SameValueNonNumber(x, y).
|
||||
return SameValueNonNumber(realm, x, y);
|
||||
}
|
||||
|
||||
function SameValueZeroPartial(realm, x, y) {
|
||||
return SameValueZero(realm, x.throwIfNotConcrete(), y.throwIfNotConcrete());
|
||||
}
|
||||
|
||||
// ECMA262 7.2.9
|
||||
function SameValue(realm, x, y) {
|
||||
// 1. If Type(x) is different from Type(y), return false.
|
||||
if (x.getType() !== y.getType()) return false;
|
||||
|
||||
// 2. If Type(x) is Number, then
|
||||
if (x instanceof _index.NumberValue && y instanceof _index.NumberValue) {
|
||||
// a. If x is NaN and y is NaN, return true.
|
||||
if (isNaN(x.value) && isNaN(y.value)) return true;
|
||||
|
||||
// b. If x is +0 and y is -0, return false.
|
||||
if (Object.is(x.value, +0) && Object.is(y.value, -0)) return false;
|
||||
|
||||
// c. If x is -0 and y is +0, return false.
|
||||
if (Object.is(x.value, -0) && Object.is(y.value, +0)) return false;
|
||||
|
||||
// d. If x is the same Number value as y, return true.
|
||||
if (x.value === y.value) return true;
|
||||
|
||||
// e. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// 3. Return SameValueNonNumber(x, y).
|
||||
return SameValueNonNumber(realm, x, y);
|
||||
}
|
||||
|
||||
function SameValuePartial(realm, x, y) {
|
||||
return SameValue(realm, x.throwIfNotConcrete(), y.throwIfNotConcrete());
|
||||
}
|
||||
|
||||
// ECMA262 7.2.11
|
||||
function SameValueNonNumber(realm, x, y) {
|
||||
// 1. Assert: Type(x) is not Number.
|
||||
(0, _invariant2.default)(!(x instanceof _index.NumberValue), "numbers not allowed");
|
||||
|
||||
// 2. Assert: Type(x) is the same as Type(y).
|
||||
(0, _invariant2.default)(x.getType() === y.getType(), "must be same type");
|
||||
|
||||
// 3. If Type(x) is Undefined, return true.
|
||||
if (x instanceof _index.UndefinedValue) return true;
|
||||
|
||||
// 4. If Type(x) is Null, return true.
|
||||
if (x instanceof _index.NullValue) return true;
|
||||
|
||||
// 5. If Type(x) is String, then
|
||||
if (x instanceof _index.StringValue && y instanceof _index.StringValue) {
|
||||
// a. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
|
||||
return x.value === y.value;
|
||||
}
|
||||
|
||||
// 6. If Type(x) is Boolean, then
|
||||
if (x instanceof _index.BooleanValue && y instanceof _index.BooleanValue) {
|
||||
// a. If x and y are both true or both false, return true; otherwise, return false.
|
||||
return x.value === y.value;
|
||||
}
|
||||
|
||||
// 7. If Type(x) is Symbol, then
|
||||
if (x instanceof _index.SymbolValue) {
|
||||
// a. If x and y are both the same Symbol value, return true; otherwise, return false.
|
||||
return x === y;
|
||||
}
|
||||
|
||||
// 8. Return true if x and y are the same Object value. Otherwise, return false.
|
||||
return x === y;
|
||||
}
|
||||
|
||||
// Checks if two property keys are identical.
|
||||
function SamePropertyKey(realm, x, y) {
|
||||
if (typeof x === "string" && typeof y === "string") {
|
||||
return x === y;
|
||||
}
|
||||
if (x instanceof _index.StringValue && y instanceof _index.StringValue) {
|
||||
return x.value === y.value;
|
||||
}
|
||||
if (x instanceof _index.SymbolValue && y instanceof _index.SymbolValue) {
|
||||
return x === y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 12.8.5 Applying the Additive Operators to Numbers
|
||||
function Add(realm, a, b) {
|
||||
var subtract = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
||||
|
||||
// If either operand is NaN, the result is NaN.
|
||||
if (isNaN(a) || isNaN(b)) {
|
||||
return realm.intrinsics.NaN;
|
||||
}
|
||||
|
||||
// The sum of two infinities of opposite sign is NaN.
|
||||
// The sum of two infinities of the same sign is the infinity of that sign.
|
||||
// The sum of an infinity and a finite value is equal to the infinite operand.
|
||||
// The sum of two negative zeroes is -0. The sum of two positive zeroes, or of two zeroes of opposite sign, is +0.
|
||||
// The sum of a zero and a nonzero finite value is equal to the nonzero operand.
|
||||
// The sum of two nonzero finite values of the same magnitude and opposite sign is +0.
|
||||
|
||||
var anum = a;
|
||||
var bnum = b;
|
||||
|
||||
// The - operator performs subtraction when applied to two operands of numeric type,
|
||||
// producing the difference of its operands; the left operand is the minuend and the right
|
||||
// operand is the subtrahend. Given numeric operands a and b, it is always the case that
|
||||
// a-b produces the same result as a+(-b).
|
||||
if (subtract) {
|
||||
bnum = -bnum;
|
||||
}
|
||||
|
||||
return new _index.NumberValue(realm, anum + bnum);
|
||||
}
|
||||
|
||||
// ECMA262 12.10.4
|
||||
function InstanceofOperator(realm, O, C) {
|
||||
// 1. If Type(C) is not Object, throw a TypeError exception.
|
||||
if (!C.mightBeObject()) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Expecting a function in instanceof check");
|
||||
}
|
||||
|
||||
// 2. Let instOfHandler be ? GetMethod(C, @@hasInstance).
|
||||
var instOfHandler = (0, _get.GetMethod)(realm, C, realm.intrinsics.SymbolHasInstance);
|
||||
|
||||
// 3. If instOfHandler is not undefined, then
|
||||
if (!(instOfHandler instanceof _index.UndefinedValue)) {
|
||||
// a. Return ToBoolean(? Call(instOfHandler, C, « O »)).
|
||||
return _singletons.To.ToBooleanPartial(realm, (0, _call.Call)(realm, instOfHandler, C, [O]));
|
||||
}
|
||||
|
||||
// 4. If IsCallable(C) is false, throw a TypeError exception.
|
||||
if ((0, _is.IsCallable)(realm, C) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Expecting a function in instanceof check");
|
||||
}
|
||||
|
||||
// 5. Return ? OrdinaryHasInstance(C, O).
|
||||
return OrdinaryHasInstance(realm, C, O);
|
||||
}
|
||||
|
||||
// ECMA262 7.3.19
|
||||
function OrdinaryHasInstance(realm, C, O) {
|
||||
// 1. If IsCallable(C) is false, return false.
|
||||
if ((0, _is.IsCallable)(realm, C) === false) return false;
|
||||
(0, _invariant2.default)(C instanceof _index.ObjectValue);
|
||||
|
||||
// 2. If C has a [[BoundTargetFunction]] internal slot, then
|
||||
if (C instanceof _index.BoundFunctionValue) {
|
||||
// a. Let BC be the value of C's [[BoundTargetFunction]] internal slot.
|
||||
var BC = C.$BoundTargetFunction;
|
||||
|
||||
// b. Return ? InstanceofOperator(O, BC).
|
||||
return InstanceofOperator(realm, O, BC);
|
||||
}
|
||||
|
||||
// 3. If Type(O) is not Object, return false.
|
||||
O = O.throwIfNotConcrete();
|
||||
if (!(O instanceof _index.ObjectValue)) return false;
|
||||
|
||||
// 4. Let P be ? Get(C, "prototype").
|
||||
var P = (0, _get.Get)(realm, C, "prototype").throwIfNotConcrete();
|
||||
|
||||
// 5. If Type(P) is not Object, throw a TypeError exception.
|
||||
if (!(P instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(P) is not Object");
|
||||
}
|
||||
|
||||
// 6. Repeat
|
||||
while (true) {
|
||||
// a. Let O be ? O.[[GetPrototypeOf]]().
|
||||
O = O.$GetPrototypeOf();
|
||||
|
||||
// b. If O is null, return false.
|
||||
if (O instanceof _index.NullValue) return false;
|
||||
|
||||
// c. If SameValue(P, O) is true, return true.
|
||||
if (SameValue(realm, P, O) === true) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
function Type(realm, val) {
|
||||
if (val instanceof _index.UndefinedValue) {
|
||||
return "Undefined";
|
||||
} else if (val instanceof _index.NullValue) {
|
||||
return "Null";
|
||||
} else if ((0, _has.HasCompatibleType)(val, _index.BooleanValue)) {
|
||||
return "Boolean";
|
||||
} else if ((0, _has.HasCompatibleType)(val, _index.StringValue)) {
|
||||
return "String";
|
||||
} else if ((0, _has.HasCompatibleType)(val, _index.SymbolValue)) {
|
||||
return "Symbol";
|
||||
} else if ((0, _has.HasCompatibleType)(val, _index.NumberValue)) {
|
||||
return "Number";
|
||||
} else if (!val.mightNotBeObject()) {
|
||||
return "Object";
|
||||
} else {
|
||||
(0, _invariant2.default)(val instanceof _index.AbstractValue);
|
||||
_index.AbstractValue.reportIntrospectionError(val);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 19.4.3.2.1
|
||||
function SymbolDescriptiveString(realm, sym) {
|
||||
// 1. Assert: Type(sym) is Symbol.
|
||||
(0, _invariant2.default)(sym instanceof _index.SymbolValue, "expected symbol");
|
||||
|
||||
// 2. Let desc be sym's [[Description]] value.
|
||||
var desc = sym.$Description;
|
||||
|
||||
// 3. If desc is undefined, let desc be the empty string.
|
||||
if (!desc) desc = "";else desc = desc.throwIfNotConcreteString().value;
|
||||
|
||||
// 4. Assert: Type(desc) is String.
|
||||
(0, _invariant2.default)(typeof desc === "string", "expected string");
|
||||
|
||||
// 5. Return the result of concatenating the strings "Symbol(", desc, and ")".
|
||||
return "Symbol(" + desc + ")";
|
||||
}
|
||||
|
||||
// ECMA262 6.2.2.5
|
||||
function UpdateEmpty(realm, completionRecord, value) {
|
||||
// 1. Assert: If completionRecord.[[Type]] is either return or throw, then completionRecord.[[Value]] is not empty.
|
||||
if (completionRecord instanceof _completions.ReturnCompletion || completionRecord instanceof _completions.ThrowCompletion) {
|
||||
(0, _invariant2.default)(completionRecord.value, "expected completion record to have a value");
|
||||
}
|
||||
|
||||
// 2. If completionRecord.[[Value]] is not empty, return Completion(completionRecord).
|
||||
if (completionRecord instanceof _index.EmptyValue) return value;
|
||||
if (completionRecord instanceof _index.Value || completionRecord.value && !(completionRecord.value instanceof _index.EmptyValue)) return completionRecord;
|
||||
|
||||
// 3. Return Completion{[[Type]]: completionRecord.[[Type]], [[Value]]: value, [[Target]]: completionRecord.[[Target]] }.'
|
||||
completionRecord.value = value;
|
||||
return completionRecord;
|
||||
}
|
||||
//# sourceMappingURL=abstract.js.map
|
||||
1
build/node_modules/prepack/lib/methods/abstract.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/abstract.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
457
build/node_modules/prepack/lib/methods/arraybuffer.js
generated
vendored
Normal file
457
build/node_modules/prepack/lib/methods/arraybuffer.js
generated
vendored
Normal file
@@ -0,0 +1,457 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.CreateByteDataBlock = CreateByteDataBlock;
|
||||
exports.CopyDataBlockBytes = CopyDataBlockBytes;
|
||||
exports.AllocateArrayBuffer = AllocateArrayBuffer;
|
||||
exports.DetachArrayBuffer = DetachArrayBuffer;
|
||||
exports.GetViewValue = GetViewValue;
|
||||
exports.GetValueFromBuffer = GetValueFromBuffer;
|
||||
exports.SetViewValue = SetViewValue;
|
||||
exports.CloneArrayBuffer = CloneArrayBuffer;
|
||||
exports.SetValueInBuffer = SetValueInBuffer;
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _construct = require("../methods/construct.js");
|
||||
|
||||
var _index2 = require("../methods/index.js");
|
||||
|
||||
var _is = require("../methods/is.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _types = require("../types.js");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 6.2.6.1
|
||||
function CreateByteDataBlock(realm, size) {
|
||||
// 1. Assert: size≥0.
|
||||
(0, _invariant2.default)(size >= 0, "size >= 0");
|
||||
|
||||
// 2. Let db be a new Data Block value consisting of size bytes. If it is impossible to create such a Data Block, throw a RangeError exception.
|
||||
var db = void 0;
|
||||
try {
|
||||
db = new Uint8Array(size);
|
||||
} catch (e) {
|
||||
if (e instanceof RangeError) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "Invalid typed array length");
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Set all of the bytes of db to 0.
|
||||
for (var i = 0; i < size; ++i) {
|
||||
db[i] = 0;
|
||||
}
|
||||
|
||||
// 4. Return db.
|
||||
return db;
|
||||
}
|
||||
|
||||
// ECMA262 6.2.6.2
|
||||
/**
|
||||
* 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 CopyDataBlockBytes(realm, toBlock, toIndex, fromBlock, fromIndex, count) {
|
||||
// 1. Assert: fromBlock and toBlock are distinct Data Block values.
|
||||
(0, _invariant2.default)(toBlock instanceof Uint8Array && fromBlock instanceof Uint8Array && toBlock !== fromBlock);
|
||||
|
||||
// 2. Assert: fromIndex, toIndex, and count are integer values ≥ 0.
|
||||
(0, _invariant2.default)(toIndex >= 0 && fromIndex >= 0 && count >= 0);
|
||||
|
||||
// 3. Let fromSize be the number of bytes in fromBlock.
|
||||
var fromSize = fromBlock.length;
|
||||
|
||||
// 4. Assert: fromIndex+count ≤ fromSize.
|
||||
(0, _invariant2.default)(fromIndex + count <= fromSize, "fromIndex+count ≤ fromSize");
|
||||
|
||||
// 5. Let toSize be the number of bytes in toBlock.
|
||||
var toSize = toBlock.length;
|
||||
|
||||
// 6. Assert: toIndex+count ≤ toSize.
|
||||
(0, _invariant2.default)(toIndex + count <= toSize, "toIndex+count ≤ toSize");
|
||||
|
||||
// 7. Repeat, while count>0
|
||||
while (count > 0) {
|
||||
// a. Set toBlock[toIndex] to the value of fromBlock[fromIndex].
|
||||
toBlock[toIndex] = fromBlock[fromIndex];
|
||||
|
||||
// b. Increment toIndex and fromIndex each by 1.
|
||||
toIndex += 1;
|
||||
fromIndex += 1;
|
||||
|
||||
// c. Decrement count by 1.
|
||||
count -= 1;
|
||||
}
|
||||
|
||||
// 8. Return NormalCompletion(empty).
|
||||
return realm.intrinsics.empty;
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.1
|
||||
function AllocateArrayBuffer(realm, constructor, byteLength) {
|
||||
// 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", « [[ArrayBufferData]], [[ArrayBufferByteLength]] »).
|
||||
var obj = _singletons.Create.OrdinaryCreateFromConstructor(realm, constructor, "ArrayBufferPrototype", {
|
||||
$ArrayBufferData: undefined,
|
||||
$ArrayBufferByteLength: undefined
|
||||
});
|
||||
|
||||
// 2. Assert: byteLength is an integer value ≥ 0.
|
||||
(0, _invariant2.default)(typeof byteLength === "number" && byteLength >= 0, "byteLength is an integer value ≥ 0");
|
||||
|
||||
// 3. Let block be ? CreateByteDataBlock(byteLength).
|
||||
var block = CreateByteDataBlock(realm, byteLength);
|
||||
|
||||
// 4. Set obj's [[ArrayBufferData]] internal slot to block.
|
||||
obj.$ArrayBufferData = block;
|
||||
|
||||
// 5. Set obj's [[ArrayBufferByteLength]] internal slot to byteLength.
|
||||
obj.$ArrayBufferByteLength = byteLength;
|
||||
|
||||
// 6. Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.3
|
||||
function DetachArrayBuffer(realm, arrayBuffer) {
|
||||
// 1. Assert: Type(arrayBuffer) is Object and it has [[ArrayBufferData]] and [[ArrayBufferByteLength]] internal slots.
|
||||
(0, _invariant2.default)(arrayBuffer instanceof _index.ObjectValue && "$ArrayBufferData" in arrayBuffer && "$ArrayBufferByteLength" in arrayBuffer);
|
||||
|
||||
// 2. Set arrayBuffer.[[ArrayBufferData]] to null.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, arrayBuffer, "$ArrayBufferData").$ArrayBufferData = null;
|
||||
|
||||
// 3. Set arrayBuffer.[[ArrayBufferByteLength]] to 0.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, arrayBuffer, "$ArrayBufferByteLength").$ArrayBufferByteLength = 0;
|
||||
|
||||
// 4. Return NormalCompletion(null).
|
||||
return realm.intrinsics.null;
|
||||
}
|
||||
|
||||
// ECMA262 24.2.1.1
|
||||
function GetViewValue(realm, view, requestIndex, isLittleEndian, type) {
|
||||
view = view.throwIfNotConcrete();
|
||||
|
||||
// 1. If Type(view) is not Object, throw a TypeError exception.
|
||||
if (!(view instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(view) is not Object");
|
||||
}
|
||||
|
||||
// 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
|
||||
if (!("$DataView" in view)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "view does not have a [[DataView]] internal slot");
|
||||
}
|
||||
|
||||
// 3. Assert: view has a [[ViewedArrayBuffer]] internal slot.
|
||||
(0, _invariant2.default)(view.$ViewedArrayBuffer);
|
||||
|
||||
// 4. Let getIndex be ? ToIndex(requestIndex).
|
||||
var getIndex = _singletons.To.ToIndexPartial(realm, requestIndex);
|
||||
|
||||
// 5. Let littleEndian be ToBoolean(isLittleEndian).
|
||||
var littleEndian = _singletons.To.ToBooleanPartial(realm, isLittleEndian);
|
||||
|
||||
// 6. Let buffer be view.[[ViewedArrayBuffer]].
|
||||
var buffer = view.$ViewedArrayBuffer;
|
||||
(0, _invariant2.default)(buffer);
|
||||
|
||||
// 7. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, buffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(buffer) is true");
|
||||
}
|
||||
|
||||
// 8. Let viewOffset be view.[[ByteOffset]].
|
||||
var viewOffset = view.$ByteOffset;
|
||||
(0, _invariant2.default)(typeof viewOffset === "number");
|
||||
|
||||
// 9. Let viewSize be view.[[ByteLength]].
|
||||
var viewSize = view.$ByteLength;
|
||||
(0, _invariant2.default)(typeof viewSize === "number");
|
||||
|
||||
// 10. Let elementSize be the Number value of the Element Size value specified in Table 50 for Element Type type.
|
||||
var elementSize = _types.ElementSize[type];
|
||||
|
||||
// 11. If getIndex + elementSize > viewSize, throw a RangeError exception.
|
||||
if (getIndex + elementSize > viewSize) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "getIndex + elementSize > viewSize");
|
||||
}
|
||||
|
||||
// 12. Let bufferIndex be getIndex + viewOffset.
|
||||
var bufferIndex = getIndex + viewOffset;
|
||||
|
||||
// 13. Return GetValueFromBuffer(buffer, bufferIndex, type, littleEndian).
|
||||
return GetValueFromBuffer(realm, buffer, bufferIndex, type, littleEndian);
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.5
|
||||
function GetValueFromBuffer(realm, arrayBuffer, byteIndex, type, isLittleEndian) {
|
||||
// 1. Assert: IsDetachedBuffer(arrayBuffer) is false.
|
||||
(0, _invariant2.default)((0, _is.IsDetachedBuffer)(realm, arrayBuffer) === false);
|
||||
|
||||
// 2. Assert: There are sufficient bytes in arrayBuffer starting at byteIndex to represent a value of type.
|
||||
(0, _invariant2.default)(arrayBuffer.$ArrayBufferData instanceof Uint8Array && byteIndex + _types.ElementSize[type] <= arrayBuffer.$ArrayBufferData.length);
|
||||
|
||||
// 3. Assert: byteIndex is an integer value ≥ 0.
|
||||
(0, _invariant2.default)(byteIndex >= 0);
|
||||
|
||||
// 4. Let block be arrayBuffer.[[ArrayBufferData]].
|
||||
var block = arrayBuffer.$ArrayBufferData;
|
||||
(0, _invariant2.default)(block instanceof Uint8Array);
|
||||
|
||||
// 5. Let elementSize be the Number value of the Element Size value specified in Table 50 for Element Type type.
|
||||
var elementSize = _types.ElementSize[type];
|
||||
|
||||
// 6. Let rawValue be a List of elementSize containing, in order, the elementSize sequence of bytes starting with block[byteIndex].
|
||||
var rawValue = new DataView(block.buffer, byteIndex, elementSize);
|
||||
|
||||
// 7. If isLittleEndian is not present, set isLittleEndian to either true or false. The choice is implementation dependent and should be the alternative that is most efficient for the implementation. An implementation must use the same value each time this step is executed and the same value must be used for the corresponding step in the SetValueInBuffer abstract operation.
|
||||
if (isLittleEndian === undefined) isLittleEndian = true;
|
||||
|
||||
// 8. If isLittleEndian is false, reverse the order of the elements of rawValue.
|
||||
|
||||
// 9. If type is "Float32", then
|
||||
if (type === "Float32") {
|
||||
// a. Let value be the byte elements of rawValue concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2008 binary32 value.
|
||||
// b. If value is an IEEE 754-2008 binary32 NaN value, return the NaN Number value.
|
||||
// c. Return the Number value that corresponds to value.
|
||||
return new _index.NumberValue(realm, rawValue.getFloat32(0, isLittleEndian));
|
||||
}
|
||||
|
||||
// 10. If type is "Float64", then
|
||||
if (type === "Float64") {
|
||||
// a. Let value be the byte elements of rawValue concatenated and interpreted as a little-endian bit string encoding of an IEEE 754-2008 binary64 value.
|
||||
// b. If value is an IEEE 754-2008 binary64 NaN value, return the NaN Number value.
|
||||
// c. Return the Number value that corresponds to value.
|
||||
return new _index.NumberValue(realm, rawValue.getFloat64(0, isLittleEndian));
|
||||
}
|
||||
|
||||
var intValue = void 0;
|
||||
// 11. If the first code unit of type is "U", then
|
||||
if (type === "Uint8" || type === "Uint16" || type === "Uint32" || type === "Uint8Clamped") {
|
||||
// a. Let intValue be the byte elements of rawValue concatenated and interpreted as a bit string encoding of an unsigned little-endian binary number.
|
||||
if (elementSize === 1) {
|
||||
intValue = rawValue.getUint8(0);
|
||||
} else if (elementSize === 2) {
|
||||
intValue = rawValue.getUint16(0, isLittleEndian);
|
||||
} else {
|
||||
intValue = rawValue.getUint32(0, isLittleEndian);
|
||||
}
|
||||
} else {
|
||||
// 12. Else,
|
||||
// a. Let intValue be the byte elements of rawValue concatenated and interpreted as a bit string encoding of a binary little-endian 2's complement number of bit length elementSize × 8.
|
||||
if (elementSize === 1) {
|
||||
intValue = rawValue.getInt8(0);
|
||||
} else if (elementSize === 2) {
|
||||
intValue = rawValue.getInt16(0, isLittleEndian);
|
||||
} else {
|
||||
intValue = rawValue.getInt32(0, isLittleEndian);
|
||||
}
|
||||
}
|
||||
|
||||
// 13. Return the Number value that corresponds to intValue.
|
||||
return new _index.NumberValue(realm, intValue);
|
||||
}
|
||||
|
||||
// ECMA262 24.2.1.2
|
||||
function SetViewValue(realm, view, requestIndex, isLittleEndian, type, value) {
|
||||
view = view.throwIfNotConcrete();
|
||||
|
||||
// 1. If Type(view) is not Object, throw a TypeError exception.
|
||||
if (!(view instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(view) is not Object");
|
||||
}
|
||||
|
||||
// 2. If view does not have a [[DataView]] internal slot, throw a TypeError exception.
|
||||
if (!("$DataView" in view)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "view does not have a [[DataView]] internal slot");
|
||||
}
|
||||
|
||||
// 3. Assert: view has a [[ViewedArrayBuffer]] internal slot.
|
||||
(0, _invariant2.default)(view.$ViewedArrayBuffer);
|
||||
|
||||
// 4. Let getIndex be ? ToIndex(requestIndex).
|
||||
var getIndex = _singletons.To.ToIndexPartial(realm, requestIndex);
|
||||
|
||||
// 5. Let numberValue be ? ToNumber(value).
|
||||
var numberValue = _singletons.To.ToNumber(realm, value);
|
||||
|
||||
// 6. Let littleEndian be ToBoolean(isLittleEndian).
|
||||
var littleEndian = _singletons.To.ToBooleanPartial(realm, isLittleEndian);
|
||||
|
||||
// 7. Let buffer be view.[[ViewedArrayBuffer]].
|
||||
var buffer = view.$ViewedArrayBuffer;
|
||||
(0, _invariant2.default)(buffer);
|
||||
|
||||
// 8. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, buffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(buffer) is true");
|
||||
}
|
||||
|
||||
// 9. Let viewOffset be view.[[ByteOffset]].
|
||||
var viewOffset = view.$ByteOffset;
|
||||
(0, _invariant2.default)(typeof viewOffset === "number");
|
||||
|
||||
// 10. Let viewSize be view.[[ByteLength]].
|
||||
var viewSize = view.$ByteLength;
|
||||
(0, _invariant2.default)(typeof viewSize === "number");
|
||||
|
||||
// 11. Let elementSize be the Number value of the Element Size value specified in Table 50 for Element Type type.
|
||||
var elementSize = _types.ElementSize[type];
|
||||
|
||||
// 12. If getIndex + elementSize > viewSize, throw a RangeError exception.
|
||||
if (getIndex + elementSize > viewSize) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "getIndex + elementSize > viewSize");
|
||||
}
|
||||
|
||||
// 13. Let bufferIndex be getIndex + viewOffset.
|
||||
var bufferIndex = getIndex + viewOffset;
|
||||
|
||||
// 14. Return SetValueInBuffer(buffer, bufferIndex, type, numberValue, littleEndian).
|
||||
return SetValueInBuffer(realm, buffer, bufferIndex, type, numberValue, littleEndian);
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.4
|
||||
function CloneArrayBuffer(realm, srcBuffer, srcByteOffset, cloneConstructor) {
|
||||
// 1. Assert: Type(srcBuffer) is Object and it has an [[ArrayBufferData]] internal slot.
|
||||
(0, _invariant2.default)(srcBuffer instanceof _index.ObjectValue && srcBuffer.$ArrayBufferData);
|
||||
|
||||
// 2. If cloneConstructor is not present, then
|
||||
if (cloneConstructor === undefined) {
|
||||
// a. Let cloneConstructor be ? SpeciesConstructor(srcBuffer, %ArrayBuffer%).
|
||||
cloneConstructor = (0, _construct.SpeciesConstructor)(realm, srcBuffer, realm.intrinsics.ArrayBuffer);
|
||||
|
||||
// b. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, srcBuffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(srcBuffer) is true");
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Else, Assert: IsConstructor(cloneConstructor) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsConstructor)(realm, cloneConstructor) === true, "IsConstructor(cloneConstructor) is true");
|
||||
|
||||
// 4. Let srcLength be the value of srcBuffer's [[ArrayBufferByteLength]] internal slot.
|
||||
var srcLength = srcBuffer.$ArrayBufferByteLength;
|
||||
(0, _invariant2.default)(typeof srcLength === "number");
|
||||
|
||||
// 5. Assert: srcByteOffset ≤ srcLength.
|
||||
(0, _invariant2.default)(srcByteOffset <= srcLength, "srcByteOffset ≤ srcLength");
|
||||
|
||||
// 6. Let cloneLength be srcLength - srcByteOffset.
|
||||
var cloneLength = srcLength - srcByteOffset;
|
||||
|
||||
// 7. Let srcBlock be srcBuffer.[[ArrayBufferData]].
|
||||
var srcBlock = srcBuffer.$ArrayBufferData;
|
||||
(0, _invariant2.default)(srcBlock);
|
||||
|
||||
// 8. Let targetBuffer be ? AllocateArrayBuffer(cloneConstructor, srcLength).
|
||||
var targetBuffer = AllocateArrayBuffer(realm, cloneConstructor, srcLength);
|
||||
|
||||
// 9. If IsDetachedBuffer(srcBuffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, srcBuffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(srcBuffer) is true");
|
||||
}
|
||||
|
||||
// 10. Let targetBlock be targetBuffer.[[ArrayBufferData]].
|
||||
var targetBlock = targetBuffer.$ArrayBufferData;
|
||||
(0, _invariant2.default)(targetBlock);
|
||||
|
||||
// 11. Perform CopyDataBlockBytes(targetBlock, 0, srcBlock, srcByteOffset, cloneLength).
|
||||
CopyDataBlockBytes(realm, targetBlock, 0, srcBlock, srcByteOffset, cloneLength);
|
||||
|
||||
// 12. Return targetBuffer.
|
||||
return targetBuffer;
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.6
|
||||
function SetValueInBuffer(realm, arrayBuffer, byteIndex, type, value, isLittleEndian) {
|
||||
// 1. Assert: IsDetachedBuffer(arrayBuffer) is false.
|
||||
(0, _invariant2.default)((0, _is.IsDetachedBuffer)(realm, arrayBuffer) === false);
|
||||
|
||||
// 2. Assert: There are sufficient bytes in arrayBuffer starting at byteIndex to represent a value of type.
|
||||
(0, _invariant2.default)(arrayBuffer.$ArrayBufferData instanceof Uint8Array && byteIndex + _types.ElementSize[type] <= arrayBuffer.$ArrayBufferData.length);
|
||||
|
||||
// 3. Assert: byteIndex is an integer value ≥ 0.
|
||||
(0, _invariant2.default)(byteIndex >= 0);
|
||||
|
||||
// 4. Assert: Type(value) is Number.
|
||||
(0, _invariant2.default)(typeof value === "number");
|
||||
|
||||
// 5. Let block be arrayBuffer.[[ArrayBufferData]].
|
||||
var block = _singletons.Properties.ThrowIfInternalSlotNotWritable(realm, arrayBuffer, "$ArrayBufferData").$ArrayBufferData;
|
||||
|
||||
// 6. Assert: block is not undefined.
|
||||
(0, _invariant2.default)(block instanceof Uint8Array);
|
||||
|
||||
// 7. If isLittleEndian is not present, set isLittleEndian to either true or false. The choice is implementation dependent and should be the alternative that is most efficient for the implementation. An implementation must use the same value each time this step is executed and the same value must be used for the corresponding step in the SetValueInBuffer abstract operation.
|
||||
if (isLittleEndian === undefined) isLittleEndian = true;
|
||||
|
||||
var rawBytes = new Uint8Array(_types.ElementSize[type]);
|
||||
// 8. If type is "Float32", then
|
||||
if (type === "Float32") {
|
||||
// a. Set rawBytes to a List containing the 4 bytes that are the result of converting value to IEEE 754-2008 binary32 format using “Round to nearest, ties to even” rounding mode. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary32 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.
|
||||
new DataView(rawBytes.buffer).setFloat32(0, value, isLittleEndian);
|
||||
} else if (type === "Float64") {
|
||||
// 9. Else if type is "Float64", then
|
||||
// a. Set rawBytes to a List containing the 8 bytes that are the IEEE 754-2008 binary64 format encoding of value. If isLittleEndian is false, the bytes are arranged in big endian order. Otherwise, the bytes are arranged in little endian order. If value is NaN, rawValue may be set to any implementation chosen IEEE 754-2008 binary64 format Not-a-Number encoding. An implementation must always choose the same encoding for each implementation distinguishable NaN value.
|
||||
new DataView(rawBytes.buffer).setFloat64(0, value, isLittleEndian);
|
||||
} else {
|
||||
// 10. Else,
|
||||
// a. Let n be the Number value of the Element Size specified in Table 50 for Element Type type.
|
||||
var n = _types.ElementSize[type];
|
||||
|
||||
// b. Let convOp be the abstract operation named in the Conversion Operation column in Table 50 for Element Type type.
|
||||
var convOp = _singletons.To.ElementConv[type];
|
||||
|
||||
// c. Let intValue be convOp(value).
|
||||
var intValue = convOp(realm, value);
|
||||
|
||||
// d. If intValue ≥ 0, then
|
||||
if (intValue > 0) {
|
||||
// i. Let rawBytes be a List containing the n-byte binary encoding of intValue. If isLittleEndian is false, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little endian order.
|
||||
if (n === 1) {
|
||||
new DataView(rawBytes.buffer).setUint8(0, intValue);
|
||||
} else if (n === 2) {
|
||||
new DataView(rawBytes.buffer).setUint16(0, intValue, isLittleEndian);
|
||||
} else if (n === 4) {
|
||||
new DataView(rawBytes.buffer).setUint32(0, intValue, isLittleEndian);
|
||||
} else {
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
} else {
|
||||
// e. Else,
|
||||
// i. Let rawBytes be a List containing the n-byte binary 2's complement encoding of intValue. If isLittleEndian is false, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little endian order.
|
||||
if (n === 1) {
|
||||
new DataView(rawBytes.buffer).setInt8(0, intValue);
|
||||
} else if (n === 2) {
|
||||
new DataView(rawBytes.buffer).setInt16(0, intValue, isLittleEndian);
|
||||
} else if (n === 4) {
|
||||
new DataView(rawBytes.buffer).setInt32(0, intValue, isLittleEndian);
|
||||
} else {
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 11. Store the individual bytes of rawBytes into block, in order, starting at block[byteIndex].
|
||||
for (var i = 0; i < rawBytes.length; ++i) {
|
||||
block[byteIndex + i] = rawBytes[i];
|
||||
}
|
||||
|
||||
// 12. Return NormalCompletion(undefined).
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
//# sourceMappingURL=arraybuffer.js.map
|
||||
1
build/node_modules/prepack/lib/methods/arraybuffer.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/arraybuffer.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
497
build/node_modules/prepack/lib/methods/call.js
generated
vendored
Normal file
497
build/node_modules/prepack/lib/methods/call.js
generated
vendored
Normal file
@@ -0,0 +1,497 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||
|
||||
exports.ArgumentListEvaluation = ArgumentListEvaluation;
|
||||
exports.Invoke = Invoke;
|
||||
exports.EvaluateCall = EvaluateCall;
|
||||
exports.PrepareForOrdinaryCall = PrepareForOrdinaryCall;
|
||||
exports.OrdinaryCallBindThis = OrdinaryCallBindThis;
|
||||
exports.OrdinaryCallEvaluateBody = OrdinaryCallEvaluateBody;
|
||||
exports.EvaluateDirectCall = EvaluateDirectCall;
|
||||
exports.EvaluateDirectCallWithArgList = EvaluateDirectCallWithArgList;
|
||||
exports.PrepareForTailCall = PrepareForTailCall;
|
||||
exports.Call = Call;
|
||||
|
||||
var _environment = require("../environment.js");
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _realm = require("../realm.js");
|
||||
|
||||
var _Value = require("../values/Value.js");
|
||||
|
||||
var _Value2 = _interopRequireDefault(_Value);
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _index2 = require("./index.js");
|
||||
|
||||
var _generator = require("../methods/generator.js");
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _get = require("../methods/get.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _babelTypes = require("babel-types");
|
||||
|
||||
var t = _interopRequireWildcard(_babelTypes);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// ECMA262 12.3.6.1
|
||||
function ArgumentListEvaluation(realm, strictCode, env, argNodes) {
|
||||
if (Array.isArray(argNodes)) {
|
||||
var args = [];
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = argNodes[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var node_ = _step.value;
|
||||
|
||||
if (node_.type === "SpreadElement") {
|
||||
var node = node_;
|
||||
// 1. Let list be a new empty List.
|
||||
var list = args;
|
||||
|
||||
// 2. Let spreadRef be the result of evaluating AssignmentExpression.
|
||||
var spreadRef = env.evaluate(node.argument, strictCode);
|
||||
|
||||
// 3. Let spreadObj be ? GetValue(spreadRef).
|
||||
var spreadObj = _singletons.Environment.GetValue(realm, spreadRef);
|
||||
|
||||
// 4. Let iterator be ? GetIterator(spreadObj).
|
||||
var iterator = (0, _index2.GetIterator)(realm, spreadObj);
|
||||
|
||||
// 5. Repeat
|
||||
while (true) {
|
||||
// a. Let next be ? IteratorStep(iterator).
|
||||
var next = (0, _index2.IteratorStep)(realm, iterator);
|
||||
|
||||
// b. If next is false, return list.
|
||||
if (!next) {
|
||||
break;
|
||||
}
|
||||
|
||||
// c. Let nextArg be ? IteratorValue(next).
|
||||
var nextArg = (0, _index2.IteratorValue)(realm, next);
|
||||
|
||||
// d. Append nextArg as the last element of list.
|
||||
list.push(nextArg);
|
||||
}
|
||||
} else {
|
||||
var ref = env.evaluate(node_, strictCode);
|
||||
var expr = _singletons.Environment.GetValue(realm, ref);
|
||||
args.push(expr);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
} else {
|
||||
var _node = argNodes;
|
||||
if (_node.expressions.length === 0) {
|
||||
// 1. Let templateLiteral be this TemplateLiteral.
|
||||
var templateLiteral = _node;
|
||||
|
||||
// 2. Let siteObj be GetTemplateObject(templateLiteral).
|
||||
var siteObj = (0, _get.GetTemplateObject)(realm, templateLiteral);
|
||||
|
||||
// 3. Return a List containing the one element which is siteObj.
|
||||
return [siteObj];
|
||||
} else {
|
||||
// 1. Let templateLiteral be this TemplateLiteral.
|
||||
var _templateLiteral = _node;
|
||||
|
||||
// 2. Let siteObj be GetTemplateObject(templateLiteral).
|
||||
var _siteObj = (0, _get.GetTemplateObject)(realm, _templateLiteral);
|
||||
|
||||
// 3. Let firstSubRef be the result of evaluating Expression.
|
||||
var firstSubRef = env.evaluate(_node.expressions[0], strictCode);
|
||||
|
||||
// 4. Let firstSub be ? GetValue(firstSubRef).
|
||||
var firstSub = _singletons.Environment.GetValue(realm, firstSubRef);
|
||||
|
||||
// 5. Let restSub be SubstitutionEvaluation of TemplateSpans.
|
||||
var restSub = _node.expressions.slice(1, _node.expressions.length).map(function (expr) {
|
||||
return _singletons.Environment.GetValue(realm, env.evaluate(expr, strictCode));
|
||||
});
|
||||
|
||||
// 6. ReturnIfAbrupt(restSub).
|
||||
|
||||
// 7. Assert: restSub is a List.
|
||||
(0, _invariant2.default)(restSub.constructor === Array, "restSub is a List");
|
||||
|
||||
// 8. Return a List whose first element is siteObj, whose second elements is firstSub, and whose subsequent elements are the elements of restSub, in order. restSub may contain no elements.
|
||||
return [_siteObj, firstSub].concat(_toConsumableArray(restSub));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 7.3.18
|
||||
function Invoke(realm, V, P, argumentsList) {
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsPropertyKey)(realm, P), "expected property key");
|
||||
|
||||
// 2. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||
if (!argumentsList) argumentsList = [];
|
||||
|
||||
// 3. Let func be ? GetV(V, P).
|
||||
var func = (0, _get.GetV)(realm, V, P);
|
||||
|
||||
// 4. Return ? Call(func, V, argumentsList).
|
||||
return Call(realm, func, V, argumentsList);
|
||||
}
|
||||
|
||||
// ECMA262 12.3.4.2
|
||||
function EvaluateCall(realm, strictCode, env, ref, args) {
|
||||
var thisValue = void 0;
|
||||
|
||||
// 1. Let func be ? GetValue(ref).
|
||||
var func = _singletons.Environment.GetValue(realm, ref);
|
||||
|
||||
// 2. If Type(ref) is Reference, then
|
||||
if (ref instanceof _environment.Reference) {
|
||||
// a. If IsPropertyReference(ref) is true, then
|
||||
if (_singletons.Environment.IsPropertyReference(realm, ref)) {
|
||||
// i. Let thisValue be GetThisValue(ref).
|
||||
thisValue = (0, _get.GetThisValue)(realm, ref);
|
||||
} else {
|
||||
// b. Else, the base of ref is an Environment Record
|
||||
// i. Let refEnv be GetBase(ref).
|
||||
var refEnv = _singletons.Environment.GetBase(realm, ref);
|
||||
(0, _invariant2.default)(refEnv instanceof _environment.EnvironmentRecord);
|
||||
|
||||
// ii. Let thisValue be refEnv.WithBaseObject().
|
||||
thisValue = refEnv.WithBaseObject();
|
||||
}
|
||||
} else {
|
||||
// 3. Else Type(ref) is not Reference,
|
||||
// a. Let thisValue be undefined.
|
||||
thisValue = realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// 4. Return ? EvaluateDirectCall(func, thisValue, arguments, tailPosition).
|
||||
return EvaluateDirectCall(realm, strictCode, env, ref, func, thisValue, args);
|
||||
}
|
||||
|
||||
// ECMA262 9.2.1.1
|
||||
function PrepareForOrdinaryCall(realm, F, newTarget) {
|
||||
// 1. Assert: Type(newTarget) is Undefined or Object.
|
||||
(0, _invariant2.default)(newTarget === undefined || newTarget instanceof _index.ObjectValue, "expected undefined or object value for new target");
|
||||
|
||||
// 2. Let callerContext be the running execution context.
|
||||
var callerContext = realm.getRunningContext();
|
||||
|
||||
// 3. Let calleeContext be a new ECMAScript code execution context.
|
||||
var calleeContext = realm.createExecutionContext();
|
||||
|
||||
// 4. Set the Function of calleeContext to F.
|
||||
calleeContext.setFunction(F);
|
||||
calleeContext.setCaller(realm.getRunningContext());
|
||||
|
||||
// 5. Let calleeRealm be the value of F's [[Realm]] internal slot.
|
||||
var calleeRealm = realm;
|
||||
|
||||
// 6. Set the Realm of calleeContext to calleeRealm.
|
||||
calleeContext.realm = calleeRealm;
|
||||
|
||||
// 7. Set the ScriptOrModule of calleeContext to the value of F's [[ScriptOrModule]] internal slot.
|
||||
calleeContext.ScriptOrModule = F.$ScriptOrModule;
|
||||
|
||||
// 8. Let localEnv be NewFunctionEnvironment(F, newTarget).
|
||||
var localEnv = _singletons.Environment.NewFunctionEnvironment(realm, F, newTarget);
|
||||
|
||||
// 9. Set the LexicalEnvironment of calleeContext to localEnv.
|
||||
calleeContext.lexicalEnvironment = localEnv;
|
||||
|
||||
// 10. Set the VariableEnvironment of calleeContext to localEnv.
|
||||
calleeContext.variableEnvironment = localEnv;
|
||||
|
||||
// 11. If callerContext is not already suspended, suspend callerContext.
|
||||
callerContext.suspend();
|
||||
|
||||
// 12. Push calleeContext onto the execution context stack; calleeContext is now the running execution context.
|
||||
realm.pushContext(calleeContext);
|
||||
|
||||
// 13. NOTE Any exception objects produced after this point are associated with calleeRealm.
|
||||
|
||||
// 14. Return calleeContext.
|
||||
return calleeContext;
|
||||
}
|
||||
|
||||
// ECMA262 9.2.1.2
|
||||
function OrdinaryCallBindThis(realm, F, calleeContext, thisArgument) {
|
||||
// 1. Let thisMode be the value of F's [[ThisMode]] internal slot.
|
||||
var thisMode = F.$ThisMode;
|
||||
|
||||
// 2. If thisMode is lexical, return NormalCompletion(undefined).
|
||||
if (thisMode === "lexical") return realm.intrinsics.undefined;
|
||||
|
||||
// 3. Let calleeRealm be the value of F's [[Realm]] internal slot.
|
||||
var calleeRealm = F.$Realm;
|
||||
|
||||
// 4. Let localEnv be the LexicalEnvironment of calleeContext.
|
||||
var localEnv = calleeContext.lexicalEnvironment;
|
||||
|
||||
var thisValue = void 0;
|
||||
// 5. If thisMode is strict, let thisValue be thisArgument.
|
||||
if (thisMode === "strict") {
|
||||
thisValue = thisArgument;
|
||||
} else {
|
||||
// 6. Else,
|
||||
// a. If thisArgument is null or undefined, then
|
||||
if ((0, _index2.HasSomeCompatibleType)(thisArgument, _index.NullValue, _index.UndefinedValue)) {
|
||||
// i. Let globalEnv be calleeRealm.[[GlobalEnv]].
|
||||
var globalEnv = realm.$GlobalEnv;
|
||||
|
||||
// ii. Let globalEnvRec be globalEnv's EnvironmentRecord.
|
||||
var globalEnvRec = globalEnv.environmentRecord;
|
||||
(0, _invariant2.default)(globalEnvRec instanceof _environment.GlobalEnvironmentRecord);
|
||||
|
||||
// iii. Let thisValue be globalEnvRec.[[GlobalThisValue]].
|
||||
thisValue = globalEnvRec.$GlobalThisValue;
|
||||
} else {
|
||||
// b. Else,
|
||||
// i. Let thisValue be ! ToObject(thisArgument).
|
||||
thisValue = _singletons.To.ToObjectPartial(calleeRealm, thisArgument);
|
||||
|
||||
// ii. NOTE ToObject produces wrapper objects using calleeRealm.
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Let envRec be localEnv's EnvironmentRecord.
|
||||
(0, _invariant2.default)(localEnv !== undefined);
|
||||
var envRec = localEnv.environmentRecord;
|
||||
|
||||
// 8. Assert: The next step never returns an abrupt completion because envRec.[[ThisBindingStatus]] is not "initialized".
|
||||
|
||||
// 9. Return envRec.BindThisValue(thisValue).
|
||||
return envRec.BindThisValue(thisValue);
|
||||
}
|
||||
|
||||
// ECMA262 9.2.1.3
|
||||
function OrdinaryCallEvaluateBody(realm, F, argumentsList) {
|
||||
if (F instanceof _index.NativeFunctionValue) {
|
||||
var env = realm.getRunningContext().lexicalEnvironment;
|
||||
try {
|
||||
return F.callCallback(env.environmentRecord.GetThisBinding(), argumentsList, env.environmentRecord.$NewTarget);
|
||||
} catch (err) {
|
||||
if (err instanceof _completions.AbruptCompletion) {
|
||||
return err;
|
||||
} else if (err instanceof Error) {
|
||||
throw err;
|
||||
} else {
|
||||
throw new _errors.FatalError(err);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(0, _invariant2.default)(F instanceof _index.ECMAScriptSourceFunctionValue);
|
||||
if (F.$FunctionKind === "generator") {
|
||||
// 1. Perform ? FunctionDeclarationInstantiation(functionObject, argumentsList).
|
||||
_singletons.Functions.FunctionDeclarationInstantiation(realm, F, argumentsList);
|
||||
|
||||
// 2. Let G be ? OrdinaryCreateFromConstructor(functionObject, "%GeneratorPrototype%", « [[GeneratorState]], [[GeneratorContext]] »).
|
||||
var G = _singletons.Create.OrdinaryCreateFromConstructor(realm, F, "GeneratorPrototype", {
|
||||
$GeneratorState: undefined,
|
||||
$GeneratorContext: undefined
|
||||
});
|
||||
|
||||
// 3. Perform GeneratorStart(G, FunctionBody).
|
||||
var code = F.$ECMAScriptCode;
|
||||
(0, _invariant2.default)(code !== undefined);
|
||||
(0, _generator.GeneratorStart)(realm, G, code);
|
||||
|
||||
// 4. Return Completion{[[Type]]: return, [[Value]]: G, [[Target]]: empty}.
|
||||
return new _completions.ReturnCompletion(G, realm.currentLocation);
|
||||
} else {
|
||||
// 1. Perform ? FunctionDeclarationInstantiation(F, argumentsList).
|
||||
_singletons.Functions.FunctionDeclarationInstantiation(realm, F, argumentsList);
|
||||
|
||||
// 2. Return the result of EvaluateBody of the parsed code that is the value of F's
|
||||
// [[ECMAScriptCode]] internal slot passing F as the argument.
|
||||
var priorSavedCompletion = realm.savedCompletion;
|
||||
try {
|
||||
realm.savedCompletion = undefined;
|
||||
var _code = F.$ECMAScriptCode;
|
||||
(0, _invariant2.default)(_code !== undefined);
|
||||
var context = realm.getRunningContext();
|
||||
var c = context.lexicalEnvironment.evaluateCompletionDeref(_code, F.$Strict);
|
||||
// We are about the leave this function and this presents a join point where all non exeptional control flows
|
||||
// converge into a single flow using the joined effects as the new state.
|
||||
c = _singletons.Functions.incorporateSavedCompletion(realm, c);
|
||||
var joinedEffects = void 0;
|
||||
if (c instanceof _completions.PossiblyNormalCompletion) {
|
||||
var e = realm.getCapturedEffects(c);
|
||||
if (e !== undefined) {
|
||||
// There were earlier, conditional exits from the function
|
||||
// We join together the current effects with the effects of any earlier returns that are tracked in c.
|
||||
realm.stopEffectCaptureAndUndoEffects(c);
|
||||
} else {
|
||||
e = (0, _realm.construct_empty_effects)(realm);
|
||||
}
|
||||
joinedEffects = _singletons.Join.joinEffectsAndPromoteNestedReturnCompletions(realm, c, e);
|
||||
} else if (c instanceof _completions.JoinedAbruptCompletions) {
|
||||
joinedEffects = _singletons.Join.joinEffectsAndPromoteNestedReturnCompletions(realm, c, (0, _realm.construct_empty_effects)(realm));
|
||||
}
|
||||
if (joinedEffects !== undefined) {
|
||||
var result = joinedEffects[0];
|
||||
if (result instanceof _completions.ReturnCompletion) {
|
||||
realm.applyEffects(joinedEffects);
|
||||
return result;
|
||||
}
|
||||
(0, _invariant2.default)(result instanceof _completions.JoinedAbruptCompletions);
|
||||
if (!(result.consequent instanceof _completions.ReturnCompletion || result.alternate instanceof _completions.ReturnCompletion)) {
|
||||
realm.applyEffects(joinedEffects);
|
||||
throw result;
|
||||
}
|
||||
// There is a normal return exit, but also one or more throw completions.
|
||||
// The throw completions must be extracted into a saved possibly normal completion
|
||||
// so that the caller can pick them up in its next completion.
|
||||
joinedEffects = extractAndSavePossiblyNormalCompletion(result);
|
||||
result = joinedEffects[0];
|
||||
(0, _invariant2.default)(result instanceof _completions.ReturnCompletion);
|
||||
realm.applyEffects(joinedEffects);
|
||||
return result;
|
||||
} else {
|
||||
(0, _invariant2.default)(c instanceof _Value2.default || c instanceof _completions.AbruptCompletion);
|
||||
return c;
|
||||
}
|
||||
} finally {
|
||||
realm.incorporatePriorSavedCompletion(priorSavedCompletion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractAndSavePossiblyNormalCompletion(c) {
|
||||
// There are throw completions that conditionally escape from the the call.
|
||||
// We need to carry on in normal mode (after arranging to capturing effects)
|
||||
// while stashing away the throw completions so that the next completion we return
|
||||
var _Join$unbundleReturnC = _singletons.Join.unbundleReturnCompletion(realm, c),
|
||||
_Join$unbundleReturnC2 = _slicedToArray(_Join$unbundleReturnC, 2),
|
||||
joinedEffects = _Join$unbundleReturnC2[0],
|
||||
possiblyNormalCompletion = _Join$unbundleReturnC2[1];
|
||||
|
||||
realm.composeWithSavedCompletion(possiblyNormalCompletion);
|
||||
return joinedEffects;
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 12.3.4.3
|
||||
function EvaluateDirectCall(realm, strictCode, env, ref, func, thisValue, args, tailPosition) {
|
||||
// 1. Let argList be ? ArgumentListEvaluation(arguments).
|
||||
var argList = ArgumentListEvaluation(realm, strictCode, env, args);
|
||||
|
||||
return EvaluateDirectCallWithArgList(realm, strictCode, env, ref, func, thisValue, argList, tailPosition);
|
||||
}
|
||||
|
||||
function EvaluateDirectCallWithArgList(realm, strictCode, env, ref, func, thisValue, argList, tailPosition) {
|
||||
if (func instanceof _index.AbstractValue && _Value2.default.isTypeCompatibleWith(func.getType(), _index.FunctionValue)) {
|
||||
return _index.AbstractValue.createTemporalFromBuildFunction(realm, _Value2.default, [func].concat(argList), function (nodes) {
|
||||
var fun_args = nodes.slice(1);
|
||||
return t.callExpression(nodes[0], fun_args);
|
||||
});
|
||||
}
|
||||
func = func.throwIfNotConcrete();
|
||||
|
||||
// 2. If Type(func) is not Object, throw a TypeError exception.
|
||||
if (!(func instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "not an object");
|
||||
}
|
||||
|
||||
// 3. If IsCallable(func) is false, throw a TypeError exception.
|
||||
if (!(0, _index2.IsCallable)(realm, func)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "not callable");
|
||||
}
|
||||
|
||||
// 4. If tailPosition is true, perform PrepareForTailCall().
|
||||
if (tailPosition === true) PrepareForTailCall(realm);
|
||||
|
||||
// 5. Let result be Call(func, thisValue, argList).
|
||||
var result = Call(realm, func, thisValue, argList);
|
||||
|
||||
// 6. Assert: If tailPosition is true, the above call will not return here, but instead
|
||||
// evaluation will continue as if the following return has already occurred.
|
||||
|
||||
// 7. Assert: If result is not an abrupt completion, then Type(result) is an ECMAScript language type.
|
||||
(0, _invariant2.default)(result instanceof _Value2.default, "expected language value type");
|
||||
|
||||
// 8. Return result.
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA262 14.6.3
|
||||
function PrepareForTailCall(realm) {
|
||||
// 1. Let leafContext be the running execution context.
|
||||
var leafContext = realm.getRunningContext();
|
||||
|
||||
// 2. Suspend leafContext.
|
||||
leafContext.suspend();
|
||||
|
||||
// 3. Pop leafContext from the execution context stack. The execution context now on the
|
||||
// top of the stack becomes the running execution context.
|
||||
realm.onDestroyScope(leafContext.lexicalEnvironment);
|
||||
realm.popContext(leafContext);
|
||||
|
||||
// TODO #1008 4. Assert: leafContext has no further use. It will never be activated as the running execution context.
|
||||
}
|
||||
|
||||
// ECMA262 7.3.12
|
||||
function Call(realm, F, V, argsList) {
|
||||
// 1. If argumentsList was not passed, let argumentsList be a new empty List.
|
||||
argsList = argsList || [];
|
||||
|
||||
// 2. If IsCallable(F) is false, throw a TypeError exception.
|
||||
if ((0, _index2.IsCallable)(realm, F) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "not callable");
|
||||
}
|
||||
if (F instanceof _index.AbstractValue && _Value2.default.isTypeCompatibleWith(F.getType(), _index.FunctionValue)) {
|
||||
var fullArgs = [F].concat(argsList);
|
||||
return _index.AbstractValue.createTemporalFromBuildFunction(realm, _Value2.default, fullArgs, function (nodes) {
|
||||
var fun_args = nodes.slice(1);
|
||||
return t.callExpression(nodes[0], fun_args);
|
||||
});
|
||||
}
|
||||
(0, _invariant2.default)(F instanceof _index.ObjectValue);
|
||||
|
||||
// 3. Return ? F.[[Call]](V, argumentsList).
|
||||
(0, _invariant2.default)(F.$Call, "no call method on this value");
|
||||
return F.$Call(V, argsList);
|
||||
}
|
||||
//# sourceMappingURL=call.js.map
|
||||
1
build/node_modules/prepack/lib/methods/call.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/call.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
231
build/node_modules/prepack/lib/methods/construct.js
generated
vendored
Normal file
231
build/node_modules/prepack/lib/methods/construct.js
generated
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.MakeConstructor = MakeConstructor;
|
||||
exports.Construct = Construct;
|
||||
exports.SpeciesConstructor = SpeciesConstructor;
|
||||
exports.MakeClassConstructor = MakeClassConstructor;
|
||||
exports.ConstructorMethod = ConstructorMethod;
|
||||
exports.NonConstructorMethodDefinitions = NonConstructorMethodDefinitions;
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 9.2.8
|
||||
function MakeConstructor(realm, F, writablePrototype, prototype) {
|
||||
// 1. Assert: F is an ECMAScript function object.
|
||||
(0, _invariant2.default)(F instanceof _index.ECMAScriptSourceFunctionValue, "expected function value");
|
||||
|
||||
// 2. Assert: F has a [[Construct]] internal method.
|
||||
(0, _invariant2.default)(F.$Construct !== undefined, "expected construct internal method");
|
||||
|
||||
// 3. Assert: F is an extensible object that does not have a prototype own property.
|
||||
(0, _invariant2.default)(F.getExtensible(), "expected extensible object that doesn't have prototype own property");
|
||||
|
||||
// 4. If the writablePrototype argument was not provided, let writablePrototype be true.
|
||||
if (writablePrototype === null || writablePrototype === undefined) {
|
||||
writablePrototype = true;
|
||||
}
|
||||
|
||||
// 5. If the prototype argument was not provided, then
|
||||
if (!prototype) {
|
||||
// a. Let prototype be ObjectCreate(%ObjectPrototype%).
|
||||
prototype = _singletons.Create.ObjectCreate(realm, realm.intrinsics.ObjectPrototype);
|
||||
prototype.originalConstructor = F;
|
||||
|
||||
// b. Perform ! DefinePropertyOrThrow(prototype, "constructor", PropertyDescriptor{[[Value]]: F, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: true }).
|
||||
_singletons.Properties.DefinePropertyOrThrow(realm, prototype, "constructor", {
|
||||
value: F,
|
||||
writable: writablePrototype,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
}
|
||||
|
||||
// 6. Perform ! DefinePropertyOrThrow(F, "prototype", PropertyDescriptor{[[Value]]: prototype, [[Writable]]: writablePrototype, [[Enumerable]]: false, [[Configurable]]: false}).
|
||||
_singletons.Properties.DefinePropertyOrThrow(realm, F, "prototype", {
|
||||
value: prototype,
|
||||
writable: writablePrototype,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// 7. Return NormalCompletion(undefined).
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.13
|
||||
/**
|
||||
* 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 Construct(realm, F, argumentsList, newTarget) {
|
||||
// If newTarget was not passed, let newTarget be F.
|
||||
if (!newTarget) newTarget = F;
|
||||
|
||||
// If argumentsList was not passed, let argumentsList be a new empty List.
|
||||
if (!argumentsList) argumentsList = [];
|
||||
|
||||
// Assert: IsConstructor(F) is true.
|
||||
(0, _invariant2.default)((0, _is.IsConstructor)(realm, F), "expected constructor");
|
||||
|
||||
// Assert: IsConstructor(newTarget) is true.
|
||||
(0, _invariant2.default)((0, _is.IsConstructor)(realm, newTarget), "expected constructor");
|
||||
|
||||
// Return ? F.[[Construct]](argumentsList, newTarget).
|
||||
(0, _invariant2.default)(F.$Construct !== undefined, "no construct method on realm value");
|
||||
return F.$Construct(argumentsList, newTarget);
|
||||
}
|
||||
|
||||
// ECMA262 7.3.20
|
||||
function SpeciesConstructor(realm, O, defaultConstructor) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue, "Type(O) is Object");
|
||||
|
||||
// 2. Let C be ? Get(O, "constructor").
|
||||
var C = (0, _get.Get)(realm, O, "constructor");
|
||||
|
||||
// 3. If C is undefined, return defaultConstructor.
|
||||
if (C instanceof _index.UndefinedValue) return defaultConstructor;
|
||||
|
||||
// 4. If Type(C) is not Object, throw a TypeError exception.
|
||||
if (C.mightNotBeObject()) {
|
||||
if (C.mightBeObject()) C.throwIfNotConcrete();
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(C) is not an object");
|
||||
}
|
||||
(0, _invariant2.default)(C instanceof _index.ObjectValue || C instanceof _index.AbstractObjectValue);
|
||||
|
||||
// 5. Let S be ? Get(C, @@species).
|
||||
var S = (0, _get.Get)(realm, C, realm.intrinsics.SymbolSpecies);
|
||||
|
||||
// 6. If S is either undefined or null, return defaultConstructor.
|
||||
if ((0, _has.HasSomeCompatibleType)(S, _index.UndefinedValue, _index.NullValue)) return defaultConstructor;
|
||||
|
||||
// 7. If IsConstructor(S) is true, return S.
|
||||
if ((0, _is.IsConstructor)(realm, S)) {
|
||||
(0, _invariant2.default)(S instanceof _index.ObjectValue);
|
||||
return S;
|
||||
}
|
||||
|
||||
// 8. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Throw a TypeError exception");
|
||||
}
|
||||
|
||||
// ECMA 9.2.9
|
||||
function MakeClassConstructor(realm, F) {
|
||||
// 1. Assert: F is an ECMAScript function object.
|
||||
(0, _invariant2.default)(F instanceof _index.ECMAScriptSourceFunctionValue, "expected function value");
|
||||
|
||||
// 2. Assert: F’s [[FunctionKind]] internal slot is "normal".
|
||||
(0, _invariant2.default)(F.$FunctionKind === "normal");
|
||||
|
||||
// 3. Set F’s [[FunctionKind]] internal slot to "classConstructor".
|
||||
F.$FunctionKind = "classConstructor";
|
||||
|
||||
// 4. Return NormalCompletion(undefined).
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA 14.5.3
|
||||
function ConstructorMethod(realm, ClassElementList) {
|
||||
var ClassElement = void 0;
|
||||
// ClassElementList : ClassElement
|
||||
if (ClassElementList.length === 1) {
|
||||
ClassElement = ClassElementList[0];
|
||||
// 1. If ClassElement is the production ClassElement : ; , return empty.
|
||||
// It looks like Babel parses out ClassElements that are only ;
|
||||
|
||||
// 2. If IsStatic of ClassElement is true, return empty.
|
||||
if ((0, _is.IsStatic)(ClassElement)) {
|
||||
return realm.intrinsics.empty;
|
||||
}
|
||||
// 3. If PropName of ClassElement is not "constructor", return empty.
|
||||
if (ClassElement.key.name !== "constructor") {
|
||||
return realm.intrinsics.empty;
|
||||
}
|
||||
|
||||
// 4. Return ClassElement.
|
||||
return ClassElement;
|
||||
} else {
|
||||
// ClassElementList : ClassElementList ClassElement
|
||||
// 1. Let head be ConstructorMethod of ClassElementList.
|
||||
var head = ConstructorMethod(realm, ClassElementList.slice(0, -1));
|
||||
// 2. If head is not empty, return head.
|
||||
if (!(head instanceof _index.EmptyValue)) {
|
||||
return head;
|
||||
}
|
||||
|
||||
ClassElement = ClassElementList[ClassElementList.length - 1];
|
||||
// 3. If ClassElement is the production ClassElement : ; , return empty.
|
||||
// It looks like Babel parses out ClassElements that are only ;
|
||||
|
||||
// 4. If IsStatic of ClassElement is true, return empty.
|
||||
if ((0, _is.IsStatic)(ClassElement)) {
|
||||
return realm.intrinsics.empty;
|
||||
}
|
||||
// If PropName of ClassElement is not "constructor", return empty.
|
||||
if (ClassElement.key.name !== "constructor") {
|
||||
return realm.intrinsics.empty;
|
||||
}
|
||||
|
||||
// Return ClassElement.
|
||||
return ClassElement;
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA 14.5.10
|
||||
function NonConstructorMethodDefinitions(realm, ClassElementList) {
|
||||
var ClassElement = void 0;
|
||||
// ClassElementList : ClassElement
|
||||
if (ClassElementList.length === 1) {
|
||||
ClassElement = ClassElementList[0];
|
||||
// If ClassElement is the production ClassElement : ; , return a new empty List.
|
||||
|
||||
// If IsStatic of ClassElement is false and PropName of ClassElement is "constructor", return a new empty List.
|
||||
if (!(0, _is.IsStatic)(ClassElement) && ClassElement.key.name === "constructor") {
|
||||
return [];
|
||||
}
|
||||
// Return a List containing ClassElement.
|
||||
return [ClassElement];
|
||||
} else {
|
||||
// ClassElementList : ClassElementList ClassElement
|
||||
ClassElement = ClassElementList[ClassElementList.length - 1];
|
||||
|
||||
// Let list be NonConstructorMethodDefinitions of ClassElementList.
|
||||
var list = NonConstructorMethodDefinitions(realm, ClassElementList.slice(0, -1));
|
||||
|
||||
// If ClassElement is the production ClassElement : ; , return list.
|
||||
|
||||
// If IsStatic of ClassElement is false and PropName of ClassElement is "constructor", return list.
|
||||
if (!(0, _is.IsStatic)(ClassElement) && ClassElement.key.name === "constructor") {
|
||||
return list;
|
||||
}
|
||||
|
||||
// Append ClassElement to the end of list.
|
||||
list.push(ClassElement);
|
||||
|
||||
// Return list.
|
||||
return list;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=construct.js.map
|
||||
1
build/node_modules/prepack/lib/methods/construct.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/construct.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1021
build/node_modules/prepack/lib/methods/create.js
generated
vendored
Normal file
1021
build/node_modules/prepack/lib/methods/create.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
build/node_modules/prepack/lib/methods/create.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/create.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
347
build/node_modules/prepack/lib/methods/date.js
generated
vendored
Normal file
347
build/node_modules/prepack/lib/methods/date.js
generated
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.msPerDay = exports.msPerHour = exports.msPerMinute = exports.msPerSecond = exports.HoursPerDay = exports.MinutesPerHour = exports.SecondsPerMinute = undefined;
|
||||
exports.Day = Day;
|
||||
exports.TimeWithinDay = TimeWithinDay;
|
||||
exports.DaysInYear = DaysInYear;
|
||||
exports.DayFromYear = DayFromYear;
|
||||
exports.TimeFromYear = TimeFromYear;
|
||||
exports.YearFromTime = YearFromTime;
|
||||
exports.InLeapYear = InLeapYear;
|
||||
exports.MonthFromTime = MonthFromTime;
|
||||
exports.DayWithinYear = DayWithinYear;
|
||||
exports.DateFromTime = DateFromTime;
|
||||
exports.WeekDay = WeekDay;
|
||||
exports.DaylightSavingTA = DaylightSavingTA;
|
||||
exports.LocalTime = LocalTime;
|
||||
exports.UTC = UTC;
|
||||
exports.HourFromTime = HourFromTime;
|
||||
exports.MinFromTime = MinFromTime;
|
||||
exports.SecFromTime = SecFromTime;
|
||||
exports.msFromTime = msFromTime;
|
||||
exports.MakeTime = MakeTime;
|
||||
exports.MakeDay = MakeDay;
|
||||
exports.MakeDate = MakeDate;
|
||||
exports.TimeClip = TimeClip;
|
||||
exports.thisTimeValue = thisTimeValue;
|
||||
exports.ToDateString = ToDateString;
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// Constants
|
||||
var SecondsPerMinute = exports.SecondsPerMinute = 60; /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var MinutesPerHour = exports.MinutesPerHour = 60;
|
||||
var HoursPerDay = exports.HoursPerDay = 24;
|
||||
var msPerSecond = exports.msPerSecond = 1000;
|
||||
var msPerMinute = exports.msPerMinute = msPerSecond * SecondsPerMinute;
|
||||
var msPerHour = exports.msPerHour = msPerMinute * MinutesPerHour;
|
||||
var msPerDay = exports.msPerDay = msPerHour * HoursPerDay;
|
||||
|
||||
var LocalTZA = -new Date(0).getTimezoneOffset() * msPerMinute;
|
||||
|
||||
// ECMA262 20.3.1.2
|
||||
function Day(realm, t) {
|
||||
return Math.floor(t / msPerDay);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.2
|
||||
function TimeWithinDay(realm, t) {
|
||||
return t % msPerDay;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.3
|
||||
function DaysInYear(realm, y) {
|
||||
if (y % 4 !== 0) return 365;
|
||||
if (y % 4 === 0 && y % 100 !== 0) return 366;
|
||||
if (y % 100 === 0 && y % 400 !== 0) return 365;
|
||||
if (y % 400 === 0) return 366;
|
||||
|
||||
(0, _invariant2.default)(false, "Invalid condition");
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.3
|
||||
function DayFromYear(realm, y) {
|
||||
return 365 * (y - 1970) + Math.floor((y - 1969) / 4) - Math.floor((y - 1901) / 100) + Math.floor((y - 1601) / 400);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.3
|
||||
function TimeFromYear(realm, y) {
|
||||
return msPerDay * DayFromYear(realm, y);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.3
|
||||
function YearFromTime(realm, t) {
|
||||
var y = Math.floor(t / (msPerDay * 365.2425)) + 1970;
|
||||
var t2 = TimeFromYear(realm, y);
|
||||
|
||||
if (t2 > t) {
|
||||
y--;
|
||||
} else {
|
||||
if (t2 + msPerDay * DaysInYear(realm, y) <= t) {
|
||||
y++;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.3
|
||||
function InLeapYear(realm, t) {
|
||||
var daysInYear = DaysInYear(realm, YearFromTime(realm, t));
|
||||
if (daysInYear === 365) return 0;
|
||||
if (daysInYear === 366) return 1;
|
||||
(0, _invariant2.default)(false, "invalid condition");
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.4
|
||||
function MonthFromTime(realm, t) {
|
||||
var step = void 0;
|
||||
var d = DayWithinYear(realm, t);
|
||||
|
||||
if (d < (step = 31)) return 0;
|
||||
|
||||
step += InLeapYear(realm, t) ? 29 : 28;
|
||||
if (d < step) return 1;
|
||||
if (d < (step += 31)) return 2;
|
||||
if (d < (step += 30)) return 3;
|
||||
if (d < (step += 31)) return 4;
|
||||
if (d < (step += 30)) return 5;
|
||||
if (d < (step += 31)) return 6;
|
||||
if (d < (step += 31)) return 7;
|
||||
if (d < (step += 30)) return 8;
|
||||
if (d < (step += 31)) return 9;
|
||||
if (d < (step += 30)) return 10;
|
||||
return 11;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.4
|
||||
function DayWithinYear(realm, t) {
|
||||
return Day(realm, t) - DayFromYear(realm, YearFromTime(realm, t));
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.5
|
||||
function DateFromTime(realm, t) {
|
||||
var step = void 0;
|
||||
var next = void 0;
|
||||
var d = DayWithinYear(realm, t);
|
||||
|
||||
if (d <= (next = 30)) return d + 1;
|
||||
|
||||
step = next;
|
||||
next += InLeapYear(realm, t) ? 29 : 28;
|
||||
if (d <= next) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 31)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 30)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 31)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 30)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 31)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 31)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 30)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 31)) return d - step;
|
||||
|
||||
step = next;
|
||||
if (d <= (next += 30)) return d - step;
|
||||
|
||||
step = next;
|
||||
return d - step;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.6
|
||||
function WeekDay(realm, t) {
|
||||
return (Day(realm, t) + 4) % 7;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.7
|
||||
function DaylightSavingTA(realm, t) {
|
||||
// TODO #1014: Implement DaylightSavingTA
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.9
|
||||
function LocalTime(realm, t) {
|
||||
// 1. Return t + LocalTZA + DaylightSavingTA(t).
|
||||
return t + LocalTZA + DaylightSavingTA(realm, t);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.10
|
||||
function UTC(realm, t) {
|
||||
if (t instanceof _index.Value) t = t.throwIfNotConcreteNumber().value;
|
||||
|
||||
// 1. Return t - LocalTZA - DaylightSavingTA(t - LocalTZA).
|
||||
return new _index.NumberValue(realm, t - LocalTZA - DaylightSavingTA(realm, t - LocalTZA));
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.11
|
||||
function HourFromTime(realm, t) {
|
||||
return Math.floor(t / msPerHour) % HoursPerDay;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.11
|
||||
function MinFromTime(realm, t) {
|
||||
return Math.floor(t / msPerMinute) % MinutesPerHour;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.11
|
||||
function SecFromTime(realm, t) {
|
||||
return Math.floor(t / msPerSecond) % SecondsPerMinute;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.11
|
||||
function msFromTime(realm, t) {
|
||||
return t % msPerSecond;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.12
|
||||
function MakeTime(realm, hour, min, sec, ms) {
|
||||
// 1. If hour is not finite or min is not finite or sec is not finite or ms is not finite, return NaN.
|
||||
if (!isFinite(hour) || !isFinite(min) || !isFinite(sec) || !isFinite(ms)) return NaN;
|
||||
|
||||
// 2. Let h be ToInteger(hour).
|
||||
var h = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, hour));
|
||||
|
||||
// 3. Let m be ToInteger(min).
|
||||
var m = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, min));
|
||||
|
||||
// 4. Let s be ToInteger(sec).
|
||||
var s = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, sec));
|
||||
|
||||
// 5. Let milli be ToInteger(ms).
|
||||
var milli = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, ms));
|
||||
|
||||
// 6. Let t be h * msPerHour + m * msPerMinute + s * msPerSecond + milli, performing the arithmetic
|
||||
// according to IEEE 754-2008 rules (that is, as if using the ECMAScript operators * and +).
|
||||
var t = h * msPerHour + m * msPerMinute + s * msPerSecond + milli;
|
||||
|
||||
// 7. Return t.
|
||||
return t;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.13
|
||||
function MakeDay(realm, year, month, date) {
|
||||
// 1. If year is not finite or month is not finite or date is not finite, return NaN.
|
||||
if (!isFinite(year) || !isFinite(month) || !isFinite(date)) return NaN;
|
||||
|
||||
// 2. Let y be ToInteger(year).
|
||||
var y = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, year));
|
||||
|
||||
// 3. Let m be ToInteger(month).
|
||||
var m = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, month));
|
||||
|
||||
// 4. Let dt be ToInteger(date).
|
||||
var dt = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, date));
|
||||
|
||||
// 5. Let ym be y + floor(m / 12).
|
||||
var ym = y + Math.floor(m / 12);
|
||||
|
||||
// 6. Let mn be m modulo 12.
|
||||
var mn = m < 0 ? m % 12 + 12 : m % 12;
|
||||
|
||||
// 7. Find a value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn and DateFromTime(t) is 1;
|
||||
// but if this is not possible (because some argument is out of range), return NaN.
|
||||
// Inspired by the V8 implementation.
|
||||
if (Math.abs(ym) >= 1000000.0 || Math.abs(mn) >= 1000000.0) {
|
||||
return NaN;
|
||||
}
|
||||
var yearDelta = 399999;
|
||||
var baseDay = 365 * (1970 + yearDelta) + Math.floor((1970 + yearDelta) / 4) - Math.floor((1970 + yearDelta) / 100) + Math.floor((1970 + yearDelta) / 400);
|
||||
var t = 365 * (ym + yearDelta) + Math.floor((ym + yearDelta) / 4) - Math.floor((ym + yearDelta) / 100) + Math.floor((ym + yearDelta) / 400) - baseDay;
|
||||
|
||||
if (ym % 4 !== 0 || ym % 100 === 0 && ym % 400 !== 0) {
|
||||
t += [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334][mn];
|
||||
} else {
|
||||
t += [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335][mn];
|
||||
}
|
||||
|
||||
// 8. Return Day(t) + dt - 1.
|
||||
return t + dt - 1;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.14
|
||||
function MakeDate(realm, day, time) {
|
||||
// 1. If day is not finite or time is not finite, return NaN.
|
||||
if (!isFinite(day) || !isFinite(time)) return NaN;
|
||||
|
||||
// 2. Return day × msPerDay + time.
|
||||
return day * msPerDay + time;
|
||||
}
|
||||
|
||||
// ECMA262 20.3.1.15
|
||||
function TimeClip(realm, time) {
|
||||
if (time instanceof _index.Value) time = time.throwIfNotConcreteNumber().value;
|
||||
// 1. If time is not finite, return NaN.
|
||||
if (!isFinite(time)) return realm.intrinsics.NaN;
|
||||
|
||||
// 2. If abs(time) > 8.64 × 10^15, return NaN.
|
||||
if (Math.abs(time) > 8640000000000000) {
|
||||
return realm.intrinsics.NaN;
|
||||
}
|
||||
|
||||
// 3. Let clippedTime be ToInteger(time).
|
||||
var clippedTime = _singletons.To.ToInteger(realm, new _index.NumberValue(realm, time));
|
||||
|
||||
// 4. If clippedTime is -0, let clippedTime be +0.
|
||||
if (Object.is(clippedTime, -0)) clippedTime = +0;
|
||||
|
||||
// 5. Return clippedTime.
|
||||
return new _index.NumberValue(realm, clippedTime);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.4
|
||||
function thisTimeValue(realm, value) {
|
||||
// 1. If Type(value) is Object and value has a [[DateValue]] internal slot, then
|
||||
if (value instanceof _index.ObjectValue && value.$DateValue !== undefined) {
|
||||
// a. Return the value of value's [[DateValue]] internal slot.
|
||||
return value.$DateValue;
|
||||
}
|
||||
|
||||
// 2. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// ECMA262 20.3.4.41.1
|
||||
function ToDateString(realm, tv) {
|
||||
// 1. Assert: Type(tv) is Number.
|
||||
(0, _invariant2.default)(typeof tv === "number", "expected tv to be a number");
|
||||
|
||||
// 2. If tv is NaN, return "Invalid Date".
|
||||
if (isNaN(tv)) return "Invalid Date";
|
||||
|
||||
// 3. Return an implementation-dependent String value that represents tv as a date and time in the current
|
||||
// time zone using a convenient, human-readable form.
|
||||
return new Date(tv).toString();
|
||||
}
|
||||
//# sourceMappingURL=date.js.map
|
||||
1
build/node_modules/prepack/lib/methods/date.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/date.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
71
build/node_modules/prepack/lib/methods/descriptor.js
generated
vendored
Normal file
71
build/node_modules/prepack/lib/methods/descriptor.js
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.cloneDescriptor = cloneDescriptor;
|
||||
exports.clearDescriptor = clearDescriptor;
|
||||
exports.copyDescriptor = copyDescriptor;
|
||||
exports.equalDescriptors = equalDescriptors;
|
||||
function cloneDescriptor(d) {
|
||||
if (d === undefined) return undefined;
|
||||
var clone = {};
|
||||
copyDescriptor(d, clone);
|
||||
return clone;
|
||||
} /**
|
||||
* 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 clearDescriptor(d) {
|
||||
delete d.writable;
|
||||
delete d.enumerable;
|
||||
delete d.configurable;
|
||||
delete d.value;
|
||||
delete d.get;
|
||||
delete d.set;
|
||||
}
|
||||
|
||||
function copyDescriptor(from, to) {
|
||||
if (from.hasOwnProperty("writable")) to.writable = from.writable;
|
||||
if (from.hasOwnProperty("enumerable")) to.enumerable = from.enumerable;
|
||||
if (from.hasOwnProperty("configurable")) to.configurable = from.configurable;
|
||||
if (from.hasOwnProperty("value")) {
|
||||
if (from.value instanceof Array) to.value = from.value.slice();else to.value = from.value;
|
||||
}
|
||||
if (from.hasOwnProperty("get")) to.get = from.get;
|
||||
if (from.hasOwnProperty("set")) to.set = from.set;
|
||||
}
|
||||
|
||||
// does not check if the contents of value properties are the same
|
||||
function equalDescriptors(d1, d2) {
|
||||
if (d1.hasOwnProperty("writable")) {
|
||||
if (!d2.hasOwnProperty("writable")) return false;
|
||||
if (d1.writable !== d2.writable) return false;
|
||||
}
|
||||
if (d1.hasOwnProperty("enumerable")) {
|
||||
if (!d2.hasOwnProperty("enumerable")) return false;
|
||||
if (d1.enumerable !== d2.enumerable) return false;
|
||||
}
|
||||
if (d1.hasOwnProperty("configurable")) {
|
||||
if (!d2.hasOwnProperty("configurable")) return false;
|
||||
if (d1.configurable !== d2.configurable) return false;
|
||||
}
|
||||
if (d1.hasOwnProperty("value")) {
|
||||
if (!d2.hasOwnProperty("value")) return false;
|
||||
}
|
||||
if (d1.hasOwnProperty("get")) {
|
||||
if (!d2.hasOwnProperty("get")) return false;
|
||||
if (d1.get !== d2.get) return false;
|
||||
}
|
||||
if (d1.hasOwnProperty("set")) {
|
||||
if (!d2.hasOwnProperty("set")) return false;
|
||||
if (d1.set !== d2.set) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=descriptor.js.map
|
||||
1
build/node_modules/prepack/lib/methods/descriptor.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/descriptor.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/methods/descriptor.js"],"names":["cloneDescriptor","clearDescriptor","copyDescriptor","equalDescriptors","d","undefined","clone","writable","enumerable","configurable","value","get","set","from","to","hasOwnProperty","Array","slice","d1","d2"],"mappings":";;;;;QAagBA,e,GAAAA,e;QAOAC,e,GAAAA,e;QASAC,c,GAAAA,c;QAaAC,gB,GAAAA,gB;AA7BT,SAASH,eAAT,CAAyBI,CAAzB,EAAkE;AACvE,MAAIA,MAAMC,SAAV,EAAqB,OAAOA,SAAP;AACrB,MAAIC,QAAQ,EAAZ;AACAJ,iBAAeE,CAAf,EAAkBE,KAAlB;AACA,SAAOA,KAAP;AACD,C,CAlBD;;;;;;;;;AAoBO,SAASL,eAAT,CAAyBG,CAAzB,EAAwC;AAC7C,SAAOA,EAAEG,QAAT;AACA,SAAOH,EAAEI,UAAT;AACA,SAAOJ,EAAEK,YAAT;AACA,SAAOL,EAAEM,KAAT;AACA,SAAON,EAAEO,GAAT;AACA,SAAOP,EAAEQ,GAAT;AACD;;AAEM,SAASV,cAAT,CAAwBW,IAAxB,EAA0CC,EAA1C,EAA0D;AAC/D,MAAID,KAAKE,cAAL,CAAoB,UAApB,CAAJ,EAAqCD,GAAGP,QAAH,GAAcM,KAAKN,QAAnB;AACrC,MAAIM,KAAKE,cAAL,CAAoB,YAApB,CAAJ,EAAuCD,GAAGN,UAAH,GAAgBK,KAAKL,UAArB;AACvC,MAAIK,KAAKE,cAAL,CAAoB,cAApB,CAAJ,EAAyCD,GAAGL,YAAH,GAAkBI,KAAKJ,YAAvB;AACzC,MAAII,KAAKE,cAAL,CAAoB,OAApB,CAAJ,EAAkC;AAChC,QAAIF,KAAKH,KAAL,YAAsBM,KAA1B,EAAiCF,GAAGJ,KAAH,GAAWG,KAAKH,KAAL,CAAWO,KAAX,EAAX,CAAjC,KACKH,GAAGJ,KAAH,GAAWG,KAAKH,KAAhB;AACN;AACD,MAAIG,KAAKE,cAAL,CAAoB,KAApB,CAAJ,EAAgCD,GAAGH,GAAH,GAASE,KAAKF,GAAd;AAChC,MAAIE,KAAKE,cAAL,CAAoB,KAApB,CAAJ,EAAgCD,GAAGF,GAAH,GAASC,KAAKD,GAAd;AACjC;;AAED;AACO,SAAST,gBAAT,CAA0Be,EAA1B,EAA0CC,EAA1C,EAA0D;AAC/D,MAAID,GAAGH,cAAH,CAAkB,UAAlB,CAAJ,EAAmC;AACjC,QAAI,CAACI,GAAGJ,cAAH,CAAkB,UAAlB,CAAL,EAAoC,OAAO,KAAP;AACpC,QAAIG,GAAGX,QAAH,KAAgBY,GAAGZ,QAAvB,EAAiC,OAAO,KAAP;AAClC;AACD,MAAIW,GAAGH,cAAH,CAAkB,YAAlB,CAAJ,EAAqC;AACnC,QAAI,CAACI,GAAGJ,cAAH,CAAkB,YAAlB,CAAL,EAAsC,OAAO,KAAP;AACtC,QAAIG,GAAGV,UAAH,KAAkBW,GAAGX,UAAzB,EAAqC,OAAO,KAAP;AACtC;AACD,MAAIU,GAAGH,cAAH,CAAkB,cAAlB,CAAJ,EAAuC;AACrC,QAAI,CAACI,GAAGJ,cAAH,CAAkB,cAAlB,CAAL,EAAwC,OAAO,KAAP;AACxC,QAAIG,GAAGT,YAAH,KAAoBU,GAAGV,YAA3B,EAAyC,OAAO,KAAP;AAC1C;AACD,MAAIS,GAAGH,cAAH,CAAkB,OAAlB,CAAJ,EAAgC;AAC9B,QAAI,CAACI,GAAGJ,cAAH,CAAkB,OAAlB,CAAL,EAAiC,OAAO,KAAP;AAClC;AACD,MAAIG,GAAGH,cAAH,CAAkB,KAAlB,CAAJ,EAA8B;AAC5B,QAAI,CAACI,GAAGJ,cAAH,CAAkB,KAAlB,CAAL,EAA+B,OAAO,KAAP;AAC/B,QAAIG,GAAGP,GAAH,KAAWQ,GAAGR,GAAlB,EAAuB,OAAO,KAAP;AACxB;AACD,MAAIO,GAAGH,cAAH,CAAkB,KAAlB,CAAJ,EAA8B;AAC5B,QAAI,CAACI,GAAGJ,cAAH,CAAkB,KAAlB,CAAL,EAA+B,OAAO,KAAP;AAC/B,QAAIG,GAAGN,GAAH,KAAWO,GAAGP,GAAlB,EAAuB,OAAO,KAAP;AACxB;AACD,SAAO,IAAP;AACD","file":"descriptor.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nimport type { Descriptor } from \"../types.js\";\n\nexport function cloneDescriptor(d: void | Descriptor): void | Descriptor {\n if (d === undefined) return undefined;\n let clone = {};\n copyDescriptor(d, clone);\n return clone;\n}\n\nexport function clearDescriptor(d: Descriptor) {\n delete d.writable;\n delete d.enumerable;\n delete d.configurable;\n delete d.value;\n delete d.get;\n delete d.set;\n}\n\nexport function copyDescriptor(from: Descriptor, to: Descriptor) {\n if (from.hasOwnProperty(\"writable\")) to.writable = from.writable;\n if (from.hasOwnProperty(\"enumerable\")) to.enumerable = from.enumerable;\n if (from.hasOwnProperty(\"configurable\")) to.configurable = from.configurable;\n if (from.hasOwnProperty(\"value\")) {\n if (from.value instanceof Array) to.value = from.value.slice();\n else to.value = from.value;\n }\n if (from.hasOwnProperty(\"get\")) to.get = from.get;\n if (from.hasOwnProperty(\"set\")) to.set = from.set;\n}\n\n// does not check if the contents of value properties are the same\nexport function equalDescriptors(d1: Descriptor, d2: Descriptor) {\n if (d1.hasOwnProperty(\"writable\")) {\n if (!d2.hasOwnProperty(\"writable\")) return false;\n if (d1.writable !== d2.writable) return false;\n }\n if (d1.hasOwnProperty(\"enumerable\")) {\n if (!d2.hasOwnProperty(\"enumerable\")) return false;\n if (d1.enumerable !== d2.enumerable) return false;\n }\n if (d1.hasOwnProperty(\"configurable\")) {\n if (!d2.hasOwnProperty(\"configurable\")) return false;\n if (d1.configurable !== d2.configurable) return false;\n }\n if (d1.hasOwnProperty(\"value\")) {\n if (!d2.hasOwnProperty(\"value\")) return false;\n }\n if (d1.hasOwnProperty(\"get\")) {\n if (!d2.hasOwnProperty(\"get\")) return false;\n if (d1.get !== d2.get) return false;\n }\n if (d1.hasOwnProperty(\"set\")) {\n if (!d2.hasOwnProperty(\"set\")) return false;\n if (d1.set !== d2.set) return false;\n }\n return true;\n}\n"]}
|
||||
461
build/node_modules/prepack/lib/methods/destructuring.js
generated
vendored
Normal file
461
build/node_modules/prepack/lib/methods/destructuring.js
generated
vendored
Normal file
@@ -0,0 +1,461 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.DestructuringAssignmentEvaluation = DestructuringAssignmentEvaluation;
|
||||
exports.IteratorDestructuringAssignmentEvaluation = IteratorDestructuringAssignmentEvaluation;
|
||||
exports.KeyedDestructuringAssignmentEvaluation = KeyedDestructuringAssignmentEvaluation;
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _environment = require("../environment.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _ObjectExpression = require("../evaluators/ObjectExpression.js");
|
||||
|
||||
var _index2 = require("./index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 12.15.5.2
|
||||
function DestructuringAssignmentEvaluation(realm, pattern, value, strictCode, env) {
|
||||
if (pattern.type === "ObjectPattern") {
|
||||
// 1. Perform ? RequireObjectCoercible(value).
|
||||
(0, _index2.RequireObjectCoercible)(realm, value);
|
||||
|
||||
// 2. Return the result of performing DestructuringAssignmentEvaluation for AssignmentPropertyList using value as the argument.
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = pattern.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var property = _step.value;
|
||||
|
||||
// 1. Let name be the result of evaluating PropertyName.
|
||||
var name = (0, _ObjectExpression.EvalPropertyName)(property, env, realm, strictCode);
|
||||
|
||||
// 2. ReturnIfAbrupt(name).
|
||||
|
||||
// 3. Return the result of performing KeyedDestructuringAssignmentEvaluation of AssignmentElement with value and name as the arguments.
|
||||
KeyedDestructuringAssignmentEvaluation(realm, property.value, value, name, strictCode, env);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (pattern.type === "ArrayPattern") {
|
||||
// 1. Let iterator be ? GetIterator(value).
|
||||
var iterator = (0, _index2.GetIterator)(realm, value);
|
||||
|
||||
// 2. Let iteratorRecord be Record {[[Iterator]]: iterator, [[Done]]: false}.
|
||||
var iteratorRecord = {
|
||||
$Iterator: iterator,
|
||||
$Done: false
|
||||
};
|
||||
|
||||
// 3. Let result be the result of performing IteratorDestructuringAssignmentEvaluation of AssignmentElementList using iteratorRecord as the argument.
|
||||
var result = void 0;
|
||||
try {
|
||||
result = IteratorDestructuringAssignmentEvaluation(realm, pattern.elements, iteratorRecord, strictCode, env);
|
||||
} catch (error) {
|
||||
// 4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
|
||||
if (iteratorRecord.$Done === false && error instanceof _completions.AbruptCompletion) {
|
||||
throw (0, _index2.IteratorClose)(realm, iterator, error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 4. If iteratorRecord.[[Done]] is false, return ? IteratorClose(iterator, result).
|
||||
if (iteratorRecord.$Done === false) {
|
||||
var completion = (0, _index2.IteratorClose)(realm, iterator, new _completions.NormalCompletion(realm.intrinsics.undefined));
|
||||
if (completion instanceof _completions.AbruptCompletion) {
|
||||
throw completion;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Return result.
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 12.15.5.3
|
||||
/**
|
||||
* 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 IteratorDestructuringAssignmentEvaluation(realm, elements, iteratorRecord, strictCode, env) {
|
||||
// Check if the last element is a rest element. If so then we want to save the
|
||||
// element and handle it separately after we iterate through the other
|
||||
// formals. This also enforces that a rest element may only ever be in the
|
||||
// last position.
|
||||
var restEl = void 0;
|
||||
if (elements.length > 0) {
|
||||
var lastEl = elements[elements.length - 1];
|
||||
if (lastEl !== null && lastEl.type === "RestElement") {
|
||||
restEl = lastEl;
|
||||
elements = elements.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = elements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var element = _step2.value;
|
||||
|
||||
if (element === null) {
|
||||
// Elision handling
|
||||
|
||||
// 1. If iteratorRecord.[[Done]] is false, then
|
||||
if (iteratorRecord.$Done === false) {
|
||||
// a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||
var _next = void 0;
|
||||
try {
|
||||
_next = (0, _index2.IteratorStep)(realm, iteratorRecord.$Iterator);
|
||||
} catch (e) {
|
||||
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
// c. ReturnIfAbrupt(next).
|
||||
throw e;
|
||||
}
|
||||
// d. If next is false, set iteratorRecord.[[Done]] to true.
|
||||
if (_next === false) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
}
|
||||
// 2. Return NormalCompletion(empty).
|
||||
continue;
|
||||
}
|
||||
|
||||
// AssignmentElement : DestructuringAssignmentTarget Initializer
|
||||
|
||||
var DestructuringAssignmentTarget = void 0;
|
||||
var Initializer = void 0;
|
||||
|
||||
if (element.type === "AssignmentPattern") {
|
||||
Initializer = element.right;
|
||||
DestructuringAssignmentTarget = element.left;
|
||||
} else {
|
||||
DestructuringAssignmentTarget = element;
|
||||
}
|
||||
|
||||
var lref = void 0;
|
||||
|
||||
// 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||
//
|
||||
// The spec assumes we haven't yet distinguished between literals and
|
||||
// patterns, but our parser does that work for us. That means we check for
|
||||
// "*Pattern" instead of "*Literal" like the spec text suggests.
|
||||
if (DestructuringAssignmentTarget.type !== "ObjectPattern" && DestructuringAssignmentTarget.type !== "ArrayPattern") {
|
||||
// a. Let lref be the result of evaluating DestructuringAssignmentTarget.
|
||||
lref = env.evaluate(DestructuringAssignmentTarget, strictCode);
|
||||
|
||||
// b. ReturnIfAbrupt(lref).
|
||||
}
|
||||
|
||||
var value = void 0;
|
||||
|
||||
// 2. If iteratorRecord.[[Done]] is false, then
|
||||
if (iteratorRecord.$Done === false) {
|
||||
// a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||
var _next2 = void 0;
|
||||
try {
|
||||
_next2 = (0, _index2.IteratorStep)(realm, iteratorRecord.$Iterator);
|
||||
} catch (e) {
|
||||
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
// c. ReturnIfAbrupt(next).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// d. If next is false, set iteratorRecord.[[Done]] to true.
|
||||
if (_next2 === false) {
|
||||
iteratorRecord.$Done = true;
|
||||
// Normally this assignment would be done in step 3, but we do it
|
||||
// here so that Flow knows `value` will always be initialized by step 4.
|
||||
value = realm.intrinsics.undefined;
|
||||
} else {
|
||||
// e. Else,
|
||||
// i. Let value be IteratorValue(next).
|
||||
try {
|
||||
value = (0, _index2.IteratorValue)(realm, _next2);
|
||||
} catch (e) {
|
||||
// ii. If value is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
// iii. ReturnIfAbrupt(v).
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 3. If iteratorRecord.[[Done]] is true, let value be undefined.
|
||||
value = realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
var v = void 0;
|
||||
|
||||
// 4. If Initializer is present and value is undefined, then
|
||||
if (Initializer && value instanceof _index.UndefinedValue) {
|
||||
// a. Let defaultValue be the result of evaluating Initializer.
|
||||
var defaultValue = env.evaluate(Initializer, strictCode);
|
||||
|
||||
// b. Let v be ? GetValue(defaultValue).
|
||||
v = _singletons.Environment.GetValue(realm, defaultValue);
|
||||
} else {
|
||||
// 5. Else, let v be value.
|
||||
v = value;
|
||||
}
|
||||
|
||||
// 6. If DestructuringAssignmentTarget is an ObjectLiteral or an ArrayLiteral, then
|
||||
//
|
||||
// The spec assumes we haven't yet distinguished between literals and
|
||||
// patterns, but our parser does that work for us. That means we check for
|
||||
// "*Pattern" instead of "*Literal" like the spec text suggests.
|
||||
if (DestructuringAssignmentTarget.type === "ObjectPattern" || DestructuringAssignmentTarget.type === "ArrayPattern") {
|
||||
// a. Let nestedAssignmentPattern be the parse of the source text corresponding to DestructuringAssignmentTarget using either AssignmentPattern or AssignmentPattern[Yield] as the goal symbol depending upon whether this AssignmentElement has the [Yield] parameter.
|
||||
var _nestedAssignmentPattern = DestructuringAssignmentTarget;
|
||||
|
||||
// b. Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with v as the argument.
|
||||
DestructuringAssignmentEvaluation(realm, _nestedAssignmentPattern, v, strictCode, env);
|
||||
continue;
|
||||
}
|
||||
|
||||
// We know `lref` exists because of how the algorithm is setup, but tell
|
||||
// Flow that `lref` exists with an `invariant()`.
|
||||
(0, _invariant2.default)(lref);
|
||||
|
||||
// 7. If Initializer is present and value is undefined and IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of DestructuringAssignmentTarget are both true, then
|
||||
if (Initializer && value instanceof _index.UndefinedValue && (0, _index2.IsAnonymousFunctionDefinition)(realm, Initializer) && (0, _index2.IsIdentifierRef)(realm, DestructuringAssignmentTarget) && v instanceof _index.ObjectValue) {
|
||||
// a. Let hasNameProperty be ? HasOwnProperty(v, "name").
|
||||
var hasNameProperty = (0, _index2.HasOwnProperty)(realm, v, "name");
|
||||
|
||||
// b. If hasNameProperty is false, perform SetFunctionName(v, GetReferencedName(lref)).
|
||||
if (hasNameProperty === false) {
|
||||
// All of the nodes that may be evaluated to produce lref create
|
||||
// references. Assert this with an invariant as GetReferencedName may
|
||||
// not be called with a value.
|
||||
(0, _invariant2.default)(lref instanceof _environment.Reference);
|
||||
|
||||
_singletons.Functions.SetFunctionName(realm, v, _singletons.Environment.GetReferencedName(realm, lref));
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Return ? PutValue(lref, v).
|
||||
_singletons.Properties.PutValue(realm, lref, v);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle the rest element if we have one.
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (restEl) {
|
||||
// AssignmentRestElement : ...DestructuringAssignmentTarget
|
||||
var DestructuringAssignmentTarget = restEl.argument;
|
||||
|
||||
var lref = void 0;
|
||||
|
||||
// 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||
//
|
||||
// The spec assumes we haven't yet distinguished between literals and
|
||||
// patterns, but our parser does that work for us. That means we check for
|
||||
// "*Pattern" instead of "*Literal" like the spec text suggests.
|
||||
if (DestructuringAssignmentTarget.type !== "ObjectPattern" && DestructuringAssignmentTarget.type !== "ArrayPattern") {
|
||||
// a. Let lref be the result of evaluating DestructuringAssignmentTarget.
|
||||
lref = env.evaluate(DestructuringAssignmentTarget, strictCode);
|
||||
|
||||
// b. ReturnIfAbrupt(lref).
|
||||
}
|
||||
|
||||
// 2. Let A be ArrayCreate(0).
|
||||
var A = _singletons.Create.ArrayCreate(realm, 0);
|
||||
|
||||
// 3. Let n be 0.
|
||||
var n = 0;
|
||||
|
||||
// 4. Repeat while iteratorRecord.[[Done]] is false,
|
||||
while (iteratorRecord.$Done === false) {
|
||||
// a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||
var next = void 0;
|
||||
try {
|
||||
next = (0, _index2.IteratorStep)(realm, iteratorRecord.$Iterator);
|
||||
} catch (e) {
|
||||
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
// c. ReturnIfAbrupt(next).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// d. If next is false, set iteratorRecord.[[Done]] to true.
|
||||
if (next === false) {
|
||||
iteratorRecord.$Done = true;
|
||||
} else {
|
||||
// e. Else,
|
||||
// i. Let nextValue be IteratorValue(next).
|
||||
var nextValue = void 0;
|
||||
try {
|
||||
nextValue = (0, _index2.IteratorValue)(realm, next);
|
||||
} catch (e) {
|
||||
// ii. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
// iii. ReturnIfAbrupt(nextValue).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// iv. Let status be CreateDataProperty(A, ! ToString(n), nextValue).
|
||||
var status = _singletons.Create.CreateDataProperty(realm, A, n.toString(), nextValue);
|
||||
|
||||
// v. Assert: status is true.
|
||||
(0, _invariant2.default)(status, "expected to create data property");
|
||||
|
||||
// vi. Increment n by 1.
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||
if (DestructuringAssignmentTarget.type !== "ObjectPattern" && DestructuringAssignmentTarget.type !== "ArrayPattern") {
|
||||
// `lref` will always be defined at this point. Let Flow know with an
|
||||
// invariant.
|
||||
(0, _invariant2.default)(lref);
|
||||
|
||||
// a. Return ? PutValue(lref, A).
|
||||
_singletons.Properties.PutValue(realm, lref, A);
|
||||
} else {
|
||||
// 6. Let nestedAssignmentPattern be the parse of the source text corresponding to DestructuringAssignmentTarget using either AssignmentPattern or AssignmentPattern[Yield] as the goal symbol depending upon whether this AssignmentElement has the [Yield] parameter.
|
||||
var nestedAssignmentPattern = DestructuringAssignmentTarget;
|
||||
|
||||
// 7. Return the result of performing DestructuringAssignmentEvaluation of nestedAssignmentPattern with A as the argument.
|
||||
DestructuringAssignmentEvaluation(realm, nestedAssignmentPattern, A, strictCode, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 12.15.5.4
|
||||
function KeyedDestructuringAssignmentEvaluation(realm, node, value, propertyName, strictCode, env) {
|
||||
var DestructuringAssignmentTarget = void 0;
|
||||
var Initializer = void 0;
|
||||
|
||||
if (node.type === "AssignmentPattern") {
|
||||
Initializer = node.right;
|
||||
DestructuringAssignmentTarget = node.left;
|
||||
} else {
|
||||
DestructuringAssignmentTarget = node;
|
||||
}
|
||||
|
||||
var lref = void 0;
|
||||
|
||||
// 1. If DestructuringAssignmentTarget is neither an ObjectLiteral nor an ArrayLiteral, then
|
||||
//
|
||||
// The spec assumes we haven't yet distinguished between literals and
|
||||
// patterns, but our parser does that work for us. That means we check for
|
||||
// "*Pattern" instead of "*Literal" like the spec text suggests.
|
||||
if (DestructuringAssignmentTarget.type !== "ObjectPattern" && DestructuringAssignmentTarget.type !== "ArrayPattern") {
|
||||
// a. Let lref be the result of evaluating DestructuringAssignmentTarget.
|
||||
lref = env.evaluate(DestructuringAssignmentTarget, strictCode);
|
||||
|
||||
// b. ReturnIfAbrupt(lref).
|
||||
}
|
||||
|
||||
var rhsValue = void 0;
|
||||
|
||||
// 2. Let v be ? GetV(value, propertyName).
|
||||
var v = (0, _index2.GetV)(realm, value, propertyName);
|
||||
|
||||
// 3. If Initializer is present and v is undefined, then
|
||||
if (Initializer && v instanceof _index.UndefinedValue) {
|
||||
// a. Let defaultValue be the result of evaluating Initializer.
|
||||
var defaultValue = env.evaluate(Initializer, strictCode);
|
||||
|
||||
// b. Let rhsValue be ? GetValue(defaultValue).
|
||||
rhsValue = _singletons.Environment.GetValue(realm, defaultValue);
|
||||
} else {
|
||||
// 4. Else, let rhsValue be v.
|
||||
rhsValue = v;
|
||||
}
|
||||
|
||||
// 5. If DestructuringAssignmentTarget is an ObjectLiteral or an ArrayLiteral, then
|
||||
//
|
||||
// The spec assumes we haven't yet distinguished between literals and
|
||||
// patterns, but our parser does that work for us. That means we check for
|
||||
// "*Pattern" instead of "*Literal" like the spec text suggests.
|
||||
if (DestructuringAssignmentTarget.type === "ObjectPattern" || DestructuringAssignmentTarget.type === "ArrayPattern") {
|
||||
// a. Let assignmentPattern be the parse of the source text corresponding to DestructuringAssignmentTarget using either AssignmentPattern or AssignmentPattern[Yield] as the goal symbol depending upon whether this AssignmentElement has the [Yield] parameter.
|
||||
var assignmentPattern = DestructuringAssignmentTarget;
|
||||
|
||||
// b. Return the result of performing DestructuringAssignmentEvaluation of assignmentPattern with rhsValue as the argument.
|
||||
return DestructuringAssignmentEvaluation(realm, assignmentPattern, rhsValue, strictCode, env);
|
||||
}
|
||||
|
||||
// `lref` will always be defined at this point. Let Flow know with an
|
||||
// invariant.
|
||||
(0, _invariant2.default)(lref);
|
||||
|
||||
// 6. If Initializer is present and v is undefined and IsAnonymousFunctionDefinition(Initializer) and IsIdentifierRef of DestructuringAssignmentTarget are both true, then
|
||||
if (Initializer && v instanceof _index.UndefinedValue && (0, _index2.IsAnonymousFunctionDefinition)(realm, Initializer) && (0, _index2.IsIdentifierRef)(realm, DestructuringAssignmentTarget) && rhsValue instanceof _index.ObjectValue) {
|
||||
// a. Let hasNameProperty be ? HasOwnProperty(rhsValue, "name").
|
||||
var hasNameProperty = (0, _index2.HasOwnProperty)(realm, rhsValue, "name");
|
||||
|
||||
// b. If hasNameProperty is false, perform SetFunctionName(rhsValue, GetReferencedName(lref)).
|
||||
if (hasNameProperty === false) {
|
||||
// All of the nodes that may be evaluated to produce lref create
|
||||
// references. Assert this with an invariant as GetReferencedName may
|
||||
// not be called with a value.
|
||||
(0, _invariant2.default)(lref instanceof _environment.Reference);
|
||||
|
||||
_singletons.Functions.SetFunctionName(realm, rhsValue, _singletons.Environment.GetReferencedName(realm, lref));
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Return ? PutValue(lref, rhsValue).
|
||||
return _singletons.Properties.PutValue(realm, lref, rhsValue);
|
||||
}
|
||||
//# sourceMappingURL=destructuring.js.map
|
||||
1
build/node_modules/prepack/lib/methods/destructuring.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/destructuring.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1301
build/node_modules/prepack/lib/methods/environment.js
generated
vendored
Normal file
1301
build/node_modules/prepack/lib/methods/environment.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
build/node_modules/prepack/lib/methods/environment.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/environment.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
2192
build/node_modules/prepack/lib/methods/function.js
generated
vendored
Normal file
2192
build/node_modules/prepack/lib/methods/function.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
build/node_modules/prepack/lib/methods/function.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/function.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
173
build/node_modules/prepack/lib/methods/generator.js
generated
vendored
Normal file
173
build/node_modules/prepack/lib/methods/generator.js
generated
vendored
Normal file
@@ -0,0 +1,173 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.GeneratorStart = GeneratorStart;
|
||||
exports.GeneratorValidate = GeneratorValidate;
|
||||
exports.GeneratorResume = GeneratorResume;
|
||||
exports.GeneratorResumeAbrupt = GeneratorResumeAbrupt;
|
||||
exports.GeneratorYield = GeneratorYield;
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA26225.3.3.1
|
||||
function GeneratorStart(realm, generator, generatorBody) {
|
||||
// Note that generator is a new object, and we can thus write to internal slots
|
||||
(0, _invariant2.default)(realm.isNewObject(generator));
|
||||
|
||||
// 1. Assert: The value of generator.[[GeneratorState]] is undefined.
|
||||
(0, _invariant2.default)(generator instanceof _index.ObjectValue && generator.$GeneratorState === undefined, "The value of generator.[[GeneratorState]] is undefined");
|
||||
|
||||
// 2. Let genContext be the running execution context.
|
||||
var genContext = realm.getRunningContext();
|
||||
|
||||
// 3. Set the Generator component of genContext to generator.
|
||||
|
||||
// 4. Set the code evaluation state of genContext such that when evaluation is resumed for that execution context the following steps will be performed:
|
||||
// a. Let result be the result of evaluating generatorBody.
|
||||
// b. Assert: If we return here, the generator either threw an exception or performed either an implicit or explicit return.
|
||||
// c. Remove genContext from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
|
||||
// d. Set generator.[[GeneratorState]] to "completed".
|
||||
// e. Once a generator enters the "completed" state it never leaves it and its associated execution context is never resumed. Any execution state associated with generator can be discarded at this point.
|
||||
// f. If result is a normal completion, let resultValue be undefined.
|
||||
// g. Else,
|
||||
// i. If result.[[Type]] is return, let resultValue be result.[[Value]].
|
||||
// ii. Else, return Completion(result).
|
||||
// h. Return CreateIterResultObject(resultValue, true).
|
||||
|
||||
// 5. Set generator.[[GeneratorContext]] to genContext.
|
||||
generator.$GeneratorContext = genContext;
|
||||
|
||||
// 6. Set generator.[[GeneratorState]] to "suspendedStart".
|
||||
generator.$GeneratorState = "suspendedStart";
|
||||
|
||||
// 7. Return NormalCompletion(undefined).
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA26225.3.3.2
|
||||
/**
|
||||
* 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 GeneratorValidate(realm, generator) {
|
||||
// 1. If Type(generator) is not Object, throw a TypeError exception.
|
||||
if (!(generator instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "Type(generator) is not Object");
|
||||
}
|
||||
|
||||
// 2. If generator does not have a [[GeneratorState]] internal slot, throw a TypeError exception.
|
||||
if (!("$GeneratorState" in generator)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "Type(generator) is not Object");
|
||||
}
|
||||
|
||||
// 3. Assert: generator also has a [[GeneratorContext]] internal slot.
|
||||
(0, _invariant2.default)("$GeneratorContext" in generator);
|
||||
|
||||
// 4. Let state be generator.[[GeneratorState]].
|
||||
var state = generator.$GeneratorState;
|
||||
|
||||
// 5. If state is "executing", throw a TypeError exception.
|
||||
if (state === "executing") {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "Type(generator) is not Object");
|
||||
}
|
||||
|
||||
// 6. Return state.
|
||||
return state;
|
||||
}
|
||||
|
||||
// ECMA26225.3.3.3
|
||||
function GeneratorResume(realm, generator, value) {
|
||||
// 1. Let state be ? GeneratorValidate(generator).
|
||||
var state = GeneratorValidate(realm, generator);
|
||||
(0, _invariant2.default)(generator instanceof _index.ObjectValue);
|
||||
|
||||
// 2. If state is "completed", return CreateIterResultObject(undefined, true).
|
||||
if (state === "completed") return _singletons.Create.CreateIterResultObject(realm, realm.intrinsics.undefined, true);
|
||||
|
||||
// 3. Assert: state is either "suspendedStart" or "suspendedYield".
|
||||
(0, _invariant2.default)(state === "suspendedStart" || state === "suspendedYield", "state is either 'suspendedStart' or 'suspendedYield'");
|
||||
|
||||
// 4. Let genContext be generator.[[GeneratorContext]].
|
||||
var genContext = generator.$GeneratorContext;
|
||||
(0, _invariant2.default)(genContext);
|
||||
|
||||
// 5. Let methodContext be the running execution context.
|
||||
var methodContext = realm.getRunningContext();
|
||||
|
||||
// 6. Suspend methodContext.
|
||||
methodContext.suspend();
|
||||
|
||||
// 7. Set generator.[[GeneratorState]] to "executing".
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, generator, "$GeneratorState").$GeneratorState = "executing";
|
||||
|
||||
// 8. Push genContext onto the execution context stack; genContext is now the running execution context.
|
||||
realm.pushContext(genContext);
|
||||
|
||||
// 9. Resume the suspended evaluation of genContext using NormalCompletion(value) as the result of the operation that suspended it. Let result be the value returned by the resumed computation.
|
||||
var result = genContext.resume();
|
||||
|
||||
// 10. Assert: When we return here, genContext has already been removed from the execution context stack and methodContext is the currently running execution context.
|
||||
(0, _invariant2.default)(realm.getRunningContext() === methodContext);
|
||||
|
||||
// 11. Return Completion(result).
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA26225.3.3.4
|
||||
function GeneratorResumeAbrupt(realm, generator, abruptCompletion) {
|
||||
// 1. Let state be ? GeneratorValidate(generator).
|
||||
// 2. If state is "suspendedStart", then
|
||||
// a. Set generator.[[GeneratorState]] to "completed".
|
||||
// b. Once a generator enters the "completed" state it never leaves it and its associated execution context is never resumed. Any execution state associated with generator can be discarded at this point.
|
||||
// c. Let state be "completed".
|
||||
// 3. If state is "completed", then
|
||||
// a. If abruptCompletion.[[Type]] is return, then
|
||||
// i. Return CreateIterResultObject(abruptCompletion.[[Value]], true).
|
||||
// b. Return Completion(abruptCompletion).
|
||||
// 4. Assert: state is "suspendedYield".
|
||||
// 5. Let genContext be generator.[[GeneratorContext]].
|
||||
// 6. Let methodContext be the running execution context.
|
||||
// 7. Suspend methodContext.
|
||||
// 8. Set generator.[[GeneratorState]] to "executing".
|
||||
// 9. Push genContext onto the execution context stack; genContext is now the running execution context.
|
||||
// 10. Resume the suspended evaluation of genContext using abruptCompletion as the result of the operation that suspended it. Let result be the completion record returned by the resumed computation.
|
||||
// 11. Assert: When we return here, genContext has already been removed from the execution context stack and methodContext is the currently running execution context.
|
||||
// 12. Return Completion(result).
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA26225.3.3.5
|
||||
function GeneratorYield(realm, iterNextObj) {
|
||||
// 1. Assert: iterNextObj is an Object that implements the IteratorResult interface.
|
||||
|
||||
// 2. Let genContext be the running execution context.
|
||||
// 3. Assert: genContext is the execution context of a generator.
|
||||
// 4. Let generator be the value of the Generator component of genContext.
|
||||
// 5. Set generator.[[GeneratorState]] to "suspendedYield".
|
||||
// 6. Remove genContext from the execution context stack and restore the execution context that is at the top of the execution context stack as the running execution context.
|
||||
// 7. Set the code evaluation state of genContext such that when evaluation is resumed with a Completion resumptionValue the following steps will be performed:
|
||||
// a. Return resumptionValue.
|
||||
// b. NOTE: This returns to the evaluation of the YieldExpression production that originally called this abstract operation.
|
||||
// 8. Return NormalCompletion(iterNextObj).
|
||||
return realm.intrinsics.undefined;
|
||||
|
||||
// 9. NOTE: This returns to the evaluation of the operation that had most previously resumed evaluation of genContext.
|
||||
}
|
||||
//# sourceMappingURL=generator.js.map
|
||||
1
build/node_modules/prepack/lib/methods/generator.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/generator.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
532
build/node_modules/prepack/lib/methods/get.js
generated
vendored
Normal file
532
build/node_modules/prepack/lib/methods/get.js
generated
vendored
Normal file
@@ -0,0 +1,532 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
exports.GetFunctionRealm = GetFunctionRealm;
|
||||
exports.OrdinaryGet = OrdinaryGet;
|
||||
exports.GetGlobalObject = GetGlobalObject;
|
||||
exports.GetSubstitution = GetSubstitution;
|
||||
exports.GetMethod = GetMethod;
|
||||
exports.GetPrototypeFromConstructor = GetPrototypeFromConstructor;
|
||||
exports.Get = Get;
|
||||
exports.GetV = GetV;
|
||||
exports.GetThisValue = GetThisValue;
|
||||
exports.GetNewTarget = GetNewTarget;
|
||||
exports.GetTemplateObject = GetTemplateObject;
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _realm = require("../realm.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _environment = require("../environment.js");
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _integrity = require("./integrity.js");
|
||||
|
||||
var _index2 = require("./index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 7.3.22
|
||||
function GetFunctionRealm(realm, obj) {
|
||||
// 1. Assert: obj is a callable object.
|
||||
(0, _invariant2.default)((0, _index2.IsCallable)(realm, obj), "expected callable object");
|
||||
|
||||
// 2. If obj has a [[Realm]] internal slot, then
|
||||
if (obj.$Realm) {
|
||||
// a. Return obj's [[Realm]] internal slot.
|
||||
return obj.$Realm;
|
||||
}
|
||||
|
||||
// 3. If obj is a Bound Function exotic object, then
|
||||
if (obj instanceof _index.BoundFunctionValue) {
|
||||
// a. Let target be obj's [[BoundTargetFunction]] internal slot.
|
||||
var target = obj.$BoundTargetFunction;
|
||||
|
||||
// b. Return ? GetFunctionRealm(target).
|
||||
return GetFunctionRealm(realm, target);
|
||||
}
|
||||
|
||||
// 4. If obj is a Proxy exotic object, then
|
||||
if (obj instanceof _index.ProxyValue) {
|
||||
// a. If the value of the [[ProxyHandler]] internal slot of obj is null, throw a TypeError exception.
|
||||
if (obj.$ProxyHandler instanceof _index.NullValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "proxy handler is null");
|
||||
}
|
||||
(0, _invariant2.default)(obj.$ProxyTarget instanceof _index.ObjectValue);
|
||||
|
||||
// b. Let proxyTarget be the value of obj's [[ProxyTarget]] internal slot.
|
||||
var proxyTarget = obj.$ProxyTarget;
|
||||
|
||||
// c. Return ? GetFunctionRealm(proxyTarget).
|
||||
return GetFunctionRealm(realm, proxyTarget);
|
||||
}
|
||||
|
||||
// 5. Return the current Realm Record.
|
||||
return realm;
|
||||
}
|
||||
|
||||
// ECMA262 9.1.8.1
|
||||
function OrdinaryGet(realm, O, P, Receiver, dataOnly) {
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsPropertyKey)(realm, P), "expected property key");
|
||||
|
||||
// 2. Let desc be ? O.[[GetOwnProperty]](P).
|
||||
var desc = O.$GetOwnProperty(P);
|
||||
if (desc !== undefined && desc.joinCondition !== undefined) {
|
||||
// joined descriptors need special treatment
|
||||
var joinCondition = desc.joinCondition;
|
||||
if (joinCondition !== undefined) {
|
||||
var descriptor2 = desc.descriptor2;
|
||||
desc = desc.descriptor1;
|
||||
|
||||
var _Path$withCondition = _singletons.Path.withCondition(joinCondition, function () {
|
||||
return desc !== undefined ? realm.evaluateForEffects(function () {
|
||||
return OrdinaryGetHelper();
|
||||
}) : (0, _realm.construct_empty_effects)(realm);
|
||||
}),
|
||||
_Path$withCondition2 = _slicedToArray(_Path$withCondition, 5),
|
||||
compl1 = _Path$withCondition2[0],
|
||||
gen1 = _Path$withCondition2[1],
|
||||
bindings1 = _Path$withCondition2[2],
|
||||
properties1 = _Path$withCondition2[3],
|
||||
createdObj1 = _Path$withCondition2[4];
|
||||
|
||||
desc = descriptor2;
|
||||
|
||||
var _Path$withInverseCond = _singletons.Path.withInverseCondition(joinCondition, function () {
|
||||
return desc !== undefined ? realm.evaluateForEffects(function () {
|
||||
return OrdinaryGetHelper();
|
||||
}) : (0, _realm.construct_empty_effects)(realm);
|
||||
}),
|
||||
_Path$withInverseCond2 = _slicedToArray(_Path$withInverseCond, 5),
|
||||
compl2 = _Path$withInverseCond2[0],
|
||||
gen2 = _Path$withInverseCond2[1],
|
||||
bindings2 = _Path$withInverseCond2[2],
|
||||
properties2 = _Path$withInverseCond2[3],
|
||||
createdObj2 = _Path$withInverseCond2[4];
|
||||
|
||||
// Join the effects, creating an abstract view of what happened, regardless
|
||||
// of the actual value of ownDesc.joinCondition.
|
||||
|
||||
|
||||
var joinedEffects = _singletons.Join.joinEffects(realm, joinCondition, [compl1, gen1, bindings1, properties1, createdObj1], [compl2, gen2, bindings2, properties2, createdObj2]);
|
||||
var completion = joinedEffects[0];
|
||||
if (completion instanceof _completions.PossiblyNormalCompletion) {
|
||||
// in this case one of the branches may complete abruptly, which means that
|
||||
// not all control flow branches join into one flow at this point.
|
||||
// Consequently we have to continue tracking changes until the point where
|
||||
// all the branches come together into one.
|
||||
completion = realm.composeWithSavedCompletion(completion);
|
||||
}
|
||||
// Note that the effects of (non joining) abrupt branches are not included
|
||||
// in joinedEffects, but are tracked separately inside completion.
|
||||
realm.applyEffects(joinedEffects);
|
||||
|
||||
// return or throw completion
|
||||
if (completion instanceof _completions.AbruptCompletion) throw completion;
|
||||
(0, _invariant2.default)(completion instanceof _index.Value);
|
||||
return completion;
|
||||
}
|
||||
}
|
||||
|
||||
return OrdinaryGetHelper();
|
||||
|
||||
function OrdinaryGetHelper() {
|
||||
var descValue = !desc ? realm.intrinsics.undefined : desc.value === undefined ? realm.intrinsics.undefined : desc.value;
|
||||
(0, _invariant2.default)(descValue instanceof _index.Value);
|
||||
|
||||
// 3. If desc is undefined, then
|
||||
if (!desc || descValue.mightHaveBeenDeleted()) {
|
||||
// a. Let parent be ? O.[[GetPrototypeOf]]().
|
||||
var parent = O.$GetPrototypeOf();
|
||||
|
||||
// b. If parent is null, return undefined.
|
||||
if (parent instanceof _index.NullValue) {
|
||||
// Return the property value since it is now known to be the right value
|
||||
// even in the case when it is empty.
|
||||
return descValue;
|
||||
}
|
||||
|
||||
// c. Return ? parent.[[Get]](P, Receiver).
|
||||
if (descValue.mightHaveBeenDeleted() && descValue instanceof _index.AbstractValue) {
|
||||
// We don't know for sure that O.P does not exist.
|
||||
var parentVal = OrdinaryGet(realm, parent, P, descValue, true);
|
||||
if (parentVal instanceof _index.UndefinedValue)
|
||||
// even O.P returns undefined it is still the right value.
|
||||
return descValue;
|
||||
// Join with parent value with descValue because the actual value will be
|
||||
// descValue unless it is empty.
|
||||
// Only get the parent value if it does not involve a getter call.
|
||||
// Use a property get for the joined value since it does the check for empty.
|
||||
var cond = _index.AbstractValue.createFromBinaryOp(realm, "!==", descValue, realm.intrinsics.empty);
|
||||
return _singletons.Join.joinValuesAsConditional(realm, cond, descValue, parentVal);
|
||||
}
|
||||
(0, _invariant2.default)(!desc || descValue instanceof _index.EmptyValue);
|
||||
return parent.$Get(P, Receiver);
|
||||
}
|
||||
|
||||
// 4. If IsDataDescriptor(desc) is true, return desc.[[Value]].
|
||||
if ((0, _index2.IsDataDescriptor)(realm, desc)) return descValue;
|
||||
if (dataOnly) {
|
||||
(0, _invariant2.default)(descValue instanceof _index.AbstractValue);
|
||||
_index.AbstractValue.reportIntrospectionError(descValue);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
|
||||
// 5. Assert: IsAccessorDescriptor(desc) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsAccessorDescriptor)(realm, desc), "expected accessor descriptor");
|
||||
|
||||
// 6. Let getter be desc.[[Get]].
|
||||
var getter = desc.get;
|
||||
|
||||
// 7. If getter is undefined, return undefined.
|
||||
if (!getter || getter instanceof _index.UndefinedValue) return realm.intrinsics.undefined;
|
||||
|
||||
// 8. Return ? Call(getter, Receiver).
|
||||
return (0, _index2.Call)(realm, getter, Receiver);
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 8.3.6
|
||||
function GetGlobalObject(realm) {
|
||||
// 1. Let ctx be the running execution context.
|
||||
var ctx = realm.getRunningContext();
|
||||
|
||||
// 2. Let currentRealm be ctx's Realm.
|
||||
var currentRealm = ctx.realm;
|
||||
|
||||
// 3. Return currentRealm.[[GlobalObject]].
|
||||
return currentRealm.$GlobalObject;
|
||||
}
|
||||
|
||||
// ECMA262 21.1.3.14.1
|
||||
function GetSubstitution(realm, matched, str, position, captures, replacement) {
|
||||
// 1. Assert: Type(matched) is String.
|
||||
(0, _invariant2.default)(typeof matched === "string", "expected matched to be a stirng");
|
||||
|
||||
// 2. Let matchLength be the number of code units in matched.
|
||||
var matchLength = matched.length;
|
||||
|
||||
// 3. Assert: Type(str) is String.
|
||||
(0, _invariant2.default)(typeof str === "string", "expected matched to be a stirng");
|
||||
|
||||
// 4. Let stringLength be the number of code units in str.
|
||||
var stringLength = str.length;
|
||||
|
||||
// 5. Assert: position is a nonnegative integer.
|
||||
(0, _invariant2.default)(position >= 0, "expected position to be a nonegative integer");
|
||||
|
||||
// 6. Assert: position ≤ stringLength.
|
||||
(0, _invariant2.default)(position <= stringLength, "expected position to be less than string length");
|
||||
|
||||
// 7. Assert: captures is a possibly empty List of Strings.
|
||||
(0, _invariant2.default)(Array.isArray(captures), "expected captures to be an array");
|
||||
|
||||
// 8. Assert: Type(replacement) is String.
|
||||
(0, _invariant2.default)(typeof replacement === "string", "expected replacement to be a stirng");
|
||||
|
||||
// 9. Let tailPos be position + matchLength.
|
||||
var tailPos = position + matchLength;
|
||||
|
||||
// 10. Let m be the number of elements in captures.
|
||||
var m = captures.length;
|
||||
|
||||
// 11. Let result be a String value derived from replacement by copying code unit elements
|
||||
// from replacement to result while performing replacements as specified in Table 46.
|
||||
// These $ replacements are done left-to-right, and, once such a replacement is performed,
|
||||
// the new replacement text is not subject to further replacements.
|
||||
var result = "";
|
||||
for (var i = 0; i < replacement.length; ++i) {
|
||||
var ch = replacement.charAt(i);
|
||||
if (ch !== "$" || i + 1 >= replacement.length) {
|
||||
result += ch;
|
||||
continue;
|
||||
}
|
||||
var peek = replacement.charAt(i + 1);
|
||||
if (peek === "&") {
|
||||
result += matched;
|
||||
} else if (peek === "$") {
|
||||
result += "$";
|
||||
} else if (peek === "`") {
|
||||
result += str.substr(0, position);
|
||||
} else if (peek === "'") {
|
||||
result += str.substr(tailPos);
|
||||
} else if (peek >= "0" && peek <= "9") {
|
||||
var idx = peek.charCodeAt(0) - "0".charCodeAt(0);
|
||||
if (i + 2 < replacement.length) {
|
||||
var peek2 = replacement.charAt(i + 2);
|
||||
if (peek2 >= "0" && peek2 <= "9") {
|
||||
var newIdx = idx * 10 + (peek2.charCodeAt(0) - "0".charCodeAt(0));
|
||||
if (newIdx <= m) {
|
||||
idx = newIdx;
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (idx > 0 && idx <= m) {
|
||||
result += captures[idx - 1] || "";
|
||||
} else {
|
||||
result += "$" + idx;
|
||||
}
|
||||
} else {
|
||||
result += "$" + peek;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
// 12. Return result.
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.9
|
||||
function GetMethod(realm, V, P) {
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsPropertyKey)(realm, P), "expected property key");
|
||||
|
||||
// 2. Let func be ? GetV(V, P).
|
||||
var func = GetV(realm, V, P);
|
||||
|
||||
// 3. If func is either undefined or null, return undefined.
|
||||
if ((0, _index2.HasSomeCompatibleType)(func, _index.NullValue, _index.UndefinedValue)) {
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// 4. If IsCallable(func) is false, throw a TypeError exception.
|
||||
if (!(0, _index2.IsCallable)(realm, func)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "not callable");
|
||||
}
|
||||
|
||||
// 5. Return func.
|
||||
return func;
|
||||
}
|
||||
|
||||
// ECMA262 9.1.14
|
||||
function GetPrototypeFromConstructor(realm, constructor, intrinsicDefaultProto) {
|
||||
// 1. Assert: intrinsicDefaultProto is a String value that is this specification's name of an intrinsic
|
||||
// object. The corresponding object must be an intrinsic that is intended to be used as the [[Prototype]]
|
||||
// value of an object.
|
||||
(0, _invariant2.default)(realm.intrinsics[intrinsicDefaultProto], "not a valid proto ref");
|
||||
|
||||
// 2. Assert: IsCallable(constructor) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsCallable)(realm, constructor) === true, "expected constructor to be callable");
|
||||
|
||||
// 3. Let proto be ? Get(constructor, "prototype").
|
||||
var proto = Get(realm, constructor, new _index.StringValue(realm, "prototype"));
|
||||
|
||||
// 4. If Type(proto) is not Object, then
|
||||
if (!(proto instanceof _index.ObjectValue)) {
|
||||
// a. Let realm be ? GetFunctionRealm(constructor).
|
||||
realm = GetFunctionRealm(realm, constructor);
|
||||
|
||||
// b. Let proto be realm's intrinsic object named intrinsicDefaultProto.
|
||||
proto = realm.intrinsics[intrinsicDefaultProto];
|
||||
}
|
||||
|
||||
// 5. Return proto.
|
||||
return proto;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.1
|
||||
function Get(realm, O, P) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue || O instanceof _index.AbstractObjectValue, "Not an object value");
|
||||
|
||||
// 2. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsPropertyKey)(realm, P), "Not a valid property key");
|
||||
|
||||
// 3. Return ? O.[[Get]](P, O).
|
||||
return O.$Get(P, O);
|
||||
}
|
||||
|
||||
// ECMA262 7.3.2
|
||||
function GetV(realm, V, P) {
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index2.IsPropertyKey)(realm, P), "Not a valid property key");
|
||||
|
||||
// 2. Let O be ? ToObject(V).
|
||||
var O = _singletons.To.ToObjectPartial(realm, V);
|
||||
|
||||
// 3. Return ? O.[[Get]](P, V).
|
||||
return O.$Get(P, V);
|
||||
}
|
||||
|
||||
// ECMA262 6.2.3.3
|
||||
function GetThisValue(realm, V) {
|
||||
// 1. Assert: IsPropertyReference(V) is true.
|
||||
(0, _invariant2.default)(_singletons.Environment.IsPropertyReference(realm, V), "expected property reference");
|
||||
|
||||
// 2. If IsSuperReference(V) is true, then
|
||||
if (_singletons.Environment.IsSuperReference(realm, V)) {
|
||||
(0, _invariant2.default)(V.thisValue !== undefined);
|
||||
// a. Return the value of the thisValue component of the reference V.
|
||||
return V.thisValue;
|
||||
}
|
||||
|
||||
// 3. Return GetBase(V).
|
||||
var result = _singletons.Environment.GetBase(realm, V);
|
||||
(0, _invariant2.default)(result instanceof _index.Value);
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA262 8.3.5
|
||||
function GetNewTarget(realm) {
|
||||
// 1. Let envRec be GetThisEnvironment( ).
|
||||
var envRec = _singletons.Environment.GetThisEnvironment(realm);
|
||||
|
||||
// 2. Assert: envRec has a [[NewTarget]] field.
|
||||
if (!("$NewTarget" in envRec)) {
|
||||
// In the spec we should not get here because earlier static checks are supposed to prevent it.
|
||||
// However, we do not have an appropriate place to do this check earlier.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "new.target not allowed here");
|
||||
}
|
||||
|
||||
// 3. Return envRec.[[NewTarget]].
|
||||
return envRec.$NewTarget || realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
function GetTemplateObject(realm, templateLiteral) {
|
||||
// 1. Let rawStrings be TemplateStrings of templateLiteral with argument true.
|
||||
var rawStrings = templateLiteral.quasis.map(function (quasi) {
|
||||
return quasi.value.raw;
|
||||
});
|
||||
|
||||
// 2. Let realm be the current Realm Record.
|
||||
realm;
|
||||
|
||||
// 3. Let templateRegistry be realm.[[TemplateMap]].
|
||||
var templateRegistry = realm.$TemplateMap;
|
||||
|
||||
// 4. For each element e of templateRegistry, do
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = templateRegistry[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var e = _step.value;
|
||||
|
||||
var same = void 0;
|
||||
if (e.$Strings.length === rawStrings.length) {
|
||||
same = true;
|
||||
for (var i = 0; i < rawStrings.length; ++i) {
|
||||
if (e.$Strings[i] !== rawStrings[i]) {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
same = false;
|
||||
}
|
||||
|
||||
// a. If e.[[Strings]] and rawStrings contain the same values in the same order, then
|
||||
if (same) {
|
||||
// i. Return e.[[Array]].
|
||||
return e.$Array;
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Let cookedStrings be TemplateStrings of templateLiteral with argument false.
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cookedStrings = templateLiteral.quasis.map(function (quasi) {
|
||||
return quasi.value.cooked;
|
||||
});
|
||||
|
||||
// 6. Let count be the number of elements in the List cookedStrings.
|
||||
var count = cookedStrings.length;
|
||||
|
||||
// 7. Let template be ArrayCreate(count).
|
||||
var template = _singletons.Create.ArrayCreate(realm, count);
|
||||
|
||||
// 8. Let rawObj be ArrayCreate(count).
|
||||
var rawObj = _singletons.Create.ArrayCreate(realm, count);
|
||||
|
||||
// 9. Let index be 0.
|
||||
var index = 0;
|
||||
|
||||
// 10. Repeat while index < count
|
||||
while (index < count) {
|
||||
// a. Let prop be ! ToString(index).
|
||||
var prop = _singletons.To.ToString(realm, new _index.NumberValue(realm, index));
|
||||
|
||||
// b. Let cookedValue be the String value cookedStrings[index].
|
||||
var cookedValue = new _index.StringValue(realm, cookedStrings[index]);
|
||||
|
||||
// c. Call template.[[DefineOwnProperty]](prop, PropertyDescriptor{[[Value]]: cookedValue, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false}).
|
||||
template.$DefineOwnProperty(prop, {
|
||||
value: cookedValue,
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// d. Let rawValue be the String value rawStrings[index].
|
||||
var rawValue = new _index.StringValue(realm, rawStrings[index]);
|
||||
|
||||
// e. Call rawObj.[[DefineOwnProperty]](prop, PropertyDescriptor{[[Value]]: rawValue, [[Writable]]: false, [[Enumerable]]: true, [[Configurable]]: false}).
|
||||
rawObj.$DefineOwnProperty(prop, {
|
||||
value: rawValue,
|
||||
writable: false,
|
||||
enumerable: true,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// f. Let index be index+1.
|
||||
index = index + 1;
|
||||
}
|
||||
|
||||
// 11. Perform SetIntegrityLevel(rawObj, "frozen").
|
||||
(0, _integrity.SetIntegrityLevel)(realm, rawObj, "frozen");
|
||||
|
||||
// 12. Call template.[[DefineOwnProperty]]("raw", PropertyDescriptor{[[Value]]: rawObj, [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false}).
|
||||
template.$DefineOwnProperty("raw", {
|
||||
value: rawObj,
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// 13. Perform SetIntegrityLevel(template, "frozen").
|
||||
(0, _integrity.SetIntegrityLevel)(realm, template, "frozen");
|
||||
|
||||
// 14. Append the Record{[[Strings]]: rawStrings, [[Array]]: template} to templateRegistry.
|
||||
templateRegistry.push({ $Strings: rawStrings, $Array: template });
|
||||
|
||||
// 15. Return template.
|
||||
return template;
|
||||
}
|
||||
//# sourceMappingURL=get.js.map
|
||||
1
build/node_modules/prepack/lib/methods/get.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/get.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
162
build/node_modules/prepack/lib/methods/has.js
generated
vendored
Normal file
162
build/node_modules/prepack/lib/methods/has.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.HasName = HasName;
|
||||
exports.HasProperty = HasProperty;
|
||||
exports.HasOwnProperty = HasOwnProperty;
|
||||
exports.OrdinaryHasProperty = OrdinaryHasProperty;
|
||||
exports.HasCompatibleType = HasCompatibleType;
|
||||
exports.HasSomeCompatibleType = HasSomeCompatibleType;
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _index = require("./index.js");
|
||||
|
||||
var _index2 = require("../values/index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// 12.2.1.2 Static Semantics: HasName
|
||||
// 14.1.9 Static Semantics: HasName
|
||||
// 14.2.7 Static Semantics: HasName
|
||||
// 14.5.6 Static Semantics: HasName
|
||||
// 14.2.7 Static Semantics: HasName
|
||||
|
||||
function HasName(realm, ast) {
|
||||
// 12.2.1.2 Static Semantics: HasName
|
||||
// CoverParenthesizedExpressionAndArrowParameterList
|
||||
|
||||
// 14.2.7 Static Semantics: HasName
|
||||
if (ast.type === "ArrowFunctionExpression") return false;
|
||||
|
||||
// 14.1.9 Static Semantics: HasName
|
||||
if (ast.type === "FunctionExpression") {
|
||||
// FunctionExpression: function (FormalParameters) {FunctionBody}
|
||||
if (ast.id === null)
|
||||
// 1. Return false.
|
||||
return false;
|
||||
// FunctionExpression: functionBindingIdentifier (FormalParameters) {FunctionBody}
|
||||
if (ast.id !== null)
|
||||
// 2. Return true
|
||||
return true;
|
||||
}
|
||||
|
||||
// 14.5.6 Static Semantics: HasName
|
||||
if (ast.type === "ClassExpression") {
|
||||
// ClassExpression : class ClassTail
|
||||
if (ast.id === null)
|
||||
//1. Return false.
|
||||
return false;
|
||||
// ClassExpression : class BindingIdentifier ClassTail
|
||||
if (ast.id !== null)
|
||||
//1. return true;
|
||||
return true;
|
||||
}
|
||||
// 14.4.7 Static Semantics: HasName
|
||||
// GeneratorExpression
|
||||
throw Error("Unexpected AST node type : " + ast.type);
|
||||
}
|
||||
|
||||
// ECMA262 7.3.10
|
||||
/**
|
||||
* 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 HasProperty(realm, O, P) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
|
||||
// 2. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index.IsPropertyKey)(realm, P), "expected property key");
|
||||
|
||||
// 3. Return ? O.[[HasProperty]](P).
|
||||
return O.$HasProperty(P);
|
||||
}
|
||||
|
||||
// ECMA262 7.3.11
|
||||
function HasOwnProperty(realm, O, P) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
|
||||
// 2. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)((0, _index.IsPropertyKey)(realm, P), "not a valid property key");
|
||||
|
||||
// 3. Let desc be ? O.[[GetOwnProperty]](P).
|
||||
var desc = O.$GetOwnProperty(P);
|
||||
|
||||
// 4. If desc is undefined, return false.
|
||||
if (desc === undefined) return false;
|
||||
_singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value);
|
||||
|
||||
// 5. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 9.1.7.1
|
||||
function OrdinaryHasProperty(realm, O, P) {
|
||||
// 1. Assert: IsPropertyKey(P) is true.
|
||||
(0, _invariant2.default)(typeof P === "string" || (0, _index.IsPropertyKey)(realm, P), "expected property key");
|
||||
|
||||
// 2. Let hasOwn be ? O.[[GetOwnProperty]](P).
|
||||
var hasOwn = O.$GetOwnProperty(P);
|
||||
|
||||
// 3. If hasOwn is not undefined, return true.
|
||||
if (hasOwn !== undefined) {
|
||||
_singletons.Properties.ThrowIfMightHaveBeenDeleted(hasOwn.value);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4. Let parent be ? O.[[GetPrototypeOf]]().
|
||||
var parent = O.$GetPrototypeOf();
|
||||
|
||||
// 5. If parent is not null, then
|
||||
if (!(parent instanceof _index2.NullValue)) {
|
||||
(0, _invariant2.default)(parent instanceof _index2.ObjectValue);
|
||||
|
||||
// a. Return ? parent.[[HasProperty]](P).
|
||||
return parent.$HasProperty(P);
|
||||
}
|
||||
|
||||
// 6. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checks if the given value is equal to or a subtype of the given type.
|
||||
// If the value is an abstract value without precise type information,
|
||||
// an introspection error is thrown.
|
||||
function HasCompatibleType(value, type) {
|
||||
var valueType = value.getType();
|
||||
if (valueType === _index2.Value) {
|
||||
(0, _invariant2.default)(value instanceof _index2.AbstractValue);
|
||||
_index2.AbstractValue.reportIntrospectionError(value);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
return _index2.Value.isTypeCompatibleWith(valueType, type);
|
||||
}
|
||||
|
||||
function HasSomeCompatibleType(value) {
|
||||
var valueType = value.getType();
|
||||
if (valueType === _index2.Value) {
|
||||
(0, _invariant2.default)(value instanceof _index2.AbstractValue);
|
||||
_index2.AbstractValue.reportIntrospectionError(value);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
|
||||
for (var _len = arguments.length, manyTypes = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
manyTypes[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
return manyTypes.some(_index2.Value.isTypeCompatibleWith.bind(null, valueType));
|
||||
}
|
||||
//# sourceMappingURL=has.js.map
|
||||
1
build/node_modules/prepack/lib/methods/has.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/has.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
185
build/node_modules/prepack/lib/methods/hash.js
generated
vendored
Normal file
185
build/node_modules/prepack/lib/methods/hash.js
generated
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.HashSet = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||
|
||||
exports.hashBinary = hashBinary;
|
||||
exports.hashCall = hashCall;
|
||||
exports.hashTernary = hashTernary;
|
||||
exports.hashString = hashString;
|
||||
exports.hashUnary = hashUnary;
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
/**
|
||||
* 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 hashBinary(op, x, y) {
|
||||
var xHash = x.getHash();
|
||||
var yHash = y.getHash();
|
||||
if (yHash < xHash) {
|
||||
// Check if the operation is commutative so that we can normalize the arguments on hash value order.
|
||||
var commutative = void 0;
|
||||
switch (op) {
|
||||
case "*":
|
||||
case "==":
|
||||
case "!=":
|
||||
case "===":
|
||||
case "!==":
|
||||
// If both operands might be objects, the operation does not commute because of the possibility
|
||||
// that arbitrary code can run on both operands while converting them, in which case the order of the
|
||||
// operands must be maintained to make sure any side-effects happen in the right order.
|
||||
commutative = !(x.mightBeObject() && y.mightBeObject());
|
||||
break;
|
||||
case "+":
|
||||
// As above, but in addition, if one of the operands might be a string the operation does not commute
|
||||
commutative = !(x.mightBeObject() && y.mightBeObject()) && !(x.mightBeString() || y.mightBeString());
|
||||
break;
|
||||
default:
|
||||
// The operation itself is not commutative
|
||||
commutative = false;
|
||||
break;
|
||||
}
|
||||
if (commutative) {
|
||||
var _ref = [y, x];
|
||||
x = _ref[0];
|
||||
y = _ref[1];
|
||||
var _ref2 = [yHash, xHash];
|
||||
xHash = _ref2[0];
|
||||
yHash = _ref2[1];
|
||||
}
|
||||
}
|
||||
var hash = (hashString(op) * 13 ^ xHash) * 13 ^ yHash;
|
||||
return [hash, [x, y]];
|
||||
}
|
||||
|
||||
function hashCall(calleeName) {
|
||||
var hash = hashString(calleeName);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = args[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var a = _step.value;
|
||||
hash = hash * 13 ^ a.getHash();
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [hash, args];
|
||||
}
|
||||
|
||||
function hashTernary(x, y, z) {
|
||||
var hash = (x.getHash() * 13 ^ y.getHash()) * 13 ^ z.getHash();
|
||||
return [hash, [x, y, z]];
|
||||
}
|
||||
|
||||
function hashString(value) {
|
||||
var hash = 5381;
|
||||
for (var i = value.length - 1; i >= 0; i--) {
|
||||
hash = hash * 33 ^ value.charCodeAt(i);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
function hashUnary(op, x) {
|
||||
return hashString(op) * 13 ^ x.getHash();
|
||||
}
|
||||
|
||||
var HashSet = exports.HashSet = function () {
|
||||
function HashSet() {
|
||||
var expectedEntries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 32 * 1024;
|
||||
|
||||
_classCallCheck(this, HashSet);
|
||||
|
||||
var initialSize = 16;
|
||||
expectedEntries *= 2;
|
||||
while (initialSize < expectedEntries) {
|
||||
initialSize *= 2;
|
||||
}this._entries = new Array(initialSize);
|
||||
this._count = 0;
|
||||
}
|
||||
|
||||
_createClass(HashSet, [{
|
||||
key: "add",
|
||||
value: function add(e) {
|
||||
var entries = this._entries;
|
||||
var n = entries.length;
|
||||
var key = e.getHash();
|
||||
var i = key & n - 1;
|
||||
while (true) {
|
||||
var entry = entries[i];
|
||||
if (entry === undefined) {
|
||||
entries[i] = e;
|
||||
if (++this._count > n / 2) this.expand();
|
||||
return e;
|
||||
} else if (e.equals(entry)) {
|
||||
return entry;
|
||||
}
|
||||
if (++i >= n) i = 0;
|
||||
}
|
||||
(0, _invariant2.default)(false); // otherwise Flow thinks this method can return undefined
|
||||
}
|
||||
}, {
|
||||
key: "expand",
|
||||
value: function expand() {
|
||||
var oldEntries = this._entries;
|
||||
var n = oldEntries.length;
|
||||
var m = n * 2;
|
||||
if (m <= 0) return;
|
||||
var entries = new Array(m);
|
||||
for (var i = 0; i < n; i++) {
|
||||
var oldEntry = oldEntries[i];
|
||||
if (oldEntry === undefined) continue;
|
||||
var key = oldEntry.getHash();
|
||||
var j = key & m - 1;
|
||||
while (true) {
|
||||
var entry = entries[j];
|
||||
if (entry === undefined) {
|
||||
entries[j] = oldEntry;
|
||||
break;
|
||||
}
|
||||
if (++j >= m) j = 0;
|
||||
}
|
||||
}
|
||||
this._entries = entries;
|
||||
}
|
||||
}]);
|
||||
|
||||
return HashSet;
|
||||
}();
|
||||
//# sourceMappingURL=hash.js.map
|
||||
1
build/node_modules/prepack/lib/methods/hash.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/hash.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
198
build/node_modules/prepack/lib/methods/index.js
generated
vendored
Normal file
198
build/node_modules/prepack/lib/methods/index.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _abstract = require("./abstract.js");
|
||||
|
||||
Object.keys(_abstract).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _abstract[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _call = require("./call.js");
|
||||
|
||||
Object.keys(_call).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _call[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _construct = require("./construct.js");
|
||||
|
||||
Object.keys(_construct).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _construct[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _date = require("./date.js");
|
||||
|
||||
Object.keys(_date).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _date[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _descriptor = require("./descriptor.js");
|
||||
|
||||
Object.keys(_descriptor).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _descriptor[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
Object.keys(_get).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _get[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
Object.keys(_has).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _has[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _hash = require("./hash.js");
|
||||
|
||||
Object.keys(_hash).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _hash[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _integrity = require("./integrity.js");
|
||||
|
||||
Object.keys(_integrity).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _integrity[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
Object.keys(_is).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _is[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _iterator = require("./iterator.js");
|
||||
|
||||
Object.keys(_iterator).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _iterator[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _own = require("./own.js");
|
||||
|
||||
Object.keys(_own).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _own[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _destructuring = require("./destructuring.js");
|
||||
|
||||
Object.keys(_destructuring).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _destructuring[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _regexp = require("./regexp.js");
|
||||
|
||||
Object.keys(_regexp).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _regexp[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _promise = require("./promise.js");
|
||||
|
||||
Object.keys(_promise).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _promise[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _arraybuffer = require("./arraybuffer.js");
|
||||
|
||||
Object.keys(_arraybuffer).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _arraybuffer[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
build/node_modules/prepack/lib/methods/index.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["../../src/methods/index.js"],"names":[],"mappings":";;;;;;;;AAWA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","file":"index.js","sourcesContent":["/**\n * Copyright (c) 2017-present, Facebook, Inc.\n * All rights reserved.\n *\n * This source code is licensed under the BSD-style license found in the\n * LICENSE file in the root directory of this source tree. An additional grant\n * of patent rights can be found in the PATENTS file in the same directory.\n */\n\n/* @flow */\n\nexport * from \"./abstract.js\";\nexport * from \"./call.js\";\nexport * from \"./construct.js\";\nexport * from \"./date.js\";\nexport * from \"./descriptor.js\";\nexport * from \"./get.js\";\nexport * from \"./has.js\";\nexport * from \"./hash.js\";\nexport * from \"./integrity.js\";\nexport * from \"./is.js\";\nexport * from \"./iterator.js\";\nexport * from \"./own.js\";\nexport * from \"./destructuring.js\";\nexport * from \"./regexp.js\";\nexport * from \"./promise.js\";\nexport * from \"./arraybuffer.js\";\n"]}
|
||||
2
build/node_modules/prepack/lib/methods/integerindexed.js
generated
vendored
Normal file
2
build/node_modules/prepack/lib/methods/integerindexed.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
//# sourceMappingURL=integerindexed.js.map
|
||||
1
build/node_modules/prepack/lib/methods/integerindexed.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/integerindexed.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":"","file":"integerindexed.js","sourcesContent":[]}
|
||||
210
build/node_modules/prepack/lib/methods/integrity.js
generated
vendored
Normal file
210
build/node_modules/prepack/lib/methods/integrity.js
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.OrdinaryPreventExtensions = OrdinaryPreventExtensions;
|
||||
exports.SetIntegrityLevel = SetIntegrityLevel;
|
||||
exports.TestIntegrityLevel = TestIntegrityLevel;
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _index2 = require("./index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 9.1.4.1
|
||||
/**
|
||||
* 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 OrdinaryPreventExtensions(realm, O) {
|
||||
if (O.isLeakedObject() && O.getExtensible()) {
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
|
||||
// 1. Set the value of the [[Extensible]] internal slot of O to false.
|
||||
O.setExtensible(false);
|
||||
|
||||
// 2. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.14
|
||||
function SetIntegrityLevel(realm, O, level) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue, "expected an object");
|
||||
|
||||
// 2. Assert: level is either "sealed" or "frozen".
|
||||
(0, _invariant2.default)(level === "sealed" || level === "frozen", "invalid level");
|
||||
|
||||
// 3. Let status be ? O.[[PreventExtensions]]().
|
||||
var status = O.$PreventExtensions();
|
||||
|
||||
// 4. If status is false, return false.
|
||||
if (status === false) return false;
|
||||
|
||||
// 5. Let keys be ? O.[[OwnPropertyKeys]]().
|
||||
var keys = O.$OwnPropertyKeys();
|
||||
|
||||
// 6. If level is "sealed", then
|
||||
if (level === "sealed") {
|
||||
// a. Repeat for each element k of keys,
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var k = _step.value;
|
||||
|
||||
// i. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor{[[Configurable]]: false}).
|
||||
_singletons.Properties.DefinePropertyOrThrow(realm, O, k, {
|
||||
configurable: false
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (level === "frozen") {
|
||||
// 7. Else level is "frozen",
|
||||
// a. Repeat for each element k of keys,
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = keys[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var _k = _step2.value;
|
||||
|
||||
// i. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
var currentDesc = O.$GetOwnProperty(_k);
|
||||
|
||||
// ii. If currentDesc is not undefined, then
|
||||
if (currentDesc) {
|
||||
_singletons.Properties.ThrowIfMightHaveBeenDeleted(currentDesc.value);
|
||||
var desc = void 0;
|
||||
|
||||
// 1. If IsAccessorDescriptor(currentDesc) is true, then
|
||||
if ((0, _index2.IsAccessorDescriptor)(realm, currentDesc)) {
|
||||
// a. Let desc be the PropertyDescriptor{[[Configurable]]: false}.
|
||||
desc = { configurable: false };
|
||||
} else {
|
||||
// 2. Else,
|
||||
// b. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
|
||||
desc = { configurable: false, writable: false };
|
||||
}
|
||||
|
||||
// 3. Perform ? DefinePropertyOrThrow(O, k, desc).
|
||||
_singletons.Properties.DefinePropertyOrThrow(realm, O, _k, desc);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.15
|
||||
function TestIntegrityLevel(realm, O, level) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue, "expected an object");
|
||||
|
||||
// 2. Assert: level is either "sealed" or "frozen".
|
||||
(0, _invariant2.default)(level === "sealed" || level === "frozen", "invalid level");
|
||||
|
||||
// 3. Let status be ? IsExtensible(O).
|
||||
var status = (0, _index2.IsExtensible)(realm, O);
|
||||
|
||||
// 4. If status is true, return false.
|
||||
if (status === true) return false;
|
||||
|
||||
// 5. NOTE If the object is extensible, none of its properties are examined.
|
||||
|
||||
// 6. Let keys be ? O.[[OwnPropertyKeys]]().
|
||||
var keys = O.$OwnPropertyKeys();
|
||||
|
||||
// 7. Repeat for each element k of keys,
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = keys[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var k = _step3.value;
|
||||
|
||||
// a. Let currentDesc be ? O.[[GetOwnProperty]](k).
|
||||
var currentDesc = O.$GetOwnProperty(k);
|
||||
|
||||
// b. If currentDesc is not undefined, then
|
||||
if (currentDesc) {
|
||||
_singletons.Properties.ThrowIfMightHaveBeenDeleted(currentDesc.value);
|
||||
|
||||
// i. If currentDesc.[[Configurable]] is true, return false.
|
||||
if (currentDesc.configurable === true) return false;
|
||||
|
||||
// ii. If level is "frozen" and IsDataDescriptor(currentDesc) is true, then
|
||||
if (level === "frozen" && (0, _index2.IsDataDescriptor)(realm, currentDesc) === true) {
|
||||
// 1. If currentDesc.[[Writable]] is true, return false.
|
||||
if (currentDesc.writable === true) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Return true.
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
||||
_iterator3.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//# sourceMappingURL=integrity.js.map
|
||||
1
build/node_modules/prepack/lib/methods/integrity.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/integrity.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
417
build/node_modules/prepack/lib/methods/is.js
generated
vendored
Normal file
417
build/node_modules/prepack/lib/methods/is.js
generated
vendored
Normal file
@@ -0,0 +1,417 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.IsConcatSpreadable = IsConcatSpreadable;
|
||||
exports.IsGenericDescriptor = IsGenericDescriptor;
|
||||
exports.IsAccessorDescriptor = IsAccessorDescriptor;
|
||||
exports.IsDataDescriptor = IsDataDescriptor;
|
||||
exports.OrdinaryIsExtensible = OrdinaryIsExtensible;
|
||||
exports.IsExtensible = IsExtensible;
|
||||
exports.IsCallable = IsCallable;
|
||||
exports.IsConstructor = IsConstructor;
|
||||
exports.IsInteger = IsInteger;
|
||||
exports.IsPropertyKey = IsPropertyKey;
|
||||
exports.IsArray = IsArray;
|
||||
exports.IsInTailPosition = IsInTailPosition;
|
||||
exports.IsRegExp = IsRegExp;
|
||||
exports.IsIdentifierRef = IsIdentifierRef;
|
||||
exports.IsFunctionDefinition = IsFunctionDefinition;
|
||||
exports.IsAnonymousFunctionDefinition = IsAnonymousFunctionDefinition;
|
||||
exports.IsArrayIndex = IsArrayIndex;
|
||||
exports.IsPromise = IsPromise;
|
||||
exports.IsDetachedBuffer = IsDetachedBuffer;
|
||||
exports.IsIntrospectionError = IsIntrospectionError;
|
||||
exports.IsStatic = IsStatic;
|
||||
exports.IsStatement = IsStatement;
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
var _babelTypes = require("babel-types");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 22.1.3.1.1
|
||||
/**
|
||||
* 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 IsConcatSpreadable(realm, O) {
|
||||
// 1. If Type(O) is not Object, return false.
|
||||
if (!O.mightBeObject()) return false;
|
||||
O = O.throwIfNotObject();
|
||||
|
||||
// 2. Let spreadable be ? Get(O, @@isConcatSpreadable).
|
||||
var spreadable = (0, _get.Get)(realm, O, realm.intrinsics.SymbolIsConcatSpreadable);
|
||||
|
||||
// 3. If spreadable is not undefined, return ToBoolean(spreadable).
|
||||
if (!spreadable.mightBeUndefined()) return _singletons.To.ToBooleanPartial(realm, spreadable);
|
||||
spreadable.throwIfNotConcrete();
|
||||
|
||||
// 4. Return ? IsArray(O).
|
||||
return IsArray(realm, O);
|
||||
}
|
||||
|
||||
// ECMA262 6.2.4.3
|
||||
function IsGenericDescriptor(realm, Desc) {
|
||||
// 1. If Desc is undefined, return false.
|
||||
if (!Desc) return false;
|
||||
|
||||
// 2. If IsAccessorDescriptor(Desc) and IsDataDescriptor(Desc) are both false, return true.
|
||||
if (!IsAccessorDescriptor(realm, Desc) && !IsDataDescriptor(realm, Desc)) return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 6.2.4.1
|
||||
function IsAccessorDescriptor(realm, Desc) {
|
||||
// 1. If Desc is undefined, return false.
|
||||
if (!Desc) return false;
|
||||
|
||||
// 2. If both Desc.[[Get]] and Desc.[[Set]] are absent, return false.
|
||||
if (!("get" in Desc) && !("set" in Desc)) return false;
|
||||
|
||||
// 3. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 6.2.4.2
|
||||
function IsDataDescriptor(realm, Desc) {
|
||||
// If Desc is undefined, return false.
|
||||
if (!Desc) return false;
|
||||
|
||||
// If both Desc.[[Value]] and Desc.[[Writable]] are absent, return false.
|
||||
if (!("value" in Desc) && !("writable" in Desc)) return false;
|
||||
|
||||
// Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 9.1.3.1
|
||||
function OrdinaryIsExtensible(realm, O) {
|
||||
// 1. Return the value of the [[Extensible]] internal slot of O.
|
||||
return O.getExtensible();
|
||||
}
|
||||
|
||||
// ECMA262 7.2.5
|
||||
function IsExtensible(realm, O) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
|
||||
// 2. Return ? O.[[IsExtensible]]().
|
||||
return O.$IsExtensible();
|
||||
}
|
||||
|
||||
// ECMA262 7.2.3
|
||||
function IsCallable(realm, func) {
|
||||
// 1. If Type(argument) is not Object, return false.
|
||||
if (!func.mightBeObject()) return false;
|
||||
if ((0, _has.HasCompatibleType)(func, _index.FunctionValue)) return true;
|
||||
|
||||
// 2. If argument has a [[Call]] internal method, return true.
|
||||
func = func.throwIfNotConcreteObject();
|
||||
if (func.$Call) return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.4
|
||||
function IsConstructor(realm, argument) {
|
||||
// 1. If Type(argument) is not Object, return false.
|
||||
if (!argument.mightBeObject()) return false;
|
||||
|
||||
// 2. If argument has a [[Construct]] internal method, return true.
|
||||
argument = argument.throwIfNotConcreteObject();
|
||||
if (argument.$Construct) return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.6
|
||||
function IsInteger(realm, argument) {
|
||||
// 1. If Type(argument) is not Number, return false.
|
||||
(0, _invariant2.default)(typeof argument === "number", "Type(argument) is not number");
|
||||
|
||||
// 2. If argument is NaN, +∞, or -∞, return false.
|
||||
if (isNaN(argument) || argument === +Infinity || argument === -Infinity) return false;
|
||||
|
||||
// 3. If floor(abs(argument)) ≠ abs(argument), return false.
|
||||
if (Math.floor(Math.abs(argument)) !== Math.abs(argument)) return false;
|
||||
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.7
|
||||
function IsPropertyKey(realm, arg) {
|
||||
// We allow native strings to be passed around to avoid constructing a StringValue
|
||||
if (typeof arg === "string") return true;
|
||||
|
||||
// 1. If Type(argument) is String, return true.
|
||||
if (arg instanceof _index.StringValue) return true;
|
||||
|
||||
// 2. If Type(argument) is Symbol, return true.
|
||||
if (arg instanceof _index.SymbolValue) return true;
|
||||
|
||||
if (arg instanceof _index.AbstractValue) {
|
||||
_index.AbstractValue.reportIntrospectionError(arg);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.2
|
||||
function IsArray(realm, argument) {
|
||||
// 1. If Type(argument) is not Object, return false.
|
||||
if (!argument.mightBeObject()) return false;
|
||||
|
||||
// 2. If argument is an Array exotic object, return true.
|
||||
if (argument instanceof _index.ArrayValue || argument === realm.intrinsics.ArrayPrototype) return true;
|
||||
|
||||
// 3. If argument is a Proxy exotic object, then
|
||||
if (argument instanceof _index.ProxyValue) {
|
||||
// a. If the value of the [[ProxyHandler]] internal slot of argument is null, throw a TypeError exception.
|
||||
if (!argument.$ProxyHandler || argument.$ProxyHandler instanceof _index.NullValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// b. Let target be the value of the [[ProxyTarget]] internal slot of argument.
|
||||
var target = argument.$ProxyTarget;
|
||||
|
||||
// c. Return ? IsArray(target).
|
||||
return IsArray(realm, target);
|
||||
}
|
||||
|
||||
// 4. Return false.
|
||||
argument.throwIfNotConcrete();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 14.6.1
|
||||
function IsInTailPosition(realm, node) {
|
||||
// TODO #1008: implement tail calls
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 7.2.8
|
||||
function IsRegExp(realm, argument) {
|
||||
// 1. If Type(argument) is not Object, return false.
|
||||
if (!argument.mightBeObject()) return false;
|
||||
argument = argument.throwIfNotObject();
|
||||
|
||||
// 2. Let isRegExp be ? Get(argument, @@match).
|
||||
var isRegExp = (0, _get.Get)(realm, argument, realm.intrinsics.SymbolMatch);
|
||||
|
||||
// 3. If isRegExp is not undefined, return ToBoolean(isRegExp).
|
||||
if (isRegExp !== undefined) return _singletons.To.ToBooleanPartial(realm, isRegExp) === true;
|
||||
|
||||
// 4. If argument has a [[RegExpMatcher]] internal slot, return true.
|
||||
if (argument.$RegExpMatcher) return true;
|
||||
|
||||
// 5. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
// ECMA262 12.2.1.4 Static Semantics: IsIdentifierRef
|
||||
// ECMA262 12.3.1.4 Static Semantics: IsIdentifierRef
|
||||
function IsIdentifierRef(realm, node) {
|
||||
switch (node.type) {
|
||||
// ECMA262 12.2.1.4 Static Semantics: IsIdentifierRef
|
||||
case "Identifier":
|
||||
return true;
|
||||
// ECMA262 12.3.1.4 Static Semantics: IsIdentifierRef
|
||||
case "MemberExpression":
|
||||
return false;
|
||||
default:
|
||||
throw Error("Unexpected AST form : " + node.type);
|
||||
}
|
||||
}
|
||||
|
||||
// 12.2.1.3 Static Semantics: IsFunctionDefinition
|
||||
// 12.2.1.3 Static Semantics: IsFunctionDefinition
|
||||
// 12.13 Binary Logical Operators
|
||||
// 12.3.1.2 Static Semantics: IsFunctionDefinition
|
||||
// 12.15.2 Static Semantics: IsFunctionDefinition
|
||||
function IsFunctionDefinition(realm, node) {
|
||||
switch (node.type) {
|
||||
// 12.2.1.3 Static Semantics: IsFunctionDefinition
|
||||
case "ThisExpression":
|
||||
case "Identifier":
|
||||
case "StringLiteral":
|
||||
case "NumericLiteral":
|
||||
case "BooleanLiteral":
|
||||
case "NullLiteral":
|
||||
case "RegExpLiteral":
|
||||
case "ArrayExpression":
|
||||
case "ObjectExpression":
|
||||
case "TemplateLiteral":
|
||||
case "ConditionalExpression":
|
||||
return false;
|
||||
// 12.2.1.3 Static Semantics: IsFunctionDefinition
|
||||
case "UpdateExpression":
|
||||
return false;
|
||||
// 12.13 Binary Logical Operators
|
||||
case "BinaryExpression":
|
||||
case "LogicalExpression":
|
||||
return false;
|
||||
// 12.3.1.2 Static Semantics: IsFunctionDefinition
|
||||
case "MemberExpression":
|
||||
case "CallExpression":
|
||||
case "NewExpression":
|
||||
case "MetaProperty":
|
||||
case "TaggedTemplateExpression":
|
||||
return false;
|
||||
//12.5.1 Static Semantics: IsFunctionDefinition
|
||||
case "UnaryExpression":
|
||||
return false;
|
||||
//12.15.2 Static Semantics: IsFunctionDefinition
|
||||
case "AssignmentExpression":
|
||||
return false;
|
||||
//12.16.1 Static Semantics: IsFunctionDefinition
|
||||
case "SequenceExpression":
|
||||
return false;
|
||||
case "ArrowFunctionExpression":
|
||||
case "FunctionExpression":
|
||||
return true;
|
||||
// 14.5.8 Static Semantics: IsFunctionDefinition
|
||||
case "ClassExpression":
|
||||
return true;
|
||||
// JSX Extensions: http://facebook.github.io/jsx/
|
||||
case "JSXElement":
|
||||
return false;
|
||||
default:
|
||||
throw Error("Unexpected AST form : " + node.type);
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 14.1.10
|
||||
function IsAnonymousFunctionDefinition(realm, node) {
|
||||
// 1. If IsFunctionDefinition of production is false, return false.
|
||||
if (!IsFunctionDefinition(realm, node)) return false;
|
||||
|
||||
// 2. Let hasName be the result of HasName of production.
|
||||
var hasName = (0, _has.HasName)(realm, node);
|
||||
|
||||
// 3. If hasName is true, return false.
|
||||
if (hasName === true) return false;
|
||||
|
||||
// 4. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 9.4.2
|
||||
function IsArrayIndex(realm, P) {
|
||||
var key = void 0;
|
||||
if (typeof P === "string") {
|
||||
key = P;
|
||||
} else if (P instanceof _index.StringValue) {
|
||||
key = P.value;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
var i = _singletons.To.ToUint32(realm, new _index.StringValue(realm, key));
|
||||
return i !== Math.pow(2, 32) - 1 && _singletons.To.ToString(realm, new _index.NumberValue(realm, i)) === key;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.6
|
||||
function IsPromise(realm, x) {
|
||||
// 1. If Type(x) is not Object, return false.
|
||||
if (!x.mightBeObject()) return false;
|
||||
|
||||
// 2. If x does not have a [[PromiseState]] internal slot, return false.
|
||||
x = x.throwIfNotConcreteObject();
|
||||
if (!x.$PromiseState) return false;
|
||||
|
||||
// 3. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 24.1.1.2
|
||||
function IsDetachedBuffer(realm, arrayBuffer) {
|
||||
// 1. Assert: Type(arrayBuffer) is Object and it has an [[ArrayBufferData]] internal slot.
|
||||
(0, _invariant2.default)(arrayBuffer instanceof _index.ObjectValue && "$ArrayBufferData" in arrayBuffer);
|
||||
|
||||
// 2. If arrayBuffer's [[ArrayBufferData]] internal slot is null, return true.
|
||||
if (arrayBuffer.$ArrayBufferData === null) return true;
|
||||
|
||||
// 3. Return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
function IsIntrospectionError(realm, value) {
|
||||
if (!value.mightBeObject()) return false;
|
||||
value = value.throwIfNotConcreteObject();
|
||||
return value.$GetPrototypeOf() === realm.intrinsics.__IntrospectionErrorPrototype;
|
||||
}
|
||||
|
||||
function IsStatic(classElement) {
|
||||
// $FlowFixMe need to backport static property to BabelNodeClassMethod
|
||||
return classElement.static;
|
||||
}
|
||||
|
||||
function IsStatement(node) {
|
||||
switch (node.type) {
|
||||
case "BlockStatement":
|
||||
case "BreakStatement":
|
||||
case "ContinueStatement":
|
||||
case "DebuggerStatement":
|
||||
case "DoWhileStatement":
|
||||
case "EmptyStatement":
|
||||
case "ExpressionStatement":
|
||||
case "ForInStatement":
|
||||
case "ForStatement":
|
||||
case "FunctionDeclaration":
|
||||
case "IfStatement":
|
||||
case "LabeledStatement":
|
||||
case "ReturnStatement":
|
||||
case "SwitchStatement":
|
||||
case "ThrowStatement":
|
||||
case "TryStatement":
|
||||
case "VariableDeclaration":
|
||||
case "WhileStatement":
|
||||
case "WithStatement":
|
||||
case "ClassDeclaration":
|
||||
case "ExportAllDeclaration":
|
||||
case "ExportDefaultDeclaration":
|
||||
case "ExportNamedDeclaration":
|
||||
case "ForOfStatement":
|
||||
case "ImportDeclaration":
|
||||
case "DeclareClass":
|
||||
case "DeclareFunction":
|
||||
case "DeclareInterface":
|
||||
case "DeclareModule":
|
||||
case "DeclareModuleExports":
|
||||
case "DeclareTypeAlias":
|
||||
case "DeclareVariable":
|
||||
case "InterfaceDeclaration":
|
||||
case "TypeAlias":
|
||||
case "ForAwaitStatement":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//# sourceMappingURL=is.js.map
|
||||
1
build/node_modules/prepack/lib/methods/is.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/is.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
339
build/node_modules/prepack/lib/methods/iterator.js
generated
vendored
Normal file
339
build/node_modules/prepack/lib/methods/iterator.js
generated
vendored
Normal file
@@ -0,0 +1,339 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.GetIterator = GetIterator;
|
||||
exports.IteratorStep = IteratorStep;
|
||||
exports.IteratorValue = IteratorValue;
|
||||
exports.IteratorComplete = IteratorComplete;
|
||||
exports.IteratorNext = IteratorNext;
|
||||
exports.CreateListIterator = CreateListIterator;
|
||||
exports.CreateMapIterator = CreateMapIterator;
|
||||
exports.CreateSetIterator = CreateSetIterator;
|
||||
exports.IteratorClose = IteratorClose;
|
||||
exports.IterableToList = IterableToList;
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _index2 = require("./index.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _abstract = require("./abstract.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 7.4.1
|
||||
/**
|
||||
* 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 GetIterator(realm) {
|
||||
var obj = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : realm.intrinsics.undefined;
|
||||
var method = arguments[2];
|
||||
|
||||
// 1. If method was not passed, then
|
||||
if (!method) {
|
||||
// a. Let method be ? GetMethod(obj, @@iterator).
|
||||
method = (0, _index2.GetMethod)(realm, obj, realm.intrinsics.SymbolIterator);
|
||||
}
|
||||
|
||||
// 2. Let iterator be ? Call(method, obj).
|
||||
var iterator = (0, _index2.Call)(realm, method, obj);
|
||||
|
||||
// 3. If Type(iterator) is not Object, throw a TypeError exception.
|
||||
if (!(iterator instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 4. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
// ECMA262 7.4.5
|
||||
function IteratorStep(realm, iterator) {
|
||||
// 1. Let result be ? IteratorNext(iterator).
|
||||
var result = IteratorNext(realm, iterator);
|
||||
|
||||
// 2. Let done be ? IteratorComplete(result).
|
||||
var done = IteratorComplete(realm, result);
|
||||
|
||||
// 3. If done is true, return false.
|
||||
if (done) return false;
|
||||
|
||||
// 4. Return result.
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA262 7.4.4
|
||||
function IteratorValue(realm, iterResult) {
|
||||
// 1. Assert: Type(iterResult) is Object.
|
||||
(0, _invariant2.default)(iterResult instanceof _index.ObjectValue, "expected obj");
|
||||
|
||||
// 2. Return ? Get(iterResult, "value").
|
||||
return (0, _index2.Get)(realm, iterResult, "value");
|
||||
}
|
||||
|
||||
// ECMA262 7.4.2
|
||||
function IteratorComplete(realm, iterResult) {
|
||||
// 1. Assert: Type(iterResult) is Object.
|
||||
(0, _invariant2.default)(iterResult instanceof _index.ObjectValue, "expected obj");
|
||||
|
||||
// 2. Return ToBoolean(? Get(iterResult, "done")).
|
||||
return _singletons.To.ToBooleanPartial(realm, (0, _index2.Get)(realm, iterResult, "done"));
|
||||
}
|
||||
|
||||
// ECMA262 7.4.2
|
||||
function IteratorNext(realm, iterator, value) {
|
||||
// 1. If value was not passed, then
|
||||
var result = void 0;
|
||||
if (!value) {
|
||||
// a. Let result be ? Invoke(iterator, "next", « »).
|
||||
result = (0, _index2.Invoke)(realm, iterator, "next", []);
|
||||
} else {
|
||||
// 2. Else,
|
||||
// a. Let result be ? Invoke(iterator, "next", « value »).
|
||||
result = (0, _index2.Invoke)(realm, iterator, "next", [value]);
|
||||
}
|
||||
|
||||
// 3. If Type(result) is not Object, throw a TypeError exception.
|
||||
if (!(result instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 4. Return result.
|
||||
return result;
|
||||
}
|
||||
|
||||
// ECMA262 7.4.8
|
||||
function CreateListIterator(realm, list) {
|
||||
// 1. Let iterator be ObjectCreate(%IteratorPrototype%, « [[IteratorNext]], [[IteratedList]], [[ListIteratorNextIndex]] »).
|
||||
var iterator = _singletons.Create.ObjectCreate(realm, realm.intrinsics.IteratorPrototype, {
|
||||
$IteratorNext: undefined,
|
||||
$IteratedList: undefined,
|
||||
$ListIteratorNextIndex: undefined
|
||||
});
|
||||
|
||||
// 2. Set iterator's [[IteratedList]] internal slot to list.
|
||||
iterator.$IteratedList = list;
|
||||
|
||||
// 3. Set iterator's [[ListIteratorNextIndex]] internal slot to 0.
|
||||
iterator.$ListIteratorNextIndex = 0;
|
||||
|
||||
// 4. Let next be a new built-in function object as defined in ListIterator next (7.4.8.1).
|
||||
var next = ListIterator_next(realm);
|
||||
|
||||
// 5. Set iterator's [[IteratorNext]] internal slot to next.
|
||||
iterator.$IteratorNext = next;
|
||||
|
||||
// 6. Perform CreateMethodProperty(iterator, "next", next).
|
||||
_singletons.Create.CreateMethodProperty(realm, iterator, new _index.StringValue(realm, "next"), next);
|
||||
|
||||
// 7. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
// ECMA262 7.4.8.1
|
||||
function ListIterator_next(realm) {
|
||||
var func = new _index.NativeFunctionValue(realm, undefined, "next", 0, function (context) {
|
||||
(0, _invariant2.default)(context instanceof _index.ObjectValue);
|
||||
|
||||
// 1. Let O be the this value.
|
||||
var O = context;
|
||||
|
||||
// 2. Let f be the active function object.
|
||||
var f = func;
|
||||
|
||||
// 3. If O does not have a [[IteratorNext]] internal slot, throw a TypeError exception.
|
||||
if (!O.$IteratorNext) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "O does not have an [[IteratorNext]] internal slot");
|
||||
}
|
||||
|
||||
// 4. Let next be the value of the [[IteratorNext]] internal slot of O.
|
||||
var next = O.$IteratorNext;
|
||||
|
||||
// 5. If SameValue(f, next) is false, throw a TypeError exception.
|
||||
if (!(0, _abstract.SameValue)(realm, f, next)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 6. If O does not have an [[IteratedList]] internal slot, throw a TypeError exception.
|
||||
if (!O.$IteratedList) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "O does not have an [[IteratedList]] internal slot");
|
||||
}
|
||||
|
||||
// 7. Let list be the value of the [[IteratedList]] internal slot of O.
|
||||
var list = O.$IteratedList;
|
||||
|
||||
(0, _invariant2.default)(typeof O.$ListIteratorNextIndex === "number");
|
||||
|
||||
// 8. Let index be the value of the [[ListIteratorNextIndex]] internal slot of O.
|
||||
// Default to 0 for Flow.
|
||||
var index = O.$ListIteratorNextIndex;
|
||||
|
||||
// 9. Let len be the number of elements of list.
|
||||
var len = list.length;
|
||||
|
||||
// 10. If index ≥ len, then
|
||||
if (index >= len) {
|
||||
// a. Return CreateIterResultObject(undefined, true).
|
||||
return _singletons.Create.CreateIterResultObject(realm, realm.intrinsics.undefined, true);
|
||||
}
|
||||
|
||||
// 11. Set the value of the [[ListIteratorNextIndex]] internal slot of O to index+1.
|
||||
O.$ListIteratorNextIndex = index + 1;
|
||||
|
||||
// 12. Return CreateIterResultObject(list[index], false).
|
||||
return _singletons.Create.CreateIterResultObject(realm, list[index], false);
|
||||
});
|
||||
|
||||
return func;
|
||||
}
|
||||
|
||||
// ECMA262 23.1.5.1
|
||||
function CreateMapIterator(realm, map, kind) {
|
||||
// 1. If Type(map) is not Object, throw a TypeError exception.
|
||||
if (!(map instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 2. If map does not have a [[MapData]] internal slot, throw a TypeError exception.
|
||||
if (!map.$MapData) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 3. Let iterator be ObjectCreate(%MapIteratorPrototype%, « [[Map]], [[MapNextIndex]], [[MapIterationKind]] »).
|
||||
var iterator = _singletons.Create.ObjectCreate(realm, realm.intrinsics.MapIteratorPrototype, {
|
||||
$Map: undefined,
|
||||
$MapNextIndex: undefined,
|
||||
$MapIterationKind: undefined
|
||||
});
|
||||
|
||||
// 4. Set iterator's [[Map]] internal slot to map.
|
||||
iterator.$Map = map;
|
||||
|
||||
// 5. Set iterator's [[MapNextIndex]] internal slot to 0.
|
||||
iterator.$MapNextIndex = new _index.NumberValue(realm, 0);
|
||||
|
||||
// 6. Set iterator's [[MapIterationKind]] internal slot to kind.
|
||||
iterator.$MapIterationKind = kind;
|
||||
|
||||
// 7. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
// ECMA262 23.2.5.1
|
||||
function CreateSetIterator(realm, set, kind) {
|
||||
// 1. If Type(set) is not Object, throw a TypeError exception.
|
||||
if (!(set instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 2. If set does not have a [[SetData]] internal slot, throw a TypeError exception.
|
||||
if (!set.$SetData) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 3. Let iterator be ObjectCreate(%SetIteratorPrototype%, « [[IteratedSet]], [[SetNextIndex]], [[SetIterationKind]] »).
|
||||
var iterator = _singletons.Create.ObjectCreate(realm, realm.intrinsics.SetIteratorPrototype, {
|
||||
$IteratedSet: undefined,
|
||||
$SetNextIndex: undefined,
|
||||
$SetIterationKind: undefined
|
||||
});
|
||||
|
||||
// 4. Set iterator's [[IteratedSet]] internal slot to set.
|
||||
iterator.$IteratedSet = set;
|
||||
|
||||
// 5. Set iterator's [[SetNextIndex]] internal slot to 0.
|
||||
iterator.$SetNextIndex = 0;
|
||||
|
||||
// 6. Set iterator's [[SetIterationKind]] internal slot to kind.
|
||||
iterator.$SetIterationKind = kind;
|
||||
|
||||
// 7. Return iterator.
|
||||
return iterator;
|
||||
}
|
||||
|
||||
// ECMA262 7.4.6
|
||||
function IteratorClose(realm, iterator, completion) {
|
||||
// 1. Assert: Type(iterator) is Object.
|
||||
(0, _invariant2.default)(iterator instanceof _index.ObjectValue, "expected object");
|
||||
|
||||
// 2. Assert: completion is a Completion Record.
|
||||
(0, _invariant2.default)(completion instanceof _completions.Completion, "expected completion record");
|
||||
|
||||
// 3. Let return be ? GetMethod(iterator, "return").
|
||||
var ret = (0, _index2.GetMethod)(realm, iterator, "return");
|
||||
|
||||
// 4. If return is undefined, return Completion(completion).
|
||||
if (ret instanceof _index.UndefinedValue) return completion;
|
||||
|
||||
// 5. Let innerResult be Call(return, iterator, « »).
|
||||
var innerResult = void 0;
|
||||
try {
|
||||
innerResult = (0, _index2.Call)(realm, ret.throwIfNotConcrete(), iterator, []);
|
||||
} catch (error) {
|
||||
if (error instanceof _completions.AbruptCompletion) {
|
||||
innerResult = error;
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// 6. If completion.[[Type]] is throw, return Completion(completion).
|
||||
if (completion instanceof _completions.ThrowCompletion) return completion;
|
||||
|
||||
// 7. If innerResult.[[Type]] is throw, return Completion(innerResult).
|
||||
if (innerResult instanceof _completions.ThrowCompletion) return innerResult;
|
||||
|
||||
// 8. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
|
||||
if (!(innerResult instanceof _index.ObjectValue)) {
|
||||
return realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 9. Return Completion(completion).
|
||||
return completion;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.2.1.1
|
||||
function IterableToList(realm, items, method) {
|
||||
// 1. Let iterator be ? GetIterator(items, method).
|
||||
var iterator = GetIterator(realm, items, method);
|
||||
|
||||
// 2. Let values be a new empty List.
|
||||
var values = [];
|
||||
|
||||
// 3. Let next be true.
|
||||
var next = true;
|
||||
|
||||
// 4. Repeat, while next is not false
|
||||
while (next !== false) {
|
||||
// a. Let next be ? IteratorStep(iterator).
|
||||
next = IteratorStep(realm, iterator);
|
||||
|
||||
// b. If next is not false, then
|
||||
if (next !== false) {
|
||||
// i. Let nextValue be ? IteratorValue(next).
|
||||
var nextValue = IteratorValue(realm, next);
|
||||
|
||||
// ii. Append nextValue to the end of the List values.
|
||||
values.push(nextValue);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Return values.
|
||||
return values;
|
||||
}
|
||||
//# sourceMappingURL=iterator.js.map
|
||||
1
build/node_modules/prepack/lib/methods/iterator.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/iterator.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
759
build/node_modules/prepack/lib/methods/join.js
generated
vendored
Normal file
759
build/node_modules/prepack/lib/methods/join.js
generated
vendored
Normal file
@@ -0,0 +1,759 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.JoinImplementation = undefined;
|
||||
|
||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _environment = require("../environment.js");
|
||||
|
||||
var _index = require("../methods/index.js");
|
||||
|
||||
var _realm = require("../realm.js");
|
||||
|
||||
var _generator = require("../utils/generator.js");
|
||||
|
||||
var _index2 = require("../values/index.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function joinGenerators(realm, joinCondition, generator1, generator2) {
|
||||
var result = new _generator.Generator(realm);
|
||||
if (!generator1.empty() || !generator2.empty()) {
|
||||
result.joinGenerators(joinCondition, generator1, generator2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function joinArrays(realm, v1, v2, getAbstractValue) {
|
||||
var e = v1 && v1[0] || v2 && v2[0];
|
||||
if (e instanceof _index2.Value) return joinArraysOfValues(realm, v1, v2, getAbstractValue);else return joinArrayOfsMapEntries(realm, v1, v2, getAbstractValue);
|
||||
}
|
||||
|
||||
function joinArrayOfsMapEntries(realm, a1, a2, getAbstractValue) {
|
||||
var empty = realm.intrinsics.empty;
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
var result = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
var _ref = a1 && a1[i] || { $Key: empty, $Value: empty },
|
||||
key1 = _ref.$Key,
|
||||
val1 = _ref.$Value;
|
||||
|
||||
var _ref2 = a2 && a2[i] || { $Key: empty, $Value: empty },
|
||||
key2 = _ref2.$Key,
|
||||
val2 = _ref2.$Value;
|
||||
|
||||
if (key1 === undefined && key2 === undefined) {
|
||||
result[i] = { $Key: undefined, $Value: undefined };
|
||||
} else {
|
||||
var key3 = getAbstractValue(key1, key2);
|
||||
var val3 = getAbstractValue(val1, val2);
|
||||
result[i] = { $Key: key3, $Value: val3 };
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function joinArraysOfValues(realm, a1, a2, getAbstractValue) {
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
var result = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
result[i] = getAbstractValue(a1 && a1[i] || undefined, a2 && a2[i] || undefined);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
var JoinImplementation = exports.JoinImplementation = function () {
|
||||
function JoinImplementation() {
|
||||
_classCallCheck(this, JoinImplementation);
|
||||
}
|
||||
|
||||
_createClass(JoinImplementation, [{
|
||||
key: "stopEffectCaptureJoinApplyAndReturnCompletion",
|
||||
value: function stopEffectCaptureJoinApplyAndReturnCompletion(c1, c2, realm) {
|
||||
var e = realm.getCapturedEffects(c1);
|
||||
(0, _invariant2.default)(e !== undefined);
|
||||
realm.stopEffectCaptureAndUndoEffects(c1);
|
||||
var joined_effects = this.joinPossiblyNormalCompletionWithAbruptCompletion(realm, c1, c2, e);
|
||||
realm.applyEffects(joined_effects);
|
||||
var result = joined_effects[0];
|
||||
(0, _invariant2.default)(result instanceof _completions.AbruptCompletion);
|
||||
return result;
|
||||
}
|
||||
}, {
|
||||
key: "unbundleNormalCompletion",
|
||||
value: function unbundleNormalCompletion(completionOrValue) {
|
||||
var completion = void 0,
|
||||
value = void 0;
|
||||
if (completionOrValue instanceof _completions.PossiblyNormalCompletion) {
|
||||
completion = completionOrValue;
|
||||
value = completionOrValue.value;
|
||||
} else {
|
||||
(0, _invariant2.default)(completionOrValue instanceof _index2.Value || completionOrValue instanceof _environment.Reference);
|
||||
value = completionOrValue;
|
||||
}
|
||||
return [completion, value];
|
||||
}
|
||||
}, {
|
||||
key: "composeNormalCompletions",
|
||||
value: function composeNormalCompletions(leftCompletion, rightCompletion, resultValue, realm) {
|
||||
if (leftCompletion instanceof _completions.PossiblyNormalCompletion) {
|
||||
if (rightCompletion instanceof _completions.PossiblyNormalCompletion) {
|
||||
this.updatePossiblyNormalCompletionWithValue(realm, rightCompletion, resultValue);
|
||||
return this.composePossiblyNormalCompletions(realm, leftCompletion, rightCompletion);
|
||||
}
|
||||
this.updatePossiblyNormalCompletionWithValue(realm, leftCompletion, resultValue);
|
||||
return leftCompletion;
|
||||
} else if (rightCompletion instanceof _completions.PossiblyNormalCompletion) {
|
||||
this.updatePossiblyNormalCompletionWithValue(realm, rightCompletion, resultValue);
|
||||
return rightCompletion;
|
||||
} else {
|
||||
(0, _invariant2.default)(leftCompletion === undefined && rightCompletion === undefined);
|
||||
return resultValue;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "composePossiblyNormalCompletions",
|
||||
value: function composePossiblyNormalCompletions(realm, pnc, c) {
|
||||
//merge the two pathConditions
|
||||
var composedPath = [];
|
||||
composedPath = pnc.pathConditions.concat(c.pathConditions);
|
||||
var savedPathConditions = pnc.savedPathConditions;
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
var _pnc$alternateEffects = _slicedToArray(pnc.alternateEffects, 5),
|
||||
_g = _pnc$alternateEffects[1],
|
||||
_b = _pnc$alternateEffects[2],
|
||||
_p = _pnc$alternateEffects[3],
|
||||
_o = _pnc$alternateEffects[4];
|
||||
|
||||
var _newAlternateEffects = [c, _g, _b, _p, _o];
|
||||
return new _completions.PossiblyNormalCompletion(c.value, pnc.joinCondition, pnc.consequent, pnc.consequentEffects, c, _newAlternateEffects, composedPath, savedPathConditions, pnc.savedEffects);
|
||||
}
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
var new_alternate = this.composePossiblyNormalCompletions(realm, pnc.alternate, c);
|
||||
|
||||
var _pnc$alternateEffects2 = _slicedToArray(pnc.alternateEffects, 5),
|
||||
g = _pnc$alternateEffects2[1],
|
||||
b = _pnc$alternateEffects2[2],
|
||||
p = _pnc$alternateEffects2[3],
|
||||
o = _pnc$alternateEffects2[4];
|
||||
|
||||
var newAlternateEffects = [new_alternate, g, b, p, o];
|
||||
return new _completions.PossiblyNormalCompletion(new_alternate.value, pnc.joinCondition, pnc.consequent, pnc.consequentEffects, new_alternate, newAlternateEffects, composedPath, savedPathConditions, pnc.savedEffects);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.AbruptCompletion);
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
var _pnc$consequentEffect = _slicedToArray(pnc.consequentEffects, 5),
|
||||
_g3 = _pnc$consequentEffect[1],
|
||||
_b3 = _pnc$consequentEffect[2],
|
||||
_p3 = _pnc$consequentEffect[3],
|
||||
_o3 = _pnc$consequentEffect[4];
|
||||
|
||||
var _newConsequentEffects = [c, _g3, _b3, _p3, _o3];
|
||||
return new _completions.PossiblyNormalCompletion(c.value, pnc.joinCondition, c, _newConsequentEffects, pnc.alternate, pnc.alternateEffects, composedPath, savedPathConditions, pnc.savedEffects);
|
||||
}
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
var new_consequent = this.composePossiblyNormalCompletions(realm, pnc.consequent, c);
|
||||
|
||||
var _pnc$consequentEffect2 = _slicedToArray(pnc.consequentEffects, 5),
|
||||
_g2 = _pnc$consequentEffect2[1],
|
||||
_b2 = _pnc$consequentEffect2[2],
|
||||
_p2 = _pnc$consequentEffect2[3],
|
||||
_o2 = _pnc$consequentEffect2[4];
|
||||
|
||||
var newConsequentEffects = [new_consequent, _g2, _b2, _p2, _o2];
|
||||
return new _completions.PossiblyNormalCompletion(new_consequent.value, pnc.joinCondition, new_consequent, newConsequentEffects, pnc.alternate, pnc.alternateEffects, composedPath, savedPathConditions, pnc.savedEffects);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "updatePossiblyNormalCompletionWithSubsequentEffects",
|
||||
value: function updatePossiblyNormalCompletionWithSubsequentEffects(realm, pnc, subsequentEffects) {
|
||||
var v = subsequentEffects[0];
|
||||
(0, _invariant2.default)(v instanceof _index2.Value);
|
||||
pnc.value = v;
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
pnc.alternate = v;
|
||||
pnc.alternateEffects = realm.composeEffects(pnc.alternateEffects, subsequentEffects);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
this.updatePossiblyNormalCompletionWithSubsequentEffects(realm, pnc.alternate, subsequentEffects);
|
||||
}
|
||||
} else {
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
pnc.consequent = v;
|
||||
pnc.consequentEffects = realm.composeEffects(pnc.consequentEffects, subsequentEffects);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
this.updatePossiblyNormalCompletionWithSubsequentEffects(realm, pnc.consequent, subsequentEffects);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "updatePossiblyNormalCompletionWithValue",
|
||||
value: function updatePossiblyNormalCompletionWithValue(realm, pnc, v) {
|
||||
pnc.value = v;
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
pnc.alternate = v;
|
||||
pnc.alternateEffects[0] = v;
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
this.updatePossiblyNormalCompletionWithValue(realm, pnc.alternate, v);
|
||||
}
|
||||
} else {
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
pnc.consequent = v;
|
||||
pnc.consequentEffects[0] = v;
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
this.updatePossiblyNormalCompletionWithValue(realm, pnc.consequent, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the joined effects of all of the paths in pnc.
|
||||
// The normal path in pnc is modified to become terminated by ac,
|
||||
// so the overall completion will always be an instance of JoinedAbruptCompletions
|
||||
|
||||
}, {
|
||||
key: "joinPossiblyNormalCompletionWithAbruptCompletion",
|
||||
value: function joinPossiblyNormalCompletionWithAbruptCompletion(realm,
|
||||
// a forked path with a non abrupt (normal) component
|
||||
pnc,
|
||||
// an abrupt completion that completes the normal path
|
||||
ac,
|
||||
// effects collected after pnc was constructed
|
||||
e) {
|
||||
// set up e with ac as the completion. It's OK to do this repeatedly since ac is not changed by recursive calls.
|
||||
e[0] = ac;
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
return this.joinEffects(realm, pnc.joinCondition, pnc.consequentEffects, realm.composeEffects(pnc.alternateEffects, e));
|
||||
}
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
var alternate_effects = this.joinPossiblyNormalCompletionWithAbruptCompletion(realm, pnc.alternate, ac, e);
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.AbruptCompletion);
|
||||
return this.joinEffects(realm, pnc.joinCondition, pnc.consequentEffects, alternate_effects);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.AbruptCompletion);
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
return this.joinEffects(realm, pnc.joinCondition, realm.composeEffects(pnc.consequentEffects, e), pnc.alternateEffects);
|
||||
}
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
var consequent_effects = this.joinPossiblyNormalCompletionWithAbruptCompletion(realm, pnc.consequent, ac, e);
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.AbruptCompletion);
|
||||
return this.joinEffects(realm, pnc.joinCondition, consequent_effects, pnc.alternateEffects);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "joinPossiblyNormalCompletionWithValue",
|
||||
value: function joinPossiblyNormalCompletionWithValue(realm, joinCondition, pnc, v) {
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
pnc.alternate = this.joinValuesAsConditional(realm, joinCondition, pnc.alternate, v);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
this.joinPossiblyNormalCompletionWithValue(realm, joinCondition, pnc.alternate, v);
|
||||
}
|
||||
} else {
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
pnc.consequent = this.joinValuesAsConditional(realm, joinCondition, pnc.consequent, v);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
this.joinPossiblyNormalCompletionWithValue(realm, joinCondition, pnc.consequent, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "joinValueWithPossiblyNormalCompletion",
|
||||
value: function joinValueWithPossiblyNormalCompletion(realm, joinCondition, pnc, v) {
|
||||
if (pnc.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (pnc.alternate instanceof _index2.Value) {
|
||||
pnc.alternate = this.joinValuesAsConditional(realm, joinCondition, v, pnc.alternate);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
this.joinValueWithPossiblyNormalCompletion(realm, joinCondition, pnc.alternate, v);
|
||||
}
|
||||
} else {
|
||||
if (pnc.consequent instanceof _index2.Value) {
|
||||
pnc.consequent = this.joinValuesAsConditional(realm, joinCondition, v, pnc.consequent);
|
||||
} else {
|
||||
(0, _invariant2.default)(pnc.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
this.joinValueWithPossiblyNormalCompletion(realm, joinCondition, pnc.consequent, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "joinAndRemoveNestedReturnCompletions",
|
||||
value: function joinAndRemoveNestedReturnCompletions(realm, c) {
|
||||
if (c instanceof _completions.ReturnCompletion) {
|
||||
return c.value;
|
||||
}
|
||||
if (c instanceof _completions.JoinedAbruptCompletions) {
|
||||
var c1 = this.joinAndRemoveNestedReturnCompletions(realm, c.consequent);
|
||||
var c2 = this.joinAndRemoveNestedReturnCompletions(realm, c.alternate);
|
||||
c.consequentEffects[0] = c1;
|
||||
c.alternateEffects[0] = c2;
|
||||
return this.joinResults(realm, c.joinCondition, c1, c2, c.consequentEffects, c.alternateEffects);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}, {
|
||||
key: "joinEffectsAndPromoteNestedReturnCompletions",
|
||||
value: function joinEffectsAndPromoteNestedReturnCompletions(realm, c, e, nested_effects) {
|
||||
if (c instanceof _index2.Value) {
|
||||
// If not undefined, the nested effects were captured when evaluating a conditional code block that ended normally.
|
||||
// e represent effects that were captured since reaching the join point where the normal and abrupt
|
||||
// completions came together into the completion supplied to the outermost call to this recursive function.
|
||||
if (nested_effects !== undefined) e = realm.composeEffects(nested_effects, e);
|
||||
return e;
|
||||
}
|
||||
if (c instanceof _completions.AbruptCompletion && !(c instanceof _completions.JoinedAbruptCompletions)) {
|
||||
// The nested effects were captured when evaluating a conditional code block that ended abruptly.
|
||||
// An abrupt completion does not care about the effects that were collected since the join point.
|
||||
(0, _invariant2.default)(nested_effects !== undefined);
|
||||
return nested_effects;
|
||||
}
|
||||
if (c instanceof _completions.PossiblyNormalCompletion) {
|
||||
var _e = this.joinEffectsAndPromoteNestedReturnCompletions(realm, c.consequent, e, c.consequentEffects);
|
||||
var _e2 = this.joinEffectsAndPromoteNestedReturnCompletions(realm, c.alternate, e, c.alternateEffects);
|
||||
if (_e[0] instanceof _completions.AbruptCompletion) {
|
||||
if (_e2[0] instanceof _index2.Value) _e2[0] = new _completions.ReturnCompletion(realm.intrinsics.undefined, realm.currentLocation);
|
||||
return this.joinEffects(realm, c.joinCondition, _e, _e2);
|
||||
} else if (_e2[0] instanceof _completions.AbruptCompletion) {
|
||||
if (_e[0] instanceof _index2.Value) _e[0] = new _completions.ReturnCompletion(realm.intrinsics.undefined, realm.currentLocation);
|
||||
return this.joinEffects(realm, c.joinCondition, _e, _e2);
|
||||
}
|
||||
}
|
||||
(0, _invariant2.default)(c instanceof _completions.JoinedAbruptCompletions);
|
||||
// e will be ignored in the calls below since the branches are all abrupt.
|
||||
var e1 = this.joinEffectsAndPromoteNestedReturnCompletions(realm, c.consequent, e, c.consequentEffects);
|
||||
var e2 = this.joinEffectsAndPromoteNestedReturnCompletions(realm, c.alternate, e, c.alternateEffects);
|
||||
var _ref3 = [e1[0], e2[0]],
|
||||
r1 = _ref3[0],
|
||||
r2 = _ref3[1];
|
||||
|
||||
if (r1 instanceof _completions.ReturnCompletion) {
|
||||
(0, _invariant2.default)(!(r2 instanceof _completions.ReturnCompletion)); // Otherwise their values should have been joined
|
||||
if (r2 instanceof _completions.JoinedAbruptCompletions) {
|
||||
if (r2.consequent instanceof _completions.ReturnCompletion) {
|
||||
var r1jr2c = this.joinEffects(realm, c.joinCondition, e1, r2.consequentEffects);
|
||||
(0, _invariant2.default)(r1jr2c[0] instanceof _completions.ReturnCompletion);
|
||||
var or = _index2.AbstractValue.createFromLogicalOp(realm, "||", c.joinCondition, r2.joinCondition);
|
||||
(0, _invariant2.default)(or instanceof _index2.AbstractValue);
|
||||
return this.joinEffects(realm, or, r1jr2c, r2.alternateEffects);
|
||||
}
|
||||
if (r2.alternate instanceof _completions.ReturnCompletion) {
|
||||
var r1jr2a = this.joinEffects(realm, c.joinCondition, e1, r2.alternateEffects);
|
||||
(0, _invariant2.default)(r1jr2a[0] instanceof _completions.ReturnCompletion);
|
||||
var notR2jc = _index2.AbstractValue.createFromUnaryOp(realm, "!", r2.joinCondition);
|
||||
var _or = _index2.AbstractValue.createFromLogicalOp(realm, "||", c.joinCondition, notR2jc);
|
||||
(0, _invariant2.default)(_or instanceof _index2.AbstractValue);
|
||||
return this.joinEffects(realm, _or, r1jr2a, r2.consequentEffects);
|
||||
}
|
||||
}
|
||||
} else if (r2 instanceof _completions.ReturnCompletion) {
|
||||
(0, _invariant2.default)(!(r1 instanceof _completions.ReturnCompletion)); // Otherwise their values should have been joined
|
||||
if (r1 instanceof _completions.JoinedAbruptCompletions) {
|
||||
if (r1.consequent instanceof _completions.ReturnCompletion) {
|
||||
var r2jr1c = this.joinEffects(realm, c.joinCondition, r1.consequentEffects, e2);
|
||||
(0, _invariant2.default)(r2jr1c[0] instanceof _completions.ReturnCompletion);
|
||||
var _or2 = _index2.AbstractValue.createFromLogicalOp(realm, "||", c.joinCondition, r1.joinCondition);
|
||||
(0, _invariant2.default)(_or2 instanceof _index2.AbstractValue);
|
||||
return this.joinEffects(realm, _or2, r2jr1c, r1.alternateEffects);
|
||||
}
|
||||
if (r1.alternate instanceof _completions.ReturnCompletion) {
|
||||
var r2jr1a = this.joinEffects(realm, c.joinCondition, r1.alternateEffects, e2);
|
||||
var notR1jc = _index2.AbstractValue.createFromUnaryOp(realm, "!", r1.joinCondition);
|
||||
(0, _invariant2.default)(r2jr1a[0] instanceof _completions.ReturnCompletion);
|
||||
var _or3 = _index2.AbstractValue.createFromLogicalOp(realm, "||", c.joinCondition, notR1jc);
|
||||
(0, _invariant2.default)(_or3 instanceof _index2.AbstractValue);
|
||||
return this.joinEffects(realm, _or3, r2jr1a, r1.consequentEffects);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.joinEffects(realm, c.joinCondition, e1, e2);
|
||||
}
|
||||
}, {
|
||||
key: "unbundleReturnCompletion",
|
||||
value: function unbundleReturnCompletion(realm, c) {
|
||||
var empty_effects = (0, _realm.construct_empty_effects)(realm);
|
||||
var v = realm.intrinsics.empty;
|
||||
if (c.consequent instanceof _completions.ReturnCompletion) {
|
||||
var negation = _index2.AbstractValue.createFromUnaryOp(realm, "!", c.joinCondition);
|
||||
// Simply negating the (known to be abstract) join condition should
|
||||
// not become a concrete value
|
||||
(0, _invariant2.default)(negation instanceof _index2.AbstractValue);
|
||||
var pathConditions = [negation];
|
||||
var pnc = new _completions.PossiblyNormalCompletion(v, c.joinCondition, v, empty_effects, c.alternate, c.alternateEffects, pathConditions, []);
|
||||
return [c.consequentEffects, pnc];
|
||||
} else if (c.alternate instanceof _completions.ReturnCompletion) {
|
||||
var _pnc = new _completions.PossiblyNormalCompletion(v, c.joinCondition, c.consequent, c.consequentEffects, v, empty_effects, [c.joinCondition], []);
|
||||
return [c.alternateEffects, _pnc];
|
||||
} else {
|
||||
(0, _invariant2.default)(false, "unbundleReturnCompletion needs an argument that contains a non nested return completion");
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "removeNormalEffects",
|
||||
value: function removeNormalEffects(realm, c) {
|
||||
if (c.consequent instanceof _completions.AbruptCompletion) {
|
||||
if (c.alternate instanceof _index2.Value) {
|
||||
var result = c.alternateEffects;
|
||||
c.alternateEffects = (0, _realm.construct_empty_effects)(realm);
|
||||
return result;
|
||||
} else {
|
||||
(0, _invariant2.default)(c.alternate instanceof _completions.PossiblyNormalCompletion);
|
||||
var _result = realm.composeEffects(c.alternateEffects, this.removeNormalEffects(realm, c.alternate));
|
||||
c.alternateEffects = (0, _realm.construct_empty_effects)(realm);
|
||||
return _result;
|
||||
}
|
||||
} else {
|
||||
if (c.consequent instanceof _index2.Value) {
|
||||
var _result2 = c.consequentEffects;
|
||||
c.consequentEffects = (0, _realm.construct_empty_effects)(realm);
|
||||
return _result2;
|
||||
} else {
|
||||
(0, _invariant2.default)(c.consequent instanceof _completions.PossiblyNormalCompletion);
|
||||
var _result3 = realm.composeEffects(c.consequentEffects, this.removeNormalEffects(realm, c.consequent));
|
||||
c.consequentEffects = (0, _realm.construct_empty_effects)(realm);
|
||||
return _result3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "joinEffects",
|
||||
value: function joinEffects(realm, joinCondition, e1, e2) {
|
||||
var _e3 = _slicedToArray(e1, 5),
|
||||
result1 = _e3[0],
|
||||
gen1 = _e3[1],
|
||||
bindings1 = _e3[2],
|
||||
properties1 = _e3[3],
|
||||
createdObj1 = _e3[4];
|
||||
|
||||
var _e4 = _slicedToArray(e2, 5),
|
||||
result2 = _e4[0],
|
||||
gen2 = _e4[1],
|
||||
bindings2 = _e4[2],
|
||||
properties2 = _e4[3],
|
||||
createdObj2 = _e4[4];
|
||||
|
||||
var result = this.joinResults(realm, joinCondition, result1, result2, e1, e2);
|
||||
if (result1 instanceof _completions.AbruptCompletion) {
|
||||
if (!(result2 instanceof _completions.AbruptCompletion)) {
|
||||
(0, _invariant2.default)(result instanceof _completions.PossiblyNormalCompletion);
|
||||
return [result, gen2, bindings2, properties2, createdObj2];
|
||||
}
|
||||
} else if (result2 instanceof _completions.AbruptCompletion) {
|
||||
(0, _invariant2.default)(result instanceof _completions.PossiblyNormalCompletion);
|
||||
return [result, gen1, bindings1, properties1, createdObj1];
|
||||
}
|
||||
|
||||
var bindings = this.joinBindings(realm, joinCondition, bindings1, bindings2);
|
||||
var properties = this.joinPropertyBindings(realm, joinCondition, properties1, properties2, createdObj1, createdObj2);
|
||||
var createdObjects = new Set();
|
||||
createdObj1.forEach(function (o) {
|
||||
createdObjects.add(o);
|
||||
});
|
||||
createdObj2.forEach(function (o) {
|
||||
createdObjects.add(o);
|
||||
});
|
||||
|
||||
var generator = joinGenerators(realm, joinCondition, gen1, gen2);
|
||||
|
||||
return [result, generator, bindings, properties, createdObjects];
|
||||
}
|
||||
}, {
|
||||
key: "joinResults",
|
||||
value: function joinResults(realm, joinCondition, result1, result2, e1, e2) {
|
||||
var _this = this;
|
||||
|
||||
var getAbstractValue = function getAbstractValue(v1, v2) {
|
||||
return _this.joinValuesAsConditional(realm, joinCondition, v1, v2);
|
||||
};
|
||||
if (result1 instanceof _environment.Reference || result2 instanceof _environment.Reference) {
|
||||
_index2.AbstractValue.reportIntrospectionError(joinCondition);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
if (result1 instanceof _completions.BreakCompletion && result2 instanceof _completions.BreakCompletion && result1.target === result2.target) {
|
||||
return new _completions.BreakCompletion(realm.intrinsics.empty, joinCondition.expressionLocation, result1.target);
|
||||
}
|
||||
if (result1 instanceof _completions.ContinueCompletion && result2 instanceof _completions.ContinueCompletion && result1.target === result2.target) {
|
||||
return new _completions.ContinueCompletion(realm.intrinsics.empty, joinCondition.expressionLocation, result1.target);
|
||||
}
|
||||
if (result1 instanceof _completions.ReturnCompletion && result2 instanceof _completions.ReturnCompletion) {
|
||||
var val = this.joinValues(realm, result1.value, result2.value, getAbstractValue);
|
||||
(0, _invariant2.default)(val instanceof _index2.Value);
|
||||
return new _completions.ReturnCompletion(val, joinCondition.expressionLocation);
|
||||
}
|
||||
if (result1 instanceof _completions.ThrowCompletion && result2 instanceof _completions.ThrowCompletion) {
|
||||
var _val = this.joinValues(realm, result1.value, result2.value, getAbstractValue);
|
||||
(0, _invariant2.default)(_val instanceof _index2.Value);
|
||||
return new _completions.ThrowCompletion(_val, result1.location);
|
||||
}
|
||||
if (result1 instanceof _completions.AbruptCompletion && result2 instanceof _completions.AbruptCompletion) {
|
||||
return new _completions.JoinedAbruptCompletions(realm, joinCondition, result1, e1, result2, e2);
|
||||
}
|
||||
if (result1 instanceof _index2.Value && result2 instanceof _index2.Value) {
|
||||
var _val2 = this.joinValues(realm, result1, result2, getAbstractValue);
|
||||
(0, _invariant2.default)(_val2 instanceof _index2.Value);
|
||||
return _val2;
|
||||
}
|
||||
if (result1 instanceof _completions.PossiblyNormalCompletion && result2 instanceof _completions.PossiblyNormalCompletion) {
|
||||
return this.composePossiblyNormalCompletions(realm, result1, result2);
|
||||
}
|
||||
if (result1 instanceof _completions.AbruptCompletion) {
|
||||
var value = result2;
|
||||
var savedEffects = void 0;
|
||||
var pathConditions = void 0;
|
||||
var savedPathConditions = [];
|
||||
if (result2 instanceof _completions.PossiblyNormalCompletion) {
|
||||
value = result2.value;
|
||||
savedEffects = result2.savedEffects;
|
||||
pathConditions = [joinCondition].concat(result2.pathConditions);
|
||||
savedPathConditions = result2.savedPathConditions;
|
||||
} else {
|
||||
pathConditions = [joinCondition];
|
||||
}
|
||||
(0, _invariant2.default)(value instanceof _index2.Value);
|
||||
return new _completions.PossiblyNormalCompletion(value, joinCondition, result1, e1, result2, e2, pathConditions, savedPathConditions, savedEffects);
|
||||
}
|
||||
if (result2 instanceof _completions.AbruptCompletion) {
|
||||
var _value = result1;
|
||||
var _savedEffects = void 0;
|
||||
var _pathConditions = void 0;
|
||||
var _savedPathConditions = [];
|
||||
if (result1 instanceof _completions.PossiblyNormalCompletion) {
|
||||
_value = result1.value;
|
||||
_savedEffects = result1.savedEffects;
|
||||
_pathConditions = [joinCondition].concat(result1.pathConditions);
|
||||
_savedPathConditions = result1.savedPathConditions;
|
||||
} else {
|
||||
_pathConditions = [joinCondition];
|
||||
}
|
||||
(0, _invariant2.default)(_value instanceof _index2.Value);
|
||||
return new _completions.PossiblyNormalCompletion(_value, joinCondition, result1, e1, result2, e2, _pathConditions, _savedPathConditions, _savedEffects);
|
||||
}
|
||||
if (result1 instanceof _completions.PossiblyNormalCompletion) {
|
||||
(0, _invariant2.default)(result2 instanceof _index2.Value);
|
||||
this.joinPossiblyNormalCompletionWithValue(realm, joinCondition, result1, result2);
|
||||
return result1;
|
||||
}
|
||||
if (result2 instanceof _completions.PossiblyNormalCompletion) {
|
||||
(0, _invariant2.default)(result1 instanceof _index2.Value);
|
||||
this.joinValueWithPossiblyNormalCompletion(realm, joinCondition, result2, result1);
|
||||
return result2;
|
||||
}
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
}, {
|
||||
key: "composeGenerators",
|
||||
value: function composeGenerators(realm, generator1, generator2) {
|
||||
var result = new _generator.Generator(realm);
|
||||
if (!generator1.empty() || !generator2.empty()) {
|
||||
result.composeGenerators(generator1, generator2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Creates a single map that joins together maps m1 and m2 using the given join
|
||||
// operator. If an entry is present in one map but not the other, the missing
|
||||
// entry is treated as if it were there and its value were undefined.
|
||||
|
||||
}, {
|
||||
key: "joinMaps",
|
||||
value: function joinMaps(m1, m2, join) {
|
||||
var m3 = new Map();
|
||||
m1.forEach(function (val1, key, map1) {
|
||||
var val2 = m2.get(key);
|
||||
var val3 = join(key, val1, val2);
|
||||
m3.set(key, val3);
|
||||
});
|
||||
m2.forEach(function (val2, key, map2) {
|
||||
if (!m1.has(key)) {
|
||||
m3.set(key, join(key, undefined, val2));
|
||||
}
|
||||
});
|
||||
return m3;
|
||||
}
|
||||
|
||||
// Creates a single map that has an key, value pair for the union of the key
|
||||
// sets of m1 and m2. The value of a pair is the join of m1[key] and m2[key]
|
||||
// where the join is defined to be just m1[key] if m1[key] === m2[key] and
|
||||
// and abstract value with expression "joinCondition ? m1[key] : m2[key]" if not.
|
||||
|
||||
}, {
|
||||
key: "joinBindings",
|
||||
value: function joinBindings(realm, joinCondition, m1, m2) {
|
||||
var _this2 = this;
|
||||
|
||||
var getAbstractValue = function getAbstractValue(v1, v2) {
|
||||
return _this2.joinValuesAsConditional(realm, joinCondition, v1, v2);
|
||||
};
|
||||
var join = function join(b, b1, b2) {
|
||||
var l1 = b1 === undefined ? b.hasLeaked : b1.hasLeaked;
|
||||
var l2 = b2 === undefined ? b.hasLeaked : b2.hasLeaked;
|
||||
var v1 = b1 === undefined ? b.value : b1.value;
|
||||
var v2 = b2 === undefined ? b.value : b2.value;
|
||||
var hasLeaked = l1 || l2; // If either has leaked, then this binding has leaked.
|
||||
var value = _this2.joinValues(realm, v1, v2, getAbstractValue);
|
||||
(0, _invariant2.default)(value instanceof _index2.Value);
|
||||
return { hasLeaked: hasLeaked, value: value };
|
||||
};
|
||||
return this.joinMaps(m1, m2, join);
|
||||
}
|
||||
|
||||
// If v1 is known and defined and v1 === v2 return v1,
|
||||
// otherwise return getAbstractValue(v1, v2)
|
||||
|
||||
}, {
|
||||
key: "joinValues",
|
||||
value: function joinValues(realm, v1, v2, getAbstractValue) {
|
||||
if (Array.isArray(v1) || Array.isArray(v2)) {
|
||||
(0, _invariant2.default)(v1 === undefined || Array.isArray(v1));
|
||||
(0, _invariant2.default)(v2 === undefined || Array.isArray(v2));
|
||||
return joinArrays(realm, v1, v2, getAbstractValue);
|
||||
}
|
||||
(0, _invariant2.default)(v1 === undefined || v1 instanceof _index2.Value);
|
||||
(0, _invariant2.default)(v2 === undefined || v2 instanceof _index2.Value);
|
||||
if (v1 !== undefined && v2 !== undefined && !(v1 instanceof _index2.AbstractValue) && !(v2 instanceof _index2.AbstractValue) && (0, _index.StrictEqualityComparison)(realm, v1.throwIfNotConcrete(), v2.throwIfNotConcrete())) {
|
||||
return v1;
|
||||
} else {
|
||||
return getAbstractValue(v1, v2);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "joinValuesAsConditional",
|
||||
value: function joinValuesAsConditional(realm, condition, v1, v2) {
|
||||
return _index2.AbstractValue.createFromConditionalOp(realm, condition, v1, v2);
|
||||
}
|
||||
}, {
|
||||
key: "joinPropertyBindings",
|
||||
value: function joinPropertyBindings(realm, joinCondition, m1, m2, c1, c2) {
|
||||
var _this3 = this;
|
||||
|
||||
var join = function join(b, d1, d2) {
|
||||
// If the PropertyBinding object has been freshly allocated do not join
|
||||
if (d1 === undefined) {
|
||||
if (b.object instanceof _index2.ObjectValue && c2.has(b.object)) return d2; // no join
|
||||
if (b.descriptor !== undefined && m1.has(b)) {
|
||||
// property was deleted
|
||||
d1 = (0, _index.cloneDescriptor)(b.descriptor);
|
||||
(0, _invariant2.default)(d1 !== undefined);
|
||||
d1.value = realm.intrinsics.empty;
|
||||
} else {
|
||||
// no write to property
|
||||
d1 = b.descriptor; //Get value of property before the split
|
||||
}
|
||||
}
|
||||
if (d2 === undefined) {
|
||||
if (b.object instanceof _index2.ObjectValue && c1.has(b.object)) return d1; // no join
|
||||
if (b.descriptor !== undefined && m2.has(b)) {
|
||||
// property was deleted
|
||||
d2 = (0, _index.cloneDescriptor)(b.descriptor);
|
||||
(0, _invariant2.default)(d2 !== undefined);
|
||||
d2.value = realm.intrinsics.empty;
|
||||
} else {
|
||||
// no write to property
|
||||
d2 = b.descriptor; //Get value of property before the split
|
||||
}
|
||||
}
|
||||
return _this3.joinDescriptors(realm, joinCondition, d1, d2);
|
||||
};
|
||||
return this.joinMaps(m1, m2, join);
|
||||
}
|
||||
}, {
|
||||
key: "joinDescriptors",
|
||||
value: function joinDescriptors(realm, joinCondition, d1, d2) {
|
||||
var _this4 = this;
|
||||
|
||||
var getAbstractValue = function getAbstractValue(v1, v2) {
|
||||
return _this4.joinValuesAsConditional(realm, joinCondition, v1, v2);
|
||||
};
|
||||
var clone_with_abstract_value = function clone_with_abstract_value(d) {
|
||||
if (!(0, _index.IsDataDescriptor)(realm, d)) {
|
||||
var d3 = {};
|
||||
d3.joinCondition = joinCondition;
|
||||
return d3;
|
||||
}
|
||||
var dc = (0, _index.cloneDescriptor)(d);
|
||||
(0, _invariant2.default)(dc !== undefined);
|
||||
var dcValue = dc.value;
|
||||
if (Array.isArray(dcValue)) {
|
||||
(0, _invariant2.default)(dcValue.length > 0);
|
||||
var elem0 = dcValue[0];
|
||||
if (elem0 instanceof _index2.Value) {
|
||||
dc.value = dcValue.map(function (e) {
|
||||
return getAbstractValue(e, realm.intrinsics.empty);
|
||||
});
|
||||
} else {
|
||||
dc.value = dcValue.map(function (e) {
|
||||
var _ref4 = e,
|
||||
key1 = _ref4.$Key,
|
||||
val1 = _ref4.$Value;
|
||||
|
||||
var key3 = getAbstractValue(key1, realm.intrinsics.empty);
|
||||
var val3 = getAbstractValue(val1, realm.intrinsics.empty);
|
||||
return { $Key: key3, $Value: val3 };
|
||||
});
|
||||
}
|
||||
} else {
|
||||
(0, _invariant2.default)(dcValue === undefined || dcValue instanceof _index2.Value);
|
||||
dc.value = getAbstractValue(dcValue, realm.intrinsics.empty);
|
||||
}
|
||||
return dc;
|
||||
};
|
||||
if (d1 === undefined) {
|
||||
if (d2 === undefined) return undefined;
|
||||
// d2 is a new property created in only one branch, join with empty
|
||||
var d3 = clone_with_abstract_value(d2);
|
||||
if (!(0, _index.IsDataDescriptor)(realm, d2)) d3.descriptor2 = d2;
|
||||
return d3;
|
||||
} else if (d2 === undefined) {
|
||||
(0, _invariant2.default)(d1 !== undefined);
|
||||
// d1 is a new property created in only one branch, join with empty
|
||||
var _d = clone_with_abstract_value(d1);
|
||||
if (!(0, _index.IsDataDescriptor)(realm, d1)) _d.descriptor1 = d1;
|
||||
return _d;
|
||||
} else {
|
||||
if ((0, _index.equalDescriptors)(d1, d2) && (0, _index.IsDataDescriptor)(realm, d1)) {
|
||||
var dc = (0, _index.cloneDescriptor)(d1);
|
||||
(0, _invariant2.default)(dc !== undefined);
|
||||
dc.value = this.joinValues(realm, d1.value, d2.value, getAbstractValue);
|
||||
return dc;
|
||||
}
|
||||
var _d2 = {};
|
||||
_d2.joinCondition = joinCondition;
|
||||
_d2.descriptor1 = d1;
|
||||
_d2.descriptor2 = d2;
|
||||
return _d2;
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
return JoinImplementation;
|
||||
}();
|
||||
//# sourceMappingURL=join.js.map
|
||||
1
build/node_modules/prepack/lib/methods/join.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/join.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
123
build/node_modules/prepack/lib/methods/json.js
generated
vendored
Normal file
123
build/node_modules/prepack/lib/methods/json.js
generated
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.InternalizeJSONProperty = InternalizeJSONProperty;
|
||||
|
||||
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 _own = require("../methods/own.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 24.3.1.1
|
||||
/**
|
||||
* 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 InternalizeJSONProperty(realm, reviver, holder, name) {
|
||||
// 1. Let val be ? Get(holder, name).
|
||||
var val = (0, _get.Get)(realm, holder, name);
|
||||
// 2. If Type(val) is Object, then
|
||||
if (val instanceof _index.ObjectValue) {
|
||||
// a. Let isArray be ? IsArray(val).
|
||||
var isArray = (0, _is.IsArray)(realm, val);
|
||||
|
||||
// b. If isArray is true, then
|
||||
if (isArray === true) {
|
||||
// i. Set I to 0.
|
||||
var I = 0;
|
||||
|
||||
// ii. Let len be ? ToLength(? Get(val, "length")).
|
||||
var len = _singletons.To.ToLength(realm, (0, _get.Get)(realm, val, "length"));
|
||||
|
||||
// iii. Repeat while I < len,
|
||||
while (I < len) {
|
||||
// 1. Let newElement be ? InternalizeJSONProperty(val, ! ToString(I)).
|
||||
var newElement = InternalizeJSONProperty(realm, reviver, val, _singletons.To.ToString(realm, new _index.NumberValue(realm, I)));
|
||||
|
||||
// 2. If newElement is undefined, then
|
||||
if (newElement instanceof _index.UndefinedValue) {
|
||||
// a. Perform ? val.[[Delete]](! ToString(I)).
|
||||
val.$Delete(_singletons.To.ToString(realm, new _index.NumberValue(realm, I)));
|
||||
} else {
|
||||
// 3. Else,
|
||||
// a. Perform ? CreateDataProperty(val, ! ToString(I), newElement).
|
||||
_singletons.Create.CreateDataProperty(realm, val, _singletons.To.ToString(realm, new _index.NumberValue(realm, I)), newElement.throwIfNotConcrete());
|
||||
|
||||
// b. NOTE This algorithm intentionally does not throw an exception if CreateDataProperty returns false.
|
||||
}
|
||||
|
||||
// 4. Add 1 to I.
|
||||
I += 1;
|
||||
}
|
||||
} else {
|
||||
// c. Else,
|
||||
// i. Let keys be ? EnumerableOwnProperties(val, "key").
|
||||
var keys = (0, _own.EnumerableOwnProperties)(realm, val, "key");
|
||||
|
||||
// ii. For each String P in keys do,
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var P = _step.value;
|
||||
|
||||
(0, _invariant2.default)(P instanceof _index.StringValue);
|
||||
|
||||
// 1. Let newElement be ? InternalizeJSONProperty(val, P).
|
||||
var _newElement = InternalizeJSONProperty(realm, reviver, val, P);
|
||||
|
||||
// 2. If newElement is undefined, then
|
||||
if (_newElement instanceof _index.UndefinedValue) {
|
||||
// a. Perform ? val.[[Delete]](P).
|
||||
val.$Delete(P);
|
||||
} else {
|
||||
// 3. Else,
|
||||
// a. Perform ? CreateDataProperty(val, P, newElement).
|
||||
_singletons.Create.CreateDataProperty(realm, val, P, _newElement);
|
||||
|
||||
// b. NOTE This algorithm intentionally does not throw an exception if CreateDataProperty returns false.
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Return ? Call(reviver, holder, « name, val »).
|
||||
return (0, _call.Call)(realm, reviver, holder, [typeof name === "string" ? new _index.StringValue(realm, name) : name, val]);
|
||||
}
|
||||
//# sourceMappingURL=json.js.map
|
||||
1
build/node_modules/prepack/lib/methods/json.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/json.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
255
build/node_modules/prepack/lib/methods/own.js
generated
vendored
Normal file
255
build/node_modules/prepack/lib/methods/own.js
generated
vendored
Normal file
@@ -0,0 +1,255 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.GetOwnPropertyKeys = GetOwnPropertyKeys;
|
||||
exports.OrdinaryOwnPropertyKeys = OrdinaryOwnPropertyKeys;
|
||||
exports.EnumerableOwnProperties = EnumerableOwnProperties;
|
||||
|
||||
var _index = require("./index.js");
|
||||
|
||||
var _index2 = require("../values/index.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 19.1.2.8.1
|
||||
/**
|
||||
* 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 GetOwnPropertyKeys(realm, O, Type) {
|
||||
// 1. Let obj be ? ToObject(O).
|
||||
var obj = _singletons.To.ToObject(realm, O.throwIfNotConcrete());
|
||||
|
||||
// 2. Let keys be ? obj.[[OwnPropertyKeys]]().
|
||||
var keys = obj.$OwnPropertyKeys();
|
||||
|
||||
// 3. Let nameList be a new empty List.
|
||||
var nameList = [];
|
||||
|
||||
// 4. Repeat for each element nextKey of keys in List order,
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = keys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var nextKey = _step.value;
|
||||
|
||||
// a. If Type(nextKey) is Type, then
|
||||
if (nextKey instanceof Type) {
|
||||
// i. Append nextKey as the last element of nameList.
|
||||
nameList.push(nextKey);
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Return CreateArrayFromList(nameList).
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _singletons.Create.CreateArrayFromList(realm, nameList);
|
||||
}
|
||||
|
||||
// ECMA262 9.1.11.1
|
||||
function OrdinaryOwnPropertyKeys(realm, o) {
|
||||
// 1. Let keys be a new empty List.
|
||||
var keys = [];
|
||||
|
||||
// 2. For each own property key P of O that is an integer index, in ascending numeric index order
|
||||
var properties = o.getOwnPropertyKeysArray();
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = properties.filter(function (x) {
|
||||
return (0, _index.IsArrayIndex)(realm, x);
|
||||
}).map(function (x) {
|
||||
return parseInt(x, 10);
|
||||
}).sort(function (x, y) {
|
||||
return x - y;
|
||||
})[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var key = _step2.value;
|
||||
|
||||
// i. Add P as the last element of keys.
|
||||
keys.push(new _index2.StringValue(realm, key + ""));
|
||||
}
|
||||
|
||||
// 3. For each own property key P of O that is a String but is not an integer index, in ascending chronological order of property creation
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion3 = true;
|
||||
var _didIteratorError3 = false;
|
||||
var _iteratorError3 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator3 = properties.filter(function (x) {
|
||||
return !(0, _index.IsArrayIndex)(realm, x);
|
||||
})[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
||||
var _key = _step3.value;
|
||||
|
||||
// i. Add P as the last element of keys.
|
||||
keys.push(new _index2.StringValue(realm, _key));
|
||||
}
|
||||
|
||||
// 4. For each own property key P of O that is a Symbol, in ascending chronological order of property creation
|
||||
} catch (err) {
|
||||
_didIteratorError3 = true;
|
||||
_iteratorError3 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
||||
_iterator3.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError3) {
|
||||
throw _iteratorError3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion4 = true;
|
||||
var _didIteratorError4 = false;
|
||||
var _iteratorError4 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator4 = o.symbols.keys()[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
||||
var _key2 = _step4.value;
|
||||
|
||||
// i. Add P as the last element of keys.
|
||||
keys.push(_key2);
|
||||
}
|
||||
|
||||
// 5. Return keys.
|
||||
} catch (err) {
|
||||
_didIteratorError4 = true;
|
||||
_iteratorError4 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
||||
_iterator4.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError4) {
|
||||
throw _iteratorError4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
// ECMA262 7.3.21
|
||||
function EnumerableOwnProperties(realm, O, kind) {
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(O instanceof _index2.ObjectValue, "expected object");
|
||||
|
||||
// 2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
|
||||
var ownKeys = O.$OwnPropertyKeys();
|
||||
|
||||
// 3. Let properties be a new empty List.
|
||||
var properties = [];
|
||||
|
||||
// 4. Repeat, for each element key of ownKeys in List order
|
||||
var _iteratorNormalCompletion5 = true;
|
||||
var _didIteratorError5 = false;
|
||||
var _iteratorError5 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator5 = ownKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
||||
var key = _step5.value;
|
||||
|
||||
// a. If Type(key) is String, then
|
||||
if (key instanceof _index2.StringValue) {
|
||||
// i. Let desc be ? O.[[GetOwnProperty]](key).
|
||||
var desc = O.$GetOwnProperty(key);
|
||||
|
||||
// ii. If desc is not undefined and desc.[[Enumerable]] is true, then
|
||||
if (desc && desc.enumerable) {
|
||||
_singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value);
|
||||
|
||||
// 1. If kind is "key", append key to properties.
|
||||
if (kind === "key") {
|
||||
properties.push(key);
|
||||
} else {
|
||||
// 2. Else,
|
||||
// a. Let value be ? Get(O, key).
|
||||
var value = (0, _index.Get)(realm, O, key);
|
||||
|
||||
// b. If kind is "value", append value to properties.
|
||||
if (kind === "value") {
|
||||
properties.push(value);
|
||||
} else {
|
||||
// c. Else,
|
||||
// i. Assert: kind is "key+value".
|
||||
(0, _invariant2.default)(kind === "key+value", "expected kind to be key+value");
|
||||
|
||||
// ii. Let entry be CreateArrayFromList(« key, value »).
|
||||
var entry = _singletons.Create.CreateArrayFromList(realm, [key, value]);
|
||||
|
||||
// iii. Append entry to properties.
|
||||
properties.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Order the elements of properties so they are in the same relative order as would be produced by the Iterator that would be returned if the EnumerateObjectProperties internal method was invoked with O.
|
||||
|
||||
// 6. Return properties.
|
||||
} catch (err) {
|
||||
_didIteratorError5 = true;
|
||||
_iteratorError5 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
||||
_iterator5.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError5) {
|
||||
throw _iteratorError5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
//# sourceMappingURL=own.js.map
|
||||
1
build/node_modules/prepack/lib/methods/own.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/own.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
630
build/node_modules/prepack/lib/methods/promise.js
generated
vendored
Normal file
630
build/node_modules/prepack/lib/methods/promise.js
generated
vendored
Normal file
@@ -0,0 +1,630 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
|
||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
exports.EnqueueJob = EnqueueJob;
|
||||
exports.NewPromiseCapability = NewPromiseCapability;
|
||||
exports.PerformPromiseAll = PerformPromiseAll;
|
||||
exports.PerformPromiseRace = PerformPromiseRace;
|
||||
exports.PerformPromiseThen = PerformPromiseThen;
|
||||
exports.PromiseReactionJob = PromiseReactionJob;
|
||||
exports.CreateResolvingFunctions = CreateResolvingFunctions;
|
||||
exports.FulfillPromise = FulfillPromise;
|
||||
exports.RejectPromise = RejectPromise;
|
||||
exports.TriggerPromiseReactions = TriggerPromiseReactions;
|
||||
exports.HostPromiseRejectionTracker = HostPromiseRejectionTracker;
|
||||
exports.PromiseResolveThenableJob = PromiseResolveThenableJob;
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _abstract = require("../methods/abstract.js");
|
||||
|
||||
var _construct = require("../methods/construct.js");
|
||||
|
||||
var _get = require("../methods/get.js");
|
||||
|
||||
var _call = require("../methods/call.js");
|
||||
|
||||
var _is = require("../methods/is.js");
|
||||
|
||||
var _iterator2 = require("../methods/iterator.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 8.4.1
|
||||
function EnqueueJob(realm, queueName, job, args) {}
|
||||
|
||||
// ECMA262 25.4.1.5
|
||||
function NewPromiseCapability(realm, C) {
|
||||
// 1. If IsConstructor(C) is false, throw a TypeError exception.
|
||||
if ((0, _is.IsConstructor)(realm, C) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsConstructor(C) is false");
|
||||
}
|
||||
(0, _invariant2.default)(C instanceof _index.ObjectValue);
|
||||
|
||||
// 2. NOTE C is assumed to be a constructor function that supports the parameter conventions of the Promise constructor (see 25.4.3.1).
|
||||
|
||||
// 3. Let promiseCapability be a new PromiseCapability { [[Promise]]: undefined, [[Resolve]]: undefined, [[Reject]]: undefined }.
|
||||
var promiseCapability = {
|
||||
promise: realm.intrinsics.undefined,
|
||||
resolve: realm.intrinsics.undefined,
|
||||
reject: realm.intrinsics.undefined
|
||||
};
|
||||
|
||||
// 4. Let executor be a new built-in function object as defined in GetCapabilitiesExecutor Functions (25.4.1.5.1).
|
||||
var executor = new _index.NativeFunctionValue(realm, undefined, undefined, 2, function (context, _ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
resolve = _ref2[0],
|
||||
reject = _ref2[1];
|
||||
|
||||
// 1. Assert: F has a [[Capability]] internal slot whose value is a PromiseCapability Record.
|
||||
(0, _invariant2.default)(executor.$Capability, "F has a [[Capability]] internal slot whose value is a PromiseCapability Record");
|
||||
|
||||
// 2. Let promiseCapability be the value of F's [[Capability]] internal slot.
|
||||
(0, _invariant2.default)(promiseCapability === executor.$Capability);
|
||||
|
||||
// 3. If promiseCapability.[[Resolve]] is not undefined, throw a TypeError exception.
|
||||
if (!promiseCapability.resolve.mightBeUndefined()) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "promiseCapability.[[Resolve]] is not undefined");
|
||||
}
|
||||
promiseCapability.resolve.throwIfNotConcrete();
|
||||
|
||||
// 4. If promiseCapability.[[Reject]] is not undefined, throw a TypeError exception.
|
||||
if (!promiseCapability.reject.mightBeUndefined()) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "promiseCapability.[[Reject]] is not undefined");
|
||||
}
|
||||
promiseCapability.reject.throwIfNotConcrete();
|
||||
|
||||
// 5. Set promiseCapability.[[Resolve]] to resolve.
|
||||
promiseCapability.resolve = resolve;
|
||||
|
||||
// 6. Set promiseCapability.[[Reject]] to reject.
|
||||
promiseCapability.reject = reject;
|
||||
|
||||
// 7. Return undefined.
|
||||
return realm.intrinsics.undefined;
|
||||
}, false);
|
||||
|
||||
// 5. Set the [[Capability]] internal slot of executor to promiseCapability.
|
||||
executor.$Capability = promiseCapability;
|
||||
|
||||
// 6. Let promise be ? Construct(C, « executor »).
|
||||
var promise = (0, _construct.Construct)(realm, C, [executor]);
|
||||
|
||||
// 7. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception.
|
||||
if ((0, _is.IsCallable)(realm, promiseCapability.resolve) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsCallable(promiseCapability.[[Resolve]]) is false");
|
||||
}
|
||||
|
||||
// 8. If IsCallable(promiseCapability.[[Reject]]) is false, throw a TypeError exception.
|
||||
if ((0, _is.IsCallable)(realm, promiseCapability.reject) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsCallable(promiseCapability.[[Reject]]) is false");
|
||||
}
|
||||
|
||||
// 9. Set promiseCapability.[[Promise]] to promise.
|
||||
promiseCapability.promise = promise;
|
||||
|
||||
// 10. Return promiseCapability.
|
||||
return promiseCapability;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.4.1.1j
|
||||
function createResolveElementFunction(realm) {
|
||||
var resolveElement = new _index.NativeFunctionValue(realm, undefined, undefined, 1, function (context, _ref3) {
|
||||
var _ref4 = _slicedToArray(_ref3, 1),
|
||||
x = _ref4[0];
|
||||
|
||||
// 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
|
||||
var alreadyCalled = resolveElement.$AlreadyCalled;
|
||||
(0, _invariant2.default)(alreadyCalled);
|
||||
|
||||
// 2. If alreadyCalled.[[Value]] is true, return undefined.
|
||||
if (alreadyCalled.value === true) {
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// 3. Set alreadyCalled.[[Value]] to true.
|
||||
alreadyCalled.value = true;
|
||||
|
||||
// 4. Let index be the value of F's [[Index]] internal slot.
|
||||
var myIndex = resolveElement.$Index;
|
||||
(0, _invariant2.default)(typeof myIndex === "number");
|
||||
|
||||
// 5. Let values be the value of F's [[Values]] internal slot.
|
||||
var values = resolveElement.$Values;
|
||||
(0, _invariant2.default)(values instanceof Array);
|
||||
|
||||
// 6. Let promiseCapability be the value of F's [[Capabilities]] internal slot.
|
||||
var promiseCapability = resolveElement.$Capabilities;
|
||||
(0, _invariant2.default)(promiseCapability);
|
||||
|
||||
// 7. Let remainingElementsCount be the value of F's [[RemainingElements]] internal slot.
|
||||
var remainingElementsCount = resolveElement.$RemainingElements;
|
||||
(0, _invariant2.default)(remainingElementsCount);
|
||||
|
||||
// 8. Set values[index] to x.
|
||||
values[myIndex] = x;
|
||||
|
||||
// 9. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
|
||||
remainingElementsCount.value = remainingElementsCount.value - 1;
|
||||
|
||||
// 10. If remainingElementsCount.[[Value]] is 0, then
|
||||
if (remainingElementsCount.value === 0) {
|
||||
// a. Let valuesArray be CreateArrayFromList(values).
|
||||
var valuesArray = _singletons.Create.CreateArrayFromList(realm, values);
|
||||
|
||||
// b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
|
||||
(0, _call.Call)(realm, promiseCapability.resolve, realm.intrinsics.undefined, [valuesArray]);
|
||||
}
|
||||
|
||||
// 11. Return undefined.
|
||||
return realm.intrinsics.undefined;
|
||||
}, false);
|
||||
return resolveElement;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.4.1.1
|
||||
function PerformPromiseAll(realm, iteratorRecord, constructor, resultCapability) {
|
||||
// 1. Assert: constructor is a constructor function.
|
||||
(0, _invariant2.default)(constructor instanceof _index.FunctionValue && (0, _is.IsConstructor)(realm, constructor), "constructor is a constructor function");
|
||||
|
||||
// 2. Assert: resultCapability is a PromiseCapability record.
|
||||
resultCapability;
|
||||
|
||||
// 3. Let values be a new empty List.
|
||||
var values = [];
|
||||
|
||||
// 4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
|
||||
var remainingElementsCount = { value: 1 };
|
||||
|
||||
// 5. Let index be 0.
|
||||
var index = 0;
|
||||
|
||||
// 6. Repeat
|
||||
while (true) {
|
||||
// a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||
var next = void 0;
|
||||
try {
|
||||
next = (0, _iterator2.IteratorStep)(realm, iteratorRecord.$Iterator);
|
||||
} catch (e) {
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
|
||||
// c. ReturnIfAbrupt(next).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// d. If next is false, then
|
||||
if (next === false) {
|
||||
// i. Set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
|
||||
// ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
|
||||
remainingElementsCount.value = remainingElementsCount.value - 1;
|
||||
|
||||
// iii. If remainingElementsCount.[[Value]] is 0, then
|
||||
if (remainingElementsCount.value === 0) {
|
||||
// 1. Let valuesArray be CreateArrayFromList(values).
|
||||
var valuesArray = _singletons.Create.CreateArrayFromList(realm, values);
|
||||
|
||||
// 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
|
||||
(0, _call.Call)(realm, resultCapability.resolve, realm.intrinsics.undefined, [valuesArray]);
|
||||
}
|
||||
|
||||
// iv. Return resultCapability.[[Promise]].
|
||||
return resultCapability.promise;
|
||||
}
|
||||
|
||||
// e. Let nextValue be IteratorValue(next).
|
||||
var nextValue = void 0;
|
||||
try {
|
||||
nextValue = (0, _iterator2.IteratorValue)(realm, next);
|
||||
} catch (e) {
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
// f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
|
||||
// g. ReturnIfAbrupt(nextValue).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// h. Append undefined to values.
|
||||
values.push(realm.intrinsics.undefined);
|
||||
|
||||
// i. Let nextPromise be ? Invoke(constructor, "resolve", « nextValue »).
|
||||
var nextPromise = (0, _call.Invoke)(realm, constructor, "resolve", [nextValue]);
|
||||
|
||||
// j. Let resolveElement be a new built-in function object as defined in Promise.all Resolve Element Functions.
|
||||
var resolveElement = createResolveElementFunction(realm);
|
||||
|
||||
// k. Set the [[AlreadyCalled]] internal slot of resolveElement to a new Record {[[Value]]: false }.
|
||||
resolveElement.$AlreadyCalled = { value: false };
|
||||
|
||||
// l. Set the [[Index]] internal slot of resolveElement to index.
|
||||
resolveElement.$Index = index;
|
||||
|
||||
// m. Set the [[Values]] internal slot of resolveElement to values.
|
||||
resolveElement.$Values = values;
|
||||
|
||||
// n. Set the [[Capabilities]] internal slot of resolveElement to resultCapability.
|
||||
resolveElement.$Capabilities = resultCapability;
|
||||
|
||||
// o. Set the [[RemainingElements]] internal slot of resolveElement to remainingElementsCount.
|
||||
resolveElement.$RemainingElements = remainingElementsCount;
|
||||
|
||||
// p. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1.
|
||||
remainingElementsCount.value = remainingElementsCount.value + 1;
|
||||
|
||||
// q. Perform ? Invoke(nextPromise, "then", « resolveElement, resultCapability.[[Reject]] »).
|
||||
(0, _call.Invoke)(realm, nextPromise, "then", [resolveElement, resultCapability.reject]);
|
||||
|
||||
// r. Set index to index + 1.
|
||||
index = index + 1;
|
||||
}
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
|
||||
// ECMA262 25.4.4.3.1
|
||||
function PerformPromiseRace(realm, iteratorRecord, resultCapability, C) {
|
||||
// 1. Assert: constructor is a constructor function.
|
||||
(0, _invariant2.default)((0, _is.IsConstructor)(realm, C), "constructor is a constructor function");
|
||||
|
||||
// 2. Assert: resultCapability is a PromiseCapability Record.
|
||||
resultCapability;
|
||||
|
||||
// 3. Repeat
|
||||
while (true) {
|
||||
// a. Let next be IteratorStep(iteratorRecord.[[Iterator]]).
|
||||
var next = void 0;
|
||||
try {
|
||||
next = (0, _iterator2.IteratorStep)(realm, iteratorRecord.$Iterator);
|
||||
} catch (e) {
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
// b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
|
||||
// c. ReturnIfAbrupt(next).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// d. If next is false, then
|
||||
if (next === false) {
|
||||
// i. Set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
|
||||
// ii. Return resultCapability.[[Promise]].
|
||||
(0, _invariant2.default)(resultCapability.promise instanceof _index.ObjectValue);
|
||||
return resultCapability.promise;
|
||||
}
|
||||
|
||||
// e. Let nextValue be IteratorValue(next).
|
||||
var nextValue = void 0;
|
||||
try {
|
||||
nextValue = (0, _iterator2.IteratorValue)(realm, next);
|
||||
} catch (e) {
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
// f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
|
||||
iteratorRecord.$Done = true;
|
||||
}
|
||||
|
||||
// g. ReturnIfAbrupt(nextValue).
|
||||
throw e;
|
||||
}
|
||||
|
||||
// h. Let nextPromise be ? Invoke(C, "resolve", « nextValue »).
|
||||
var nextPromise = (0, _call.Invoke)(realm, C, "resolve", [nextValue]);
|
||||
|
||||
// i. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], resultCapability.[[Reject]] »).
|
||||
(0, _call.Invoke)(realm, nextPromise, "then", [resultCapability.resolve, resultCapability.reject]);
|
||||
}
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
|
||||
// ECMA262 25.4.5.3.1
|
||||
function PerformPromiseThen(realm, promise, onFulfilled, onRejected, resultCapability) {
|
||||
// 1. Assert: IsPromise(promise) is true.
|
||||
(0, _invariant2.default)((0, _is.IsPromise)(realm, promise), "IsPromise(promise) is true");
|
||||
|
||||
// 2. Assert: resultCapability is a PromiseCapability record.
|
||||
resultCapability;
|
||||
|
||||
// 3. If IsCallable(onFulfilled) is false, then
|
||||
if ((0, _is.IsCallable)(realm, onFulfilled) === false) {
|
||||
// a. Let onFulfilled be "Identity".
|
||||
onFulfilled = new _index.StringValue(realm, "Identity");
|
||||
}
|
||||
|
||||
// 4. If IsCallable(onRejected) is false, then
|
||||
if ((0, _is.IsCallable)(realm, onRejected)) {
|
||||
// a. Let onRejected be "Thrower".
|
||||
onRejected = new _index.StringValue(realm, "Thrower");
|
||||
}
|
||||
|
||||
// 5. Let fulfillReaction be the PromiseReaction { [[Capabilities]]: resultCapability, [[Handler]]: onFulfilled }.
|
||||
var fulfillReaction = { capabilities: resultCapability, handler: onFulfilled };
|
||||
|
||||
// 6. Let rejectReaction be the PromiseReaction { [[Capabilities]]: resultCapability, [[Handler]]: onRejected}.
|
||||
var rejectReaction = { capabilities: resultCapability, handler: onRejected };
|
||||
|
||||
// 7. If the value of promise's [[PromiseState]] internal slot is "pending", then
|
||||
if (promise.$PromiseState === "pending") {
|
||||
// a. Append fulfillReaction as the last element of the List that is the value of promise's [[PromiseFulfillReactions]] internal slot.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseFulfillReactions");
|
||||
(0, _invariant2.default)(promise.$PromiseFulfillReactions);
|
||||
promise.$PromiseFulfillReactions.push(fulfillReaction);
|
||||
// b. Append rejectReaction as the last element of the List that is the value of promise's [[PromiseRejectReactions]] internal slot.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseRejectReactions");
|
||||
(0, _invariant2.default)(promise.$PromiseRejectReactions);
|
||||
promise.$PromiseRejectReactions.push(rejectReaction);
|
||||
} else if (promise.$PromiseState === "fulfilled") {
|
||||
// 8. Else if the value of promise's [[PromiseState]] internal slot is "fulfilled", then
|
||||
// a. Let value be the value of promise's [[PromiseResult]] internal slot.
|
||||
var value = promise.$PromiseResult;
|
||||
// b. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, « fulfillReaction, value »).
|
||||
EnqueueJob(realm, "PromiseJobs", PromiseReactionJob, [fulfillReaction, value]);
|
||||
} else {
|
||||
// 9. Else,
|
||||
// a. Assert: The value of promise's [[PromiseState]] internal slot is "rejected".
|
||||
(0, _invariant2.default)(promise.$PromiseState === "rejected");
|
||||
|
||||
// b. Let reason be the value of promise's [[PromiseResult]] internal slot.
|
||||
var reason = promise.$PromiseResult;
|
||||
|
||||
// c. If the value of promise's [[PromiseIsHandled]] internal slot is false, perform HostPromiseRejectionTracker(promise, "handle").
|
||||
if (promise.$PromiseIsHandled === false) HostPromiseRejectionTracker(realm, promise, "handle");
|
||||
|
||||
// d. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, « rejectReaction, reason »).
|
||||
EnqueueJob(realm, "PromiseJobs", PromiseReactionJob, [rejectReaction, reason]);
|
||||
}
|
||||
|
||||
// 10. Set promise's [[PromiseIsHandled]] internal slot to true.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseIsHandled").$PromiseIsHandled = true;
|
||||
|
||||
// 11. Return resultCapability.[[Promise]].
|
||||
(0, _invariant2.default)(resultCapability.promise instanceof _index.ObjectValue);
|
||||
return resultCapability.promise;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.2.1
|
||||
function PromiseReactionJob(realm, reaction, argument) {
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.3.2
|
||||
function createResolveFunction(realm) {
|
||||
// 2. Let resolve be a new built-in function object as defined in Promise Resolve Functions (25.4.1.3.2).
|
||||
var resolve = new _index.NativeFunctionValue(realm, undefined, undefined, 1, function (context, _ref5) {
|
||||
var _ref6 = _slicedToArray(_ref5, 1),
|
||||
resolution = _ref6[0];
|
||||
|
||||
// 1. Assert: F has a [[Promise]] internal slot whose value is an Object.
|
||||
(0, _invariant2.default)(resolve.$Promise instanceof _index.ObjectValue, "F has a [[Promise]] internal slot whose value is an Object");
|
||||
|
||||
// 2. Let promise be the value of F's [[Promise]] internal slot.
|
||||
var promise = resolve.$Promise;
|
||||
|
||||
// 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot.
|
||||
var alreadyResolved = resolve.$AlreadyResolved;
|
||||
(0, _invariant2.default)(alreadyResolved !== undefined);
|
||||
|
||||
// 4. If alreadyResolved.[[Value]] is true, return undefined.
|
||||
if (alreadyResolved.value === true) return realm.intrinsics.undefined;
|
||||
|
||||
// 5. Set alreadyResolved.[[Value]] to true.
|
||||
alreadyResolved.value = true;
|
||||
|
||||
// 6. If SameValue(resolution, promise) is true, then
|
||||
if ((0, _abstract.SameValue)(realm, resolution.throwIfNotConcrete(), promise)) {
|
||||
// a. Let selfResolutionError be a newly created TypeError object.
|
||||
var selfResolutionError = (0, _construct.Construct)(realm, realm.intrinsics.TypeError, [new _index.StringValue(realm, "resolve")]);
|
||||
|
||||
// b. Return RejectPromise(promise, selfResolutionError).
|
||||
return RejectPromise(realm, promise, selfResolutionError);
|
||||
}
|
||||
// 7. If Type(resolution) is not Object, then
|
||||
if (!(resolution instanceof _index.ObjectValue)) {
|
||||
// a. Return FulfillPromise(promise, resolution).
|
||||
return FulfillPromise(realm, promise, resolution);
|
||||
}
|
||||
|
||||
// 8. Let then be Get(resolution, "then").
|
||||
var then = void 0;
|
||||
try {
|
||||
then = (0, _get.Get)(realm, resolution, "then");
|
||||
} catch (e) {
|
||||
// 9. If then is an abrupt completion, then
|
||||
if (e instanceof _completions.AbruptCompletion) {
|
||||
// a. Return RejectPromise(promise, then.[[Value]]).
|
||||
return RejectPromise(realm, promise, e);
|
||||
} else throw e;
|
||||
}
|
||||
|
||||
// 10. Let thenAction be then.[[Value]].
|
||||
var thenAction = then;
|
||||
|
||||
// 11. If IsCallable(thenAction) is false, then
|
||||
if ((0, _is.IsCallable)(realm, thenAction)) {
|
||||
// a. Return FulfillPromise(promise, resolution).
|
||||
return FulfillPromise(realm, promise, resolution);
|
||||
}
|
||||
|
||||
// 12. Perform EnqueueJob("PromiseJobs", PromiseResolveThenableJob, « promise, resolution, thenAction »).
|
||||
EnqueueJob(realm, "PromiseJobs", PromiseResolveThenableJob, [promise, resolution, thenAction]);
|
||||
|
||||
// 13. Return undefined.
|
||||
return realm.intrinsics.undefined;
|
||||
}, false);
|
||||
return resolve;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.3.1
|
||||
function createRejectFunction(realm) {
|
||||
// 5. Let reject be a new built-in function object as defined in Promise Reject Functions (25.4.1.3.1).
|
||||
var reject = new _index.NativeFunctionValue(realm, undefined, undefined, 1, function (context, _ref7) {
|
||||
var _ref8 = _slicedToArray(_ref7, 1),
|
||||
reason = _ref8[0];
|
||||
|
||||
// 1. Assert: F has a [[Promise]] internal slot whose value is an Object.
|
||||
(0, _invariant2.default)(reject.$Promise instanceof _index.ObjectValue, "F has a [[Promise]] internal slot whose value is an Object");
|
||||
|
||||
// 2. Let promise be the value of F's [[Promise]] internal slot.
|
||||
var promise = reject.$Promise;
|
||||
|
||||
// 3. Let alreadyResolved be the value of F's [[AlreadyResolved]] internal slot.
|
||||
var alreadyResolved = reject.$AlreadyResolved;
|
||||
(0, _invariant2.default)(alreadyResolved !== undefined);
|
||||
|
||||
// 4. If alreadyResolved.[[Value]] is true, return undefined.
|
||||
if (alreadyResolved.value === true) return realm.intrinsics.undefined;
|
||||
|
||||
// 5. Set alreadyResolved.[[Value]] to true.
|
||||
alreadyResolved.value = true;
|
||||
|
||||
// 6. Return RejectPromise(promise, reason).
|
||||
return RejectPromise(realm, promise, reason);
|
||||
}, false);
|
||||
return reject;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.3
|
||||
function CreateResolvingFunctions(realm, promise) {
|
||||
// 1. Let alreadyResolved be a new Record { [[Value]]: false }.
|
||||
var alreadyResolved = { value: false };
|
||||
|
||||
// 2. Let resolve be a new built-in function object as defined in Promise Resolve Functions (25.4.1.3.2).
|
||||
var resolve = createResolveFunction(realm);
|
||||
|
||||
// 3. Set the [[Promise]] internal slot of resolve to promise.
|
||||
resolve.$Promise = promise;
|
||||
|
||||
// 4. Set the [[AlreadyResolved]] internal slot of resolve to alreadyResolved.
|
||||
resolve.$AlreadyResolved = alreadyResolved;
|
||||
|
||||
// 5. Let reject be a new built-in function object as defined in Promise Reject Functions (25.4.1.3.1).
|
||||
var reject = createRejectFunction(realm);
|
||||
|
||||
// 6. Set the [[Promise]] internal slot of reject to promise.
|
||||
reject.$Promise = promise;
|
||||
|
||||
// 7. Set the [[AlreadyResolved]] internal slot of reject to alreadyResolved.
|
||||
reject.$AlreadyResolved = alreadyResolved;
|
||||
|
||||
// 8. Return a new Record { [[Resolve]]: resolve, [[Reject]]: reject }.
|
||||
return { resolve: resolve, reject: reject };
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.4
|
||||
function FulfillPromise(realm, promise, value) {
|
||||
// 1. Assert: The value of promise.[[PromiseState]] is "pending".
|
||||
(0, _invariant2.default)(promise.$PromiseState === "pending");
|
||||
|
||||
// 2. Let reactions be promise.[[PromiseFulfillReactions]].
|
||||
var reactions = promise.$PromiseFulfillReactions;
|
||||
(0, _invariant2.default)(reactions);
|
||||
|
||||
// 3. Set promise.[[PromiseResult]] to value.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseResult").$PromiseResult = value;
|
||||
|
||||
// 4. Set promise.[[PromiseFulfillReactions]] to undefined.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseFulfillReactions").$PromiseFulfillReactions = undefined;
|
||||
|
||||
// 5. Set promise.[[PromiseRejectReactions]] to undefined.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseRejectReactions").$PromiseRejectReactions = undefined;
|
||||
|
||||
// 6. Set promise.[[PromiseState]] to "fulfilled".
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseState").$PromiseState = "fulfilled";
|
||||
|
||||
// 7. Return TriggerPromiseReactions(reactions, value).
|
||||
return TriggerPromiseReactions(realm, reactions, value);
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.7
|
||||
function RejectPromise(realm, promise, reason) {
|
||||
// 1. Assert: The value of promise.[[PromiseState]] is "pending".
|
||||
(0, _invariant2.default)(promise.$PromiseState === "pending");
|
||||
|
||||
// 2. Let reactions be promise.[[PromiseRejectReactions]].
|
||||
var reactions = promise.$PromiseFulfillReactions;
|
||||
(0, _invariant2.default)(reactions);
|
||||
|
||||
// 3. Set promise.[[PromiseResult]] to reason.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseResult").$PromiseResult = reason;
|
||||
|
||||
// 4. Set promise.[[PromiseFulfillReactions]] to undefined.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseFulfillReactions").$PromiseFulfillReactions = undefined;
|
||||
|
||||
// 5. Set promise.[[PromiseRejectReactions]] to undefined.
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseRejectReactions").$PromiseRejectReactions = undefined;
|
||||
|
||||
// 6. Set promise.[[PromiseState]] to "rejected".
|
||||
_singletons.Properties.ThrowIfInternalSlotNotWritable(realm, promise, "$PromiseState").$PromiseState = "rejected";
|
||||
|
||||
// 7. If promise.[[PromiseIsHandled]] is false, perform HostPromiseRejectionTracker(promise, "reject").
|
||||
if (promise.$PromiseIsHandled === false) HostPromiseRejectionTracker(realm, promise, "reject");
|
||||
|
||||
// 8. Return TriggerPromiseReactions(reactions, reason).
|
||||
return TriggerPromiseReactions(realm, reactions, reason);
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.8
|
||||
function TriggerPromiseReactions(realm, reactions, argument) {
|
||||
// 1. Repeat for each reaction in reactions, in original insertion order
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = reactions[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var reaction = _step.value;
|
||||
|
||||
// a. Perform EnqueueJob("PromiseJobs", PromiseReactionJob, « reaction, argument »).
|
||||
EnqueueJob(realm, "PromiseJobs", PromiseReactionJob, [reaction, argument]);
|
||||
}
|
||||
// 2. Return undefined.
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return realm.intrinsics.undefined;
|
||||
}
|
||||
|
||||
// ECMA262 25.4.1.9
|
||||
function HostPromiseRejectionTracker(realm, promise, operation) {}
|
||||
|
||||
// ECMA262 25.4.2.2
|
||||
function PromiseResolveThenableJob(realm, promiseToResolve, thenable, then) {}
|
||||
//# sourceMappingURL=promise.js.map
|
||||
1
build/node_modules/prepack/lib/methods/promise.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/promise.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1555
build/node_modules/prepack/lib/methods/properties.js
generated
vendored
Normal file
1555
build/node_modules/prepack/lib/methods/properties.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1
build/node_modules/prepack/lib/methods/properties.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/properties.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
167
build/node_modules/prepack/lib/methods/proxy.js
generated
vendored
Normal file
167
build/node_modules/prepack/lib/methods/proxy.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ProxyCall = ProxyCall;
|
||||
exports.ProxyConstruct = ProxyConstruct;
|
||||
exports.ProxyCreate = ProxyCreate;
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _construct = require("./construct.js");
|
||||
|
||||
var _call = require("./call.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 9.5.12
|
||||
/**
|
||||
* 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 ProxyCall(realm, O, thisArgument, argumentsList) {
|
||||
// 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
|
||||
var handler = O.$ProxyHandler;
|
||||
|
||||
// 2. If handler is null, throw a TypeError exception.
|
||||
if (handler instanceof _index.NullValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 3. Assert: Type(handler) is Object.
|
||||
(0, _invariant2.default)(handler instanceof _index.ObjectValue, "expected an object");
|
||||
|
||||
// 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
|
||||
var target = O.$ProxyTarget;
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "apply").
|
||||
var trap = (0, _get.GetMethod)(realm, handler, "apply");
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (trap instanceof _index.UndefinedValue) {
|
||||
// a. Return ? Call(target, thisArgument, argumentsList).
|
||||
return (0, _call.Call)(realm, target, thisArgument, argumentsList);
|
||||
}
|
||||
|
||||
// 7. Let argArray be CreateArrayFromList(argumentsList).
|
||||
var argArray = _singletons.Create.CreateArrayFromList(realm, argumentsList);
|
||||
|
||||
// 8. Return ? Call(trap, handler, « target, thisArgument, argArray »).
|
||||
return (0, _call.Call)(realm, trap.throwIfNotConcrete(), handler, [target, thisArgument, argArray]);
|
||||
}
|
||||
|
||||
// ECMA262 9.5.13
|
||||
function ProxyConstruct(realm, O, argumentsList, newTarget) {
|
||||
// 1. Let handler be the value of the [[ProxyHandler]] internal slot of O.
|
||||
var handler = O.$ProxyHandler;
|
||||
|
||||
// 2. If handler is null, throw a TypeError exception.
|
||||
if (handler instanceof _index.NullValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 3. Assert: Type(handler) is Object.
|
||||
(0, _invariant2.default)(handler instanceof _index.ObjectValue, "expected an object");
|
||||
|
||||
// 4. Let target be the value of the [[ProxyTarget]] internal slot of O.
|
||||
var target = O.$ProxyTarget;
|
||||
(0, _invariant2.default)(target instanceof _index.ObjectValue);
|
||||
|
||||
// 5. Let trap be ? GetMethod(handler, "construct").
|
||||
var trap = (0, _get.GetMethod)(realm, handler, "construct");
|
||||
|
||||
// 6. If trap is undefined, then
|
||||
if (trap instanceof _index.UndefinedValue) {
|
||||
// a. Assert: target has a [[Construct]] internal method.
|
||||
(0, _invariant2.default)(target.$Construct, "expected construct method");
|
||||
|
||||
// b. Return ? Construct(target, argumentsList, newTarget).
|
||||
return (0, _construct.Construct)(realm, target, argumentsList, newTarget);
|
||||
}
|
||||
|
||||
// 7. Let argArray be CreateArrayFromList(argumentsList).
|
||||
var argArray = _singletons.Create.CreateArrayFromList(realm, argumentsList);
|
||||
|
||||
// 8. Let newObj be ? Call(trap, handler, « target, argArray, newTarget »).
|
||||
var newObj = (0, _call.Call)(realm, trap.throwIfNotConcrete(), handler, [target, argArray, newTarget]).throwIfNotConcrete();
|
||||
|
||||
// 9. If Type(newObj) is not Object, throw a TypeError exception.
|
||||
if (!(newObj instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 10. Return newObj.
|
||||
return newObj;
|
||||
}
|
||||
|
||||
// ECMA262 9.5.14
|
||||
function ProxyCreate(realm, target, handler) {
|
||||
target = target.throwIfNotConcrete();
|
||||
|
||||
// 1. If Type(target) is not Object, throw a TypeError exception.
|
||||
if (!(target instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 2. If target is a Proxy exotic object and the value of the [[ProxyHandler]] internal slot of target is null, throw a TypeError exception.
|
||||
if (target instanceof _index.ProxyValue && (!target.$ProxyHandler || target.$ProxyHandler instanceof _index.NullValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
handler = handler.throwIfNotConcrete();
|
||||
// 3. If Type(handler) is not Object, throw a TypeError exception.
|
||||
if (!(handler instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 4. If handler is a Proxy exotic object and the value of the [[ProxyHandler]] internal slot of handler is null, throw a TypeError exception.
|
||||
if (handler instanceof _index.ProxyValue && (!handler.$ProxyHandler || handler.$ProxyHandler instanceof _index.NullValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 5. Let P be a newly created object.
|
||||
// 6. Set P's essential internal methods (except for [[Call]] and [[Construct]]) to the definitions specified in 9.5.
|
||||
var P = new _index.ProxyValue(realm);
|
||||
|
||||
// 7. If IsCallable(target) is true, then
|
||||
if ((0, _is.IsCallable)(realm, target)) {
|
||||
// a. Set the [[Call]] internal method of P as specified in 9.5.12.
|
||||
P.$Call = function (thisArgument, argsList) {
|
||||
return ProxyCall(realm, P, thisArgument, argsList);
|
||||
};
|
||||
|
||||
// b. If target has a [[Construct]] internal method, then
|
||||
if (target.$Construct) {
|
||||
// i. Set the [[Construct]] internal method of P as specified in 9.5.13.
|
||||
P.$Construct = function (argumentsList, newTarget) {
|
||||
return ProxyConstruct(realm, P, argumentsList, newTarget);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Set the [[ProxyTarget]] internal slot of P to target.
|
||||
P.$ProxyTarget = target;
|
||||
|
||||
// 9. Set the [[ProxyHandler]] internal slot of P to handler.
|
||||
P.$ProxyHandler = handler;
|
||||
|
||||
// 10. Return P.
|
||||
return P;
|
||||
}
|
||||
//# sourceMappingURL=proxy.js.map
|
||||
1
build/node_modules/prepack/lib/methods/proxy.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/proxy.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
388
build/node_modules/prepack/lib/methods/regexp.js
generated
vendored
Normal file
388
build/node_modules/prepack/lib/methods/regexp.js
generated
vendored
Normal file
@@ -0,0 +1,388 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.RegExpCreate = RegExpCreate;
|
||||
exports.RegExpAlloc = RegExpAlloc;
|
||||
exports.RegExpInitialize = RegExpInitialize;
|
||||
exports.RegExpExec = RegExpExec;
|
||||
exports.RegExpBuiltinExec = RegExpBuiltinExec;
|
||||
exports.AdvanceStringIndex = AdvanceStringIndex;
|
||||
exports.EscapeRegExpPattern = EscapeRegExpPattern;
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
var _call = require("./call.js");
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// ECMA262 21.2.3.2.3
|
||||
/**
|
||||
* 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 RegExpCreate(realm, P, F) {
|
||||
// 1. Let obj be ? RegExpAlloc(%RegExp%).
|
||||
var obj = RegExpAlloc(realm, realm.intrinsics.RegExp);
|
||||
|
||||
// 2. Return ? RegExpInitialize(obj, P, F).
|
||||
return RegExpInitialize(realm, obj, P, F);
|
||||
}
|
||||
|
||||
// ECMA262 21.2.3.2.1
|
||||
function RegExpAlloc(realm, newTarget) {
|
||||
// 1. Let obj be ? OrdinaryCreateFromConstructor(newTarget, "%RegExpPrototype%", « [[RegExpMatcher]],
|
||||
// [[OriginalSource]], [[OriginalFlags]] »).
|
||||
var obj = _singletons.Create.OrdinaryCreateFromConstructor(realm, newTarget, "RegExpPrototype", {
|
||||
$RegExpMatcher: undefined, // always initialized to not undefined before use
|
||||
$OriginalSource: undefined, // ditto
|
||||
$OriginalFlags: undefined // ditto
|
||||
});
|
||||
|
||||
// 2. Perform ! DefinePropertyOrThrow(obj, "lastIndex", PropertyDescriptor {[[Writable]]: true,
|
||||
// [[Enumerable]]: false, [[Configurable]]: false}).
|
||||
_singletons.Properties.DefinePropertyOrThrow(realm, obj, "lastIndex", {
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: false
|
||||
});
|
||||
|
||||
// 3. Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ECMA262 21.2.3.2.2
|
||||
function RegExpInitialize(realm, obj, pattern, flags) {
|
||||
// Note that obj is a new object, and we can thus write to internal slots
|
||||
(0, _invariant2.default)(realm.isNewObject(obj));
|
||||
|
||||
// 1. If pattern is undefined, let P be the empty String.
|
||||
var P = void 0;
|
||||
if (!pattern || (0, _has.HasCompatibleType)(pattern, _index.UndefinedValue)) {
|
||||
P = "";
|
||||
} else {
|
||||
// 2. Else, let P be ? ToString(pattern).
|
||||
P = _singletons.To.ToStringPartial(realm, pattern);
|
||||
}
|
||||
|
||||
// 3. If flags is undefined, let F be the empty String.
|
||||
var F = void 0;
|
||||
if (!flags || (0, _has.HasCompatibleType)(flags, _index.UndefinedValue)) {
|
||||
F = "";
|
||||
} else {
|
||||
// 4. Else, let F be ? ToString(flags).
|
||||
F = _singletons.To.ToStringPartial(realm, flags);
|
||||
}
|
||||
|
||||
// 5. If F contains any code unit other than "g", "i", "m", "u", or "y" or if it contains the same code unit more than once, throw a SyntaxError exception.
|
||||
for (var i = 0; i < F.length; ++i) {
|
||||
if ("gimuy".indexOf(F.charAt(i)) < 0) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "invalid RegExp flag");
|
||||
}
|
||||
for (var j = i + 1; j < F.length; ++j) {
|
||||
if (F.charAt(i) === F.charAt(j)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "duplicate RegExp flag");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 6. If F contains "u", let BMP be false; else let BMP be true.
|
||||
var BMP = F.indexOf("u") >= 0 ? false : true;
|
||||
|
||||
// 7. If BMP is true, then
|
||||
if (BMP) {
|
||||
// a. Parse P using the grammars in 21.2.1 and interpreting each of its 16-bit elements as a Unicode BMP
|
||||
// code point. UTF-16 decoding is not applied to the elements. The goal symbol for the parse is
|
||||
// Pattern. Throw a SyntaxError exception if P did not conform to the grammar, if any elements of P
|
||||
// were not matched by the parse, or if any Early Error conditions exist.
|
||||
// b. Let patternCharacters be a List whose elements are the code unit elements of P.
|
||||
} else {}
|
||||
// 8. Else,
|
||||
// a. Parse P using the grammars in 21.2.1 and interpreting P as UTF-16 encoded Unicode code points
|
||||
// (6.1.4). The goal symbol for the parse is Pattern[U]. Throw a SyntaxError exception if P did not
|
||||
// conform to the grammar, if any elements of P were not matched by the parse, or if any Early Error
|
||||
// conditions exist.
|
||||
// b. Let patternCharacters be a List whose elements are the code points resulting from applying UTF-16
|
||||
// decoding to P's sequence of elements.
|
||||
|
||||
|
||||
// 9. Set the value of obj's [[OriginalSource]] internal slot to P.
|
||||
obj.$OriginalSource = P;
|
||||
|
||||
// 10. Set the value of obj's [[OriginalFlags]] internal slot to F.
|
||||
obj.$OriginalFlags = F;
|
||||
|
||||
// 11. Set obj's [[RegExpMatcher]] internal slot to the internal procedure that evaluates the above parse of
|
||||
// P by applying the semantics provided in 21.2.2 using patternCharacters as the pattern's List of
|
||||
// SourceCharacter values and F as the flag parameters.
|
||||
try {
|
||||
var computedFlags = "y";
|
||||
if (F.indexOf("i") >= 0) computedFlags += "i";
|
||||
if (F.indexOf("u") >= 0) computedFlags += "u";
|
||||
if (F.indexOf("m") >= 0) computedFlags += "m";
|
||||
var matcher = new RegExp(P, computedFlags);
|
||||
|
||||
obj.$RegExpMatcher = function (S, lastIndex) {
|
||||
matcher.lastIndex = lastIndex;
|
||||
var match = matcher.exec(S);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
endIndex: match.index + match[0].length,
|
||||
captures: match
|
||||
};
|
||||
};
|
||||
} catch (e) {
|
||||
if (e instanceof SyntaxError) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.SyntaxError, "invalid RegExp");
|
||||
} else throw e;
|
||||
}
|
||||
|
||||
// 12. Perform ? Set(obj, "lastIndex", 0, true).
|
||||
_singletons.Properties.Set(realm, obj, "lastIndex", realm.intrinsics.zero, true);
|
||||
|
||||
// 13. Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ECMA262 21.2.5.2.1
|
||||
function RegExpExec(realm, R, S) {
|
||||
// 1. Assert: Type(R) is Object.
|
||||
(0, _invariant2.default)(R instanceof _index.ObjectValue, "Type(R) is Object");
|
||||
|
||||
// 2. Assert: Type(S) is String.
|
||||
(0, _invariant2.default)(typeof S === "string", "Type(S) is String");
|
||||
|
||||
// 3. Let exec be ? Get(R, "exec").
|
||||
var exec = (0, _get.Get)(realm, R, "exec");
|
||||
|
||||
// 4. If IsCallable(exec) is true, then
|
||||
if ((0, _is.IsCallable)(realm, exec)) {
|
||||
// a. Let result be ? Call(exec, R, « S »).
|
||||
var result = (0, _call.Call)(realm, exec, R, [new _index.StringValue(realm, S)]);
|
||||
|
||||
// b. If Type(result) is neither Object or Null, throw a TypeError exception.
|
||||
if (!(0, _has.HasSomeCompatibleType)(result, _index.ObjectValue, _index.NullValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(result) is neither Object or Null");
|
||||
}
|
||||
|
||||
// c. Return result.
|
||||
return result.throwIfNotConcrete();
|
||||
}
|
||||
|
||||
// 5. If R does not have a [[RegExpMatcher]] internal slot, throw a TypeError exception.
|
||||
if (R.$RegExpMatcher === undefined) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "R does not have a [[RegExpMatcher]] internal slot");
|
||||
}
|
||||
|
||||
// 6. Return ? RegExpBuiltinExec(R, S).
|
||||
return RegExpBuiltinExec(realm, R, S);
|
||||
}
|
||||
|
||||
// ECMA262 21.2.5.2.2
|
||||
function RegExpBuiltinExec(realm, R, S) {
|
||||
// 1. Assert: R is an initialized RegExp instance.
|
||||
(0, _invariant2.default)(R.$RegExpMatcher !== undefined && R.$OriginalSource !== undefined && R.$OriginalFlags !== undefined, "R is an initialized RegExp instance");
|
||||
|
||||
// 2. Assert: Type(S) is String.
|
||||
(0, _invariant2.default)(typeof S === "string", "Type(S) is String");
|
||||
|
||||
// 3. Let length be the number of code units in S.
|
||||
var length = S.length;
|
||||
|
||||
// 4. Let lastIndex be ? ToLength(? Get(R, "lastIndex")).
|
||||
var lastIndex = _singletons.To.ToLength(realm, (0, _get.Get)(realm, R, "lastIndex"));
|
||||
|
||||
// 5. Let flags be R.[[OriginalFlags]].
|
||||
var flags = R.$OriginalFlags;
|
||||
(0, _invariant2.default)(typeof flags === "string");
|
||||
|
||||
// 6 .If flags contains "g", let global be true, else let global be false.
|
||||
var global = flags.indexOf("g") >= 0 ? true : false;
|
||||
|
||||
// 7. If flags contains "y", let sticky be true, else let sticky be false.
|
||||
var sticky = flags.indexOf("y") >= 0 ? true : false;
|
||||
|
||||
// 8. If global is false and sticky is false, let lastIndex be 0.
|
||||
if (global === false && sticky === false) lastIndex = 0;
|
||||
|
||||
// 9. Let matcher be the value of R's [[RegExpMatcher]] internal slot.
|
||||
var matcher = R.$RegExpMatcher;
|
||||
(0, _invariant2.default)(matcher !== undefined);
|
||||
|
||||
// 10. If flags contains "u", let fullUnicode be true, else let fullUnicode be false.
|
||||
var fullUnicode = flags.indexOf("u") >= 0 ? true : false;
|
||||
|
||||
// 11. Let matchSucceeded be false.
|
||||
var matchSucceeded = false;
|
||||
|
||||
var r = null;
|
||||
// 12. Repeat, while matchSucceeded is false
|
||||
while (!matchSucceeded) {
|
||||
// a. If lastIndex > length, then
|
||||
if (lastIndex > length) {
|
||||
// i. Perform ? Set(R, "lastIndex", 0, true).
|
||||
_singletons.Properties.Set(realm, R, "lastIndex", realm.intrinsics.zero, true);
|
||||
// ii. Return null.
|
||||
return realm.intrinsics.null;
|
||||
}
|
||||
|
||||
// b. Let r be matcher(S, lastIndex).
|
||||
r = matcher(S, lastIndex);
|
||||
|
||||
// c. If r is failure, then
|
||||
if (r == null) {
|
||||
// i. If sticky is true, then
|
||||
if (sticky) {
|
||||
// 1. Perform ? Set(R, "lastIndex", 0, true).
|
||||
_singletons.Properties.Set(realm, R, "lastIndex", realm.intrinsics.zero, true);
|
||||
|
||||
// 2. Return null.
|
||||
return realm.intrinsics.null;
|
||||
}
|
||||
// ii. Let lastIndex be AdvanceStringIndex(S, lastIndex, fullUnicode).
|
||||
lastIndex = AdvanceStringIndex(realm, S, lastIndex, fullUnicode);
|
||||
} else {
|
||||
// d. Else,
|
||||
// i. Assert: r is a State.
|
||||
(0, _invariant2.default)(r, "r is a State");
|
||||
|
||||
// ii. Set matchSucceeded to true.
|
||||
matchSucceeded = true;
|
||||
|
||||
// (not in standard) Let lastIndex be the index of the captures
|
||||
lastIndex = r.captures.index;
|
||||
}
|
||||
}
|
||||
(0, _invariant2.default)(r != null);
|
||||
|
||||
// 13. Let e be r's endIndex value.
|
||||
var e = r.endIndex;
|
||||
|
||||
// 14. If fullUnicode is true, then
|
||||
if (fullUnicode) {}
|
||||
// TODO #1018 a. e is an index into the Input character list, derived from S, matched by matcher. Let eUTF be the smallest index into S that corresponds to the character at element e of Input. If e is greater than or equal to the length of Input, then eUTF is the number of code units in S.
|
||||
// b. Let e be eUTF.
|
||||
|
||||
|
||||
// 15. If global is true or sticky is true, then
|
||||
if (global === true || sticky === true) {
|
||||
// a. Perform ? Set(R, "lastIndex", e, true).
|
||||
_singletons.Properties.Set(realm, R, "lastIndex", new _index.NumberValue(realm, e), true);
|
||||
}
|
||||
|
||||
// 16. Let n be the length of r's captures List. (This is the same value as 21.2.2.1's NcapturingParens.)
|
||||
var n = r.captures.length - 1;
|
||||
|
||||
// 17. Let A be ArrayCreate(n + 1).
|
||||
var A = _singletons.Create.ArrayCreate(realm, n + 1);
|
||||
|
||||
// 18. Assert: The value of A's "length" property is n + 1.
|
||||
var lengthOfA = (0, _get.Get)(realm, A, "length").throwIfNotConcrete();
|
||||
(0, _invariant2.default)(lengthOfA instanceof _index.NumberValue);
|
||||
(0, _invariant2.default)(lengthOfA.value === n + 1, 'The value of A\'s "length" property is n + 1');
|
||||
|
||||
// 19. Let matchIndex be lastIndex.
|
||||
var matchIndex = lastIndex;
|
||||
|
||||
// 20. Perform ! CreateDataProperty(A, "index", matchIndex).
|
||||
_singletons.Create.CreateDataProperty(realm, A, "index", new _index.NumberValue(realm, matchIndex));
|
||||
|
||||
// 21. Perform ! CreateDataProperty(A, "input", S).
|
||||
_singletons.Create.CreateDataProperty(realm, A, "input", new _index.StringValue(realm, S));
|
||||
|
||||
// 22. Let matchedSubstr be the matched substring (i.e. the portion of S between offset lastIndex inclusive and offset e exclusive).
|
||||
var matchedSubstr = S.substr(lastIndex, e - lastIndex);
|
||||
|
||||
// 23. Perform ! CreateDataProperty(A, "0", matchedSubstr).
|
||||
_singletons.Create.CreateDataProperty(realm, A, "0", new _index.StringValue(realm, matchedSubstr));
|
||||
|
||||
// 24. For each integer i such that i > 0 and i ≤ n
|
||||
for (var i = 1; i <= n; ++i) {
|
||||
// a. Let captureI be ith element of r's captures List.
|
||||
var captureI = r.captures[i];
|
||||
|
||||
var capturedValue = void 0;
|
||||
// b. If captureI is undefined, let capturedValue be undefined.
|
||||
if (captureI === undefined) {
|
||||
capturedValue = realm.intrinsics.undefined;
|
||||
} else if (fullUnicode) {
|
||||
// c. Else if fullUnicode is true, then
|
||||
// TODO #1018: i. Assert: captureI is a List of code points.
|
||||
// ii. Let capturedValue be a string whose code units are the UTF16Encoding of the code points of captureI.
|
||||
capturedValue = realm.intrinsics.undefined;
|
||||
} else {
|
||||
// d. Else, fullUnicode is false,
|
||||
// i. Assert: captureI is a List of code units.
|
||||
(0, _invariant2.default)(typeof captureI === "string");
|
||||
|
||||
// ii. Let capturedValue be a string consisting of the code units of captureI.
|
||||
capturedValue = new _index.StringValue(realm, captureI);
|
||||
}
|
||||
|
||||
// e. Perform ! CreateDataProperty(A, ! ToString(i), capturedValue).
|
||||
_singletons.Create.CreateDataProperty(realm, A, _singletons.To.ToString(realm, new _index.NumberValue(realm, i)), capturedValue);
|
||||
}
|
||||
|
||||
// 25. Return A.
|
||||
return A;
|
||||
}
|
||||
|
||||
function AdvanceStringIndex(realm, S, index, unicode) {
|
||||
// 1. Assert: Type(S) is String.
|
||||
(0, _invariant2.default)(typeof S === "string", "Type(S) is String");
|
||||
|
||||
// 2. Assert: index is an integer such that 0≤index≤253-1.
|
||||
(0, _invariant2.default)(index >= 0 && index <= Math.pow(2, 53) - 1, "index is an integer such that 0≤index≤253-1");
|
||||
|
||||
// 3. Assert: Type(unicode) is Boolean.
|
||||
(0, _invariant2.default)(typeof unicode === "boolean", "Type(unicode) is Boolean");
|
||||
|
||||
// 4. If unicode is false, return index+1.
|
||||
if (unicode === false) return index + 1;
|
||||
|
||||
// 5. Let length be the number of code units in S.
|
||||
var length = S.length;
|
||||
|
||||
// 6. If index+1 ≥ length, return index+1.
|
||||
if (index + 1 >= length) return index + 1;
|
||||
|
||||
// 7. Let first be the code unit value at index index in S.
|
||||
var first = S.charCodeAt(index);
|
||||
|
||||
// 8. If first < 0xD800 or first > 0xDBFF, return index+1.
|
||||
if (first < 0xd800 || first > 0xdbff) return index + 1;
|
||||
|
||||
// 9. Let second be the code unit value at index index+1 in S.
|
||||
var second = S.charCodeAt(index + 1);
|
||||
|
||||
// 10. If second < 0xDC00 or second > 0xDFFF, return index+1.
|
||||
if (second < 0xdc00 || second > 0xdfff) return index + 1;
|
||||
|
||||
// 11. Return index+2.
|
||||
return index + 2;
|
||||
}
|
||||
|
||||
function EscapeRegExpPattern(realm, P, F) {
|
||||
return P.replace("/", "/");
|
||||
}
|
||||
//# sourceMappingURL=regexp.js.map
|
||||
1
build/node_modules/prepack/lib/methods/regexp.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/regexp.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
884
build/node_modules/prepack/lib/methods/to.js
generated
vendored
Normal file
884
build/node_modules/prepack/lib/methods/to.js
generated
vendored
Normal file
@@ -0,0 +1,884 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ToImplementation = undefined;
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var _get = require("./get.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _has = require("./has.js");
|
||||
|
||||
var _call = require("./call.js");
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _is = require("./is.js");
|
||||
|
||||
var _abstract = require("./abstract.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function modulo(x, y) {
|
||||
return x < 0 ? x % y + y : x % y;
|
||||
}
|
||||
|
||||
var ToImplementation = exports.ToImplementation = function () {
|
||||
function ToImplementation() {
|
||||
_classCallCheck(this, ToImplementation);
|
||||
|
||||
this.ElementConv = {
|
||||
Int8: this.ToInt8.bind(this),
|
||||
Int16: this.ToInt16.bind(this),
|
||||
Int32: this.ToInt32.bind(this),
|
||||
Uint8: this.ToUint8.bind(this),
|
||||
Uint16: this.ToUint16.bind(this),
|
||||
Uint32: this.ToUint32.bind(this),
|
||||
Uint8Clamped: this.ToUint8Clamp.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
_createClass(ToImplementation, [{
|
||||
key: "ToInt32",
|
||||
|
||||
|
||||
// ECMA262 7.1.5
|
||||
value: function ToInt32(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int16bit be int modulo 2^32.
|
||||
var int32bit = modulo(int, Math.pow(2, 32));
|
||||
|
||||
// 5. If int32bit ≥ 2^31, return int32bit - 2^32; otherwise return int32bit.
|
||||
return int32bit >= Math.pow(2, 31) ? int32bit - Math.pow(2, 32) : int32bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.6
|
||||
|
||||
}, {
|
||||
key: "ToUint32",
|
||||
value: function ToUint32(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int16bit be int modulo 2^32.
|
||||
var int32bit = modulo(int, Math.pow(2, 32));
|
||||
|
||||
// 5. Return int32bit.
|
||||
return int32bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.7
|
||||
|
||||
}, {
|
||||
key: "ToInt16",
|
||||
value: function ToInt16(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int16bit be int modulo 2^16.
|
||||
var int16bit = modulo(int, Math.pow(2, 16));
|
||||
|
||||
// 5. If int16bit ≥ 2^15, return int16bit - 2^16; otherwise return int16bit.
|
||||
return int16bit >= Math.pow(2, 15) ? int16bit - Math.pow(2, 16) : int16bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.8
|
||||
|
||||
}, {
|
||||
key: "ToUint16",
|
||||
value: function ToUint16(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int16bit be int modulo 2^16.
|
||||
var int16bit = modulo(int, Math.pow(2, 16));
|
||||
|
||||
// 5. Return int16bit.
|
||||
return int16bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.9
|
||||
|
||||
}, {
|
||||
key: "ToInt8",
|
||||
value: function ToInt8(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int8bit be int modulo 2^8.
|
||||
var int8bit = modulo(int, Math.pow(2, 8));
|
||||
|
||||
// 5. If int8bit ≥ 2^7, return int8bit - 2^8; otherwise return int8bit.
|
||||
return int8bit >= Math.pow(2, 7) ? int8bit - Math.pow(2, 8) : int8bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.10
|
||||
|
||||
}, {
|
||||
key: "ToUint8",
|
||||
value: function ToUint8(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, +0, -0, +∞, or -∞, return +0.
|
||||
if (isNaN(number) || number === 0 || !isFinite(number)) return +0;
|
||||
|
||||
// 3. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
var int = number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
|
||||
// 4. Let int8bit be int modulo 2^8.
|
||||
var int8bit = modulo(int, Math.pow(2, 8));
|
||||
|
||||
// 5. Return int8bit.
|
||||
return int8bit;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.11
|
||||
|
||||
}, {
|
||||
key: "ToUint8Clamp",
|
||||
value: function ToUint8Clamp(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, return +0.
|
||||
if (isNaN(number)) return +0;
|
||||
|
||||
// 3. If number ≤ 0, return +0.
|
||||
if (number <= 0) return +0;
|
||||
|
||||
// 4. If number ≥ 255, return 255.
|
||||
if (number >= 255) return 255;
|
||||
|
||||
// 5. Let f be floor(number).
|
||||
var f = Math.floor(number);
|
||||
|
||||
// 6. If f + 0.5 < number, return f + 1.
|
||||
if (f + 0.5 < number) return f + 1;
|
||||
|
||||
// 7. If number < f + 0.5, return f.
|
||||
if (number < f + 0.5) return f;
|
||||
|
||||
// 8. If f is odd, return f + 1.
|
||||
if (f % 2 === 1) return f + 1;
|
||||
|
||||
// 9. Return f.
|
||||
return f;
|
||||
}
|
||||
|
||||
// ECMA262 19.3.3.1
|
||||
|
||||
}, {
|
||||
key: "thisBooleanValue",
|
||||
value: function thisBooleanValue(realm, value) {
|
||||
// 1. If Type(value) is Boolean, return value.
|
||||
if (value instanceof _index.BooleanValue) return value;
|
||||
|
||||
// 2. If Type(value) is Object and value has a [[BooleanData]] internal slot, then
|
||||
if (value instanceof _index.ObjectValue && value.$BooleanData) {
|
||||
var booleanData = value.$BooleanData.throwIfNotConcreteBoolean();
|
||||
// a. Assert: value's [[BooleanData]] internal slot is a Boolean value.
|
||||
(0, _invariant2.default)(booleanData instanceof _index.BooleanValue, "expected boolean data internal slot to be a boolean value");
|
||||
|
||||
// b. Return the value of value's [[BooleanData]] internal slot.
|
||||
return booleanData;
|
||||
}
|
||||
|
||||
value.throwIfNotConcrete();
|
||||
|
||||
// 3. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// ECMA262 20.1.3
|
||||
|
||||
}, {
|
||||
key: "thisNumberValue",
|
||||
value: function thisNumberValue(realm, value) {
|
||||
// 1. If Type(value) is Number, return value.
|
||||
if (value instanceof _index.NumberValue) return value;
|
||||
|
||||
// 2. If Type(value) is Object and value has a [[NumberData]] internal slot, then
|
||||
if (value instanceof _index.ObjectValue && value.$NumberData) {
|
||||
var numberData = value.$NumberData.throwIfNotConcreteNumber();
|
||||
// a. Assert: value's [[NumberData]] internal slot is a Number value.
|
||||
(0, _invariant2.default)(numberData instanceof _index.NumberValue, "expected number data internal slot to be a number value");
|
||||
|
||||
// b. Return the value of value's [[NumberData]] internal slot.
|
||||
return numberData;
|
||||
}
|
||||
|
||||
value = value.throwIfNotConcrete();
|
||||
|
||||
// 3. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// ECMA262 21.1.3
|
||||
|
||||
}, {
|
||||
key: "thisStringValue",
|
||||
value: function thisStringValue(realm, value) {
|
||||
// 1. If Type(value) is String, return value.
|
||||
if (value instanceof _index.StringValue) return value;
|
||||
|
||||
// 2. If Type(value) is Object and value has a [[StringData]] internal slot, then
|
||||
if (value instanceof _index.ObjectValue && value.$StringData) {
|
||||
var stringData = value.$StringData.throwIfNotConcreteString();
|
||||
// a. Assert: value's [[StringData]] internal slot is a String value.
|
||||
(0, _invariant2.default)(stringData instanceof _index.StringValue, "expected string data internal slot to be a string value");
|
||||
|
||||
// b. Return the value of value's [[StringData]] internal slot.
|
||||
return stringData;
|
||||
}
|
||||
|
||||
value = value.throwIfNotConcrete();
|
||||
|
||||
// 3. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// ECMA262 6.2.4.5
|
||||
|
||||
}, {
|
||||
key: "ToPropertyDescriptor",
|
||||
value: function ToPropertyDescriptor(realm, Obj) {
|
||||
Obj = Obj.throwIfNotConcrete();
|
||||
|
||||
// 1. If Type(Obj) is not Object, throw a TypeError exception.
|
||||
if (!(Obj instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 2. Let desc be a new Property Descriptor that initially has no fields.
|
||||
var desc = {};
|
||||
|
||||
// 3. Let hasEnumerable be ? HasProperty(Obj, "enumerable").
|
||||
var hasEnumerable = (0, _has.HasProperty)(realm, Obj, "enumerable");
|
||||
|
||||
// 4. If hasEnumerable is true, then
|
||||
if (hasEnumerable === true) {
|
||||
// a. Let enum be ToBoolean(? Get(Obj, "enumerable")).
|
||||
var enu = this.ToBooleanPartial(realm, (0, _get.Get)(realm, Obj, "enumerable"));
|
||||
|
||||
// b. Set the [[Enumerable]] field of desc to enum.
|
||||
desc.enumerable = enu === true;
|
||||
}
|
||||
|
||||
// 5. Let hasConfigurable be ? HasProperty(Obj, "configurable").
|
||||
var hasConfigurable = (0, _has.HasProperty)(realm, Obj, "configurable");
|
||||
|
||||
// 6. If hasConfigurable is true, then
|
||||
if (hasConfigurable === true) {
|
||||
// a. Let conf be ToBoolean(? Get(Obj, "configurable")).
|
||||
var conf = this.ToBooleanPartial(realm, (0, _get.Get)(realm, Obj, "configurable"));
|
||||
|
||||
// b. Set the [[Configurable]] field of desc to conf.
|
||||
desc.configurable = conf === true;
|
||||
}
|
||||
|
||||
// 7. Let hasValue be ? HasProperty(Obj, "value").
|
||||
var hasValue = (0, _has.HasProperty)(realm, Obj, "value");
|
||||
|
||||
// 8. If hasValue is true, then
|
||||
if (hasValue === true) {
|
||||
// a. Let value be ? Get(Obj, "value").
|
||||
var value = (0, _get.Get)(realm, Obj, "value");
|
||||
|
||||
// b. Set the [[Value]] field of desc to value.
|
||||
desc.value = value;
|
||||
}
|
||||
|
||||
// 9. Let hasWritable be ? HasProperty(Obj, "writable").
|
||||
var hasWritable = (0, _has.HasProperty)(realm, Obj, "writable");
|
||||
|
||||
// 10. If hasWritable is true, then
|
||||
if (hasWritable === true) {
|
||||
// a. Let writable be ToBoolean(? Get(Obj, "writable")).
|
||||
var writable = this.ToBooleanPartial(realm, (0, _get.Get)(realm, Obj, "writable"));
|
||||
|
||||
// b. Set the [[Writable]] field of desc to writable.
|
||||
desc.writable = writable === true;
|
||||
}
|
||||
|
||||
// 11. Let hasGet be ? HasProperty(Obj, "get").
|
||||
var hasGet = (0, _has.HasProperty)(realm, Obj, "get");
|
||||
|
||||
// 12. If hasGet is true, then
|
||||
if (hasGet === true) {
|
||||
// a. Let getter be ? Get(Obj, "get").
|
||||
var getter = (0, _get.Get)(realm, Obj, "get");
|
||||
|
||||
// b. If IsCallable(getter) is false and getter is not undefined, throw a TypeError exception.
|
||||
if ((0, _is.IsCallable)(realm, getter) === false && !getter.mightBeUndefined()) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
getter.throwIfNotConcrete();
|
||||
|
||||
// c. Set the [[Get]] field of desc to getter.
|
||||
desc.get = getter;
|
||||
}
|
||||
|
||||
// 13. Let hasSet be ? HasProperty(Obj, "set").
|
||||
var hasSet = (0, _has.HasProperty)(realm, Obj, "set");
|
||||
|
||||
// 14. If hasSet is true, then
|
||||
if (hasSet === true) {
|
||||
// a. Let setter be ? Get(Obj, "set").
|
||||
var setter = (0, _get.Get)(realm, Obj, "set");
|
||||
|
||||
// b. If IsCallable(setter) is false and setter is not undefined, throw a TypeError exception.
|
||||
if ((0, _is.IsCallable)(realm, setter) === false && !setter.mightBeUndefined()) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
setter.throwIfNotConcrete();
|
||||
|
||||
// c. Set the [[Set]] field of desc to setter.
|
||||
desc.set = setter;
|
||||
}
|
||||
|
||||
// 15. If either desc.[[Get]] or desc.[[Set]] is present, then
|
||||
if (desc.get || desc.set) {
|
||||
// a. If either desc.[[Value]] or desc.[[Writable]] is present, throw a TypeError exception.
|
||||
if ("value" in desc || "writable" in desc) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
}
|
||||
|
||||
// 16. Return desc.
|
||||
return desc;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.13
|
||||
|
||||
}, {
|
||||
key: "ToObject",
|
||||
value: function ToObject(realm, arg) {
|
||||
if (arg instanceof _index.UndefinedValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
} else if (arg instanceof _index.NullValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
} else if (arg instanceof _index.BooleanValue) {
|
||||
var obj = new _index.ObjectValue(realm, realm.intrinsics.BooleanPrototype);
|
||||
obj.$BooleanData = arg;
|
||||
return obj;
|
||||
} else if (arg instanceof _index.NumberValue) {
|
||||
var _obj = new _index.ObjectValue(realm, realm.intrinsics.NumberPrototype);
|
||||
_obj.$NumberData = arg;
|
||||
return _obj;
|
||||
} else if (arg instanceof _index.StringValue) {
|
||||
var _obj2 = _singletons.Create.StringCreate(realm, arg, realm.intrinsics.StringPrototype);
|
||||
return _obj2;
|
||||
} else if (arg instanceof _index.SymbolValue) {
|
||||
var _obj3 = new _index.ObjectValue(realm, realm.intrinsics.SymbolPrototype);
|
||||
_obj3.$SymbolData = arg;
|
||||
return _obj3;
|
||||
} else if (arg instanceof _index.ObjectValue) {
|
||||
return arg;
|
||||
}
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
}, {
|
||||
key: "_WrapAbstractInObject",
|
||||
value: function _WrapAbstractInObject(realm, arg) {
|
||||
var obj = void 0;
|
||||
switch (arg.types.getType()) {
|
||||
case _index.NumberValue:
|
||||
obj = new _index.ObjectValue(realm, realm.intrinsics.NumberPrototype);
|
||||
obj.$NumberData = arg;
|
||||
break;
|
||||
|
||||
case _index.StringValue:
|
||||
obj = new _index.ObjectValue(realm, realm.intrinsics.StringPrototype);
|
||||
obj.$StringData = arg;
|
||||
break;
|
||||
|
||||
case _index.BooleanValue:
|
||||
obj = new _index.ObjectValue(realm, realm.intrinsics.BooleanPrototype);
|
||||
obj.$BooleanData = arg;
|
||||
break;
|
||||
|
||||
case _index.SymbolValue:
|
||||
obj = new _index.ObjectValue(realm, realm.intrinsics.SymbolPrototype);
|
||||
obj.$SymbolData = arg;
|
||||
break;
|
||||
|
||||
case _index.UndefinedValue:
|
||||
case _index.NullValue:
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
|
||||
default:
|
||||
obj = arg.throwIfNotConcreteObject();
|
||||
break;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}, {
|
||||
key: "ToObjectPartial",
|
||||
value: function ToObjectPartial(realm, arg) {
|
||||
if (arg instanceof _index.AbstractObjectValue) return arg;
|
||||
if (arg instanceof _index.AbstractValue) {
|
||||
return this._WrapAbstractInObject(realm, arg);
|
||||
}
|
||||
arg = arg.throwIfNotConcrete();
|
||||
return this.ToObject(realm, arg);
|
||||
}
|
||||
|
||||
// ECMA262 7.1.15
|
||||
|
||||
}, {
|
||||
key: "ToLength",
|
||||
value: function ToLength(realm, argument) {
|
||||
// Let len be ? ToInteger(argument).
|
||||
var len = this.ToInteger(realm, argument);
|
||||
|
||||
// If len ≤ +0, return +0.
|
||||
if (len <= 0) return +0;
|
||||
|
||||
// If len is +∞, return 2^53-1.
|
||||
if (len === +Infinity) return Math.pow(2, 53) - 1;
|
||||
|
||||
// Return min(len, 2^53-1).
|
||||
return Math.min(len, Math.pow(2, 53) - 1);
|
||||
}
|
||||
|
||||
// ECMA262 7.1.4
|
||||
|
||||
}, {
|
||||
key: "ToInteger",
|
||||
value: function ToInteger(realm, argument) {
|
||||
// 1. Let number be ? ToNumber(argument).
|
||||
var number = this.ToNumber(realm, argument);
|
||||
|
||||
// 2. If number is NaN, return +0.
|
||||
if (isNaN(number)) return +0;
|
||||
|
||||
// 3. If number is +0, -0, +∞, or -∞, return number.
|
||||
if (!isFinite(number) || number === 0) return number;
|
||||
|
||||
// 4. Return the number value that is the same sign as number and whose magnitude is floor(abs(number)).
|
||||
return number < 0 ? -Math.floor(Math.abs(number)) : Math.floor(Math.abs(number));
|
||||
}
|
||||
|
||||
// ECMA262 7.1.17
|
||||
|
||||
}, {
|
||||
key: "ToIndex",
|
||||
value: function ToIndex(realm, value) {
|
||||
var index = void 0;
|
||||
// 1. If value is undefined, then
|
||||
if (value instanceof _index.UndefinedValue) {
|
||||
// a. Let index be 0.
|
||||
index = 0;
|
||||
} else {
|
||||
// 2. Else,
|
||||
// a. Let integerIndex be ? ToInteger(value).
|
||||
var integerIndex = this.ToInteger(realm, value);
|
||||
|
||||
// b. If integerIndex < 0, throw a RangeError exception.
|
||||
if (integerIndex < 0) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "integerIndex < 0");
|
||||
}
|
||||
|
||||
// c. Let index be ! ToLength(integerIndex).
|
||||
index = this.ToLength(realm, integerIndex);
|
||||
|
||||
// d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception.
|
||||
if ((0, _abstract.SameValueZero)(realm, new _index.NumberValue(realm, integerIndex), new _index.NumberValue(realm, index)) === false) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.RangeError, "integerIndex < 0");
|
||||
}
|
||||
}
|
||||
// 3. Return index.
|
||||
return index;
|
||||
}
|
||||
}, {
|
||||
key: "ToIndexPartial",
|
||||
value: function ToIndexPartial(realm, value) {
|
||||
return this.ToIndex(realm, typeof value === "number" ? value : value.throwIfNotConcrete());
|
||||
}
|
||||
}, {
|
||||
key: "ToNumber",
|
||||
value: function ToNumber(realm, val) {
|
||||
var num = this.ToNumberOrAbstract(realm, val);
|
||||
if (typeof num !== "number") {
|
||||
_index.AbstractValue.reportIntrospectionError(num);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.3
|
||||
|
||||
}, {
|
||||
key: "ToNumberOrAbstract",
|
||||
value: function ToNumberOrAbstract(realm, val) {
|
||||
if (typeof val === "number") {
|
||||
return val;
|
||||
} else if (val instanceof _index.AbstractValue) {
|
||||
return val;
|
||||
} else if (val instanceof _index.UndefinedValue) {
|
||||
return NaN;
|
||||
} else if (val instanceof _index.NullValue) {
|
||||
return +0;
|
||||
} else if (val instanceof _index.ObjectValue) {
|
||||
var prim = this.ToPrimitiveOrAbstract(realm, val, "number");
|
||||
return this.ToNumberOrAbstract(realm, prim);
|
||||
} else if (val instanceof _index.BooleanValue) {
|
||||
if (val.value === true) {
|
||||
return 1;
|
||||
} else {
|
||||
// `val.value === false`
|
||||
return 0;
|
||||
}
|
||||
} else if (val instanceof _index.NumberValue) {
|
||||
return val.value;
|
||||
} else if (val instanceof _index.StringValue) {
|
||||
return Number(val.value);
|
||||
} else if (val instanceof _index.SymbolValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
} else {
|
||||
(0, _invariant2.default)(false, "unexpected type of value");
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "IsToNumberPure",
|
||||
value: function IsToNumberPure(realm, val) {
|
||||
if (val instanceof _index.Value) {
|
||||
if (this.IsToPrimitivePure(realm, val)) {
|
||||
var type = val.getType();
|
||||
return type !== _index.SymbolValue && type !== _index.PrimitiveValue && type !== _index.Value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.1
|
||||
|
||||
}, {
|
||||
key: "ToPrimitive",
|
||||
value: function ToPrimitive(realm, input, hint) {
|
||||
return this.ToPrimitiveOrAbstract(realm, input, hint).throwIfNotConcretePrimitive();
|
||||
}
|
||||
}, {
|
||||
key: "ToPrimitiveOrAbstract",
|
||||
value: function ToPrimitiveOrAbstract(realm, input, hint) {
|
||||
if (input instanceof _index.PrimitiveValue) {
|
||||
return input;
|
||||
}
|
||||
|
||||
// When Type(input) is Object, the following steps are taken
|
||||
(0, _invariant2.default)(input instanceof _index.ObjectValue, "expected an object");
|
||||
|
||||
// 1. If PreferredType was not passed, let hint be "default".
|
||||
hint = hint || "default";
|
||||
|
||||
// Following two steps are redundant since we just pass string hints.
|
||||
// 2. Else if PreferredType is hint String, let hint be "string".
|
||||
// 3. Else PreferredType is hint Number, let hint be "number".
|
||||
|
||||
// 4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
|
||||
var exoticToPrim = (0, _get.GetMethod)(realm, input, realm.intrinsics.SymbolToPrimitive);
|
||||
|
||||
// 5. If exoticToPrim is not undefined, then
|
||||
if (!(exoticToPrim instanceof _index.UndefinedValue)) {
|
||||
// a. Let result be ? Call(exoticToPrim, input, « hint »).
|
||||
var result = (0, _call.Call)(realm, exoticToPrim, input, [new _index.StringValue(realm, hint)]);
|
||||
|
||||
// b. If Type(result) is not Object, return result.
|
||||
if (!(result instanceof _index.ObjectValue)) {
|
||||
(0, _invariant2.default)(result instanceof _index.PrimitiveValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
// c. Throw a TypeError exception.
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
}
|
||||
|
||||
// 6. If hint is "default", let hint be "number".
|
||||
if (hint === "default") hint = "number";
|
||||
|
||||
// 7. Return ? OrdinaryToPrimitive(input, hint).
|
||||
return this.OrdinaryToPrimitiveOrAbstract(realm, input, hint);
|
||||
}
|
||||
|
||||
// Returns result type of ToPrimitive if it is pure (terminates, does not throw exception, does not read or write heap), otherwise undefined.
|
||||
|
||||
}, {
|
||||
key: "GetToPrimitivePureResultType",
|
||||
value: function GetToPrimitivePureResultType(realm, input) {
|
||||
var type = input.getType();
|
||||
if (input instanceof _index.PrimitiveValue) return type;
|
||||
if (input instanceof _index.AbstractValue && _index.Value.isTypeCompatibleWith(type, _index.PrimitiveValue)) return type;
|
||||
return undefined;
|
||||
}
|
||||
}, {
|
||||
key: "IsToPrimitivePure",
|
||||
value: function IsToPrimitivePure(realm, input) {
|
||||
return this.GetToPrimitivePureResultType(realm, input) !== undefined;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.1
|
||||
|
||||
}, {
|
||||
key: "OrdinaryToPrimitive",
|
||||
value: function OrdinaryToPrimitive(realm, input, hint) {
|
||||
return this.OrdinaryToPrimitiveOrAbstract(realm, input, hint).throwIfNotConcretePrimitive();
|
||||
}
|
||||
}, {
|
||||
key: "OrdinaryToPrimitiveOrAbstract",
|
||||
value: function OrdinaryToPrimitiveOrAbstract(realm, input, hint) {
|
||||
var methodNames = void 0;
|
||||
|
||||
// 1. Assert: Type(O) is Object.
|
||||
(0, _invariant2.default)(input instanceof _index.ObjectValue, "Expected object");
|
||||
|
||||
// 2. Assert: Type(hint) is String and its value is either "string" or "number".
|
||||
(0, _invariant2.default)(hint === "string" || hint === "number", "Expected string or number hint");
|
||||
|
||||
// 3. If hint is "string", then
|
||||
if (hint === "string") {
|
||||
// a. Let methodNames be « "toString", "valueOf" ».
|
||||
methodNames = ["toString", "valueOf"];
|
||||
} else {
|
||||
// 4. Else,
|
||||
// a. Let methodNames be « "valueOf", "toString" ».
|
||||
methodNames = ["valueOf", "toString"];
|
||||
}
|
||||
|
||||
// 5. For each name in methodNames in List order, do
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = methodNames[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var name = _step.value;
|
||||
|
||||
// a. Let method be ? Get(O, name).
|
||||
var method = (0, _get.Get)(realm, input, new _index.StringValue(realm, name));
|
||||
|
||||
// b. If IsCallable(method) is true, then
|
||||
if ((0, _is.IsCallable)(realm, method)) {
|
||||
// i. Let result be ? Call(method, O).
|
||||
var result = (0, _call.Call)(realm, method, input);
|
||||
var resultType = result.getType();
|
||||
|
||||
// ii. If Type(result) is not Object, return result.
|
||||
if (_index.Value.isTypeCompatibleWith(resultType, _index.PrimitiveValue)) {
|
||||
(0, _invariant2.default)(result instanceof _index.AbstractValue || result instanceof _index.PrimitiveValue);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Throw a TypeError exception.
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "can't turn to primitive");
|
||||
}
|
||||
|
||||
// ECMA262 7.1.12
|
||||
|
||||
}, {
|
||||
key: "ToString",
|
||||
value: function ToString(realm, val) {
|
||||
if (typeof val === "string") {
|
||||
return val;
|
||||
} else if (val instanceof _index.StringValue) {
|
||||
return val.value;
|
||||
} else if (val instanceof _index.NumberValue) {
|
||||
return val.value + "";
|
||||
} else if (val instanceof _index.UndefinedValue) {
|
||||
return "undefined";
|
||||
} else if (val instanceof _index.NullValue) {
|
||||
return "null";
|
||||
} else if (val instanceof _index.SymbolValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
} else if (val instanceof _index.BooleanValue) {
|
||||
return val.value ? "true" : "false";
|
||||
} else if (val instanceof _index.ObjectValue) {
|
||||
var primValue = this.ToPrimitive(realm, val, "string");
|
||||
return this.ToString(realm, primValue);
|
||||
} else {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "unknown value type, can't coerce to string");
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "ToStringPartial",
|
||||
value: function ToStringPartial(realm, val) {
|
||||
return this.ToString(realm, typeof val === "string" ? val : val.throwIfNotConcrete());
|
||||
}
|
||||
}, {
|
||||
key: "ToStringValue",
|
||||
value: function ToStringValue(realm, val) {
|
||||
if (val.getType() === _index.StringValue) return val;
|
||||
var str = void 0;
|
||||
if (typeof val === "string") {
|
||||
str = val;
|
||||
} else if (val instanceof _index.NumberValue) {
|
||||
str = val.value + "";
|
||||
} else if (val instanceof _index.UndefinedValue) {
|
||||
str = "undefined";
|
||||
} else if (val instanceof _index.NullValue) {
|
||||
str = "null";
|
||||
} else if (val instanceof _index.SymbolValue) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError);
|
||||
} else if (val instanceof _index.BooleanValue) {
|
||||
str = val.value ? "true" : "false";
|
||||
} else if (val instanceof _index.ObjectValue) {
|
||||
var primValue = this.ToPrimitiveOrAbstract(realm, val, "string");
|
||||
if (primValue.getType() === _index.StringValue) return primValue;
|
||||
str = this.ToStringPartial(realm, primValue);
|
||||
} else {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "unknown value type, can't coerce to string");
|
||||
}
|
||||
return new _index.StringValue(realm, str);
|
||||
}
|
||||
|
||||
// ECMA262 7.1.2
|
||||
|
||||
}, {
|
||||
key: "ToBoolean",
|
||||
value: function ToBoolean(realm, val) {
|
||||
if (val instanceof _index.BooleanValue) {
|
||||
return val.value;
|
||||
} else if (val instanceof _index.UndefinedValue) {
|
||||
return false;
|
||||
} else if (val instanceof _index.NullValue) {
|
||||
return false;
|
||||
} else if (val instanceof _index.NumberValue) {
|
||||
return val.value !== 0 && !isNaN(val.value);
|
||||
} else if (val instanceof _index.StringValue) {
|
||||
return val.value.length > 0;
|
||||
} else if (val instanceof _index.ObjectValue) {
|
||||
return true;
|
||||
} else if (val instanceof _index.SymbolValue) {
|
||||
return true;
|
||||
} else {
|
||||
(0, _invariant2.default)(!(val instanceof _index.AbstractValue));
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "unknown value type, can't coerce to a boolean");
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "ToBooleanPartial",
|
||||
value: function ToBooleanPartial(realm, val) {
|
||||
if (!val.mightNotBeObject()) return true;
|
||||
return this.ToBoolean(realm, val.throwIfNotConcrete());
|
||||
}
|
||||
|
||||
// ECMA262 7.1.14
|
||||
|
||||
}, {
|
||||
key: "ToPropertyKey",
|
||||
value: function ToPropertyKey(realm, arg) /* but not StringValue */{
|
||||
// 1. Let key be ? ToPrimitive(argument, hint String).
|
||||
var key = this.ToPrimitive(realm, arg, "string");
|
||||
|
||||
// 2. If Type(key) is Symbol, then
|
||||
if (key instanceof _index.SymbolValue) {
|
||||
// a. Return key.
|
||||
return key;
|
||||
}
|
||||
|
||||
// 3. Return ! ToString(key).
|
||||
return this.ToString(realm, key);
|
||||
}
|
||||
}, {
|
||||
key: "ToPropertyKeyPartial",
|
||||
value: function ToPropertyKeyPartial(realm, arg) /* but not StringValue */{
|
||||
if (arg instanceof _index.ConcreteValue) return this.ToPropertyKey(realm, arg);
|
||||
if (arg.mightNotBeString() && arg.mightNotBeNumber()) arg.throwIfNotConcrete();
|
||||
(0, _invariant2.default)(arg instanceof _index.AbstractValue);
|
||||
return arg;
|
||||
}
|
||||
|
||||
// ECMA262 7.1.16
|
||||
|
||||
}, {
|
||||
key: "CanonicalNumericIndexString",
|
||||
value: function CanonicalNumericIndexString(realm, argument) {
|
||||
// 1. Assert: Type(argument) is String.
|
||||
(0, _invariant2.default)(argument instanceof _index.StringValue);
|
||||
|
||||
// 2. If argument is "-0", return −0.
|
||||
if (argument.value === "-0") return -0;
|
||||
|
||||
// 3. Let n be ToNumber(argument).
|
||||
var n = this.ToNumber(realm, argument);
|
||||
|
||||
// 4. If SameValue(ToString(n), argument) is false, return undefined.
|
||||
if ((0, _abstract.SameValue)(realm, new _index.StringValue(realm, this.ToString(realm, new _index.NumberValue(realm, n))), argument) === false) return undefined;
|
||||
|
||||
// 5. Return n.
|
||||
return n;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ToImplementation;
|
||||
}();
|
||||
//# sourceMappingURL=to.js.map
|
||||
1
build/node_modules/prepack/lib/methods/to.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/to.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
364
build/node_modules/prepack/lib/methods/typedarray.js
generated
vendored
Normal file
364
build/node_modules/prepack/lib/methods/typedarray.js
generated
vendored
Normal file
@@ -0,0 +1,364 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ArrayElementType = exports.ArrayElementSize = undefined;
|
||||
exports.IntegerIndexedObjectCreate = IntegerIndexedObjectCreate;
|
||||
exports.IntegerIndexedElementGet = IntegerIndexedElementGet;
|
||||
exports.IntegerIndexedElementSet = IntegerIndexedElementSet;
|
||||
exports.ValidateTypedArray = ValidateTypedArray;
|
||||
exports.AllocateTypedArray = AllocateTypedArray;
|
||||
exports.AllocateTypedArrayBuffer = AllocateTypedArrayBuffer;
|
||||
exports.TypedArrayCreate = TypedArrayCreate;
|
||||
exports.TypedArraySpeciesCreate = TypedArraySpeciesCreate;
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _get = require("../methods/get.js");
|
||||
|
||||
var _arraybuffer = require("../methods/arraybuffer.js");
|
||||
|
||||
var _is = require("../methods/is.js");
|
||||
|
||||
var _construct = require("../methods/construct.js");
|
||||
|
||||
var _singletons = require("../singletons.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var ArrayElementSize = exports.ArrayElementSize = {
|
||||
Float32Array: 4,
|
||||
Float64Array: 8,
|
||||
Int8Array: 1,
|
||||
Int16Array: 2,
|
||||
Int32Array: 4,
|
||||
Uint8Array: 1,
|
||||
Uint16Array: 2,
|
||||
Uint32Array: 4,
|
||||
Uint8ClampedArray: 1
|
||||
}; /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var ArrayElementType = exports.ArrayElementType = {
|
||||
Float32Array: "Float32",
|
||||
Float64Array: "Float64",
|
||||
Int8Array: "Int8",
|
||||
Int16Array: "Int16",
|
||||
Int32Array: "Int32",
|
||||
Uint8Array: "Uint8",
|
||||
Uint16Array: "Uint16",
|
||||
Uint32Array: "Uint32",
|
||||
Uint8ClampedArray: "Uint8Clamped"
|
||||
};
|
||||
|
||||
// ECMA262 9.4.5.7
|
||||
function IntegerIndexedObjectCreate(realm, prototype, internalSlotsList) {
|
||||
// 1. Assert: internalSlotsList contains the names [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]].
|
||||
(0, _invariant2.default)("$ViewedArrayBuffer" in internalSlotsList && "$ArrayLength" in internalSlotsList && "$ByteOffset" in internalSlotsList && "$TypedArrayName" in internalSlotsList);
|
||||
|
||||
// 2. Let A be a newly created object with an internal slot for each name in internalSlotsList.
|
||||
var A = new _index.IntegerIndexedExotic(realm);
|
||||
Object.assign(A, internalSlotsList);
|
||||
|
||||
// 3. Set A's essential internal methods to the default ordinary object definitions specified in 9.1.
|
||||
// 4. Set the [[GetOwnProperty]] internal method of A as specified in 9.4.5.1.
|
||||
// 5. Set the [[HasProperty]] internal method of A as specified in 9.4.5.2.
|
||||
// 6. Set the [[DefineOwnProperty]] internal method of A as specified in 9.4.5.3.
|
||||
// 7. Set the [[Get]] internal method of A as specified in 9.4.5.4.
|
||||
// 8. Set the [[Set]] internal method of A as specified in 9.4.5.5.
|
||||
// 9. Set the [[OwnPropertyKeys]] internal method of A as specified in 9.4.5.6.
|
||||
|
||||
// 10. Set A.[[Prototype]] to prototype.
|
||||
A.$Prototype = prototype;
|
||||
|
||||
// 11. Set A.[[Extensible]] to true.
|
||||
A.setExtensible(true);
|
||||
|
||||
// 12. Return A.
|
||||
return A;
|
||||
}
|
||||
|
||||
// ECMA262 9.4.5.8
|
||||
function IntegerIndexedElementGet(realm, O, index) {
|
||||
// 1. Assert: Type(index) is Number.
|
||||
(0, _invariant2.default)(typeof index === "number", "Type(index) is Number");
|
||||
|
||||
// 2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue && O.$ViewedArrayBuffer && O.$ArrayLength !== undefined && O.$ByteOffset !== undefined && O.$TypedArrayName);
|
||||
|
||||
// 3. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
var buffer = O.$ViewedArrayBuffer;
|
||||
|
||||
// 4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, buffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(buffer) is true");
|
||||
}
|
||||
|
||||
// 5. If IsInteger(index) is false, return undefined.
|
||||
if ((0, _is.IsInteger)(realm, index) === false) return realm.intrinsics.undefined;
|
||||
|
||||
// 6. If index = -0, return undefined.
|
||||
if (Object.is(index, -0)) return realm.intrinsics.undefined;
|
||||
|
||||
// 7. Let length be O.[[ArrayLength]].
|
||||
var length = O.$ArrayLength;
|
||||
(0, _invariant2.default)(typeof length === "number");
|
||||
|
||||
// 8. If index < 0 or index ≥ length, return undefined.
|
||||
if (index < 0 || index >= length) return realm.intrinsics.undefined;
|
||||
|
||||
// 9. Let offset be O.[[ByteOffset]].
|
||||
var offset = O.$ByteOffset;
|
||||
(0, _invariant2.default)(typeof offset === "number");
|
||||
|
||||
// 10. Let arrayTypeName be the String value of O.[[TypedArrayName]].
|
||||
var arrayTypeName = O.$TypedArrayName;
|
||||
(0, _invariant2.default)(typeof arrayTypeName === "string");
|
||||
|
||||
// 11. Let elementSize be the Number value of the Element Size value specified in Table 50 for arrayTypeName.
|
||||
var elementSize = ArrayElementSize[arrayTypeName];
|
||||
|
||||
// 12. Let indexedPosition be (index × elementSize) + offset.
|
||||
var indexedPosition = index * elementSize + offset;
|
||||
|
||||
// 13. Let elementType be the String value of the Element Type value in Table 50 for arrayTypeName.
|
||||
var elementType = ArrayElementType[arrayTypeName];
|
||||
|
||||
// 14. Return GetValueFromBuffer(buffer, indexedPosition, elementType).
|
||||
return (0, _arraybuffer.GetValueFromBuffer)(realm, buffer, indexedPosition, elementType);
|
||||
}
|
||||
|
||||
// ECMA262 9.4.5.9
|
||||
function IntegerIndexedElementSet(realm, O, index, value) {
|
||||
// 1. Assert: Type(index) is Number.
|
||||
(0, _invariant2.default)(typeof index === "number", "Type(index) is Number");
|
||||
|
||||
// 2. Assert: O is an Object that has [[ViewedArrayBuffer]], [[ArrayLength]], [[ByteOffset]], and [[TypedArrayName]] internal slots.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue && O.$ViewedArrayBuffer && O.$ArrayLength !== undefined && O.$ByteOffset !== undefined && O.$TypedArrayName);
|
||||
|
||||
// 3. Let numValue be ? ToNumber(value).
|
||||
var numValue = _singletons.To.ToNumber(realm, value);
|
||||
|
||||
// 4. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
var buffer = O.$ViewedArrayBuffer;
|
||||
(0, _invariant2.default)(buffer);
|
||||
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, buffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(buffer) is true");
|
||||
}
|
||||
|
||||
// 6. If IsInteger(index) is false, return false.
|
||||
if ((0, _is.IsInteger)(realm, index) === false) return false;
|
||||
|
||||
// 7. If index = -0, return false.
|
||||
if (Object.is(index, -0)) return false;
|
||||
|
||||
// 8. Let length be O.[[ArrayLength]].
|
||||
var length = O.$ArrayLength;
|
||||
(0, _invariant2.default)(typeof length === "number");
|
||||
|
||||
// 9. If index < 0 or index ≥ length, return false.
|
||||
if (index < 0 || index >= length) return false;
|
||||
|
||||
// 10. Let offset be O.[[ByteOffset]].
|
||||
var offset = O.$ByteOffset;
|
||||
(0, _invariant2.default)(typeof offset === "number");
|
||||
|
||||
// 11. Let arrayTypeName be the String value of O.[[TypedArrayName]].
|
||||
var arrayTypeName = O.$TypedArrayName;
|
||||
(0, _invariant2.default)(typeof arrayTypeName === "string");
|
||||
|
||||
// 12. Let elementSize be the Number value of the Element Size value specified in Table 50 for arrayTypeName.
|
||||
var elementSize = ArrayElementSize[arrayTypeName];
|
||||
|
||||
// 13. Let indexedPosition be (index × elementSize) + offset.
|
||||
var indexedPosition = index * elementSize + offset;
|
||||
|
||||
// 14. Let elementType be the String value of the Element Type value in Table 50 for arrayTypeName.
|
||||
var elementType = ArrayElementType[arrayTypeName];
|
||||
|
||||
// 15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue).
|
||||
(0, _arraybuffer.SetValueInBuffer)(realm, buffer, indexedPosition, elementType, numValue);
|
||||
|
||||
// 16. Return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.3.5.1
|
||||
function ValidateTypedArray(realm, O) {
|
||||
O = O.throwIfNotConcrete();
|
||||
|
||||
// 1. If Type(O) is not Object, throw a TypeError exception.
|
||||
if (!(O instanceof _index.ObjectValue)) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(O) is not Object");
|
||||
}
|
||||
|
||||
// 2. If O does not have a [[TypedArrayName]] internal slot, throw a TypeError exception.
|
||||
if (!O.$TypedArrayName) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "Type(O) is not Object");
|
||||
}
|
||||
|
||||
// 3. Assert: O has a [[ViewedArrayBuffer]] internal slot.
|
||||
(0, _invariant2.default)(O.$ViewedArrayBuffer, "O has a [[ViewedArrayBuffer]] internal slot");
|
||||
|
||||
// 4. Let buffer be O.[[ViewedArrayBuffer]].
|
||||
var buffer = O.$ViewedArrayBuffer;
|
||||
|
||||
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
|
||||
if ((0, _is.IsDetachedBuffer)(realm, buffer) === true) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "IsDetachedBuffer(buffer) is true");
|
||||
}
|
||||
|
||||
// 6. Return buffer.
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.4.2.1
|
||||
function AllocateTypedArray(realm, constructorName, newTarget, defaultProto, length) {
|
||||
// 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto).
|
||||
var proto = (0, _get.GetPrototypeFromConstructor)(realm, newTarget, defaultProto);
|
||||
|
||||
// 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »).
|
||||
var obj = IntegerIndexedObjectCreate(realm, proto, {
|
||||
$ViewedArrayBuffer: undefined,
|
||||
$TypedArrayName: undefined,
|
||||
$ByteLength: undefined,
|
||||
$ByteOffset: undefined,
|
||||
$ArrayLength: undefined
|
||||
});
|
||||
|
||||
// 3. Assert: obj.[[ViewedArrayBuffer]] is undefined.
|
||||
(0, _invariant2.default)(obj.$ViewedArrayBuffer === undefined);
|
||||
|
||||
// 4. Set obj.[[TypedArrayName]] to constructorName.
|
||||
obj.$TypedArrayName = constructorName;
|
||||
|
||||
// 5. If length was not passed, then
|
||||
if (length === undefined) {
|
||||
// a. Set obj.[[ByteLength]] to 0.
|
||||
obj.$ByteLength = 0;
|
||||
|
||||
// b. Set obj.[[ByteOffset]] to 0.
|
||||
obj.$ByteOffset = 0;
|
||||
|
||||
// c. Set obj.[[ArrayLength]] to 0.
|
||||
obj.$ArrayLength = 0;
|
||||
} else {
|
||||
// 6. Else,
|
||||
// a. Perform ? AllocateTypedArrayBuffer(obj, length).
|
||||
AllocateTypedArrayBuffer(realm, obj, length);
|
||||
}
|
||||
|
||||
// 7. Return obj.
|
||||
return obj;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.4.2.2
|
||||
function AllocateTypedArrayBuffer(realm, O, length) {
|
||||
// Note that O is a new object, and we can thus write to internal slots
|
||||
(0, _invariant2.default)(realm.isNewObject(O));
|
||||
|
||||
// 1. Assert: O is an Object that has a [[ViewedArrayBuffer]] internal slot.
|
||||
(0, _invariant2.default)(O instanceof _index.ObjectValue && "$ViewedArrayBuffer" in O, "O is an Object that has a [[ViewedArrayBuffer]] internal slot");
|
||||
|
||||
// 2. Assert: O.[[ViewedArrayBuffer]] is undefined.
|
||||
(0, _invariant2.default)(O.$ViewedArrayBuffer === undefined, "O.[[ViewedArrayBuffer]] is undefined");
|
||||
|
||||
// 3. Assert: length ≥ 0.
|
||||
(0, _invariant2.default)(length >= 0, "length ≥ 0");
|
||||
|
||||
// 4. Let constructorName be the String value of O.[[TypedArrayName]].
|
||||
var constructorName = O.$TypedArrayName;
|
||||
(0, _invariant2.default)(constructorName);
|
||||
|
||||
// 5. Let elementSize be the Element Size value in Table 50 for constructorName.
|
||||
var elementSize = ArrayElementSize[constructorName];
|
||||
|
||||
// 6. Let byteLength be elementSize × length.
|
||||
var byteLength = elementSize * length;
|
||||
|
||||
// 7. Let data be ? AllocateArrayBuffer(%ArrayBuffer%, byteLength).
|
||||
var data = (0, _arraybuffer.AllocateArrayBuffer)(realm, realm.intrinsics.ArrayBuffer, byteLength);
|
||||
|
||||
// 8. Set O.[[ViewedArrayBuffer]] to data.
|
||||
O.$ViewedArrayBuffer = data;
|
||||
|
||||
// 9. Set O.[[ByteLength]] to byteLength.
|
||||
O.$ByteLength = byteLength;
|
||||
|
||||
// 10. Set O.[[ByteOffset]] to 0.
|
||||
O.$ByteOffset = 0;
|
||||
|
||||
// 11. Set O.[[ArrayLength]] to length.
|
||||
O.$ArrayLength = length;
|
||||
|
||||
// 12. Return O.
|
||||
return O;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.4.6
|
||||
function TypedArrayCreate(realm, constructor, argumentList) {
|
||||
// 1. Let newTypedArray be ? Construct(constructor, argumentList).
|
||||
var newTypedArray = (0, _construct.Construct)(realm, constructor, argumentList);
|
||||
|
||||
// 2. Perform ? ValidateTypedArray(newTypedArray).
|
||||
ValidateTypedArray(realm, newTypedArray);
|
||||
|
||||
// 3. If argumentList is a List of a single Number, then
|
||||
if (argumentList.length === 1 && argumentList[0].mightBeNumber()) {
|
||||
if (argumentList[0].mightNotBeNumber()) {
|
||||
(0, _invariant2.default)(argumentList[0] instanceof _index.AbstractValue);
|
||||
_index.AbstractValue.reportIntrospectionError(argumentList[0]);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
// a. If newTypedArray.[[ArrayLength]] < argumentList[0], throw a TypeError exception.
|
||||
(0, _invariant2.default)(typeof newTypedArray.$ArrayLength === "number");
|
||||
if (newTypedArray.$ArrayLength < argumentList[0].throwIfNotConcrete().value) {
|
||||
throw realm.createErrorThrowCompletion(realm.intrinsics.TypeError, "newTypedArray.[[ArrayLength]] < argumentList[0]");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Return newTypedArray.
|
||||
return newTypedArray;
|
||||
}
|
||||
|
||||
// ECMA262 22.2.4.7
|
||||
function TypedArraySpeciesCreate(realm, exemplar, argumentList) {
|
||||
// 1. Assert: exemplar is an Object that has a [[TypedArrayName]] internal slot.
|
||||
(0, _invariant2.default)(exemplar instanceof _index.ObjectValue && typeof exemplar.$TypedArrayName === "string");
|
||||
|
||||
// 2. Let defaultConstructor be the intrinsic object listed in column one of Table 50 for exemplar.[[TypedArrayName]].
|
||||
(0, _invariant2.default)(typeof exemplar.$TypedArrayName === "string");
|
||||
var defaultConstructor = {
|
||||
Float32Array: realm.intrinsics.Float32Array,
|
||||
Float64Array: realm.intrinsics.Float64Array,
|
||||
Int8Array: realm.intrinsics.Int8Array,
|
||||
Int16Array: realm.intrinsics.Int16Array,
|
||||
Int32Array: realm.intrinsics.Int32Array,
|
||||
Uint8Array: realm.intrinsics.Uint8Array,
|
||||
Uint16Array: realm.intrinsics.Uint16Array,
|
||||
Uint32Array: realm.intrinsics.Uint32Array,
|
||||
Uint8ClampedArray: realm.intrinsics.Uint8ClampedArray
|
||||
}[exemplar.$TypedArrayName];
|
||||
|
||||
// 3. Let constructor be ? SpeciesConstructor(exemplar, defaultConstructor).
|
||||
var constructor = (0, _construct.SpeciesConstructor)(realm, exemplar, defaultConstructor);
|
||||
|
||||
// 4. Return ? TypedArrayCreate(constructor, argumentList).
|
||||
return TypedArrayCreate(realm, constructor, argumentList);
|
||||
}
|
||||
//# sourceMappingURL=typedarray.js.map
|
||||
1
build/node_modules/prepack/lib/methods/typedarray.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/typedarray.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
526
build/node_modules/prepack/lib/methods/widen.js
generated
vendored
Normal file
526
build/node_modules/prepack/lib/methods/widen.js
generated
vendored
Normal file
@@ -0,0 +1,526 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.WidenImplementation = undefined;
|
||||
|
||||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
||||
|
||||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _completions = require("../completions.js");
|
||||
|
||||
var _environment = require("../environment.js");
|
||||
|
||||
var _index = require("../methods/index.js");
|
||||
|
||||
var _generator = require("../utils/generator.js");
|
||||
|
||||
var _index2 = require("../values/index.js");
|
||||
|
||||
var _invariant = require("../invariant.js");
|
||||
|
||||
var _invariant2 = _interopRequireDefault(_invariant);
|
||||
|
||||
var _babelTypes = require("babel-types");
|
||||
|
||||
var t = _interopRequireWildcard(_babelTypes);
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var WidenImplementation = exports.WidenImplementation = function () {
|
||||
function WidenImplementation() {
|
||||
_classCallCheck(this, WidenImplementation);
|
||||
}
|
||||
|
||||
_createClass(WidenImplementation, [{
|
||||
key: "_widenArrays",
|
||||
value: function _widenArrays(realm, v1, v2) {
|
||||
var e = v1 && v1[0] || v2 && v2[0];
|
||||
if (e instanceof _index2.Value) return this._widenArraysOfValues(realm, v1, v2);else return this._widenArrayOfsMapEntries(realm, v1, v2);
|
||||
}
|
||||
}, {
|
||||
key: "_widenArrayOfsMapEntries",
|
||||
value: function _widenArrayOfsMapEntries(realm, a1, a2) {
|
||||
var empty = realm.intrinsics.empty;
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
var result = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
var _ref = a1 && a1[i] || { $Key: empty, $Value: empty },
|
||||
key1 = _ref.$Key,
|
||||
val1 = _ref.$Value;
|
||||
|
||||
var _ref2 = a2 && a2[i] || { $Key: empty, $Value: empty },
|
||||
key2 = _ref2.$Key,
|
||||
val2 = _ref2.$Value;
|
||||
|
||||
if (key1 === undefined && key2 === undefined) {
|
||||
result[i] = { $Key: undefined, $Value: undefined };
|
||||
} else {
|
||||
var key3 = this.widenValues(realm, key1, key2);
|
||||
(0, _invariant2.default)(key3 instanceof _index2.Value);
|
||||
var val3 = this.widenValues(realm, val1, val2);
|
||||
(0, _invariant2.default)(val3 === undefined || val3 instanceof _index2.Value);
|
||||
result[i] = { $Key: key3, $Value: val3 };
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}, {
|
||||
key: "_widenArraysOfValues",
|
||||
value: function _widenArraysOfValues(realm, a1, a2) {
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
var result = [];
|
||||
for (var i = 0; i < n; i++) {
|
||||
var wv = this.widenValues(realm, a1 && a1[i] || undefined, a2 && a2[i] || undefined);
|
||||
(0, _invariant2.default)(wv === undefined || wv instanceof _index2.Value);
|
||||
result[i] = wv;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns a new effects summary that includes both e1 and e2.
|
||||
|
||||
}, {
|
||||
key: "widenEffects",
|
||||
value: function widenEffects(realm, e1, e2) {
|
||||
var _e = _slicedToArray(e1, 5),
|
||||
result1 = _e[0],
|
||||
bindings1 = _e[2],
|
||||
properties1 = _e[3],
|
||||
createdObj1 = _e[4];
|
||||
|
||||
var _e2 = _slicedToArray(e2, 5),
|
||||
result2 = _e2[0],
|
||||
bindings2 = _e2[2],
|
||||
properties2 = _e2[3],
|
||||
createdObj2 = _e2[4];
|
||||
|
||||
var result = this.widenResults(realm, result1, result2);
|
||||
var bindings = this.widenBindings(realm, bindings1, bindings2);
|
||||
var properties = this.widenPropertyBindings(realm, properties1, properties2, createdObj1, createdObj2);
|
||||
var createdObjects = new Set(); // Top, since the empty set knows nothing. There is no other choice for widen.
|
||||
var generator = new _generator.Generator(realm, "widen"); // code subject to widening will be generated somewhere else
|
||||
return [result, generator, bindings, properties, createdObjects];
|
||||
}
|
||||
}, {
|
||||
key: "widenResults",
|
||||
value: function widenResults(realm, result1, result2) {
|
||||
(0, _invariant2.default)(!(result1 instanceof _environment.Reference || result2 instanceof _environment.Reference), "loop bodies should not result in refs");
|
||||
(0, _invariant2.default)(!(result1 instanceof _completions.AbruptCompletion || result2 instanceof _completions.AbruptCompletion), "if a loop iteration ends abruptly, there is no need for fixed point computation");
|
||||
if (result1 instanceof _index2.Value && result2 instanceof _index2.Value) {
|
||||
var val = this.widenValues(realm, result1, result2);
|
||||
(0, _invariant2.default)(val instanceof _index2.Value);
|
||||
return val;
|
||||
}
|
||||
if (result1 instanceof _completions.PossiblyNormalCompletion || result2 instanceof _completions.PossiblyNormalCompletion) {
|
||||
//todo: #1174 figure out how to deal with loops that have embedded conditional exits
|
||||
// widen join pathConditions
|
||||
// widen normal result and Effects
|
||||
// use abrupt part of result2, depend stability to make this safe. See below.
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
(0, _invariant2.default)(false);
|
||||
}
|
||||
}, {
|
||||
key: "widenMaps",
|
||||
value: function widenMaps(m1, m2, widen) {
|
||||
var m3 = new Map();
|
||||
m1.forEach(function (val1, key, map1) {
|
||||
var val2 = m2.get(key);
|
||||
var val3 = widen(key, val1, val2);
|
||||
m3.set(key, val3);
|
||||
});
|
||||
m2.forEach(function (val2, key, map2) {
|
||||
if (!m1.has(key)) {
|
||||
m3.set(key, widen(key, undefined, val2));
|
||||
}
|
||||
});
|
||||
return m3;
|
||||
}
|
||||
}, {
|
||||
key: "widenBindings",
|
||||
value: function widenBindings(realm, m1, m2) {
|
||||
var _this = this;
|
||||
|
||||
var widen = function widen(b, b1, b2) {
|
||||
var l1 = b1 === undefined ? b.hasLeaked : b1.hasLeaked;
|
||||
var l2 = b2 === undefined ? b.hasLeaked : b2.hasLeaked;
|
||||
var hasLeaked = l1 || l2; // If either has leaked, then this binding has leaked.
|
||||
var v1 = b1 === undefined || b1.value === undefined ? b.value : b1.value;
|
||||
(0, _invariant2.default)(b2 !== undefined); // Local variables are not going to get deleted as a result of widening
|
||||
var v2 = b2.value;
|
||||
(0, _invariant2.default)(v2 !== undefined);
|
||||
var result = _this.widenValues(realm, v1, v2);
|
||||
if (result instanceof _index2.AbstractValue && result.kind === "widened") {
|
||||
var phiNode = b.phiNode;
|
||||
if (phiNode === undefined) {
|
||||
// Create a temporal location for binding
|
||||
var generator = realm.generator;
|
||||
(0, _invariant2.default)(generator !== undefined);
|
||||
phiNode = generator.derive(result.types, result.values, [b.value || realm.intrinsics.undefined], function (_ref3) {
|
||||
var _ref4 = _slicedToArray(_ref3, 1),
|
||||
n = _ref4[0];
|
||||
|
||||
return n;
|
||||
}, {
|
||||
skipInvariant: true
|
||||
});
|
||||
b.phiNode = phiNode;
|
||||
}
|
||||
// Let the widened value be a reference to the phiNode of the binding
|
||||
(0, _invariant2.default)(phiNode.intrinsicName !== undefined);
|
||||
var phiName = phiNode.intrinsicName;
|
||||
result.intrinsicName = phiName;
|
||||
result._buildNode = function (args) {
|
||||
return t.identifier(phiName);
|
||||
};
|
||||
}
|
||||
(0, _invariant2.default)(result instanceof _index2.Value);
|
||||
return { hasLeaked: hasLeaked, value: result };
|
||||
};
|
||||
return this.widenMaps(m1, m2, widen);
|
||||
}
|
||||
|
||||
// Returns an abstract value that includes both v1 and v2 as potential values.
|
||||
|
||||
}, {
|
||||
key: "widenValues",
|
||||
value: function widenValues(realm, v1, v2) {
|
||||
if (Array.isArray(v1) || Array.isArray(v2)) {
|
||||
(0, _invariant2.default)(v1 === undefined || Array.isArray(v1));
|
||||
(0, _invariant2.default)(v2 === undefined || Array.isArray(v2));
|
||||
return this._widenArrays(realm, v1, v2);
|
||||
}
|
||||
(0, _invariant2.default)(v1 === undefined || v1 instanceof _index2.Value);
|
||||
(0, _invariant2.default)(v2 === undefined || v2 instanceof _index2.Value);
|
||||
if (v1 !== undefined && v2 !== undefined && !(v1 instanceof _index2.AbstractValue) && !(v2 instanceof _index2.AbstractValue) && (0, _index.StrictEqualityComparison)(realm, v1.throwIfNotConcrete(), v2.throwIfNotConcrete())) {
|
||||
return v1; // no need to widen a loop invariant value
|
||||
} else {
|
||||
return _index2.AbstractValue.createFromWidening(realm, v1 || realm.intrinsics.empty, v2 || realm.intrinsics.undefined);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "widenPropertyBindings",
|
||||
value: function widenPropertyBindings(realm, m1, m2, c1, c2) {
|
||||
var _this2 = this;
|
||||
|
||||
var widen = function widen(b, d1, d2) {
|
||||
if (d1 === undefined && d2 === undefined) return undefined;
|
||||
// If the PropertyBinding object has been freshly allocated do not widen (that happens in AbstractObjectValue)
|
||||
if (d1 === undefined) {
|
||||
if (b.object instanceof _index2.ObjectValue && c2.has(b.object)) return d2; // no widen
|
||||
if (b.descriptor !== undefined && m1.has(b)) {
|
||||
// property was present in (n-1)th iteration and deleted in nth iteration
|
||||
d1 = (0, _index.cloneDescriptor)(b.descriptor);
|
||||
(0, _invariant2.default)(d1 !== undefined);
|
||||
d1.value = realm.intrinsics.empty;
|
||||
} else {
|
||||
// no write to property in nth iteration, use the value from the (n-1)th iteration
|
||||
d1 = b.descriptor;
|
||||
if (d1 === undefined) {
|
||||
d1 = (0, _index.cloneDescriptor)(d2);
|
||||
(0, _invariant2.default)(d1 !== undefined);
|
||||
d1.value = realm.intrinsics.empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (d2 === undefined) {
|
||||
if (b.object instanceof _index2.ObjectValue && c1.has(b.object)) return d1; // no widen
|
||||
if (m2.has(b)) {
|
||||
// property was present in nth iteration and deleted in (n+1)th iteration
|
||||
d2 = (0, _index.cloneDescriptor)(d1);
|
||||
(0, _invariant2.default)(d2 !== undefined);
|
||||
d2.value = realm.intrinsics.empty;
|
||||
} else {
|
||||
// no write to property in (n+1)th iteration, use the value from the nth iteration
|
||||
d2 = d1;
|
||||
}
|
||||
(0, _invariant2.default)(d2 !== undefined);
|
||||
}
|
||||
var result = _this2.widenDescriptors(realm, d1, d2);
|
||||
if (result && result.value instanceof _index2.AbstractValue && result.value.kind === "widened") {
|
||||
var rval = result.value;
|
||||
var pathNode = b.pathNode;
|
||||
if (pathNode === undefined) {
|
||||
//Since properties already have mutable storage locations associated with them, we do not
|
||||
//need phi nodes. What we need is an abstract value with a build node that results in a memberExpression
|
||||
//that resolves to the storage location of the property.
|
||||
|
||||
// For now, we only handle loop invariant properties
|
||||
//i.e. properties where the member expresssion does not involve any values written to inside the loop.
|
||||
var key = b.key;
|
||||
if (typeof key === "string" || !(key.mightNotBeString() && key.mightNotBeNumber())) {
|
||||
if (typeof key === "string") {
|
||||
pathNode = _index2.AbstractValue.createFromWidenedProperty(realm, rval, [b.object], function (_ref5) {
|
||||
var _ref6 = _slicedToArray(_ref5, 1),
|
||||
o = _ref6[0];
|
||||
|
||||
return t.memberExpression(o, t.identifier(key));
|
||||
});
|
||||
} else {
|
||||
pathNode = _index2.AbstractValue.createFromWidenedProperty(realm, rval, [b.object, key], function (_ref7) {
|
||||
var _ref8 = _slicedToArray(_ref7, 2),
|
||||
o = _ref8[0],
|
||||
p = _ref8[1];
|
||||
|
||||
return t.memberExpression(o, p, true);
|
||||
});
|
||||
}
|
||||
// The value of the property at the start of the loop needs to be written to the property
|
||||
// before the loop commences, otherwise the memberExpression will result in an undefined value.
|
||||
var generator = realm.generator;
|
||||
(0, _invariant2.default)(generator !== undefined);
|
||||
var initVal = b.descriptor && b.descriptor.value || realm.intrinsics.empty;
|
||||
if (!(initVal instanceof _index2.Value)) throw new _errors.FatalError("todo: handle internal properties");
|
||||
if (!(initVal instanceof _index2.EmptyValue)) {
|
||||
if (key === "length" && b.object instanceof _index2.ArrayValue) {
|
||||
// do nothing, the array length will already be initialized
|
||||
} else if (typeof key === "string") {
|
||||
generator.emitVoidExpression(rval.types, rval.values, [b.object, initVal], function (_ref9) {
|
||||
var _ref10 = _slicedToArray(_ref9, 2),
|
||||
o = _ref10[0],
|
||||
v = _ref10[1];
|
||||
|
||||
return t.assignmentExpression("=", t.memberExpression(o, t.identifier(key)), v);
|
||||
});
|
||||
} else {
|
||||
generator.emitVoidExpression(rval.types, rval.values, [b.object, b.key, initVal], function (_ref11) {
|
||||
var _ref12 = _slicedToArray(_ref11, 3),
|
||||
o = _ref12[0],
|
||||
p = _ref12[1],
|
||||
v = _ref12[2];
|
||||
|
||||
return t.assignmentExpression("=", t.memberExpression(o, p, true), v);
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new _errors.FatalError("todo: handle the case where key is an abstract value");
|
||||
}
|
||||
b.pathNode = pathNode;
|
||||
}
|
||||
result.value = pathNode;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
return this.widenMaps(m1, m2, widen);
|
||||
}
|
||||
}, {
|
||||
key: "widenDescriptors",
|
||||
value: function widenDescriptors(realm, d1, d2) {
|
||||
if (d1 === undefined) {
|
||||
// d2 is a property written to only in the (n+1)th iteration
|
||||
if (!(0, _index.IsDataDescriptor)(realm, d2)) return d2; // accessor properties need not be widened.
|
||||
var dc = (0, _index.cloneDescriptor)(d2);
|
||||
(0, _invariant2.default)(dc !== undefined);
|
||||
dc.value = this.widenValues(realm, d2.value, d2.value);
|
||||
return dc;
|
||||
} else {
|
||||
if ((0, _index.equalDescriptors)(d1, d2)) {
|
||||
if (!(0, _index.IsDataDescriptor)(realm, d1)) return d1; // identical accessor properties need not be widened.
|
||||
var _dc = (0, _index.cloneDescriptor)(d1);
|
||||
(0, _invariant2.default)(_dc !== undefined);
|
||||
_dc.value = this.widenValues(realm, d1.value, d2.value);
|
||||
return _dc;
|
||||
}
|
||||
//todo: #1174 if we get here, the loop body contains a call to create a property and different iterations
|
||||
// create them differently. That seems beyond what a fixpoint computation can reasonably handle without
|
||||
// losing precision. Report an error here.
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
}
|
||||
|
||||
// If e2 is the result of a loop iteration starting with effects e1 and it has a subset of elements of e1,
|
||||
// then we have reached a fixed point and no further calls to widen are needed. e1/e2 represent a general
|
||||
// summary of the loop, regardless of how many iterations will be performed at runtime.
|
||||
|
||||
}, {
|
||||
key: "containsEffects",
|
||||
value: function containsEffects(e1, e2) {
|
||||
var _e3 = _slicedToArray(e1, 4),
|
||||
result1 = _e3[0],
|
||||
bindings1 = _e3[2],
|
||||
properties1 = _e3[3];
|
||||
|
||||
var _e4 = _slicedToArray(e2, 4),
|
||||
result2 = _e4[0],
|
||||
bindings2 = _e4[2],
|
||||
properties2 = _e4[3];
|
||||
|
||||
if (!this.containsResults(result1, result2)) return false;
|
||||
if (!this.containsBindings(bindings1, bindings2)) return false;
|
||||
if (!this.containsPropertyBindings(properties1, properties2)) return false;
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
key: "containsResults",
|
||||
value: function containsResults(result1, result2) {
|
||||
if (result1 instanceof _index2.Value && result2 instanceof _index2.Value) return this._containsValues(result1, result2);
|
||||
return false;
|
||||
}
|
||||
}, {
|
||||
key: "containsMap",
|
||||
value: function containsMap(m1, m2, f) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = m1.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var _ref13 = _step.value;
|
||||
|
||||
var _ref14 = _slicedToArray(_ref13, 2);
|
||||
|
||||
var key1 = _ref14[0];
|
||||
var val1 = _ref14[1];
|
||||
|
||||
if (val1 === undefined) continue; // deleted
|
||||
var val2 = m2.get(key1);
|
||||
if (val2 === undefined) continue; // A key that disappears has been widened away into the unknown key
|
||||
if (!f(val1, val2)) return false;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = m2.keys()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var key2 = _step2.value;
|
||||
|
||||
if (!m1.has(key2)) return false;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
||||
_iterator2.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
key: "containsBindings",
|
||||
value: function containsBindings(m1, m2) {
|
||||
var _this3 = this;
|
||||
|
||||
var containsBinding = function containsBinding(b1, b2) {
|
||||
if (b1 === undefined || b2 === undefined || b1.value === undefined || b2.value === undefined || !_this3._containsValues(b1.value, b2.value) || b1.hasLeaked !== b2.hasLeaked) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return this.containsMap(m1, m2, containsBinding);
|
||||
}
|
||||
}, {
|
||||
key: "containsPropertyBindings",
|
||||
value: function containsPropertyBindings(m1, m2) {
|
||||
var _this4 = this;
|
||||
|
||||
var containsPropertyBinding = function containsPropertyBinding(d1, d2) {
|
||||
var v1 = d1 && d1.value,
|
||||
v2 = d2 && d2.value;
|
||||
|
||||
if (v1 === undefined) return v2 === undefined;
|
||||
if (v1 instanceof _index2.Value && v2 instanceof _index2.Value) return _this4._containsValues(v1, v2);
|
||||
if (Array.isArray(v1) && Array.isArray(v2)) {
|
||||
return _this4._containsArray(v1, v2);
|
||||
}
|
||||
return v2 === undefined;
|
||||
};
|
||||
return this.containsMap(m1, m2, containsPropertyBinding);
|
||||
}
|
||||
}, {
|
||||
key: "_containsArray",
|
||||
value: function _containsArray(v1, v2) {
|
||||
var e = v1 && v1[0] || v2 && v2[0];
|
||||
if (e instanceof _index2.Value) return this._containsArraysOfValue(v1, v2);else return this._containsArrayOfsMapEntries(v1, v2);
|
||||
}
|
||||
}, {
|
||||
key: "_containsArraysOfValue",
|
||||
value: function _containsArraysOfValue(realm, a1, a2) {
|
||||
var empty = realm.intrinsics.empty;
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
for (var i = 0; i < n; i++) {
|
||||
var _ref15 = a1 && a1[i] || { $Key: empty, $Value: empty },
|
||||
key1 = _ref15.$Key,
|
||||
val1 = _ref15.$Value;
|
||||
|
||||
var _ref16 = a2 && a2[i] || { $Key: empty, $Value: empty },
|
||||
key2 = _ref16.$Key,
|
||||
val2 = _ref16.$Value;
|
||||
|
||||
if (key1 === undefined) {
|
||||
if (key2 !== undefined) return false;
|
||||
} else {
|
||||
if (key1 instanceof _index2.Value && key2 instanceof _index2.Value && key1.equals(key2)) {
|
||||
if (val1 instanceof _index2.Value && val2 instanceof _index2.Value && this._containsValues(val1, val2)) continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}, {
|
||||
key: "_containsArrayOfsMapEntries",
|
||||
value: function _containsArrayOfsMapEntries(realm, a1, a2) {
|
||||
var n = Math.max(a1 && a1.length || 0, a2 && a2.length || 0);
|
||||
for (var i = 0; i < n; i++) {
|
||||
var val1 = a1 && a1[i],
|
||||
val2 = a2 && a2[i];
|
||||
|
||||
if (val1 instanceof _index2.Value && val2 instanceof _index2.Value && !this._containsValues(val1, val2)) return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}, {
|
||||
key: "_containsValues",
|
||||
value: function _containsValues(val1, val2) {
|
||||
if (val1 instanceof _index2.AbstractValue) {
|
||||
if (!_index2.Value.isTypeCompatibleWith(val2.getType(), val1.getType())) return false;
|
||||
return val1.values.containsValue(val2);
|
||||
}
|
||||
return val1.equals(val2);
|
||||
}
|
||||
}]);
|
||||
|
||||
return WidenImplementation;
|
||||
}();
|
||||
//# sourceMappingURL=widen.js.map
|
||||
1
build/node_modules/prepack/lib/methods/widen.js.map
generated
vendored
Normal file
1
build/node_modules/prepack/lib/methods/widen.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user