OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils) { | 5 (function(global, utils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 %WeakCollectionInitialize(this); | 36 %WeakCollectionInitialize(this); |
37 | 37 |
38 if (!IS_NULL_OR_UNDEFINED(iterable)) { | 38 if (!IS_NULL_OR_UNDEFINED(iterable)) { |
39 var adder = this.set; | 39 var adder = this.set; |
40 if (!IS_CALLABLE(adder)) { | 40 if (!IS_CALLABLE(adder)) { |
41 throw MakeTypeError(kPropertyNotFunction, adder, 'set', this); | 41 throw MakeTypeError(kPropertyNotFunction, adder, 'set', this); |
42 } | 42 } |
43 for (var nextItem of iterable) { | 43 for (var nextItem of iterable) { |
44 if (!IS_SPEC_OBJECT(nextItem)) { | 44 if (!IS_RECEIVER(nextItem)) { |
45 throw MakeTypeError(kIteratorValueNotAnObject, nextItem); | 45 throw MakeTypeError(kIteratorValueNotAnObject, nextItem); |
46 } | 46 } |
47 %_Call(adder, this, nextItem[0], nextItem[1]); | 47 %_Call(adder, this, nextItem[0], nextItem[1]); |
48 } | 48 } |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 function WeakMapGet(key) { | 53 function WeakMapGet(key) { |
54 if (!IS_WEAKMAP(this)) { | 54 if (!IS_WEAKMAP(this)) { |
55 throw MakeTypeError(kIncompatibleMethodReceiver, | 55 throw MakeTypeError(kIncompatibleMethodReceiver, |
56 'WeakMap.prototype.get', this); | 56 'WeakMap.prototype.get', this); |
57 } | 57 } |
58 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; | 58 if (!IS_RECEIVER(key)) return UNDEFINED; |
59 var hash = GetExistingHash(key); | 59 var hash = GetExistingHash(key); |
60 if (IS_UNDEFINED(hash)) return UNDEFINED; | 60 if (IS_UNDEFINED(hash)) return UNDEFINED; |
61 return %WeakCollectionGet(this, key, hash); | 61 return %WeakCollectionGet(this, key, hash); |
62 } | 62 } |
63 | 63 |
64 | 64 |
65 function WeakMapSet(key, value) { | 65 function WeakMapSet(key, value) { |
66 if (!IS_WEAKMAP(this)) { | 66 if (!IS_WEAKMAP(this)) { |
67 throw MakeTypeError(kIncompatibleMethodReceiver, | 67 throw MakeTypeError(kIncompatibleMethodReceiver, |
68 'WeakMap.prototype.set', this); | 68 'WeakMap.prototype.set', this); |
69 } | 69 } |
70 if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey); | 70 if (!IS_RECEIVER(key)) throw MakeTypeError(kInvalidWeakMapKey); |
71 return %WeakCollectionSet(this, key, value, GetHash(key)); | 71 return %WeakCollectionSet(this, key, value, GetHash(key)); |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 function WeakMapHas(key) { | 75 function WeakMapHas(key) { |
76 if (!IS_WEAKMAP(this)) { | 76 if (!IS_WEAKMAP(this)) { |
77 throw MakeTypeError(kIncompatibleMethodReceiver, | 77 throw MakeTypeError(kIncompatibleMethodReceiver, |
78 'WeakMap.prototype.has', this); | 78 'WeakMap.prototype.has', this); |
79 } | 79 } |
80 if (!IS_SPEC_OBJECT(key)) return false; | 80 if (!IS_RECEIVER(key)) return false; |
81 var hash = GetExistingHash(key); | 81 var hash = GetExistingHash(key); |
82 if (IS_UNDEFINED(hash)) return false; | 82 if (IS_UNDEFINED(hash)) return false; |
83 return %WeakCollectionHas(this, key, hash); | 83 return %WeakCollectionHas(this, key, hash); |
84 } | 84 } |
85 | 85 |
86 | 86 |
87 function WeakMapDelete(key) { | 87 function WeakMapDelete(key) { |
88 if (!IS_WEAKMAP(this)) { | 88 if (!IS_WEAKMAP(this)) { |
89 throw MakeTypeError(kIncompatibleMethodReceiver, | 89 throw MakeTypeError(kIncompatibleMethodReceiver, |
90 'WeakMap.prototype.delete', this); | 90 'WeakMap.prototype.delete', this); |
91 } | 91 } |
92 if (!IS_SPEC_OBJECT(key)) return false; | 92 if (!IS_RECEIVER(key)) return false; |
93 var hash = GetExistingHash(key); | 93 var hash = GetExistingHash(key); |
94 if (IS_UNDEFINED(hash)) return false; | 94 if (IS_UNDEFINED(hash)) return false; |
95 return %WeakCollectionDelete(this, key, hash); | 95 return %WeakCollectionDelete(this, key, hash); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 // ------------------------------------------------------------------- | 99 // ------------------------------------------------------------------- |
100 | 100 |
101 %SetCode(GlobalWeakMap, WeakMapConstructor); | 101 %SetCode(GlobalWeakMap, WeakMapConstructor); |
102 %FunctionSetLength(GlobalWeakMap, 0); | 102 %FunctionSetLength(GlobalWeakMap, 0); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 } | 134 } |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 function WeakSetAdd(value) { | 139 function WeakSetAdd(value) { |
140 if (!IS_WEAKSET(this)) { | 140 if (!IS_WEAKSET(this)) { |
141 throw MakeTypeError(kIncompatibleMethodReceiver, | 141 throw MakeTypeError(kIncompatibleMethodReceiver, |
142 'WeakSet.prototype.add', this); | 142 'WeakSet.prototype.add', this); |
143 } | 143 } |
144 if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue); | 144 if (!IS_RECEIVER(value)) throw MakeTypeError(kInvalidWeakSetValue); |
145 return %WeakCollectionSet(this, value, true, GetHash(value)); | 145 return %WeakCollectionSet(this, value, true, GetHash(value)); |
146 } | 146 } |
147 | 147 |
148 | 148 |
149 function WeakSetHas(value) { | 149 function WeakSetHas(value) { |
150 if (!IS_WEAKSET(this)) { | 150 if (!IS_WEAKSET(this)) { |
151 throw MakeTypeError(kIncompatibleMethodReceiver, | 151 throw MakeTypeError(kIncompatibleMethodReceiver, |
152 'WeakSet.prototype.has', this); | 152 'WeakSet.prototype.has', this); |
153 } | 153 } |
154 if (!IS_SPEC_OBJECT(value)) return false; | 154 if (!IS_RECEIVER(value)) return false; |
155 var hash = GetExistingHash(value); | 155 var hash = GetExistingHash(value); |
156 if (IS_UNDEFINED(hash)) return false; | 156 if (IS_UNDEFINED(hash)) return false; |
157 return %WeakCollectionHas(this, value, hash); | 157 return %WeakCollectionHas(this, value, hash); |
158 } | 158 } |
159 | 159 |
160 | 160 |
161 function WeakSetDelete(value) { | 161 function WeakSetDelete(value) { |
162 if (!IS_WEAKSET(this)) { | 162 if (!IS_WEAKSET(this)) { |
163 throw MakeTypeError(kIncompatibleMethodReceiver, | 163 throw MakeTypeError(kIncompatibleMethodReceiver, |
164 'WeakSet.prototype.delete', this); | 164 'WeakSet.prototype.delete', this); |
165 } | 165 } |
166 if (!IS_SPEC_OBJECT(value)) return false; | 166 if (!IS_RECEIVER(value)) return false; |
167 var hash = GetExistingHash(value); | 167 var hash = GetExistingHash(value); |
168 if (IS_UNDEFINED(hash)) return false; | 168 if (IS_UNDEFINED(hash)) return false; |
169 return %WeakCollectionDelete(this, value, hash); | 169 return %WeakCollectionDelete(this, value, hash); |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 // ------------------------------------------------------------------- | 173 // ------------------------------------------------------------------- |
174 | 174 |
175 %SetCode(GlobalWeakSet, WeakSetConstructor); | 175 %SetCode(GlobalWeakSet, WeakSetConstructor); |
176 %FunctionSetLength(GlobalWeakSet, 0); | 176 %FunctionSetLength(GlobalWeakSet, 0); |
177 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); | 177 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); |
178 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, | 178 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, |
179 DONT_ENUM); | 179 DONT_ENUM); |
180 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", | 180 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", |
181 DONT_ENUM | READ_ONLY); | 181 DONT_ENUM | READ_ONLY); |
182 | 182 |
183 // Set up the non-enumerable functions on the WeakSet prototype object. | 183 // Set up the non-enumerable functions on the WeakSet prototype object. |
184 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ | 184 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ |
185 "add", WeakSetAdd, | 185 "add", WeakSetAdd, |
186 "has", WeakSetHas, | 186 "has", WeakSetHas, |
187 "delete", WeakSetDelete | 187 "delete", WeakSetDelete |
188 ]); | 188 ]); |
189 | 189 |
190 }) | 190 }) |
OLD | NEW |