OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 15 matching lines...) Expand all Loading... |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 | 28 |
29 // This file relies on the fact that the following declaration has been made | 29 // This file relies on the fact that the following declaration has been made |
30 // in runtime.js: | 30 // in runtime.js: |
31 // const $Object = global.Object; | 31 // const $Object = global.Object; |
32 const $WeakMap = global.WeakMap; | 32 const $WeakMap = global.WeakMap; |
33 | 33 |
34 // ------------------------------------------------------------------- | 34 // ------------------------------------------------------------------- |
35 | 35 |
36 // Set the WeakMap function and constructor. | 36 function WeakMapConstructor() { |
37 %SetCode($WeakMap, function(x) { | |
38 if (%_IsConstructCall()) { | 37 if (%_IsConstructCall()) { |
39 %WeakMapInitialize(this); | 38 %WeakMapInitialize(this); |
40 } else { | 39 } else { |
41 return new $WeakMap(); | 40 return new $WeakMap(); |
42 } | 41 } |
43 }); | 42 } |
44 | 43 |
45 | 44 |
46 function WeakMapGet(key) { | 45 function WeakMapGet(key) { |
47 if (!IS_SPEC_OBJECT(key)) { | 46 if (!IS_SPEC_OBJECT(key)) { |
48 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 47 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
49 } | 48 } |
50 return %WeakMapGet(this, key); | 49 return %WeakMapGet(this, key); |
51 } | 50 } |
52 | 51 |
53 | 52 |
(...skipping 21 matching lines...) Expand all Loading... |
75 %WeakMapSet(this, key, void 0); | 74 %WeakMapSet(this, key, void 0); |
76 return true; | 75 return true; |
77 } else { | 76 } else { |
78 return false; | 77 return false; |
79 } | 78 } |
80 } | 79 } |
81 | 80 |
82 // ------------------------------------------------------------------- | 81 // ------------------------------------------------------------------- |
83 | 82 |
84 function SetupWeakMap() { | 83 function SetupWeakMap() { |
| 84 // Setup the WeakMap constructor function. |
| 85 %SetCode($WeakMap, WeakMapConstructor); |
| 86 |
| 87 // Setup the WeakMap prototype object. |
| 88 %FunctionSetPrototype($WeakMap, new $WeakMap()); |
| 89 |
85 // Setup the non-enumerable functions on the WeakMap prototype object. | 90 // Setup the non-enumerable functions on the WeakMap prototype object. |
86 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( | 91 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( |
87 "get", WeakMapGet, | 92 "get", WeakMapGet, |
88 "set", WeakMapSet, | 93 "set", WeakMapSet, |
89 "has", WeakMapHas, | 94 "has", WeakMapHas, |
90 "delete", WeakMapDelete | 95 "delete", WeakMapDelete |
91 )); | 96 )); |
92 } | 97 } |
93 | 98 |
94 | 99 |
95 SetupWeakMap(); | 100 SetupWeakMap(); |
OLD | NEW |