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 24 matching lines...) Expand all Loading... |
35 } | 35 } |
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('incompatible_method_receiver', | 42 throw MakeTypeError('incompatible_method_receiver', |
43 ['WeakMap.prototype.get', this]); | 43 ['WeakMap.prototype.get', this]); |
44 } | 44 } |
45 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 45 if (!IS_SPEC_OBJECT(key)) return UNDEFINED; |
46 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | |
47 } | |
48 return %WeakCollectionGet(this, key); | 46 return %WeakCollectionGet(this, key); |
49 } | 47 } |
50 | 48 |
51 | 49 |
52 function WeakMapSet(key, value) { | 50 function WeakMapSet(key, value) { |
53 if (!IS_WEAKMAP(this)) { | 51 if (!IS_WEAKMAP(this)) { |
54 throw MakeTypeError('incompatible_method_receiver', | 52 throw MakeTypeError('incompatible_method_receiver', |
55 ['WeakMap.prototype.set', this]); | 53 ['WeakMap.prototype.set', this]); |
56 } | 54 } |
57 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 55 if (!IS_SPEC_OBJECT(key)) { |
58 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 56 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
59 } | 57 } |
60 return %WeakCollectionSet(this, key, value); | 58 return %WeakCollectionSet(this, key, value); |
61 } | 59 } |
62 | 60 |
63 | 61 |
64 function WeakMapHas(key) { | 62 function WeakMapHas(key) { |
65 if (!IS_WEAKMAP(this)) { | 63 if (!IS_WEAKMAP(this)) { |
66 throw MakeTypeError('incompatible_method_receiver', | 64 throw MakeTypeError('incompatible_method_receiver', |
67 ['WeakMap.prototype.has', this]); | 65 ['WeakMap.prototype.has', this]); |
68 } | 66 } |
69 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 67 if (!IS_SPEC_OBJECT(key)) return false; |
70 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | |
71 } | |
72 return %WeakCollectionHas(this, key); | 68 return %WeakCollectionHas(this, key); |
73 } | 69 } |
74 | 70 |
75 | 71 |
76 function WeakMapDelete(key) { | 72 function WeakMapDelete(key) { |
77 if (!IS_WEAKMAP(this)) { | 73 if (!IS_WEAKMAP(this)) { |
78 throw MakeTypeError('incompatible_method_receiver', | 74 throw MakeTypeError('incompatible_method_receiver', |
79 ['WeakMap.prototype.delete', this]); | 75 ['WeakMap.prototype.delete', this]); |
80 } | 76 } |
81 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { | 77 if (!IS_SPEC_OBJECT(key)) return false; |
82 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | |
83 } | |
84 return %WeakCollectionDelete(this, key); | 78 return %WeakCollectionDelete(this, key); |
85 } | 79 } |
86 | 80 |
87 | 81 |
88 // ------------------------------------------------------------------- | 82 // ------------------------------------------------------------------- |
89 | 83 |
90 function SetUpWeakMap() { | 84 function SetUpWeakMap() { |
91 %CheckIsBootstrapping(); | 85 %CheckIsBootstrapping(); |
92 | 86 |
93 %SetCode($WeakMap, WeakMapConstructor); | 87 %SetCode($WeakMap, WeakMapConstructor); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 122 } |
129 } | 123 } |
130 } | 124 } |
131 | 125 |
132 | 126 |
133 function WeakSetAdd(value) { | 127 function WeakSetAdd(value) { |
134 if (!IS_WEAKSET(this)) { | 128 if (!IS_WEAKSET(this)) { |
135 throw MakeTypeError('incompatible_method_receiver', | 129 throw MakeTypeError('incompatible_method_receiver', |
136 ['WeakSet.prototype.add', this]); | 130 ['WeakSet.prototype.add', this]); |
137 } | 131 } |
138 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 132 if (!IS_SPEC_OBJECT(value)) { |
139 throw %MakeTypeError('invalid_weakset_value', [this, value]); | 133 throw %MakeTypeError('invalid_weakset_value', [this, value]); |
140 } | 134 } |
141 return %WeakCollectionSet(this, value, true); | 135 return %WeakCollectionSet(this, value, true); |
142 } | 136 } |
143 | 137 |
144 | 138 |
145 function WeakSetHas(value) { | 139 function WeakSetHas(value) { |
146 if (!IS_WEAKSET(this)) { | 140 if (!IS_WEAKSET(this)) { |
147 throw MakeTypeError('incompatible_method_receiver', | 141 throw MakeTypeError('incompatible_method_receiver', |
148 ['WeakSet.prototype.has', this]); | 142 ['WeakSet.prototype.has', this]); |
149 } | 143 } |
150 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 144 if (!IS_SPEC_OBJECT(value)) return false; |
151 throw %MakeTypeError('invalid_weakset_value', [this, value]); | |
152 } | |
153 return %WeakCollectionHas(this, value); | 145 return %WeakCollectionHas(this, value); |
154 } | 146 } |
155 | 147 |
156 | 148 |
157 function WeakSetDelete(value) { | 149 function WeakSetDelete(value) { |
158 if (!IS_WEAKSET(this)) { | 150 if (!IS_WEAKSET(this)) { |
159 throw MakeTypeError('incompatible_method_receiver', | 151 throw MakeTypeError('incompatible_method_receiver', |
160 ['WeakSet.prototype.delete', this]); | 152 ['WeakSet.prototype.delete', this]); |
161 } | 153 } |
162 if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) { | 154 if (!IS_SPEC_OBJECT(value)) return false; |
163 throw %MakeTypeError('invalid_weakset_value', [this, value]); | |
164 } | |
165 return %WeakCollectionDelete(this, value); | 155 return %WeakCollectionDelete(this, value); |
166 } | 156 } |
167 | 157 |
168 | 158 |
169 // ------------------------------------------------------------------- | 159 // ------------------------------------------------------------------- |
170 | 160 |
171 function SetUpWeakSet() { | 161 function SetUpWeakSet() { |
172 %CheckIsBootstrapping(); | 162 %CheckIsBootstrapping(); |
173 | 163 |
174 %SetCode($WeakSet, WeakSetConstructor); | 164 %SetCode($WeakSet, WeakSetConstructor); |
175 %FunctionSetPrototype($WeakSet, new $Object()); | 165 %FunctionSetPrototype($WeakSet, new $Object()); |
176 %AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); | 166 %AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); |
177 %AddNamedProperty( | 167 %AddNamedProperty( |
178 $WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY); | 168 $WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY); |
179 | 169 |
180 // Set up the non-enumerable functions on the WeakSet prototype object. | 170 // Set up the non-enumerable functions on the WeakSet prototype object. |
181 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( | 171 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( |
182 "add", WeakSetAdd, | 172 "add", WeakSetAdd, |
183 "has", WeakSetHas, | 173 "has", WeakSetHas, |
184 "delete", WeakSetDelete | 174 "delete", WeakSetDelete |
185 )); | 175 )); |
186 } | 176 } |
187 | 177 |
188 SetUpWeakSet(); | 178 SetUpWeakSet(); |
OLD | NEW |