Chromium Code Reviews| 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 (!(%_ClassOf(this) === 'NAME')) { | |
|
wingo
2014/09/23 18:11:25
Not sure this is right; although the function isn'
| |
| 32 throw MakeTypeError('incompatible_method_receiver', | |
| 33 ['NAME.forEach', this]); | |
| 34 } | |
|
wingo
2014/09/23 18:11:25
Also what about the text that says "A TypeError ex
| |
| 35 if (!IS_SPEC_FUNCTION(f)) { | |
| 36 throw MakeTypeError('called_non_callable', [ f ]); | |
| 37 } | |
| 38 | |
| 39 var length = %_TypedArrayGetLength(this); | |
| 40 var receiver; | |
| 41 | |
| 42 if (%_ArgumentsLength() > 1) { | |
| 43 receiver = %_Arguments(1); | |
| 44 } | |
| 45 | |
| 46 if (IS_NULL_OR_UNDEFINED(receiver)) { | |
| 47 receiver = %GetDefaultReceiver(f) || receiver; | |
| 48 } | |
| 49 var needs_wrapper = SHOULD_CREATE_WRAPPER(f, receiver); | |
| 50 | |
| 51 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); | |
| 52 for (var i = 0; i < length; i++) { | |
| 53 var element = this[i]; | |
| 54 // Prepare break slots for debugger step in. | |
| 55 if (stepping) %DebugPrepareStepInIfStepping(f); | |
| 56 var new_receiver = needs_wrapper ? ToObject(receiver) : receiver; | |
| 57 %_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f); | |
| 58 } | |
| 59 } | |
| 60 endmacro | |
| 61 | |
| 62 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) | |
| 63 | |
| 64 | |
| 65 function HarmonyTypedArrayExtendPrototypes() { | |
| 66 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) | |
| 67 %CheckIsBootstrapping(); | |
| 68 | |
| 69 // Set up non-enumerable functions on the prototype object. | |
| 70 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( | |
| 71 "forEach", NAMEForEach | |
| 72 )); | |
| 73 endmacro | |
| 74 | |
| 75 TYPED_ARRAYS(EXTEND_TYPED_ARRAY) | |
| 76 } | |
| 77 | |
| 78 HarmonyTypedArrayExtendPrototypes(); | |
| OLD | NEW |