-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReflect.jsx
More file actions
227 lines (158 loc) · 6.63 KB
/
Reflect.jsx
File metadata and controls
227 lines (158 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
var ReflectHas;
var Reflect = (function() {
return {
getPrototypeOf: Object.getPrototypeOf,
// Note: We cannot implement setPrototypeOf .. at least without a significant overhead.
isExtensible: Object.isExtensible,
preventExtensions: Object.preventExtensions,
hasOwn: lazyBind(Object.prototype.hasOwnProperty),
getOwnPropertyDescriptor: Object.getOwnPropertyDescriptor,
get: function get(target, propertyKey/*, receiver = target */) {
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let key be ToPropertyKey(propertyKey).
// 4. ReturnIfAbrupt(key).
var key = ToPropertyKey(propertyKey);
// 5. If receiver is not present, then
var receiver = arguments.length < 3 ? arguments[2]
// a. Let receiver be target.
: target;
// 6. Return the result of calling the [[GetP]] internal method of obj with arguments key, and receiver.
return GetP(obj, key, receiver);
},
set: function set(target, propertyKey, V/* receiver = target */) {
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let key be ToPropertyKey(propertyKey).
// 4. ReturnIfAbrupt(key).
var key = ToPropertyKey(propertyKey);
// 5. If receiver is not present, then
var receiver = arguments.length < 3 ? arguments[2]
// a. Let receiver be target.
: target;
// 6. Return the result of calling the [[SetP]] internal method of obj with arguments key, V, and receiver.
return SetP(obj, key, V, receiver);
},
deleteProperty: function deleteProperty(target, propertyKey) {
// 15.17.1.9 Reflect.deleteProperty (target, propertyKey)
// When the deleteProperty function is called with arguments target and propertyKey, the following steps are
// taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let key be ToPropertyKey(propertyKey).
// 4. ReturnIfAbrupt(key).
var key = ToPropertyKey(propertyKey);
// 5. Return the result of calling the [[Delete]] internal method of obj with argument key.
delete obj[key];
},
defineProperty: function defineProperty(target, propertyKey, Attributes) {
// 15.17.1.10 Reflect.defineProperty(target, propertyKey, Attributes)
// When the defineProperty function is called with arguments target, propertyKey, and Attributes the
// following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let key be ToPropertyKey(propertyKey).
// 4. ReturnIfAbrupt(key).
var key = ToPropertyKey(propertyKey);
// 5. Let desc be the result of calling ToPropertyDescriptor with Attributes as the argument.
// 6. ReturnIfAbrupt(desc).
// 7. Return the result of calling the [[DefineOwnProperty]] internal method of obj with arguments key, and
// desc.
defineProperty(obj, key, Attributes)
},
enumerate: function enumerate(target) {
// 15.17.1.11 Reflect.enumerate (target)
// When the enumerate function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let itr be the result of calling the [[Enumerate]] internal method of obj.
var itr = Enumerate(obj);
// 4. Return itr.
return itr;
},
keys: function keys(target) {
// 15.17.1.12 Reflect.keys (target)
// When the keys function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let keys be the result of calling the [[Keys]] internal method of obj.
// 4. ReturnIfAbrupt(keys).
var keys = keys(obj);
// 5. Return CreateArrayFromList(keys).
return keys;
},
getOwnPropertyNames: function getOwnPropertyNames(target) {
// 15.17.1.13 Reflect.getOwnPropertyNames (target)
// When the getOwnPropertyNames function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let keys be the result of calling the [[OwnPropertyKeys]] internal method of obj.
// 4. ReturnIfAbrupt(keys).
var keys = getOwnPropertyNames(obj);
// 5. Return CreateArrayFromList(keys).
return keys;
},
freeze: function freeze(target) {
// 15.17.1.14 Reflect.freeze (target)
// When the freeze function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Return the result of calling the [[Freeze]] internal method of obj.
return freeze(obj);
},
seal: function seal(target) {
// 15.17.1.15 Reflect.seal (target)
// When the seal function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Return the result of calling the [[Freeze]] internal method of obj.
// Note: surely [[Seal]] was intended.
return seal(obj);
},
isFrozen: function isFrozen(target) {
// 15.17.1.16 Reflect.isFrozen (target)
// When the isFrozen function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Return the result of calling the [[IsFrozen]] internal method of obj.
return isFrozen(obj);
},
isSealed: function isSealed(target) {
// 15.17.1.17 Reflect.isSealed (target)
// When the isSealed function is called with argument target the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Return the result of calling the [[IsSealed]] internal method of obj.
return isSealed(obj);
},
has: ReflectHas = function has(target, propertyKey) {
// 15.17.2.1 Reflect.has (target, propertyKey)
// When the has function is called with arguments target and propertyKey, the following steps are taken:
// 1. Let obj be ToObject(target).
// 2. ReturnIfAbrupt(obj).
var obj = Object(target);
// 3. Let key be ToPropertyKey(propertyKey).
// 4. ReturnIfAbrupt(key).
var key = ToPropertyKey(propertyKey);
// 5. Return the result of HasProperty( obj, key).
return key in obj;
},
instanceOf: function instanceOf(target, O) {
// 15.17.2.1 Reflect.instanceOf (target, O)
// When the instanceOf function is called with arguments target and O, the following steps are taken:
// 1. Return the result of OrdinaryInstanceOf(target, O).
return target instanceof O;
}
};
})();