Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: src/harmony-typedarray.js

Issue 583723002: Implement .forEach() on typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove unneeded check for holes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/harmony/typedarrays-foreach.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
wingo 2014/09/19 10:24:26 2014
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)
wingo 2014/09/19 10:24:26 need a link to the spec in a comment: http://peopl
28 function NAMEForEach(f, receiver) {
29 CHECK_OBJECT_COERCIBLE(this, "NAME.prototype.forEach");
30
31 var array = ToObject(this);
32 var length = ToLength(array.length);
wingo 2014/09/19 10:24:26 This is incorrect. The spec says: %TypedArray%.p
33
34 if (!IS_SPEC_FUNCTION(f)) {
35 throw MakeTypeError('called_non_callable', [ f ]);
36 }
37 if (IS_NULL_OR_UNDEFINED(receiver)) {
38 receiver = %GetDefaultReceiver(f) || receiver;
39 } else if (!IS_SPEC_OBJECT(receiver) && %IsSloppyModeFunction(f)) {
40 receiver = ToObject(receiver);
wingo 2014/09/19 10:24:26 If we have to create a wrapper object, it probably
41 }
42
43 var stepping = DEBUG_IS_ACTIVE && %DebugCallbackSupportsStepping(f);
44 for (var i = 0; i < length; i++) {
45 var element = array[i];
46 // Prepare break slots for debugger step in.
47 if (stepping) %DebugPrepareStepInIfStepping(f);
48 %_CallFunction(receiver, element, i, array, f);
49 }
50 }
51 endmacro
52
53 TYPED_ARRAYS(TYPED_ARRAY_CONSTRUCTOR)
54
55
56 function HarmonyTypedArrayExtendPrototypes() {
57 macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
58 %CheckIsBootstrapping();
59
60 // Set up non-enumerable functions on the prototype object.
61 InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
62 "forEach", NAMEForEach
63 ));
64 endmacro
65
66 TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
67 }
68
69 HarmonyTypedArrayExtendPrototypes();
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/harmony/typedarrays-foreach.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698