OLD | NEW |
---|---|
(Empty) | |
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. | |
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 | |
29 // ES6 draft 08-24-14, section 22.2.3.12 | |
30 function NAMEForEach(f /* thisArg */) { // length == 1 | |
31 if (!%IsTypedArray(this)) { | |
wingo
2014/10/07 11:18:44
Normally you don't want runtime calls in the hot p
| |
32 throw MakeTypeError('not_typed_array', []); | |
33 } | |
34 if (!IS_SPEC_FUNCTION(f)) { | |
35 throw MakeTypeError('called_non_callable', [ f ]); | |
36 } | |
37 | |
38 var length = %_TypedArrayGetLength(this); | |
39 var receiver; | |
40 | |
41 if (%_ArgumentsLength() > 1) { | |
42 receiver = %_Arguments(1); | |
43 } | |
44 | |
45 if (IS_NULL_OR_UNDEFINED(receiver)) { | |
46 receiver = %GetDefaultReceiver(f) || receiver; | |
47 } | |
48 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
wingo
2014/10/07 11:18:44
this needs to be in an "else" case; i.e.
var need
| |
49 | |
50 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | |
51 for (var i = 0; i < length; i++) { | |
52 var element = this[i]; | |
53 // Prepare break slots for debugger step in. | |
54 if (stepping) %DebugPrepareStepInIfStepping(f); | |
55 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | |
56 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); | |
57 } | |
58 } | |
59 endmacro | |
60 | |
61 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | |
62 | |
63 | |
64 function HarmonyTypedArrayExtendPrototypes() { | |
65 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | |
66 %CheckIsBootstrapping(); | |
67 | |
68 // Set up non-enumerable functions on the prototype object. | |
69 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( | |
70 "forEach", NAMEForEach | |
71 )); | |
72 endmacro | |
73 | |
74 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | |
75 } | |
76 | |
77 HarmonyTypedArrayExtendPrototypes(); | |
OLD | NEW |