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

Unified Diff: test/mjsunit/harmony/typedarray-reverse.js

Issue 1132723008: Implement %TypedArray%.reverse (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 5 years, 7 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
« no previous file with comments | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/typedarray-reverse.js
diff --git a/test/mjsunit/harmony/typedarray-reverse.js b/test/mjsunit/harmony/typedarray-reverse.js
new file mode 100644
index 0000000000000000000000000000000000000000..98b738787b802cd55c3aff549c9e445144c752d2
--- /dev/null
+++ b/test/mjsunit/harmony/typedarray-reverse.js
@@ -0,0 +1,56 @@
+// Copyright 2015 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-arrays
+
+function ArrayMaker(x) {
+ return x;
+}
+ArrayMaker.prototype = Array.prototype;
+
+var arrayConstructors = [
+ Uint8Array,
+ Int8Array,
+ Uint16Array,
+ Int16Array,
+ Uint32Array,
+ Int32Array,
+ Uint8ClampedArray,
+ Float32Array,
+ Float64Array,
+ ArrayMaker // Also test arrays
+];
+
+function assertArrayLikeEquals(value, expected, type) {
+ assertEquals(value.__proto__, type.prototype);
+ assertEquals(expected.length, value.length);
+ for (var i = 0; i < value.length; ++i) {
+ assertEquals(expected[i], value[i]);
+ }
+}
+
+for (var constructor of arrayConstructors) {
+ // Test reversing both even and odd length arrays
+ var a = new constructor([1, 2, 3]);
+ assertArrayLikeEquals(a.reverse(), [3, 2, 1], constructor);
+ assertArrayLikeEquals(a, [3, 2, 1], constructor);
+
+ a = new constructor([1, 2, 3, 4]);
+ assertArrayLikeEquals(a.reverse(), [4, 3, 2, 1], constructor);
+ assertArrayLikeEquals(a, [4, 3, 2, 1], constructor);
+
+ if (constructor != ArrayMaker) {
+ // Cannot be called on objects which are not TypedArrays
+ assertThrows(function () { a.reverse.call({ length: 0 }); }, TypeError);
+ } else {
+ // Array.reverse works on array-like objects
+ var x = { length: 2, 1: 5 };
+ a.reverse.call(x);
+ assertEquals(2, x.length);
+ assertFalse(Object.hasOwnProperty(x, '1'));
+ assertEquals(5, x[0]);
+ }
+
+ assertEquals(0, a.reverse.length);
+}
« no previous file with comments | « src/harmony-typedarray.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698