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

Side by Side Diff: test/mjsunit/arguments-read-and-assignment.js

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years 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
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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 // Testing basic functionality of the arguments object. 27 // Testing basic functionality of the arguments object.
28 // Introduced to ensure that the fast compiler does the right thing. 28 // Introduced to ensure that the fast compiler does the right thing.
29 // The arguments object itself. 29 // The arguments object itself.
30 assertEquals(42, function(){ return arguments;}(42)[0], 30 assertEquals(42, function(){ return arguments;}(42)[0],
Rico 2011/12/08 10:24:37 space after arguments;
31 "return arguments value"); 31 "return arguments value");
32 assertEquals(42, function(){ return arguments;}(42)[0], 32 assertEquals(42, function(){ return arguments;}(42)[0],
Rico 2011/12/08 10:24:37 space after arguments;
33 "arguments in plain value context"); 33 "arguments in plain value context");
34 assertEquals(42, function(){ arguments;return 42}(37), 34 assertEquals(42, function(){ arguments; return 42; }(37),
35 "arguments in effect context"); 35 "arguments in effect context");
36 assertEquals(42, function(){ if(arguments)return 42;}(), 36 assertEquals(42, function(){ if(arguments) return 42;}(),
Rico 2011/12/08 10:24:37 space after 42;
37 "arguments in a boolean context"); 37 "arguments in a boolean context");
38 assertEquals(42, function(){ return arguments || true;}(42)[0], 38 assertEquals(42, function(){ return arguments || true;}(42)[0],
Rico 2011/12/08 10:24:37 space after true;
39 "arguments in a short-circuit boolean context - or"); 39 "arguments in a short-circuit boolean context - or");
40 assertEquals(true, function(){ return arguments && [true];}(42)[0], 40 assertEquals(true, function(){ return arguments && [true];}(42)[0],
Rico 2011/12/08 10:24:37 space after [true];
41 "arguments in a short-circuit boolean context - and"); 41 "arguments in a short-circuit boolean context - and");
42 assertEquals(42, function(){ arguments = 42; return 42;}(), 42 assertEquals(42, function(){ arguments = 42; return 42;}(),
Rico 2011/12/08 10:24:37 space after 42;
43 "arguments assignment"); 43 "arguments assignment");
44 // Properties of the arguments object. 44 // Properties of the arguments object.
45 assertEquals(42, function(){ return arguments[0]; }(42), 45 assertEquals(42, function(){ return arguments[0]; }(42),
46 "args[0] value returned"); 46 "args[0] value returned");
47 assertEquals(42, function(){ arguments[0]; return 42}(), 47 assertEquals(42, function(){ arguments[0]; return 42; }(),
48 "args[0] value ignored"); 48 "args[0] value ignored");
49 assertEquals(42, function(){ if (arguments[0]) return 42; }(37), 49 assertEquals(42, function(){ if (arguments[0]) return 42; }(37),
50 "args[0] to boolean"); 50 "args[0] to boolean");
51 assertEquals(42, function(){ return arguments[0] || "no"; }(42), 51 assertEquals(42, function(){ return arguments[0] || "no"; }(42),
52 "args[0] short-circuit boolean or true"); 52 "args[0] short-circuit boolean or true");
53 assertEquals(42, function(){ return arguments[0] || 42; }(0), 53 assertEquals(42, function(){ return arguments[0] || 42; }(0),
54 "args[0] short-circuit boolean or false"); 54 "args[0] short-circuit boolean or false");
55 assertEquals(37, function(){ return arguments[0] && 37; }(42), 55 assertEquals(37, function(){ return arguments[0] && 37; }(42),
56 "args[0] short-circuit boolean and true"); 56 "args[0] short-circuit boolean and true");
57 assertEquals(0, function(){ return arguments[0] && 42; }(0), 57 assertEquals(0, function(){ return arguments[0] && 42; }(0),
58 "args[0] short-circuit boolean and false"); 58 "args[0] short-circuit boolean and false");
59 assertEquals(42, function(){ arguments[0] = 42; return arguments[0]; }(37), 59 assertEquals(42, function(){ arguments[0] = 42; return arguments[0]; }(37),
60 "args[0] assignment"); 60 "args[0] assignment");
61 // Link between arguments and parameters. 61 // Link between arguments and parameters.
62 assertEquals(42, function(a) { arguments[0] = 42; return a; }(37), 62 assertEquals(42, function(a) { arguments[0] = 42; return a; }(37),
63 "assign args[0]->a"); 63 "assign args[0]->a");
64 assertEquals(42, function(a) { a = 42; return arguments[0]; }(37), 64 assertEquals(42, function(a) { a = 42; return arguments[0]; }(37),
65 "assign a->args[0]"); 65 "assign a->args[0]");
66 assertEquals(54, function(a, b) { arguments[1] = 54; return b; }(42, 37), 66 assertEquals(54, function(a, b) { arguments[1] = 54; return b; }(42, 37),
67 "assign args[1]->b:b"); 67 "assign args[1]->b:b");
68 assertEquals(54, function(a, b) { b = 54; return arguments[1]; }(42, 47), 68 assertEquals(54, function(a, b) { b = 54; return arguments[1]; }(42, 47),
69 "assign b->args[1]:b"); 69 "assign b->args[1]:b");
70 assertEquals(42, function(a, b) { arguments[1] = 54; return a; }(42, 37), 70 assertEquals(42, function(a, b) { arguments[1] = 54; return a; }(42, 37),
71 "assign args[1]->b:a"); 71 "assign args[1]->b:a");
72 assertEquals(42, function(a, b) { b = 54; return arguments[0]; }(42, 47), 72 assertEquals(42, function(a, b) { b = 54; return arguments[0]; }(42, 47),
73 "assign b->args[1]:a"); 73 "assign b->args[1]:a");
74 74
Rico 2011/12/08 10:24:37 In all of the above I would prefer having the func
Lasse Reichstein 2011/12/08 12:33:18 Feel free. I'll try not to expand the scope of thi
75 // Capture parameters in nested contexts. 75 // Capture parameters in nested contexts.
76 assertEquals(33, 76 assertEquals(33,
77 function(a,b) { 77 function(a,b) {
78 return a + arguments[0] + 78 return a + arguments[0] +
79 function(b){ return a + b + arguments[0]; }(b); }(7,6), 79 function(b){ return a + b + arguments[0]; }(b); }(7,6),
80 "captured parameters"); 80 "captured parameters");
81 assertEquals(42, function(a) { 81 assertEquals(42, function(a) {
82 arguments[0] = 42; 82 arguments[0] = 42;
83 return function(b){ return a; }(); 83 return function(b){ return a; }();
84 }(37), 84 }(37),
(...skipping 30 matching lines...) Expand all
115 return b + 115 return b +
116 function() { 116 function() {
117 return a; 117 return a;
118 }(); 118 }();
119 }(); 119 }();
120 }(7,14,21), 120 }(7,14,21),
121 "deep nested capture"); 121 "deep nested capture");
122 122
123 // Assignment to captured parameters. 123 // Assignment to captured parameters.
124 assertEquals(42, function(a,b) { 124 assertEquals(42, function(a,b) {
125 arguments[1] = 11; 125 arguments[1] = 11;
Rico 2011/12/08 10:24:37 new line before function, and move last argument t
126 return a + function(){ a = b; return a; }() + a; 126 return a + function(){ a = b; return a; }() + a;
127 }(20, 37), "captured assignment"); 127 }(20, 37), "captured assignment");
128 128
129 // Inside non-function scopes. 129 // Inside non-function scopes.
130 assertEquals(42, 130 assertEquals(42,
131 function(a) { 131 function(a) {
132 arguments[0] = 20; 132 arguments[0] = 20;
133 with ({ b : 22 }) { return a + b; } 133 with ({ b : 22 }) { return a + b; }
134 }(37), 134 }(37),
135 "a in with"); 135 "a in with");
136 assertEquals(42, 136 assertEquals(42,
137 function(a) { 137 function(a) {
138 with ({ b : 22 }) { return arguments[0] + b; } 138 with ({ b : 22 }) { return arguments[0] + b; }
139 }(20), 139 }(20),
140 "args in with"); 140 "args in with");
141 assertEquals(42, 141 assertEquals(42,
142 function(a) { 142 function(a) {
143 arguments[0] = 20; 143 arguments[0] = 20;
144 with ({ b : 22 }) { 144 with ({ b : 22 }) {
145 return function() { return a; }() + b; } 145 return function() { return a; }() + b; }
146 }(37), 146 }(37),
147 "captured a in with"); 147 "captured a in with");
148 assertEquals(42, 148 assertEquals(42,
149 function(a) { 149 function(a) {
150 arguments[0] = 12; 150 arguments[0] = 12;
151 with ({ b : 22 }) { 151 with ({ b : 22 }) {
152 return function f() { 152 return function f() {
153 try { throw 8 } catch(e) { return e + a }; 153 try { throw 8; } catch(e) { return e + a; }
154 }() + b; 154 }() + b;
Rico 2011/12/08 10:24:37 indention
155 } 155 }
156 }(37), 156 }(37),
157 "in a catch in a named function captured a in with "); 157 "in a catch in a named function captured a in with ");
158 // Escaping arguments. 158 // Escaping arguments.
159 function weirdargs(a,b,c) { if (!a) return arguments; 159 function weirdargs(a,b,c) { if (!a) return arguments;
Rico 2011/12/08 10:24:37 new line before function body
160 return [b[2],c]; } 160 return [b[2],c]; }
Rico 2011/12/08 10:24:37 move } down
161 var args1 = weirdargs(false, null, 40); 161 var args1 = weirdargs(false, null, 40);
162 var res = weirdargs(true, args1, 15); 162 var res = weirdargs(true, args1, 15);
163 assertEquals(40, res[0], "return old args element"); 163 assertEquals(40, res[0], "return old args element");
164 assertEquals(15, res[1], "return own args element"); 164 assertEquals(15, res[1], "return own args element");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698