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

Side by Side Diff: test/mjsunit/switch.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/substr.js ('k') | test/mjsunit/throw-exception-for-null-access.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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 function regress_string(value) { 155 function regress_string(value) {
156 var json = 1; 156 var json = 1;
157 switch (typeof value) { 157 switch (typeof value) {
158 case 'object': 158 case 'object':
159 break; 159 break;
160 160
161 default: 161 default:
162 162
163 } 163 }
164 return json; 164 return json;
165 }; 165 }
166 assertEquals(1, regress_string('object'), 'regression-string'); 166 assertEquals(1, regress_string('object'), 'regression-string');
167 167
168 function f5(x) { 168 function f5(x) {
169 switch(x) { 169 switch(x) {
170 case -2: return true; 170 case -2: return true;
171 case -1: return false; 171 case -1: return false;
172 case 0: return true; 172 case 0: return true;
173 case 2: return false; 173 case 2: return false;
174 default: return 42; 174 default: return 42;
175 } 175 }
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 } else if (feedback !== undefined) { 360 } else if (feedback !== undefined) {
361 // Target 361 // Target
362 fn(feedback); 362 fn(feedback);
363 } else { 363 } else {
364 // None 364 // None
365 } 365 }
366 366
367 if (optimize) %OptimizeFunctionOnNextCall(fn); 367 if (optimize) %OptimizeFunctionOnNextCall(fn);
368 368
369 return fn; 369 return fn;
370 }; 370 }
371 371
372 return opt(new Function( 372 return opt(new Function(
373 'tag', 373 'tag',
374 '"' + (test_id++) + '";' + 374 '"' + (test_id++) + '";' +
375 'switch(tag) {' + 375 'switch(tag) {' +
376 values.map(function(value) { 376 values.map(function(value) {
377 return 'case ' + JSON.stringify(value) + ': return' + 377 return 'case ' + JSON.stringify(value) + ': return' +
378 JSON.stringify('ok-' + value); 378 JSON.stringify('ok-' + value);
379 }).join(';') + 379 }).join(';') +
380 '}' 380 '}'
381 )); 381 ));
382 }; 382 }
383 383
384 function test_switch(clause_type, test_type, feedback, optimize) { 384 function test_switch(clause_type, test_type, feedback, optimize) {
385 var pairs = [], 385 var pairs = [],
386 fn = switch_gen(clause_type, feedback, optimize); 386 fn = switch_gen(clause_type, feedback, optimize);
387 387
388 if (Array.isArray(test_type)) { 388 if (Array.isArray(test_type)) {
389 pairs = test_type.map(function(v) { 389 pairs = test_type.map(function(v) {
390 return { 390 return {
391 value: v, 391 value: v,
392 expected: 'ok-' + v 392 expected: 'ok-' + v
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return { 424 return {
425 value: ((v * 17)/16) - ((v*17)%16/16), 425 value: ((v * 17)/16) - ((v*17)%16/16),
426 expected: clause_type !== 'string' ? 'ok-' + v : undefined 426 expected: clause_type !== 'string' ? 'ok-' + v : undefined
427 }; 427 };
428 }); 428 });
429 } 429 }
430 430
431 pairs.forEach(function(pair) { 431 pairs.forEach(function(pair) {
432 assertEquals(fn(pair.value), pair.expected); 432 assertEquals(fn(pair.value), pair.expected);
433 }); 433 });
434 }; 434 }
435 435
436 // test_switch(clause_type, test_type, feedback, optimize); 436 // test_switch(clause_type, test_type, feedback, optimize);
437 437
438 function test_switches(opt) { 438 function test_switches(opt) {
439 var test_types = ['symbols', 'strings', 'oddball', 'smi', 'heapnum']; 439 var test_types = ['symbols', 'strings', 'oddball', 'smi', 'heapnum'];
440 440
441 function test(clause_type) { 441 function test(clause_type) {
442 var values = clause_values[clause_type]; 442 var values = clause_values[clause_type];
443 443
444 test_types.forEach(function(test_type) { 444 test_types.forEach(function(test_type) {
445 test_switch(clause_type, test_type, 'all', opt); 445 test_switch(clause_type, test_type, 'all', opt);
446 test_switch(clause_type, test_type, 'none', opt); 446 test_switch(clause_type, test_type, 'none', opt);
447 447
448 // Targeting specific clause feedback 448 // Targeting specific clause feedback
449 values.forEach(function(value) { 449 values.forEach(function(value) {
450 test_switch(clause_type, test_type, [value], value, opt); 450 test_switch(clause_type, test_type, [value], value, opt);
451 test_switch(clause_type, test_type, value, value, opt); 451 test_switch(clause_type, test_type, value, value, opt);
452 }); 452 });
453 }); 453 });
454 }; 454 }
455 455
456 test('string'); 456 test('string');
457 test('smi'); 457 test('smi');
458 test('mixed'); 458 test('mixed');
459 }; 459 }
460 460
461 test_switches(false); 461 test_switches(false);
462 test_switches(true); 462 test_switches(true);
OLDNEW
« no previous file with comments | « test/mjsunit/substr.js ('k') | test/mjsunit/throw-exception-for-null-access.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698