OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 'use strict'; |
| 6 |
| 7 // This file relies on the fact that the following declaration has been made |
| 8 // in runtime.js: |
| 9 // var $Array = global.Array; |
| 10 |
| 11 // ------------------------------------------------------------------- |
| 12 |
| 13 macro TYPED_ARRAYS(FUNCTION) |
| 14 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 15 FUNCTION(1, Uint8Array, 1) |
| 16 FUNCTION(2, Int8Array, 1) |
| 17 FUNCTION(3, Uint16Array, 2) |
| 18 FUNCTION(4, Int16Array, 2) |
| 19 FUNCTION(5, Uint32Array, 4) |
| 20 FUNCTION(6, Int32Array, 4) |
| 21 FUNCTION(7, Float32Array, 4) |
| 22 FUNCTION(8, Float64Array, 8) |
| 23 FUNCTION(9, Uint8ClampedArray, 1) |
| 24 endmacro |
| 25 |
| 26 |
| 27 macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 28 function NAMEForEach(f, receiver) { |
| 29 CHECK_OBJECT_COERCIBLE(this, "NAME.prototype.forEach"); |
| 30 |
| 31 var array = ToObject(this); |
| 32 var length = ToLength(array.length); |
| 33 |
| 34 if (!IS_SPEC_FUNCTION(f)) { |
| 35 throw MakeTypeError('called_non_callable', [ f ]); |
| 36 } |
| 37 if (IS_NULL_OR_UNDEFINED(receiver)) { |
| 38 receiver = %GetDefaultReceiver(f) || receiver; |
| 39 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
| 40 receiver = ToObject(receiver); |
| 41 } |
| 42 |
| 43 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 44 for (var i = 0; i < length; i++) { |
| 45 if (i in array) { |
| 46 var element = array[i]; |
| 47 // Prepare break slots for debugger step in. |
| 48 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 49 %_CallFunction(receiver, element, i, array, f); |
| 50 } |
| 51 } |
| 52 } |
| 53 endmacro |
| 54 |
| 55 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| 56 |
| 57 |
| 58 function HarmonyTypedArrayExtendPrototypes() { |
| 59 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| 60 %CheckIsBootstrapping(); |
| 61 |
| 62 // Set up non-enumerable functions on the prototype object. |
| 63 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( |
| 64 "forEach", NAMEForEach |
| 65 )); |
| 66 endmacro |
| 67 |
| 68 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
| 69 } |
| 70 |
| 71 HarmonyTypedArrayExtendPrototypes(); |
OLD | NEW |