jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 28 | "use strict"; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 29 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 30 | // This file relies on the fact that the following declaration has been made |
| 31 | // in runtime.js: |
| 32 | // var $Array = global.Array; |
| 33 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 34 | var $Set = global.Set; |
| 35 | var $Map = global.Map; |
| 36 | var $WeakMap = global.WeakMap; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 37 | var $WeakSet = global.WeakSet; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 38 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 39 | // Global sentinel to be used instead of undefined keys, which are not |
| 40 | // supported internally but required for Harmony sets and maps. |
| 41 | var undefined_sentinel = {}; |
| 42 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 43 | // ------------------------------------------------------------------- |
| 44 | // Harmony Set |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 45 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 46 | function SetConstructor() { |
| 47 | if (%_IsConstructCall()) { |
| 48 | %SetInitialize(this); |
| 49 | } else { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 50 | throw MakeTypeError('constructor_not_function', ['Set']); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | function SetAdd(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 56 | if (!IS_SET(this)) { |
| 57 | throw MakeTypeError('incompatible_method_receiver', |
| 58 | ['Set.prototype.add', this]); |
| 59 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 60 | if (IS_UNDEFINED(key)) { |
| 61 | key = undefined_sentinel; |
| 62 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 63 | return %SetAdd(this, key); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | function SetHas(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 68 | if (!IS_SET(this)) { |
| 69 | throw MakeTypeError('incompatible_method_receiver', |
| 70 | ['Set.prototype.has', this]); |
| 71 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 72 | if (IS_UNDEFINED(key)) { |
| 73 | key = undefined_sentinel; |
| 74 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 75 | return %SetHas(this, key); |
| 76 | } |
| 77 | |
| 78 | |
| 79 | function SetDelete(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 80 | if (!IS_SET(this)) { |
| 81 | throw MakeTypeError('incompatible_method_receiver', |
| 82 | ['Set.prototype.delete', this]); |
| 83 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 84 | if (IS_UNDEFINED(key)) { |
| 85 | key = undefined_sentinel; |
| 86 | } |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 87 | if (%SetHas(this, key)) { |
| 88 | %SetDelete(this, key); |
| 89 | return true; |
| 90 | } else { |
| 91 | return false; |
| 92 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 96 | function SetGetSize() { |
| 97 | if (!IS_SET(this)) { |
| 98 | throw MakeTypeError('incompatible_method_receiver', |
| 99 | ['Set.prototype.size', this]); |
| 100 | } |
| 101 | return %SetGetSize(this); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | function SetClear() { |
| 106 | if (!IS_SET(this)) { |
| 107 | throw MakeTypeError('incompatible_method_receiver', |
| 108 | ['Set.prototype.clear', this]); |
| 109 | } |
| 110 | // Replace the internal table with a new empty table. |
| 111 | %SetInitialize(this); |
| 112 | } |
| 113 | |
| 114 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 115 | // ------------------------------------------------------------------- |
| 116 | |
| 117 | function SetUpSet() { |
| 118 | %CheckIsBootstrapping(); |
| 119 | |
| 120 | %SetCode($Set, SetConstructor); |
| 121 | %FunctionSetPrototype($Set, new $Object()); |
| 122 | %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
| 123 | |
| 124 | // Set up the non-enumerable functions on the Set prototype object. |
| 125 | InstallGetter($Set.prototype, "size", SetGetSize); |
| 126 | InstallFunctions($Set.prototype, DONT_ENUM, $Array( |
| 127 | "add", SetAdd, |
| 128 | "has", SetHas, |
| 129 | "delete", SetDelete, |
| 130 | "clear", SetClear |
| 131 | )); |
| 132 | } |
| 133 | |
| 134 | SetUpSet(); |
| 135 | |
| 136 | |
| 137 | // ------------------------------------------------------------------- |
| 138 | // Harmony Map |
| 139 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 140 | function MapConstructor() { |
| 141 | if (%_IsConstructCall()) { |
| 142 | %MapInitialize(this); |
| 143 | } else { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 144 | throw MakeTypeError('constructor_not_function', ['Map']); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | |
| 149 | function MapGet(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 150 | if (!IS_MAP(this)) { |
| 151 | throw MakeTypeError('incompatible_method_receiver', |
| 152 | ['Map.prototype.get', this]); |
| 153 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 154 | if (IS_UNDEFINED(key)) { |
| 155 | key = undefined_sentinel; |
| 156 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 157 | return %MapGet(this, key); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | function MapSet(key, value) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 162 | if (!IS_MAP(this)) { |
| 163 | throw MakeTypeError('incompatible_method_receiver', |
| 164 | ['Map.prototype.set', this]); |
| 165 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 166 | if (IS_UNDEFINED(key)) { |
| 167 | key = undefined_sentinel; |
| 168 | } |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 169 | return %MapSet(this, key, value); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | function MapHas(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 174 | if (!IS_MAP(this)) { |
| 175 | throw MakeTypeError('incompatible_method_receiver', |
| 176 | ['Map.prototype.has', this]); |
| 177 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 178 | if (IS_UNDEFINED(key)) { |
| 179 | key = undefined_sentinel; |
| 180 | } |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 181 | return %MapHas(this, key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | function MapDelete(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 186 | if (!IS_MAP(this)) { |
| 187 | throw MakeTypeError('incompatible_method_receiver', |
| 188 | ['Map.prototype.delete', this]); |
| 189 | } |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 190 | if (IS_UNDEFINED(key)) { |
| 191 | key = undefined_sentinel; |
| 192 | } |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 193 | return %MapDelete(this, key); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 194 | } |
| 195 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 196 | |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 197 | function MapGetSize() { |
| 198 | if (!IS_MAP(this)) { |
| 199 | throw MakeTypeError('incompatible_method_receiver', |
| 200 | ['Map.prototype.size', this]); |
| 201 | } |
| 202 | return %MapGetSize(this); |
| 203 | } |
| 204 | |
| 205 | |
| 206 | function MapClear() { |
| 207 | if (!IS_MAP(this)) { |
| 208 | throw MakeTypeError('incompatible_method_receiver', |
| 209 | ['Map.prototype.clear', this]); |
| 210 | } |
| 211 | // Replace the internal table with a new empty table. |
| 212 | %MapInitialize(this); |
| 213 | } |
| 214 | |
| 215 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 216 | // ------------------------------------------------------------------- |
| 217 | |
| 218 | function SetUpMap() { |
| 219 | %CheckIsBootstrapping(); |
| 220 | |
| 221 | %SetCode($Map, MapConstructor); |
| 222 | %FunctionSetPrototype($Map, new $Object()); |
| 223 | %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
| 224 | |
| 225 | // Set up the non-enumerable functions on the Map prototype object. |
| 226 | InstallGetter($Map.prototype, "size", MapGetSize); |
| 227 | InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
| 228 | "get", MapGet, |
| 229 | "set", MapSet, |
| 230 | "has", MapHas, |
| 231 | "delete", MapDelete, |
| 232 | "clear", MapClear |
| 233 | )); |
| 234 | } |
| 235 | |
| 236 | SetUpMap(); |
| 237 | |
| 238 | |
| 239 | // ------------------------------------------------------------------- |
| 240 | // Harmony WeakMap |
| 241 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 242 | function WeakMapConstructor() { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 243 | if (%_IsConstructCall()) { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 244 | %WeakCollectionInitialize(this); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 245 | } else { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 246 | throw MakeTypeError('constructor_not_function', ['WeakMap']); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 247 | } |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 248 | } |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 249 | |
| 250 | |
| 251 | function WeakMapGet(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 252 | if (!IS_WEAKMAP(this)) { |
| 253 | throw MakeTypeError('incompatible_method_receiver', |
| 254 | ['WeakMap.prototype.get', this]); |
| 255 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 256 | if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 257 | throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 258 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 259 | return %WeakCollectionGet(this, key); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | |
| 263 | function WeakMapSet(key, value) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 264 | if (!IS_WEAKMAP(this)) { |
| 265 | throw MakeTypeError('incompatible_method_receiver', |
| 266 | ['WeakMap.prototype.set', this]); |
| 267 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 268 | if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 269 | throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 270 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 271 | return %WeakCollectionSet(this, key, value); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
| 275 | function WeakMapHas(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 276 | if (!IS_WEAKMAP(this)) { |
| 277 | throw MakeTypeError('incompatible_method_receiver', |
| 278 | ['WeakMap.prototype.has', this]); |
| 279 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 280 | if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 281 | throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 282 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 283 | return %WeakCollectionHas(this, key); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | |
| 287 | function WeakMapDelete(key) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 288 | if (!IS_WEAKMAP(this)) { |
| 289 | throw MakeTypeError('incompatible_method_receiver', |
| 290 | ['WeakMap.prototype.delete', this]); |
| 291 | } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 292 | if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 293 | throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
| 294 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 295 | return %WeakCollectionDelete(this, key); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 296 | } |
| 297 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 298 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 299 | function WeakMapClear() { |
| 300 | if (!IS_WEAKMAP(this)) { |
| 301 | throw MakeTypeError('incompatible_method_receiver', |
| 302 | ['WeakMap.prototype.clear', this]); |
| 303 | } |
| 304 | // Replace the internal table with a new empty table. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 305 | %WeakCollectionInitialize(this); |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 309 | // ------------------------------------------------------------------- |
| 310 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 311 | function SetUpWeakMap() { |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 312 | %CheckIsBootstrapping(); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 313 | |
danno@chromium.org | b645116 | 2011-08-17 14:33:23 +0000 | [diff] [blame] | 314 | %SetCode($WeakMap, WeakMapConstructor); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 315 | %FunctionSetPrototype($WeakMap, new $Object()); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 316 | %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
| 317 | |
| 318 | // Set up the non-enumerable functions on the WeakMap prototype object. |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 319 | InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 320 | "get", WeakMapGet, |
| 321 | "set", WeakMapSet, |
| 322 | "has", WeakMapHas, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 323 | "delete", WeakMapDelete, |
| 324 | "clear", WeakMapClear |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 325 | )); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | SetUpWeakMap(); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 329 | |
| 330 | |
| 331 | // ------------------------------------------------------------------- |
| 332 | // Harmony WeakSet |
| 333 | |
| 334 | function WeakSetConstructor() { |
| 335 | if (%_IsConstructCall()) { |
| 336 | %WeakCollectionInitialize(this); |
| 337 | } else { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 338 | throw MakeTypeError('constructor_not_function', ['WeakSet']); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
| 342 | |
| 343 | function WeakSetAdd(value) { |
| 344 | if (!IS_WEAKSET(this)) { |
| 345 | throw MakeTypeError('incompatible_method_receiver', |
| 346 | ['WeakSet.prototype.add', this]); |
| 347 | } |
| 348 | if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 349 | throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 350 | } |
| 351 | return %WeakCollectionSet(this, value, true); |
| 352 | } |
| 353 | |
| 354 | |
| 355 | function WeakSetHas(value) { |
| 356 | if (!IS_WEAKSET(this)) { |
| 357 | throw MakeTypeError('incompatible_method_receiver', |
| 358 | ['WeakSet.prototype.has', this]); |
| 359 | } |
| 360 | if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 361 | throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 362 | } |
| 363 | return %WeakCollectionHas(this, value); |
| 364 | } |
| 365 | |
| 366 | |
| 367 | function WeakSetDelete(value) { |
| 368 | if (!IS_WEAKSET(this)) { |
| 369 | throw MakeTypeError('incompatible_method_receiver', |
| 370 | ['WeakSet.prototype.delete', this]); |
| 371 | } |
| 372 | if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 373 | throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 374 | } |
| 375 | return %WeakCollectionDelete(this, value); |
| 376 | } |
| 377 | |
| 378 | |
| 379 | function WeakSetClear() { |
| 380 | if (!IS_WEAKSET(this)) { |
| 381 | throw MakeTypeError('incompatible_method_receiver', |
| 382 | ['WeakSet.prototype.clear', this]); |
| 383 | } |
| 384 | // Replace the internal table with a new empty table. |
| 385 | %WeakCollectionInitialize(this); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | // ------------------------------------------------------------------- |
| 390 | |
| 391 | function SetUpWeakSet() { |
| 392 | %CheckIsBootstrapping(); |
| 393 | |
| 394 | %SetCode($WeakSet, WeakSetConstructor); |
| 395 | %FunctionSetPrototype($WeakSet, new $Object()); |
| 396 | %SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); |
| 397 | |
| 398 | // Set up the non-enumerable functions on the WeakSet prototype object. |
| 399 | InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
| 400 | "add", WeakSetAdd, |
| 401 | "has", WeakSetHas, |
| 402 | "delete", WeakSetDelete, |
| 403 | "clear", WeakSetClear |
| 404 | )); |
| 405 | } |
| 406 | |
| 407 | SetUpWeakSet(); |