| 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() { | 5 (function() { |
| 6 | 6 |
| 7 "use strict"; | 7 "use strict"; |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| 11 macro TYPED_ARRAYS(FUNCTION) | 11 macro TYPED_ARRAYS(FUNCTION) |
| 12 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. | 12 // arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| 13 FUNCTION(1, Uint8Array, 1) | 13 FUNCTION(Uint8Array) |
| 14 FUNCTION(2, Int8Array, 1) | 14 FUNCTION(Int8Array) |
| 15 FUNCTION(3, Uint16Array, 2) | 15 FUNCTION(Uint16Array) |
| 16 FUNCTION(4, Int16Array, 2) | 16 FUNCTION(Int16Array) |
| 17 FUNCTION(5, Uint32Array, 4) | 17 FUNCTION(Uint32Array) |
| 18 FUNCTION(6, Int32Array, 4) | 18 FUNCTION(Int32Array) |
| 19 FUNCTION(7, Float32Array, 4) | 19 FUNCTION(Float32Array) |
| 20 FUNCTION(8, Float64Array, 8) | 20 FUNCTION(Float64Array) |
| 21 FUNCTION(9, Uint8ClampedArray, 1) | 21 FUNCTION(Uint8ClampedArray) |
| 22 endmacro | 22 endmacro |
| 23 | 23 |
| 24 macro DECLARE_GLOBALS(INDEX, NAME, SIZE) | 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 macro TYPED_ARRAY_HARMONY_ADDITIONS(ARRAY_ID, NAME, ELEMENT_SIZE) | |
| 33 | |
| 34 // ES6 draft 05-05-15, section 22.2.3.7 | 32 // ES6 draft 05-05-15, section 22.2.3.7 |
| 35 function NAMEEvery(f /* thisArg */) { // length == 1 | 33 function TypedArrayEvery(f /* thisArg */) { // length == 1 |
| 36 if (!%IsTypedArray(this)) { | 34 if (!%IsTypedArray(this)) { |
| 37 throw MakeTypeError('not_typed_array', []); | 35 throw MakeTypeError('not_typed_array', []); |
| 38 } | 36 } |
| 39 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 37 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 40 | 38 |
| 41 var length = %_TypedArrayGetLength(this); | 39 var length = %_TypedArrayGetLength(this); |
| 42 var receiver; | 40 var receiver; |
| 43 | 41 |
| 44 if (%_ArgumentsLength() > 1) { | 42 if (%_ArgumentsLength() > 1) { |
| 45 receiver = %_Arguments(1); | 43 receiver = %_Arguments(1); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 59 if (stepping) %DebugPrepareStepInIfStepping(f); | 57 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 60 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 58 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 61 if (!%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f)) { | 59 if (!%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f)) { |
| 62 return false; | 60 return false; |
| 63 } | 61 } |
| 64 } | 62 } |
| 65 return true; | 63 return true; |
| 66 } | 64 } |
| 67 | 65 |
| 68 // ES6 draft 08-24-14, section 22.2.3.12 | 66 // ES6 draft 08-24-14, section 22.2.3.12 |
| 69 function NAMEForEach(f /* thisArg */) { // length == 1 | 67 function TypedArrayForEach(f /* thisArg */) { // length == 1 |
| 70 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); | 68 if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
| 71 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); | 69 if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f); |
| 72 | 70 |
| 73 var length = %_TypedArrayGetLength(this); | 71 var length = %_TypedArrayGetLength(this); |
| 74 var receiver; | 72 var receiver; |
| 75 | 73 |
| 76 if (%_ArgumentsLength() > 1) { | 74 if (%_ArgumentsLength() > 1) { |
| 77 receiver = %_Arguments(1); | 75 receiver = %_Arguments(1); |
| 78 } | 76 } |
| 79 | 77 |
| 80 var needs_wrapper = false; | 78 var needs_wrapper = false; |
| 81 if (IS_NULL(receiver)) { | 79 if (IS_NULL(receiver)) { |
| 82 if (%IsSloppyModeFunction(mapfn)) receiver = UNDEFINED; | 80 if (%IsSloppyModeFunction(mapfn)) receiver = UNDEFINED; |
| 83 } else if (!IS_UNDEFINED(receiver)) { | 81 } else if (!IS_UNDEFINED(receiver)) { |
| 84 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | 82 needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); |
| 85 } | 83 } |
| 86 | 84 |
| 87 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | 85 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| 88 for (var i = 0; i < length; i++) { | 86 for (var i = 0; i < length; i++) { |
| 89 var element = this[i]; | 87 var element = this[i]; |
| 90 // Prepare break slots for debugger step in. | 88 // Prepare break slots for debugger step in. |
| 91 if (stepping) %DebugPrepareStepInIfStepping(f); | 89 if (stepping) %DebugPrepareStepInIfStepping(f); |
| 92 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; | 90 var new_receiver = needs_wrapper ? $toObject(receiver) : receiver; |
| 93 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); | 91 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); |
| 94 } | 92 } |
| 95 } | 93 } |
| 96 | 94 |
| 97 // ES6 draft 08-24-14, section 22.2.2.2 | 95 // ES6 draft 08-24-14, section 22.2.2.2 |
| 98 function NAMEOf() { // length == 0 | 96 function TypedArrayOf() { // length == 0 |
| 99 var length = %_ArgumentsLength(); | 97 var length = %_ArgumentsLength(); |
| 100 var array = new this(length); | 98 var array = new this(length); |
| 101 for (var i = 0; i < length; i++) { | 99 for (var i = 0; i < length; i++) { |
| 102 array[i] = %_Arguments(i); | 100 array[i] = %_Arguments(i); |
| 103 } | 101 } |
| 104 return array; | 102 return array; |
| 105 } | 103 } |
| 106 | 104 |
| 107 endmacro | 105 macro EXTEND_TYPED_ARRAY(NAME) |
| 108 | |
| 109 TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS) | |
| 110 | |
| 111 | |
| 112 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | |
| 113 // Set up non-enumerable functions on the object. | 106 // Set up non-enumerable functions on the object. |
| 114 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ | 107 $installFunctions(GlobalNAME, DONT_ENUM | DONT_DELETE | READ_ONLY, [ |
| 115 "of", NAMEOf | 108 "of", TypedArrayOf |
| 116 ]); | 109 ]); |
| 117 | 110 |
| 118 // Set up non-enumerable functions on the prototype object. | 111 // Set up non-enumerable functions on the prototype object. |
| 119 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ | 112 $installFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
| 120 "every", NAMEEvery, | 113 "every", TypedArrayEvery, |
| 121 "forEach", NAMEForEach | 114 "forEach", TypedArrayForEach |
| 122 ]); | 115 ]); |
| 123 endmacro | 116 endmacro |
| 124 | 117 |
| 125 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | 118 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
| 126 | 119 |
| 127 })(); | 120 })(); |
| OLD | NEW |