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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 } | 81 } |
82 if (%SetHas(this, key)) { | 82 if (%SetHas(this, key)) { |
83 %SetDelete(this, key); | 83 %SetDelete(this, key); |
84 return true; | 84 return true; |
85 } else { | 85 } else { |
86 return false; | 86 return false; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 function SetSize() { | |
Michael Starzinger
2012/11/06 09:32:40
I think "SetGetSize" or "SetSizeGetter" would be a
arv (Not doing code reviews)
2012/11/06 16:02:33
Done.
| |
92 if (!IS_SET(this)) { | |
93 throw MakeTypeError('incompatible_method_receiver', | |
94 ['Set.prototype.size', this]); | |
95 } | |
96 return %SetSize(this); | |
97 } | |
98 | |
99 | |
91 function MapConstructor() { | 100 function MapConstructor() { |
92 if (%_IsConstructCall()) { | 101 if (%_IsConstructCall()) { |
93 %MapInitialize(this); | 102 %MapInitialize(this); |
94 } else { | 103 } else { |
95 return new $Map(); | 104 return new $Map(); |
96 } | 105 } |
97 } | 106 } |
98 | 107 |
99 | 108 |
100 function MapGet(key) { | 109 function MapGet(key) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 throw MakeTypeError('incompatible_method_receiver', | 147 throw MakeTypeError('incompatible_method_receiver', |
139 ['Map.prototype.delete', this]); | 148 ['Map.prototype.delete', this]); |
140 } | 149 } |
141 if (IS_UNDEFINED(key)) { | 150 if (IS_UNDEFINED(key)) { |
142 key = undefined_sentinel; | 151 key = undefined_sentinel; |
143 } | 152 } |
144 return %MapDelete(this, key); | 153 return %MapDelete(this, key); |
145 } | 154 } |
146 | 155 |
147 | 156 |
157 function MapSize() { | |
Michael Starzinger
2012/11/06 09:32:40
Likewise for "MapGetSize" or "MapSizeGetter".
| |
158 if (!IS_MAP(this)) { | |
159 throw MakeTypeError('incompatible_method_receiver', | |
160 ['Map.prototype.size', this]); | |
161 } | |
162 return %MapSize(this); | |
163 } | |
164 | |
165 | |
148 function WeakMapConstructor() { | 166 function WeakMapConstructor() { |
149 if (%_IsConstructCall()) { | 167 if (%_IsConstructCall()) { |
150 %WeakMapInitialize(this); | 168 %WeakMapInitialize(this); |
151 } else { | 169 } else { |
152 return new $WeakMap(); | 170 return new $WeakMap(); |
153 } | 171 } |
154 } | 172 } |
155 | 173 |
156 | 174 |
157 function WeakMapGet(key) { | 175 function WeakMapGet(key) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 %CheckIsBootstrapping(); | 225 %CheckIsBootstrapping(); |
208 | 226 |
209 // Set up the Set and Map constructor function. | 227 // Set up the Set and Map constructor function. |
210 %SetCode($Set, SetConstructor); | 228 %SetCode($Set, SetConstructor); |
211 %SetCode($Map, MapConstructor); | 229 %SetCode($Map, MapConstructor); |
212 | 230 |
213 // Set up the constructor property on the Set and Map prototype object. | 231 // Set up the constructor property on the Set and Map prototype object. |
214 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); | 232 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
215 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 233 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
216 | 234 |
235 function DefineGetter(object, name, fun) { | |
Michael Starzinger
2012/11/06 09:32:40
Can we move this into v8natives.js near the implem
arv (Not doing code reviews)
2012/11/06 16:02:33
Done.
I also used a lower level abstraction.
| |
236 %FunctionSetName(fun, name); | |
237 var desc = new PropertyDescriptor(); | |
238 desc.setGet(fun); | |
239 desc.setConfigurable(true); | |
240 DefineObjectProperty(object, name, desc, false); | |
241 } | |
242 | |
217 // Set up the non-enumerable functions on the Set prototype object. | 243 // Set up the non-enumerable functions on the Set prototype object. |
244 DefineGetter($Set.prototype, "size", SetSize); | |
218 InstallFunctions($Set.prototype, DONT_ENUM, $Array( | 245 InstallFunctions($Set.prototype, DONT_ENUM, $Array( |
219 "add", SetAdd, | 246 "add", SetAdd, |
220 "has", SetHas, | 247 "has", SetHas, |
221 "delete", SetDelete | 248 "delete", SetDelete |
222 )); | 249 )); |
223 | 250 |
224 // Set up the non-enumerable functions on the Map prototype object. | 251 // Set up the non-enumerable functions on the Map prototype object. |
252 DefineGetter($Map.prototype, "size", MapSize); | |
225 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | 253 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
226 "get", MapGet, | 254 "get", MapGet, |
227 "set", MapSet, | 255 "set", MapSet, |
228 "has", MapHas, | 256 "has", MapHas, |
229 "delete", MapDelete | 257 "delete", MapDelete |
230 )); | 258 )); |
231 | 259 |
232 // Set up the WeakMap constructor function. | 260 // Set up the WeakMap constructor function. |
233 %SetCode($WeakMap, WeakMapConstructor); | 261 %SetCode($WeakMap, WeakMapConstructor); |
234 | 262 |
235 // Set up the constructor property on the WeakMap prototype object. | 263 // Set up the constructor property on the WeakMap prototype object. |
236 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); | 264 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
237 | 265 |
238 // Set up the non-enumerable functions on the WeakMap prototype object. | 266 // Set up the non-enumerable functions on the WeakMap prototype object. |
239 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( | 267 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( |
240 "get", WeakMapGet, | 268 "get", WeakMapGet, |
241 "set", WeakMapSet, | 269 "set", WeakMapSet, |
242 "has", WeakMapHas, | 270 "has", WeakMapHas, |
243 "delete", WeakMapDelete | 271 "delete", WeakMapDelete |
244 )); | 272 )); |
245 })(); | 273 })(); |
OLD | NEW |