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

Side by Side Diff: test/mjsunit/harmony/typedarray-tostring.js

Issue 1166623004: Implement %TypedArray%.prototype.{toString,toLocaleString,join} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
« src/harmony-typedarray.js ('K') | « src/prologue.js ('k') | no next file » | 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 2015 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 // Flags: --harmony-arrays
6
7 // Array's toString should call the object's own join method, if one exists and
8 // is callable. Otherwise, just use the original Object.toString function.
9
10 var typedArrayConstructors = [
11 Uint8Array,
12 Int8Array,
13 Uint16Array,
14 Int16Array,
15 Uint32Array,
16 Int32Array,
17 Uint8ClampedArray,
18 Float32Array,
19 Float64Array
20 ];
21
22 for (var constructor of typedArrayConstructors) {
23 var success = "[test success]";
24 var expectedThis;
25 function testJoin() {
26 assertEquals(0, arguments.length);
27 assertSame(expectedThis, this);
28 return success;
29 }
30
31
32 // On an Array object.
33
34 // Default case.
35 var a1 = new constructor([1, 2, 3]);
36 assertEquals("1,2,3", a1.toString());
37 assertEquals("1,2,3", a1.join());
38 assertEquals("1,2,3", a1.toLocaleString());
39
40 // Non-standard "join" function is called correctly.
41 var a2 = new constructor([1, 2, 3]);
42 a2.join = testJoin;
43 expectedThis = a2;
44 assertEquals(success, a2.toString());
45 assertEquals(success, a2.join());
46 assertEquals("1,2,3", a2.toLocaleString());
47
48 // Non-callable join function is ignored and Object.prototype.toString is
49 // used instead.
50 var a3 = new constructor([1, 2, 3]);
51 a3.join = "not callable";
52 assertEquals(0, a3.toString().search(/\[object .+Array\]/));
53
54 // Non-existing join function is treated same as non-callable.
55 var a4 = new constructor([1, 2, 3]);
56 a4.__proto__ = { toString: constructor.prototype.toString };
57 // No join on Array.
58 assertEquals(0, a3.toString().search(/\[object .+Array\]/));
59
60
61 // On a non-Array object, throws.
62
63 // Default looks-like-an-array case.
64 var o1 = {length: 3, 0: 1, 1: 2, 2: 3,
65 toString: constructor.prototype.toString,
66 join: constructor.prototype.join};
67 assertThrows(function() { o1.join() }, TypeError);
68 assertThrows(function() { o1.toString() }, TypeError);
69 assertThrows(function() { o1.toLocaleString() }, TypeError);
70
71 // Redefining length does not change result
72 var a5 = new constructor([1, 2, 3])
73 Object.defineProperty(a5, 'length', { value: 2 });
74 assertEquals("1,2,3", a5.join());
75 assertEquals("1,2,3", a5.toString());
76 assertEquals("1,2,3", a5.toLocaleString());
77 assertEquals("1,2", Array.prototype.join.call(a5));
78 assertEquals("1,2,3", Array.prototype.toString.call(a5));
79 assertEquals("1,2", Array.prototype.toLocaleString.call(a5));
80 }
OLDNEW
« src/harmony-typedarray.js ('K') | « src/prologue.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698