OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 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 (function(global, shared, exports) { | 5 (function(global, shared, exports) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 macro DECLARE_GLOBALS(NAME) | 24 macro DECLARE_GLOBALS(NAME) |
25 var GlobalNAME = global.NAME; | 25 var GlobalNAME = global.NAME; |
26 endmacro | 26 endmacro |
27 | 27 |
28 TYPED_ARRAYS(DECLARE_GLOBALS) | 28 TYPED_ARRAYS(DECLARE_GLOBALS) |
29 | 29 |
30 // ------------------------------------------------------------------- | 30 // ------------------------------------------------------------------- |
31 | 31 |
32 // ES6 draft 05-05-15, section 22.2.3.7 | 32 // ES6 draft 05-05-15, section 22.2.3.7 |
33 function TypedArrayEvery(f /* thisArg */) { // length == 1 | 33 function TypedArrayEvery(f, receiver) { |
34 if (!%IsTypedArray(this)) { | 34 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
35 throw MakeTypeError('not_typed_array', []); | |
36 } | |
37 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | |
38 | 35 |
39 var length = %_TypedArrayGetLength(this); | 36 var length = %_TypedArrayGetLength(this); |
40 var receiver; | |
41 | 37 |
42 if (%_ArgumentsLength() > 1) { | 38 return $innerArrayEvery(f, receiver, this, length); |
43 receiver = %_Arguments(1); | |
44 } | |
45 | |
46 var needs_wrapper = false; | |
47 if (IS_NULL(receiver)) { | |
48 if (%IsSloppyModeFunction(mapfn)) receiver = UNDEFINED; | |
49 } else if (!IS_UNDEFINED(receiver)) { | |
50 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
51 } | |
52 | |
53 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | |
54 for (var i = 0; i < length; i++) { | |
55 var element = this[i]; | |
56 // Prepare break slots for debugger step in. | |
57 if (stepping) %DebugPrepareStepInIfStepping(f); | |
58 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | |
59 if (!%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f)) { | |
60 return false; | |
61 } | |
62 } | |
63 return true; | |
64 } | 39 } |
| 40 %FunctionSetLength(TypedArrayEvery, 1); |
65 | 41 |
66 // ES6 draft 08-24-14, section 22.2.3.12 | 42 // ES6 draft 08-24-14, section 22.2.3.12 |
67 function TypedArrayForEach(f /* thisArg */) { // length == 1 | 43 function TypedArrayForEach(f, receiver) { |
68 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 44 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
69 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | |
70 | 45 |
71 var length = %_TypedArrayGetLength(this); | 46 var length = %_TypedArrayGetLength(this); |
72 var receiver; | |
73 | 47 |
74 if (%_ArgumentsLength() > 1) { | 48 $innerArrayForEach(f, receiver, this, length); |
75 receiver = %_Arguments(1); | |
76 } | |
77 | |
78 var needs_wrapper = false; | |
79 if (IS_NULL(receiver)) { | |
80 if (%IsSloppyModeFunction(mapfn)) receiver = UNDEFINED; | |
81 } else if (!IS_UNDEFINED(receiver)) { | |
82 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
83 } | |
84 | |
85 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | |
86 for (var i = 0; i < length; i++) { | |
87 var element = this[i]; | |
88 // Prepare break slots for debugger step in. | |
89 if (stepping) %DebugPrepareStepInIfStepping(f); | |
90 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | |
91 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); | |
92 } | |
93 } | 49 } |
| 50 %FunctionSetLength(TypedArrayForEach, 1); |
94 | 51 |
95 // ES6 draft 08-24-14, section 22.2.2.2 | 52 // ES6 draft 08-24-14, section 22.2.2.2 |
96 function TypedArrayOf() { // length == 0 | 53 function TypedArrayOf() { |
97 var length = %_ArgumentsLength(); | 54 var length = %_ArgumentsLength(); |
98 var array = new this(length); | 55 var array = new this(length); |
99 for (var i = 0; i < length; i++) { | 56 for (var i = 0; i < length; i++) { |
100 array[i] = %_Arguments(i); | 57 array[i] = %_Arguments(i); |
101 } | 58 } |
102 return array; | 59 return array; |
103 } | 60 } |
104 | 61 |
105 macro EXTEND_TYPED_ARRAY(NAME) | 62 macro EXTEND_TYPED_ARRAY(NAME) |
106 // Set up non-enumerable functions on the object. | 63 // Set up non-enumerable functions on the object. |
107 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ | 64 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ |
108 "of", TypedArrayOf | 65 "of", TypedArrayOf |
109 ]); | 66 ]); |
110 | 67 |
111 // Set up non-enumerable functions on the prototype object. | 68 // Set up non-enumerable functions on the prototype object. |
112 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 69 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
113 "every", TypedArrayEvery, | 70 "every", TypedArrayEvery, |
114 "forEach", TypedArrayForEach | 71 "forEach", TypedArrayForEach |
115 ]); | 72 ]); |
116 endmacro | 73 endmacro |
117 | 74 |
118 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 75 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
119 | 76 |
120 }) | 77 }) |
OLD | NEW |