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

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: Address review comments 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
« no previous file with comments | « test/mjsunit/arguments-escape.js ('k') | test/mjsunit/array-concat.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 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],
31 "return arguments value"); 31 "return arguments value");
32 assertEquals(42, function(){ return arguments;}(42)[0], 32 assertEquals(42, function(){ return arguments; }(42)[0],
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; }(),
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],
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],
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; }(),
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),
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 function(){ 114 function(){
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,
125 arguments[1] = 11; 125 function(a,b) {
126 return a + function(){ a = b; return a; }() + a; 126 arguments[1] = 11;
127 }(20, 37), "captured assignment"); 127 return a + function(){ a = b; return a; }() + a;
128 }(20, 37),
129 "captured assignment");
128 130
129 // Inside non-function scopes. 131 // Inside non-function scopes.
130 assertEquals(42, 132 assertEquals(42,
131 function(a) { 133 function(a) {
132 arguments[0] = 20; 134 arguments[0] = 20;
133 with ({ b : 22 }) { return a + b; } 135 with ({ b : 22 }) { return a + b; }
134 }(37), 136 }(37),
135 "a in with"); 137 "a in with");
136 assertEquals(42, 138 assertEquals(42,
137 function(a) { 139 function(a) {
138 with ({ b : 22 }) { return arguments[0] + b; } 140 with ({ b : 22 }) { return arguments[0] + b; }
139 }(20), 141 }(20),
140 "args in with"); 142 "args in with");
141 assertEquals(42, 143 assertEquals(42,
142 function(a) { 144 function(a) {
143 arguments[0] = 20; 145 arguments[0] = 20;
144 with ({ b : 22 }) { 146 with ({ b : 22 }) {
145 return function() { return a; }() + b; } 147 return function() { return a; }() + b; }
146 }(37), 148 }(37),
147 "captured a in with"); 149 "captured a in with");
148 assertEquals(42, 150 assertEquals(42,
149 function(a) { 151 function(a) {
150 arguments[0] = 12; 152 arguments[0] = 12;
151 with ({ b : 22 }) { 153 with ({ b : 22 }) {
152 return function f() { 154 return function f() {
153 try { throw 8 } catch(e) { return e + a }; 155 try { throw 8; } catch(e) { return e + a; }
154 }() + b; 156 }() + b;
155 } 157 }
156 }(37), 158 }(37),
157 "in a catch in a named function captured a in with "); 159 "in a catch in a named function captured a in with ");
158 // Escaping arguments. 160 // Escaping arguments.
159 function weirdargs(a,b,c) { if (!a) return arguments; 161 function weirdargs(a, b, c) {
160 return [b[2],c]; } 162 if (!a) return arguments;
163 return [b[2],c];
164 }
161 var args1 = weirdargs(false, null, 40); 165 var args1 = weirdargs(false, null, 40);
162 var res = weirdargs(true, args1, 15); 166 var res = weirdargs(true, args1, 15);
163 assertEquals(40, res[0], "return old args element"); 167 assertEquals(40, res[0], "return old args element");
164 assertEquals(15, res[1], "return own args element"); 168 assertEquals(15, res[1], "return own args element");
OLDNEW
« no previous file with comments | « test/mjsunit/arguments-escape.js ('k') | test/mjsunit/array-concat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698