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 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 function WeakMapGet(key) { | 40 function WeakMapGet(key) { |
41 if (!IS_WEAKMAP(this)) { | 41 if (!IS_WEAKMAP(this)) { |
42 throw MakeTypeError(kIncompatibleMethodReceiver, | 42 throw MakeTypeError(kIncompatibleMethodReceiver, |
43 'WeakMap.prototype.get', this); | 43 'WeakMap.prototype.get', this); |
44 } | 44 } |
45 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; | 45 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; |
46 return %WeakCollectionGet(this, key); | 46 var hash = $getExistingHash(key); |
| 47 if (IS_UNDEFINED(hash)) return UNDEFINED; |
| 48 return %WeakCollectionGet(this, key, hash); |
47 } | 49 } |
48 | 50 |
49 | 51 |
50 function WeakMapSet(key, value) { | 52 function WeakMapSet(key, value) { |
51 if (!IS_WEAKMAP(this)) { | 53 if (!IS_WEAKMAP(this)) { |
52 throw MakeTypeError(kIncompatibleMethodReceiver, | 54 throw MakeTypeError(kIncompatibleMethodReceiver, |
53 'WeakMap.prototype.set', this); | 55 'WeakMap.prototype.set', this); |
54 } | 56 } |
55 if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey); | 57 if (!IS_SPEC_OBJECT(key)) throw MakeTypeError(kInvalidWeakMapKey); |
56 return %WeakCollectionSet(this, key, value); | 58 return %WeakCollectionSet(this, key, value, $getHash(key)); |
57 } | 59 } |
58 | 60 |
59 | 61 |
60 function WeakMapHas(key) { | 62 function WeakMapHas(key) { |
61 if (!IS_WEAKMAP(this)) { | 63 if (!IS_WEAKMAP(this)) { |
62 throw MakeTypeError(kIncompatibleMethodReceiver, | 64 throw MakeTypeError(kIncompatibleMethodReceiver, |
63 'WeakMap.prototype.has', this); | 65 'WeakMap.prototype.has', this); |
64 } | 66 } |
65 if (!IS_SPEC_OBJECT(key)) return false; | 67 if (!IS_SPEC_OBJECT(key)) return false; |
66 return %WeakCollectionHas(this, key); | 68 var hash = $getExistingHash(key); |
| 69 if (IS_UNDEFINED(hash)) return false; |
| 70 return %WeakCollectionHas(this, key, hash); |
67 } | 71 } |
68 | 72 |
69 | 73 |
70 function WeakMapDelete(key) { | 74 function WeakMapDelete(key) { |
71 if (!IS_WEAKMAP(this)) { | 75 if (!IS_WEAKMAP(this)) { |
72 throw MakeTypeError(kIncompatibleMethodReceiver, | 76 throw MakeTypeError(kIncompatibleMethodReceiver, |
73 'WeakMap.prototype.delete', this); | 77 'WeakMap.prototype.delete', this); |
74 } | 78 } |
75 if (!IS_SPEC_OBJECT(key)) return false; | 79 if (!IS_SPEC_OBJECT(key)) return false; |
76 return %WeakCollectionDelete(this, key); | 80 var hash = $getExistingHash(key); |
| 81 if (IS_UNDEFINED(hash)) return false; |
| 82 return %WeakCollectionDelete(this, key, hash); |
77 } | 83 } |
78 | 84 |
79 | 85 |
80 // ------------------------------------------------------------------- | 86 // ------------------------------------------------------------------- |
81 | 87 |
82 %SetCode(GlobalWeakMap, WeakMapConstructor); | 88 %SetCode(GlobalWeakMap, WeakMapConstructor); |
83 %FunctionSetLength(GlobalWeakMap, 0); | 89 %FunctionSetLength(GlobalWeakMap, 0); |
84 %FunctionSetPrototype(GlobalWeakMap, new GlobalObject()); | 90 %FunctionSetPrototype(GlobalWeakMap, new GlobalObject()); |
85 %AddNamedProperty(GlobalWeakMap.prototype, "constructor", GlobalWeakMap, | 91 %AddNamedProperty(GlobalWeakMap.prototype, "constructor", GlobalWeakMap, |
86 DONT_ENUM); | 92 DONT_ENUM); |
(...skipping 29 matching lines...) Expand all Loading... |
116 } | 122 } |
117 } | 123 } |
118 | 124 |
119 | 125 |
120 function WeakSetAdd(value) { | 126 function WeakSetAdd(value) { |
121 if (!IS_WEAKSET(this)) { | 127 if (!IS_WEAKSET(this)) { |
122 throw MakeTypeError(kIncompatibleMethodReceiver, | 128 throw MakeTypeError(kIncompatibleMethodReceiver, |
123 'WeakSet.prototype.add', this); | 129 'WeakSet.prototype.add', this); |
124 } | 130 } |
125 if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue); | 131 if (!IS_SPEC_OBJECT(value)) throw MakeTypeError(kInvalidWeakSetValue); |
126 return %WeakCollectionSet(this, value, true); | 132 return %WeakCollectionSet(this, value, true, $getHash(value)); |
127 } | 133 } |
128 | 134 |
129 | 135 |
130 function WeakSetHas(value) { | 136 function WeakSetHas(value) { |
131 if (!IS_WEAKSET(this)) { | 137 if (!IS_WEAKSET(this)) { |
132 throw MakeTypeError(kIncompatibleMethodReceiver, | 138 throw MakeTypeError(kIncompatibleMethodReceiver, |
133 'WeakSet.prototype.has', this); | 139 'WeakSet.prototype.has', this); |
134 } | 140 } |
135 if (!IS_SPEC_OBJECT(value)) return false; | 141 if (!IS_SPEC_OBJECT(value)) return false; |
136 return %WeakCollectionHas(this, value); | 142 var hash = $getExistingHash(value); |
| 143 if (IS_UNDEFINED(hash)) return false; |
| 144 return %WeakCollectionHas(this, value, hash); |
137 } | 145 } |
138 | 146 |
139 | 147 |
140 function WeakSetDelete(value) { | 148 function WeakSetDelete(value) { |
141 if (!IS_WEAKSET(this)) { | 149 if (!IS_WEAKSET(this)) { |
142 throw MakeTypeError(kIncompatibleMethodReceiver, | 150 throw MakeTypeError(kIncompatibleMethodReceiver, |
143 'WeakSet.prototype.delete', this); | 151 'WeakSet.prototype.delete', this); |
144 } | 152 } |
145 if (!IS_SPEC_OBJECT(value)) return false; | 153 if (!IS_SPEC_OBJECT(value)) return false; |
146 return %WeakCollectionDelete(this, value); | 154 var hash = $getExistingHash(value); |
| 155 if (IS_UNDEFINED(hash)) return false; |
| 156 return %WeakCollectionDelete(this, value, hash); |
147 } | 157 } |
148 | 158 |
149 | 159 |
150 // ------------------------------------------------------------------- | 160 // ------------------------------------------------------------------- |
151 | 161 |
152 %SetCode(GlobalWeakSet, WeakSetConstructor); | 162 %SetCode(GlobalWeakSet, WeakSetConstructor); |
153 %FunctionSetLength(GlobalWeakSet, 0); | 163 %FunctionSetLength(GlobalWeakSet, 0); |
154 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); | 164 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject()); |
155 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, | 165 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet, |
156 DONT_ENUM); | 166 DONT_ENUM); |
157 %AddNamedProperty(GlobalWeakSet.prototype, symbolToStringTag, "WeakSet", | 167 %AddNamedProperty(GlobalWeakSet.prototype, symbolToStringTag, "WeakSet", |
158 DONT_ENUM | READ_ONLY); | 168 DONT_ENUM | READ_ONLY); |
159 | 169 |
160 // Set up the non-enumerable functions on the WeakSet prototype object. | 170 // Set up the non-enumerable functions on the WeakSet prototype object. |
161 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ | 171 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ |
162 "add", WeakSetAdd, | 172 "add", WeakSetAdd, |
163 "has", WeakSetHas, | 173 "has", WeakSetHas, |
164 "delete", WeakSetDelete | 174 "delete", WeakSetDelete |
165 ]); | 175 ]); |
166 | 176 |
167 }) | 177 }) |
OLD | NEW |