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

Side by Side Diff: test/mjsunit/apply.js

Issue 6869007: Cleanup of mjsunit.js code and make assertEquals more strict. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments Created 9 years, 8 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 | « no previous file | test/mjsunit/arguments-apply.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 function f0() { 28 function f0() {
29 return this; 29 return this;
30 } 30 }
31 31
32 function f1(a) { 32 function f1(a) {
33 return a; 33 return a;
34 } 34 }
35 35
36 assertTrue(this === f0.apply(), "1-0"); 36 assertSame(this, f0.apply(), "1-0");
37 37
38 assertTrue(this === f0.apply(this), "2a"); 38 assertSame(this, f0.apply(this), "2a");
39 assertTrue(this === f0.apply(this, new Array(1)), "2b"); 39 assertSame(this, f0.apply(this, new Array(1)), "2b");
40 assertTrue(this === f0.apply(this, new Array(2)), "2c"); 40 assertSame(this, f0.apply(this, new Array(2)), "2c");
41 assertTrue(this === f0.apply(this, new Array(4242)), "2d"); 41 assertSame(this, f0.apply(this, new Array(4242)), "2d");
42 42
43 assertTrue(this === f0.apply(null), "3a"); 43 assertSame(this, f0.apply(null), "3a");
44 assertTrue(this === f0.apply(null, new Array(1)), "3b"); 44 assertSame(this, f0.apply(null, new Array(1)), "3b");
45 assertTrue(this === f0.apply(null, new Array(2)), "3c"); 45 assertSame(this, f0.apply(null, new Array(2)), "3c");
46 assertTrue(this === f0.apply(this, new Array(4242)), "3d"); 46 assertSame(this, f0.apply(this, new Array(4242)), "3d");
47 47
48 assertTrue(this === f0.apply(void 0), "4a"); 48 assertSame(this, f0.apply(void 0), "4a");
49 assertTrue(this === f0.apply(void 0, new Array(1)), "4b"); 49 assertSame(this, f0.apply(void 0, new Array(1)), "4b");
50 assertTrue(this === f0.apply(void 0, new Array(2)), "4c"); 50 assertSame(this, f0.apply(void 0, new Array(2)), "4c");
51 51
52 assertTrue(void 0 === f1.apply(), "1-1"); 52 assertEquals(void 0, f1.apply(), "1-1");
53 53
54 assertTrue(void 0 === f1.apply(this), "5a"); 54 assertEquals(void 0, f1.apply(this), "5a");
55 assertTrue(void 0 === f1.apply(this, new Array(1)), "5b"); 55 assertEquals(void 0, f1.apply(this, new Array(1)), "5b");
56 assertTrue(void 0 === f1.apply(this, new Array(2)), "5c"); 56 assertEquals(void 0, f1.apply(this, new Array(2)), "5c");
57 assertTrue(void 0 === f1.apply(this, new Array(4242)), "5d"); 57 assertEquals(void 0, f1.apply(this, new Array(4242)), "5d");
58 assertTrue(42 === f1.apply(this, new Array(42, 43)), "5e"); 58 assertEquals(42, f1.apply(this, new Array(42, 43)), "5e");
59 assertEquals("foo", f1.apply(this, new Array("foo", "bar", "baz", "bo")), "5f"); 59 assertEquals("foo", f1.apply(this, new Array("foo", "bar", "baz", "bo")), "5f");
60 60
61 assertTrue(void 0 === f1.apply(null), "6a"); 61 assertEquals(void 0, f1.apply(null), "6a");
62 assertTrue(void 0 === f1.apply(null, new Array(1)), "6b"); 62 assertEquals(void 0, f1.apply(null, new Array(1)), "6b");
63 assertTrue(void 0 === f1.apply(null, new Array(2)), "6c"); 63 assertEquals(void 0, f1.apply(null, new Array(2)), "6c");
64 assertTrue(void 0 === f1.apply(null, new Array(4242)), "6d"); 64 assertEquals(void 0, f1.apply(null, new Array(4242)), "6d");
65 assertTrue(42 === f1.apply(null, new Array(42, 43)), "6e"); 65 assertEquals(42, f1.apply(null, new Array(42, 43)), "6e");
66 assertEquals("foo", f1.apply(null, new Array("foo", "bar", "baz", "bo")), "6f"); 66 assertEquals("foo", f1.apply(null, new Array("foo", "bar", "baz", "bo")), "6f");
67 67
68 assertTrue(void 0 === f1.apply(void 0), "7a"); 68 assertEquals(void 0, f1.apply(void 0), "7a");
69 assertTrue(void 0 === f1.apply(void 0, new Array(1)), "7b"); 69 assertEquals(void 0, f1.apply(void 0, new Array(1)), "7b");
70 assertTrue(void 0 === f1.apply(void 0, new Array(2)), "7c"); 70 assertEquals(void 0, f1.apply(void 0, new Array(2)), "7c");
71 assertTrue(void 0 === f1.apply(void 0, new Array(4242)), "7d"); 71 assertEquals(void 0, f1.apply(void 0, new Array(4242)), "7d");
72 assertTrue(42 === f1.apply(void 0, new Array(42, 43)), "7e"); 72 assertEquals(42, f1.apply(void 0, new Array(42, 43)), "7e");
73 assertEquals("foo", f1.apply(void 0, new Array("foo", "bar", "ba", "b")), "7f"); 73 assertEquals("foo", f1.apply(void 0, new Array("foo", "bar", "ba", "b")), "7f");
74 74
75 var arr = new Array(42, "foo", "fish", "horse"); 75 var arr = new Array(42, "foo", "fish", "horse");
76 function j(a, b, c, d, e, f, g, h, i, j, k, l) { 76 function j(a, b, c, d, e, f, g, h, i, j, k, l) {
77 return "" + a + b + c + d + e + f + g + h + i + j + k + l; 77 return "" + a + b + c + d + e + f + g + h + i + j + k + l;
78 } 78 }
79 79
80 80
81 var expect = "42foofishhorse"; 81 var expect = "42foofishhorse";
82 for (var i = 0; i < 8; i++) 82 for (var i = 0; i < 8; i++)
(...skipping 18 matching lines...) Expand all
101 var doo = this; 101 var doo = this;
102 for (var i = 0; i < arguments.length; i++) { 102 for (var i = 0; i < arguments.length; i++) {
103 doo += arguments[i]; 103 doo += arguments[i];
104 } 104 }
105 return doo; 105 return doo;
106 } 106 }
107 107
108 assertEquals("bar42foofishhorse", s.apply("bar", arr), "apply to string"); 108 assertEquals("bar42foofishhorse", s.apply("bar", arr), "apply to string");
109 109
110 function al() { 110 function al() {
111 assertEquals(345, this); 111 assertEquals(Object(345), this);
112 return arguments.length + arguments[arguments.length - 1]; 112 return arguments.length + arguments[arguments.length - 1];
113 } 113 }
114 114
115 for (var j = 1; j < 0x40000000; j <<= 1) { 115 for (var j = 1; j < 0x40000000; j <<= 1) {
116 try { 116 try {
117 var a = new Array(j); 117 var a = new Array(j);
118 a[j - 1] = 42; 118 a[j - 1] = 42;
119 assertEquals(42 + j, al.apply(345, a)); 119 assertEquals(42 + j, al.apply(345, a));
120 } catch (e) { 120 } catch (e) {
121 assertTrue(e.toString().indexOf("Maximum call stack size exceeded") != -1); 121 assertTrue(e.toString().indexOf("Maximum call stack size exceeded") != -1);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 "moreseper2"); 179 "moreseper2");
180 assertEquals("morseper", String.prototype.concat.apply("", holey, 1, 2, 3), 180 assertEquals("morseper", String.prototype.concat.apply("", holey, 1, 2, 3),
181 "morseper3"); 181 "morseper3");
182 assertEquals("morseper", String.prototype.concat.apply("", holey, 1, 2, 3, 4), 182 assertEquals("morseper", String.prototype.concat.apply("", holey, 1, 2, 3, 4),
183 "morseper4"); 183 "morseper4");
184 184
185 primes[0] = ""; 185 primes[0] = "";
186 primes[1] = holey; 186 primes[1] = holey;
187 assertThrows("String.prototype.concat.apply.apply('foo', primes)"); 187 assertThrows("String.prototype.concat.apply.apply('foo', primes)");
188 assertEquals("morseper", 188 assertEquals("morseper",
189 String.prototype.concat.apply.apply(String.prototype.concat, primes), 189 String.prototype.concat.apply.apply(String.prototype.concat, primes),
190 "moreseper-prime"); 190 "moreseper-prime");
191 191
192 delete(Array.prototype["1"]); 192 delete(Array.prototype["1"]);
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/arguments-apply.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698