first commit
This commit is contained in:
139
build/node_modules/prepack/lib/evaluators/ObjectExpression.js
generated
vendored
Normal file
139
build/node_modules/prepack/lib/evaluators/ObjectExpression.js
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.EvalPropertyName = EvalPropertyName;
|
||||
|
||||
exports.default = function (ast, strictCode, env, realm) {
|
||||
// 1. Let obj be ObjectCreate(%ObjectPrototype%).
|
||||
var obj = _singletons.Create.ObjectCreate(realm, realm.intrinsics.ObjectPrototype);
|
||||
|
||||
// 2. Let status be the result of performing PropertyDefinitionEvaluation of PropertyDefinitionList with arguments obj and true.
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = ast.properties[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var prop = _step.value;
|
||||
|
||||
if (prop.type === "ObjectProperty") {
|
||||
// 12.2.6.9 case 3
|
||||
// 1. Let propKey be the result of evaluating PropertyName.
|
||||
var propKey = EvalPropertyNamePartial(prop, env, realm, strictCode);
|
||||
|
||||
// 2. ReturnIfAbrupt(propKey).
|
||||
|
||||
// 3. Let exprValueRef be the result of evaluating AssignmentExpression.
|
||||
var exprValueRef = env.evaluate(prop.value, strictCode);
|
||||
|
||||
// 4. Let propValue be ? GetValue(exprValueRef).
|
||||
var propValue = _singletons.Environment.GetValue(realm, exprValueRef);
|
||||
|
||||
// 5. If IsAnonymousFunctionDefinition(AssignmentExpression) is true, then
|
||||
if ((0, _index2.IsAnonymousFunctionDefinition)(realm, prop.value)) {
|
||||
(0, _invariant2.default)(propValue instanceof _index.ObjectValue);
|
||||
|
||||
// a. Let hasNameProperty be ? HasOwnProperty(propValue, "name").
|
||||
var hasNameProperty = (0, _index2.HasOwnProperty)(realm, propValue, "name");
|
||||
|
||||
// b. If hasNameProperty is false, perform SetFunctionName(propValue, propKey).
|
||||
(0, _invariant2.default)(!hasNameProperty); // No expression that passes through IsAnonymousFunctionDefinition can have it here
|
||||
_singletons.Functions.SetFunctionName(realm, propValue, propKey);
|
||||
}
|
||||
|
||||
// 6. Assert: enumerable is true.
|
||||
|
||||
// 7. Return CreateDataPropertyOrThrow(object, propKey, propValue).
|
||||
if (propKey instanceof _index.AbstractValue) {
|
||||
if (propKey.mightNotBeString()) {
|
||||
var error = new _errors.CompilerDiagnostic("property key value is unknown", prop.loc, "PP0011", "FatalError");
|
||||
if (realm.handleError(error) === "Fail") throw new _errors.FatalError();
|
||||
continue; // recover by ignoring the property, which is only ever safe to do if the property is dead,
|
||||
// which is assuming a bit much, hence the designation as a FatalError.
|
||||
}
|
||||
obj.$SetPartial(propKey, propValue, obj);
|
||||
} else {
|
||||
_singletons.Create.CreateDataPropertyOrThrow(realm, obj, propKey, propValue);
|
||||
}
|
||||
} else {
|
||||
(0, _invariant2.default)(prop.type === "ObjectMethod");
|
||||
_singletons.Properties.PropertyDefinitionEvaluation(realm, prop, obj, env, strictCode, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. ReturnIfAbrupt(status).
|
||||
|
||||
// 4. Return obj.
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator.return) {
|
||||
_iterator.return();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
var _errors = require("../errors.js");
|
||||
|
||||
var _index = require("../values/index.js");
|
||||
|
||||
var _index2 = require("../methods/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 }; }
|
||||
|
||||
// Returns the result of evaluating PropertyName.
|
||||
/**
|
||||
* 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 EvalPropertyName(prop, env, realm, strictCode) {
|
||||
var result = EvalPropertyNamePartial(prop, env, realm, strictCode);
|
||||
if (result instanceof _index.AbstractValue) {
|
||||
var error = new _errors.CompilerDiagnostic("unknown computed property name", prop.loc, "PP0014", "FatalError");
|
||||
realm.handleError(error);
|
||||
throw new _errors.FatalError();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function EvalPropertyNamePartial(prop, env, realm, strictCode) {
|
||||
if (prop.computed) {
|
||||
var propertyKeyName = _singletons.Environment.GetValue(realm, env.evaluate(prop.key, strictCode));
|
||||
if (propertyKeyName instanceof _index.AbstractValue) return propertyKeyName;
|
||||
(0, _invariant2.default)(propertyKeyName instanceof _index.ConcreteValue);
|
||||
return _singletons.To.ToPropertyKey(realm, propertyKeyName);
|
||||
} else {
|
||||
if (prop.key.type === "Identifier") {
|
||||
return new _index.StringValue(realm, prop.key.name);
|
||||
} else {
|
||||
var _propertyKeyName = _singletons.Environment.GetValue(realm, env.evaluate(prop.key, strictCode));
|
||||
(0, _invariant2.default)(_propertyKeyName instanceof _index.ConcreteValue); // syntax only allows literals if !prop.computed
|
||||
return _singletons.To.ToString(realm, _propertyKeyName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ECMA262 12.2.6.8
|
||||
//# sourceMappingURL=ObjectExpression.js.map
|
||||
Reference in New Issue
Block a user