1 // Copyright 2014 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.
7 // This file relies on the fact that the following declaration has been made
9 // var $Array = global.Array;
11 // -------------------------------------------------------------------
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)
27 macro TYPED_ARRAY_HARMONY_ADDITIONS(ARRAY_ID, NAME, ELEMENT_SIZE)
29 // ES6 draft 08-24-14, section 22.2.3.12
30 function NAMEForEach(f /* thisArg */) { // length == 1
31 if (!%IsTypedArray(this)) {
32 throw MakeTypeError('not_typed_array', []);
34 if (!IS_SPEC_FUNCTION(f)) {
35 throw MakeTypeError('called_non_callable', [ f ]);
38 var length = %_TypedArrayGetLength(this);
41 if (%_ArgumentsLength() > 1) {
42 receiver = %_Arguments(1);
45 var needs_wrapper = false;
46 if (IS_NULL_OR_UNDEFINED(receiver)) {
47 receiver = %GetDefaultReceiver(f) || receiver;
49 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver);
52 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
53 for (var i = 0; i < length; i++) {
54 var element = this[i];
55 // Prepare break slots for debugger step in.
56 if (stepping) %DebugPrepareStepInIfStepping(f);
57 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver;
58 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f);
63 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
66 function HarmonyTypedArrayExtendPrototypes() {
67 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
68 %CheckIsBootstrapping();
70 // Set up non-enumerable functions on the prototype object.
71 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
72 "forEach", NAMEForEach
76 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
79 HarmonyTypedArrayExtendPrototypes();