UNPKG

6.64 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _index = require("./index.js");
9
10var _is = require("../methods/is.js");
11
12var _has = require("../methods/has.js");
13
14var _abstract = require("../methods/abstract.js");
15
16var _get = require("../methods/get.js");
17
18var _singletons = require("../singletons.js");
19
20var _invariant = _interopRequireDefault(require("../invariant.js"));
21
22function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24/**
25 * Copyright (c) 2017-present, Facebook, Inc.
26 * All rights reserved.
27 *
28 * This source code is licensed under the BSD-style license found in the
29 * LICENSE file in the root directory of this source tree. An additional grant
30 * of patent rights can be found in the PATENTS file in the same directory.
31 */
32
33/* strict-local */
34class ArgumentsExotic extends _index.ObjectValue {
35 constructor(realm, intrinsicName) {
36 super(realm, realm.intrinsics.ObjectPrototype, intrinsicName);
37 }
38
39 // ECMA262 9.4.4.1
40 $GetOwnProperty(P) {
41 // 1. Let args be the arguments object.
42 let args = this; // 2. Let desc be OrdinaryGetOwnProperty(args, P).
43
44 let desc = _singletons.Properties.OrdinaryGetOwnProperty(this.$Realm, args, P); // 3. If desc is undefined, return desc.
45
46
47 if (desc === undefined) return undefined;
48
49 _singletons.Properties.ThrowIfMightHaveBeenDeleted(desc.value); // 4. Let map be args.[[ParameterMap]].
50
51
52 let map = args.$ParameterMap;
53 (0, _invariant.default)(map); // 5. Let isMapped be ! HasOwnProperty(map, P).
54
55 let isMapped = (0, _has.HasOwnProperty)(this.$Realm, map, P); // 6. If isMapped is true, then
56
57 if (isMapped === true) {
58 // a. Set desc.[[Value]] to Get(map, P).
59 desc.value = (0, _get.Get)(this.$Realm, map, P);
60 } // 7. Return desc.
61
62
63 return desc;
64 } // ECMA262 9.4.4.2
65
66
67 $DefineOwnProperty(P, Desc) {
68 // 1. Let args be the arguments object.
69 let args = this; // 2. Let map be args.[[ParameterMap]].
70
71 let map = args.$ParameterMap;
72 (0, _invariant.default)(map); // 3. Let isMapped be HasOwnProperty(map, P).
73
74 let isMapped = (0, _has.HasOwnProperty)(this.$Realm, map, P); // 4. Let newArgDesc be Desc.
75
76 let newArgDesc = Desc; // 5. If isMapped is true and IsDataDescriptor(Desc) is true, then
77
78 if (isMapped === true && (0, _is.IsDataDescriptor)(this.$Realm, Desc) === true) {
79 // a. If Desc.[[Value]] is not present and Desc.[[Writable]] is present and its value is false, then
80 if (Desc.value === undefined && Desc.writable === false) {
81 // i. Let newArgDesc be a copy of Desc.
82 newArgDesc = Object.assign({}, Desc); // ii. Set newArgDesc.[[Value]] to Get(map, P).
83
84 newArgDesc.value = (0, _get.Get)(this.$Realm, map, P);
85 }
86 } // 6. Let allowed be ? OrdinaryDefineOwnProperty(args, P, newArgDesc).
87
88
89 let allowed = _singletons.Properties.OrdinaryDefineOwnProperty(this.$Realm, args, P, newArgDesc); // 7. If allowed is false, return false.
90
91
92 if (allowed === false) return false; // 8. If isMapped is true, then
93
94 if (isMapped === true) {
95 // a. If IsAccessorDescriptor(Desc) is true, then
96 if ((0, _is.IsAccessorDescriptor)(this.$Realm, Desc) === true) {
97 // i. Call map.[[Delete]](P).
98 map.$Delete(P);
99 } else {
100 // b. Else,
101 // i. If Desc.[[Value]] is present, then
102 if (Desc.value !== undefined) {
103 // 1. Let setStatus be Set(map, P, Desc.[[Value]], false).
104 (0, _invariant.default)(Desc.value instanceof _index.Value);
105
106 let setStatus = _singletons.Properties.Set(this.$Realm, map, P, Desc.value, false); // 2. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
107
108
109 (0, _invariant.default)(setStatus === true);
110 } // ii. If Desc.[[Writable]] is present and its value is false, then
111
112
113 if (Desc.writable === false) {
114 // 1. Call map.[[Delete]](P).
115 map.$Delete(P);
116 }
117 }
118 } // 9. Return true.
119
120
121 return true;
122 } // ECMA262 9.4.4.3
123
124
125 $Get(P, Receiver) {
126 // 1. Let args be the arguments object.
127 let args = this; // 2. Let map be args.[[ParameterMap]].
128
129 let map = args.$ParameterMap;
130 (0, _invariant.default)(map); // 3. Let isMapped be ! HasOwnProperty(map, P).
131
132 let isMapped = (0, _has.HasOwnProperty)(this.$Realm, map, P); // 4. If isMapped is false, then
133
134 if (isMapped === false) {
135 // a. Return ? OrdinaryGet(args, P, Receiver).
136 return (0, _get.OrdinaryGet)(this.$Realm, args, P, Receiver);
137 } else {
138 // 5. Else map contains a formal parameter mapping for P,
139 // b. Return Get(map, P).
140 return (0, _get.Get)(this.$Realm, map, P);
141 }
142 } // ECMA262 9.4.4.4
143
144
145 $Set(P, V, Receiver) {
146 // 1. Let args be the arguments object.
147 let args = this;
148 let isMapped, map; // 2. If SameValue(args, Receiver) is false, then
149
150 if ((0, _abstract.SameValuePartial)(this.$Realm, args, Receiver) === false) {
151 // a. Let isMapped be false.
152 isMapped = false;
153 } else {
154 // 3. Else,
155 // a. Let map be args.[[ParameterMap]].
156 map = args.$ParameterMap;
157 (0, _invariant.default)(map); // b. Let isMapped be ! HasOwnProperty(map, P).
158
159 isMapped = (0, _has.HasOwnProperty)(this.$Realm, map, P);
160 } // 4. If isMapped is true, then
161
162
163 if (isMapped === true) {
164 (0, _invariant.default)(map); // a. Let setStatus be Set(map, P, V, false).
165
166 let setStatus = _singletons.Properties.Set(this.$Realm, map, P, V, false); // b. Assert: setStatus is true because formal parameters mapped by argument objects are always writable.
167
168
169 (0, _invariant.default)(setStatus === true);
170 } // 5. Return ? OrdinarySet(args, P, V, Receiver).
171
172
173 return _singletons.Properties.OrdinarySet(this.$Realm, args, P, V, Receiver);
174 } // ECMA262 9.4.4.5
175
176
177 $Delete(P) {
178 // 1. Let args be the arguments object.
179 let args = this; // 2. Let map be args.[[ParameterMap]].
180
181 let map = args.$ParameterMap;
182 (0, _invariant.default)(map); // 3. Let isMapped be ! HasOwnProperty(map, P).
183
184 let isMapped = (0, _has.HasOwnProperty)(this.$Realm, map, P); // 4. Let result be ? OrdinaryDelete(args, P).
185
186 let result = _singletons.Properties.OrdinaryDelete(this.$Realm, args, P); // 5. If result is true and isMapped is true, then
187
188
189 if (result === true && isMapped === true) {
190 // a. Call map.[[Delete]](P).
191 map.$Delete(P);
192 } // 6. Return result.
193
194
195 return result;
196 }
197
198}
199
200exports.default = ArgumentsExotic;
201//# sourceMappingURL=ArgumentsExotic.js.map
\No newline at end of file