first commit

This commit is contained in:
s.golasch
2023-08-01 13:49:46 +02:00
commit 1fc239fd54
20238 changed files with 3112246 additions and 0 deletions

View File

@@ -0,0 +1,257 @@
"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.
*/
// ECMA262 12.3.4.1
exports.default = function (ast, strictCode, env, realm) {
realm.setNextExecutionContextLocation(ast.loc);
// 1. Let ref be the result of evaluating MemberExpression.
var _env$partiallyEvaluat = env.partiallyEvaluateCompletion(ast.callee, strictCode),
_env$partiallyEvaluat2 = _slicedToArray(_env$partiallyEvaluat, 3),
ref = _env$partiallyEvaluat2[0],
calleeAst = _env$partiallyEvaluat2[1],
calleeIO = _env$partiallyEvaluat2[2];
if (ref instanceof _completions.AbruptCompletion) return [ref, calleeAst, calleeIO];
var completion = void 0;
if (ref instanceof _completions.PossiblyNormalCompletion) {
completion = ref;
ref = completion.value;
}
(0, _invariant2.default)(ref instanceof _index2.Value || ref instanceof _environment.Reference);
// 2. Let func be ? GetValue(ref).
var func = _singletons.Environment.GetValue(realm, ref);
var io = calleeIO;
var partialArgs = [];
var argVals = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = ast.arguments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var arg = _step.value;
var _env$partiallyEvaluat3 = env.partiallyEvaluateCompletionDeref(arg, strictCode),
_env$partiallyEvaluat4 = _slicedToArray(_env$partiallyEvaluat3, 3),
argValue = _env$partiallyEvaluat4[0],
argAst = _env$partiallyEvaluat4[1],
argIO = _env$partiallyEvaluat4[2];
io = io.concat(argIO);
partialArgs.push(argAst);
if (argValue instanceof _completions.AbruptCompletion) {
if (completion instanceof _completions.PossiblyNormalCompletion) completion = _singletons.Join.stopEffectCaptureJoinApplyAndReturnCompletion(completion, argValue, realm);else completion = argValue;
var _resultAst = t.callExpression(calleeAst, partialArgs);
return [completion, _resultAst, io];
}
if (argValue instanceof _completions.PossiblyNormalCompletion) {
argVals.push(argValue.value);
if (completion instanceof _completions.PossiblyNormalCompletion) completion = _singletons.Join.composeNormalCompletions(completion, argValue, argValue.value, realm);else completion = argValue;
} else {
(0, _invariant2.default)(argValue instanceof _index2.Value);
argVals.push(argValue);
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var callResult = EvaluateCall(ref, func, ast, argVals, strictCode, env, realm);
if (callResult instanceof _completions.AbruptCompletion) {
if (completion instanceof _completions.PossiblyNormalCompletion) completion = _singletons.Join.stopEffectCaptureJoinApplyAndReturnCompletion(completion, callResult, realm);else completion = callResult;
var resultAst = t.callExpression(calleeAst, partialArgs);
return [completion, resultAst, io];
}
var callCompletion = void 0;
var _Join$unbundleNormalC = _singletons.Join.unbundleNormalCompletion(callResult);
var _Join$unbundleNormalC2 = _slicedToArray(_Join$unbundleNormalC, 2);
callCompletion = _Join$unbundleNormalC2[0];
callResult = _Join$unbundleNormalC2[1];
(0, _invariant2.default)(callResult instanceof _index2.Value);
(0, _invariant2.default)(completion === undefined || completion instanceof _completions.PossiblyNormalCompletion);
completion = _singletons.Join.composeNormalCompletions(completion, callCompletion, callResult, realm);
if (completion instanceof _completions.PossiblyNormalCompletion) {
realm.captureEffects(completion);
}
return [completion, t.callExpression(calleeAst, partialArgs), io];
};
var _completions = require("../completions.js");
var _environment = require("../environment.js");
var _index = require("../methods/index.js");
var _singletons = require("../singletons.js");
var _index2 = require("../values/index.js");
var _babelTypes = require("babel-types");
var t = _interopRequireWildcard(_babelTypes);
var _invariant = require("../invariant.js");
var _invariant2 = _interopRequireDefault(_invariant);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 callBothFunctionsAndJoinTheirEffects(funcs, ast, argVals, strictCode, env, realm) {
var _funcs = _slicedToArray(funcs, 3),
cond = _funcs[0],
func1 = _funcs[1],
func2 = _funcs[2];
(0, _invariant2.default)(cond instanceof _index2.AbstractValue && cond.getType() === _index2.BooleanValue);
(0, _invariant2.default)(_index2.Value.isTypeCompatibleWith(func1.getType(), _index2.FunctionValue));
(0, _invariant2.default)(_index2.Value.isTypeCompatibleWith(func2.getType(), _index2.FunctionValue));
var _realm$evaluateForEff = realm.evaluateForEffects(function () {
return EvaluateCall(func1, func1, ast, argVals, strictCode, env, realm);
}),
_realm$evaluateForEff2 = _slicedToArray(_realm$evaluateForEff, 5),
compl1 = _realm$evaluateForEff2[0],
gen1 = _realm$evaluateForEff2[1],
bindings1 = _realm$evaluateForEff2[2],
properties1 = _realm$evaluateForEff2[3],
createdObj1 = _realm$evaluateForEff2[4];
var _realm$evaluateForEff3 = realm.evaluateForEffects(function () {
return EvaluateCall(func2, func2, ast, argVals, strictCode, env, realm);
}),
_realm$evaluateForEff4 = _slicedToArray(_realm$evaluateForEff3, 5),
compl2 = _realm$evaluateForEff4[0],
gen2 = _realm$evaluateForEff4[1],
bindings2 = _realm$evaluateForEff4[2],
properties2 = _realm$evaluateForEff4[3],
createdObj2 = _realm$evaluateForEff4[4];
var joinedEffects = _singletons.Join.joinEffects(realm, cond, [compl1, gen1, bindings1, properties1, createdObj1], [compl2, gen2, bindings2, properties2, createdObj2]);
var joinedCompletion = joinedEffects[0];
if (joinedCompletion 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.
joinedCompletion = realm.composeWithSavedCompletion(joinedCompletion);
}
// Note that the effects of (non joining) abrupt branches are not included
// in joinedEffects, but are tracked separately inside joinedCompletion.
realm.applyEffects(joinedEffects);
// return or throw completion
(0, _invariant2.default)(joinedCompletion instanceof _completions.AbruptCompletion || joinedCompletion instanceof _index2.Value);
return joinedCompletion;
}
function EvaluateCall(ref, func, ast, argList, strictCode, env, realm) {
if (func instanceof _index2.AbstractValue && _index2.Value.isTypeCompatibleWith(func.getType(), _index2.FunctionValue)) {
if (func.kind === "conditional") return callBothFunctionsAndJoinTheirEffects(func.args, ast, argList, strictCode, env, realm);
// The called function comes from the environmental model and we require that
// such functions have no visible side-effects. Hence we can carry on
// by returning a call node with the arguments updated with their partial counterparts.
// TODO: obtain the type of the return value from the abstract function.
return _index2.AbstractValue.createFromType(realm, _index2.Value);
}
// If func is abstract and not known to be a safe function, we can't safely continue.
func = func.throwIfNotConcrete();
// 3. If Type(ref) is Reference and IsPropertyReference(ref) is false and GetReferencedName(ref) is "eval", then
if (ref instanceof _environment.Reference && !_singletons.Environment.IsPropertyReference(realm, ref) && _singletons.Environment.GetReferencedName(realm, ref) === "eval") {
// a. If SameValue(func, %eval%) is true, then
if ((0, _index.SameValue)(realm, func, realm.intrinsics.eval)) {
// i. Let argList be ? ArgumentListEvaluation(Arguments).
// ii. If argList has no elements, return undefined.
if (argList.length === 0) return realm.intrinsics.undefined;
// iii. Let evalText be the first element of argList.
var evalText = argList[0];
// iv. If the source code matching this CallExpression is strict code, let strictCaller be true. Otherwise let strictCaller be false.
var strictCaller = strictCode;
// v. Let evalRealm be the current Realm Record.
var evalRealm = realm;
// vi. Return ? PerformEval(evalText, evalRealm, strictCaller, true).
return _singletons.Functions.PerformEval(realm, evalText, evalRealm, strictCaller, true);
}
}
var thisValue = void 0;
// 4. 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, _index.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 {
// 5. Else Type(ref) is not Reference,
// a. Let thisValue be undefined.
thisValue = realm.intrinsics.undefined;
}
// 6. Let thisCall be this CallExpression.
var thisCall = ast;
// 7. Let tailCall be IsInTailPosition(thisCall). (See 14.6.1)
var tailCall = (0, _index.IsInTailPosition)(realm, thisCall);
// 8. Return ? EvaluateDirectCall(func, thisValue, Arguments, tailCall).
try {
return (0, _index.EvaluateDirectCallWithArgList)(realm, strictCode, env, ref, func, thisValue, argList, tailCall);
} catch (err) {
if (err instanceof _completions.Completion) return err;
throw err;
}
}
//# sourceMappingURL=CallExpression.js.map