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

Unified Diff: test/mjsunit/harmony/typedarrays-foreach.js

Issue 583723002: Implement .forEach() on typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Change copyright year to 2014 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 side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/typedarrays-foreach.js
diff --git a/test/mjsunit/harmony/typedarrays-foreach.js b/test/mjsunit/harmony/typedarrays-foreach.js
new file mode 100644
index 0000000000000000000000000000000000000000..36389b4f0ed08d1281326d0742830a49f725cd74
--- /dev/null
+++ b/test/mjsunit/harmony/typedarrays-foreach.js
@@ -0,0 +1,44 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-typedarrays
+
+var typedArrayConstructors = [
+ Uint8Array,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Uint8ClampedArray,
+ Float32Array,
+ Float64Array];
+
+function TestTypedArrayForEach(constructor) {
+ assertEquals(1, constructor.prototype.forEach.length);
+
+ var a = new constructor(2);
wingo 2014/09/23 18:11:25 tests needed that typed array foreach methods don'
+ a[0] = 0;
+ a[1] = 1;
+
+ var count = 0;
+ a.forEach(function (n) { count++; });
+ assertEquals(2, count);
+
+ // Use specified object as this object when calling the function.
+ var o = { value: 42 };
+ var result = [];
+ a.forEach(function (n, index, array) { result.push(this.value); }, o);
+ assertArrayEquals([42, 42], result);
+
+ // Modify the original array.
+ count = 0;
+ a.forEach(function (n, index, array) { array[index] = n + 1; count++ });
+ assertEquals(2, count);
+ assertArrayEquals([1, 2], a);
+}
+
+for (i = 0; i < typedArrayConstructors.length; i++) {
+ TestTypedArrayForEach(typedArrayConstructors[i]);
+}
« src/harmony-typedarray.js ('K') | « src/harmony-typedarray.js ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698