OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 318 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( |
319 "get", WeakMapGet, | 319 "get", WeakMapGet, |
320 "set", WeakMapSet, | 320 "set", WeakMapSet, |
321 "has", WeakMapHas, | 321 "has", WeakMapHas, |
322 "delete", WeakMapDelete, | 322 "delete", WeakMapDelete, |
323 "clear", WeakMapClear | 323 "clear", WeakMapClear |
324 )); | 324 )); |
325 } | 325 } |
326 | 326 |
327 SetUpWeakMap(); | 327 SetUpWeakMap(); |
| 328 |
| 329 |
| 330 // ------------------------------------------------------------------- |
| 331 // Harmony WeakSet |
| 332 |
| 333 var weaksetDataSymbol = %CreateSymbol(void 0); |
| 334 |
| 335 |
| 336 function WeakSet() { |
| 337 if (%_IsConstructCall()) { |
| 338 this[weaksetDataSymbol] = new $WeakMap(); |
| 339 } else { |
| 340 return new $WeakSet(); |
| 341 } |
| 342 } |
| 343 |
| 344 |
| 345 var $WeakSet = WeakSet; |
| 346 |
| 347 |
| 348 function WeakSetAdd(value) { |
| 349 var weaksetData = this[weaksetDataSymbol]; |
| 350 if (!weaksetData) { |
| 351 throw %MakeTypeError('incompatible_method_receiver', |
| 352 ['WeakSet.prototype.add', this]); |
| 353 } |
| 354 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 355 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 356 } |
| 357 return %WeakMapSet(weaksetData, value, true); |
| 358 } |
| 359 |
| 360 |
| 361 function WeakSetHas(value) { |
| 362 var weaksetData = this[weaksetDataSymbol]; |
| 363 if (!weaksetData) { |
| 364 throw %MakeTypeError('incompatible_method_receiver', |
| 365 ['WeakSet.prototype.has', this]); |
| 366 } |
| 367 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 368 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 369 } |
| 370 return %WeakMapHas(weaksetData, value); |
| 371 } |
| 372 |
| 373 |
| 374 function WeakSetDelete(value) { |
| 375 var weaksetData = this[weaksetDataSymbol]; |
| 376 if (!weaksetData) { |
| 377 throw MakeTypeError('incompatible_method_receiver', |
| 378 ['WeakSet.prototype.delete', this]); |
| 379 } |
| 380 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { |
| 381 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
| 382 } |
| 383 return %WeakMapDelete(weaksetData, value); |
| 384 } |
| 385 |
| 386 |
| 387 function WeakSetClear() { |
| 388 if (!this[weaksetDataSymbol]) { |
| 389 throw %MakeTypeError('incompatible_method_receiver', |
| 390 ['WeakSet.prototype.clear', this]); |
| 391 } |
| 392 |
| 393 this[weaksetDataSymbol] = new $WeakMap(); |
| 394 } |
| 395 |
| 396 |
| 397 // ------------------------------------------------------------------- |
| 398 |
| 399 function SetUpWeakSet() { |
| 400 %CheckIsBootstrapping(); |
| 401 |
| 402 %SetProperty(global, 'WeakSet', $WeakSet, DONT_ENUM); |
| 403 |
| 404 %FunctionSetInstanceClassName($WeakSet, 'WeakSet'); |
| 405 |
| 406 %FunctionSetPrototype($WeakSet, new $Object()); |
| 407 %SetProperty($WeakSet.prototype, 'constructor', $WeakSet, DONT_ENUM); |
| 408 |
| 409 // Set up the non-enumerable functions on the WeakSet prototype object. |
| 410 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
| 411 'add', WeakSetAdd, |
| 412 'has', WeakSetHas, |
| 413 'delete', WeakSetDelete, |
| 414 'clear', WeakSetClear |
| 415 )); |
| 416 } |
| 417 |
| 418 SetUpWeakSet(); |
OLD | NEW |