| 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 |
| 11 var $Set = global.Set; | 11 var $Set = global.Set; |
| 12 var $Map = global.Map; | 12 var $Map = global.Map; |
| 13 | 13 |
| 14 | 14 |
| 15 // Used by harmony-templates.js | |
| 16 var $MapGet; | |
| 17 var $MapSet; | |
| 18 | |
| 19 | |
| 20 (function() { | 15 (function() { |
| 21 | 16 |
| 17 %CheckIsBootstrapping(); |
| 18 |
| 22 | 19 |
| 23 function HashToEntry(table, hash, numBuckets) { | 20 function HashToEntry(table, hash, numBuckets) { |
| 24 var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets); | 21 var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets); |
| 25 return ORDERED_HASH_TABLE_BUCKET_AT(table, bucket); | 22 return ORDERED_HASH_TABLE_BUCKET_AT(table, bucket); |
| 26 } | 23 } |
| 27 %SetInlineBuiltinFlag(HashToEntry); | 24 %SetInlineBuiltinFlag(HashToEntry); |
| 28 | 25 |
| 29 | 26 |
| 30 function SetFindEntry(table, numBuckets, key, hash) { | 27 function SetFindEntry(table, numBuckets, key, hash) { |
| 31 var keyIsNaN = IS_NUMBER(key) && NUMBER_IS_NAN(key); | 28 var keyIsNaN = IS_NUMBER(key) && NUMBER_IS_NAN(key); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 var value_array = [UNDEFINED]; | 228 var value_array = [UNDEFINED]; |
| 232 while (%SetIteratorNext(iterator, value_array)) { | 229 while (%SetIteratorNext(iterator, value_array)) { |
| 233 if (stepping) %DebugPrepareStepInIfStepping(f); | 230 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 234 key = value_array[0]; | 231 key = value_array[0]; |
| 235 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 232 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 236 %_CallFunction(new_receiver, key, key, this, f); | 233 %_CallFunction(new_receiver, key, key, this, f); |
| 237 } | 234 } |
| 238 } | 235 } |
| 239 | 236 |
| 240 | 237 |
| 241 // ------------------------------------------------------------------- | 238 %SetCode($Set, SetConstructor); |
| 239 %FunctionSetPrototype($Set, new $Object()); |
| 240 %AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
| 241 %AddNamedProperty( |
| 242 $Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY); |
| 242 | 243 |
| 243 function SetUpSet() { | 244 %FunctionSetLength(SetForEach, 1); |
| 244 %CheckIsBootstrapping(); | |
| 245 | 245 |
| 246 %SetCode($Set, SetConstructor); | 246 // Set up the non-enumerable functions on the Set prototype object. |
| 247 %FunctionSetPrototype($Set, new $Object()); | 247 InstallGetter($Set.prototype, "size", SetGetSize); |
| 248 %AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM); | 248 InstallFunctions($Set.prototype, DONT_ENUM, $Array( |
| 249 %AddNamedProperty( | 249 "add", SetAdd, |
| 250 $Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY); | 250 "has", SetHas, |
| 251 | 251 "delete", SetDelete, |
| 252 %FunctionSetLength(SetForEach, 1); | 252 "clear", SetClearJS, |
| 253 | 253 "forEach", SetForEach |
| 254 // Set up the non-enumerable functions on the Set prototype object. | 254 )); |
| 255 InstallGetter($Set.prototype, "size", SetGetSize); | |
| 256 InstallFunctions($Set.prototype, DONT_ENUM, $Array( | |
| 257 "add", SetAdd, | |
| 258 "has", SetHas, | |
| 259 "delete", SetDelete, | |
| 260 "clear", SetClearJS, | |
| 261 "forEach", SetForEach | |
| 262 )); | |
| 263 } | |
| 264 | |
| 265 SetUpSet(); | |
| 266 | 255 |
| 267 | 256 |
| 268 // ------------------------------------------------------------------- | 257 // ------------------------------------------------------------------- |
| 269 // Harmony Map | 258 // Harmony Map |
| 270 | 259 |
| 271 function MapConstructor(iterable) { | 260 function MapConstructor(iterable) { |
| 272 if (!%_IsConstructCall()) { | 261 if (!%_IsConstructCall()) { |
| 273 throw MakeTypeError('constructor_not_function', ['Map']); | 262 throw MakeTypeError('constructor_not_function', ['Map']); |
| 274 } | 263 } |
| 275 | 264 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 416 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 428 var value_array = [UNDEFINED, UNDEFINED]; | 417 var value_array = [UNDEFINED, UNDEFINED]; |
| 429 while (%MapIteratorNext(iterator, value_array)) { | 418 while (%MapIteratorNext(iterator, value_array)) { |
| 430 if (stepping) %DebugPrepareStepInIfStepping(f); | 419 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 431 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | 420 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; |
| 432 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); | 421 %_CallFunction(new_receiver, value_array[1], value_array[0], this, f); |
| 433 } | 422 } |
| 434 } | 423 } |
| 435 | 424 |
| 436 | 425 |
| 437 // ------------------------------------------------------------------- | 426 %SetCode($Map, MapConstructor); |
| 427 %FunctionSetPrototype($Map, new $Object()); |
| 428 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
| 429 %AddNamedProperty( |
| 430 $Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY); |
| 438 | 431 |
| 439 function SetUpMap() { | 432 %FunctionSetLength(MapForEach, 1); |
| 440 %CheckIsBootstrapping(); | |
| 441 | 433 |
| 442 %SetCode($Map, MapConstructor); | 434 // Set up the non-enumerable functions on the Map prototype object. |
| 443 %FunctionSetPrototype($Map, new $Object()); | 435 InstallGetter($Map.prototype, "size", MapGetSize); |
| 444 %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | 436 InstallFunctions($Map.prototype, DONT_ENUM, $Array( |
| 445 %AddNamedProperty( | 437 "get", MapGet, |
| 446 $Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY); | 438 "set", MapSet, |
| 447 | 439 "has", MapHas, |
| 448 %FunctionSetLength(MapForEach, 1); | 440 "delete", MapDelete, |
| 449 | 441 "clear", MapClearJS, |
| 450 // Set up the non-enumerable functions on the Map prototype object. | 442 "forEach", MapForEach |
| 451 InstallGetter($Map.prototype, "size", MapGetSize); | 443 )); |
| 452 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | |
| 453 "get", MapGet, | |
| 454 "set", MapSet, | |
| 455 "has", MapHas, | |
| 456 "delete", MapDelete, | |
| 457 "clear", MapClearJS, | |
| 458 "forEach", MapForEach | |
| 459 )); | |
| 460 | |
| 461 $MapGet = MapGet; | |
| 462 $MapSet = MapSet; | |
| 463 } | |
| 464 | |
| 465 SetUpMap(); | |
| 466 | 444 |
| 467 })(); | 445 })(); |
| OLD | NEW |