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 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 throw MakeTypeError('incompatible_method_receiver', | 89 throw MakeTypeError('incompatible_method_receiver', |
90 ['WeakMap.prototype.delete', this]); | 90 ['WeakMap.prototype.delete', this]); |
91 } | 91 } |
92 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 92 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
93 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 93 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
94 } | 94 } |
95 return %WeakCollectionDelete(this, key); | 95 return %WeakCollectionDelete(this, key); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 function WeakMapClear() { | |
100 if (!IS_WEAKMAP(this)) { | |
101 throw MakeTypeError('incompatible_method_receiver', | |
102 ['WeakMap.prototype.clear', this]); | |
103 } | |
104 // Replace the internal table with a new empty table. | |
105 %WeakCollectionInitialize(this); | |
106 } | |
107 | |
108 | |
109 // ------------------------------------------------------------------- | 99 // ------------------------------------------------------------------- |
110 | 100 |
111 function SetUpWeakMap() { | 101 function SetUpWeakMap() { |
112 %CheckIsBootstrapping(); | 102 %CheckIsBootstrapping(); |
113 | 103 |
114 %SetCode($WeakMap, WeakMapConstructor); | 104 %SetCode($WeakMap, WeakMapConstructor); |
115 %FunctionSetPrototype($WeakMap, new $Object()); | 105 %FunctionSetPrototype($WeakMap, new $Object()); |
116 %AddNamedProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); | 106 %AddNamedProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
117 %AddNamedProperty( | 107 %AddNamedProperty( |
118 $WeakMap.prototype, symbolToStringTag, "WeakMap", DONT_ENUM | READ_ONLY); | 108 $WeakMap.prototype, symbolToStringTag, "WeakMap", DONT_ENUM | READ_ONLY); |
119 | 109 |
120 // Set up the non-enumerable functions on the WeakMap prototype object. | 110 // Set up the non-enumerable functions on the WeakMap prototype object. |
121 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 111 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( |
122 "get", WeakMapGet, | 112 "get", WeakMapGet, |
123 "set", WeakMapSet, | 113 "set", WeakMapSet, |
124 "has", WeakMapHas, | 114 "has", WeakMapHas, |
125 "delete", WeakMapDelete, | 115 "delete", WeakMapDelete |
126 "clear", WeakMapClear | |
127 )); | 116 )); |
128 } | 117 } |
129 | 118 |
130 SetUpWeakMap(); | 119 SetUpWeakMap(); |
131 | 120 |
132 | 121 |
133 // ------------------------------------------------------------------- | 122 // ------------------------------------------------------------------- |
134 // Harmony WeakSet | 123 // Harmony WeakSet |
135 | 124 |
136 function WeakSetConstructor(iterable) { | 125 function WeakSetConstructor(iterable) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 throw MakeTypeError('incompatible_method_receiver', | 180 throw MakeTypeError('incompatible_method_receiver', |
192 ['WeakSet.prototype.delete', this]); | 181 ['WeakSet.prototype.delete', this]); |
193 } | 182 } |
194 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 183 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
195 throw %MakeTypeError('invalid_weakset_value', [this, value]); | 184 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
196 } | 185 } |
197 return %WeakCollectionDelete(this, value); | 186 return %WeakCollectionDelete(this, value); |
198 } | 187 } |
199 | 188 |
200 | 189 |
201 function WeakSetClear() { | |
202 if (!IS_WEAKSET(this)) { | |
203 throw MakeTypeError('incompatible_method_receiver', | |
204 ['WeakSet.prototype.clear', this]); | |
205 } | |
206 // Replace the internal table with a new empty table. | |
207 %WeakCollectionInitialize(this); | |
208 } | |
209 | |
210 | |
211 // ------------------------------------------------------------------- | 190 // ------------------------------------------------------------------- |
212 | 191 |
213 function SetUpWeakSet() { | 192 function SetUpWeakSet() { |
214 %CheckIsBootstrapping(); | 193 %CheckIsBootstrapping(); |
215 | 194 |
216 %SetCode($WeakSet, WeakSetConstructor); | 195 %SetCode($WeakSet, WeakSetConstructor); |
217 %FunctionSetPrototype($WeakSet, new $Object()); | 196 %FunctionSetPrototype($WeakSet, new $Object()); |
218 %AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); | 197 %AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); |
219 %AddNamedProperty( | 198 %AddNamedProperty( |
220 $WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY); | 199 $WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY); |
221 | 200 |
222 // Set up the non-enumerable functions on the WeakSet prototype object. | 201 // Set up the non-enumerable functions on the WeakSet prototype object. |
223 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | 202 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
224 "add", WeakSetAdd, | 203 "add", WeakSetAdd, |
225 "has", WeakSetHas, | 204 "has", WeakSetHas, |
226 "delete", WeakSetDelete, | 205 "delete", WeakSetDelete |
227 "clear", WeakSetClear | |
228 )); | 206 )); |
229 } | 207 } |
230 | 208 |
231 SetUpWeakSet(); | 209 SetUpWeakSet(); |
OLD | NEW |