Chromium Code Reviews| Index: src/harmony-typedarray.js |
| diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..0e6754c4f29ce8dbbc673cc71fb817105bb5399c |
| --- /dev/null |
| +++ b/src/harmony-typedarray.js |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2013 the V8 project authors. All rights reserved. |
|
wingo
2014/09/19 10:24:26
2014
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +'use strict'; |
| + |
| +// This file relies on the fact that the following declaration has been made |
| +// in runtime.js: |
| +// var $Array = global.Array; |
| + |
| +// ------------------------------------------------------------------- |
| + |
| +macro TYPED_ARRAYS(FUNCTION) |
| +// arrayIds below should be synchronized with Runtime_TypedArrayInitialize. |
| +FUNCTION(1, Uint8Array, 1) |
| +FUNCTION(2, Int8Array, 1) |
| +FUNCTION(3, Uint16Array, 2) |
| +FUNCTION(4, Int16Array, 2) |
| +FUNCTION(5, Uint32Array, 4) |
| +FUNCTION(6, Int32Array, 4) |
| +FUNCTION(7, Float32Array, 4) |
| +FUNCTION(8, Float64Array, 8) |
| +FUNCTION(9, Uint8ClampedArray, 1) |
| +endmacro |
| + |
| + |
| +macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
|
wingo
2014/09/19 10:24:26
need a link to the spec in a comment: http://peopl
|
| + function NAMEForEach(f, receiver) { |
| + CHECK_OBJECT_COERCIBLE(this, "NAME.prototype.forEach"); |
| + |
| + var array = ToObject(this); |
| + var length = ToLength(array.length); |
|
wingo
2014/09/19 10:24:26
This is incorrect. The spec says:
%TypedArray%.p
|
| + |
| + if (!IS_SPEC_FUNCTION(f)) { |
| + throw MakeTypeError('called_non_callable', [ f ]); |
| + } |
| + if (IS_NULL_OR_UNDEFINED(receiver)) { |
| + receiver = %GetDefaultReceiver(f) || receiver; |
| + } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) { |
| + receiver = ToObject(receiver); |
|
wingo
2014/09/19 10:24:26
If we have to create a wrapper object, it probably
|
| + } |
| + |
| + var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f); |
| + for (var i = 0; i < length; i++) { |
| + var element = array[i]; |
| + // Prepare break slots for debugger step in. |
| + if (stepping) %DebugPrepareStepInIfStepping(f); |
| + %_CallFunction(receiver, element, i, array, f); |
| + } |
| + } |
| +endmacro |
| + |
| +TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR) |
| + |
| + |
| +function HarmonyTypedArrayExtendPrototypes() { |
| +macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE) |
| + %CheckIsBootstrapping(); |
| + |
| + // Set up non-enumerable functions on the prototype object. |
| + InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array( |
| + "forEach", NAMEForEach |
| + )); |
| +endmacro |
| + |
| + TYPED_ARRAYS(EXTEND_TYPED_ARRAY) |
| +} |
| + |
| +HarmonyTypedArrayExtendPrototypes(); |