Files
2023-08-01 13:49:46 +02:00

255 lines
7.6 KiB
JavaScript

"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