MCPcopy Index your code
hub / github.com/nodejs/node / test_switch

Function test_switch

deps/v8/test/mjsunit/switch.js:518–568  ·  view source on GitHub ↗
(clause_type, test_type, feedback, optimize)

Source from the content-addressed store, hash-verified

516};
517
518function test_switch(clause_type, test_type, feedback, optimize) {
519 var pairs = [],
520 fn = switch_gen(clause_type, feedback, optimize);
521
522 if (Array.isArray(test_type)) {
523 pairs = test_type.map(function(v) {
524 return {
525 value: v,
526 expected: 'ok-' + v
527 };
528 });
529 } else if (test_type === 'symbols') {
530 pairs = clause_values.string.map(function(v) {
531 return {
532 value: v,
533 expected: clause_type !== 'smi' ? 'ok-' + v : undefined
534 };
535 });
536 } else if (test_type === 'strings') {
537 pairs = clause_values.string.map(function(v) {
538 return {
539 value: ('%%' + v).slice(2),
540 expected: clause_type !== 'smi' ? 'ok-' + v : undefined
541 };
542 });
543 } else if (test_type === 'oddball') {
544 pairs = [
545 { value: null, expected: undefined },
546 { value: NaN, expected: undefined },
547 { value: undefined, expected: undefined }
548 ];
549 } else if (test_type === 'smi') {
550 pairs = clause_values.smi.map(function(v) {
551 return {
552 value: v,
553 expected: clause_type !== 'string' ? 'ok-' + v : undefined
554 };
555 });
556 } else if (test_type === 'heapnum') {
557 pairs = clause_values.smi.map(function(v) {
558 return {
559 value: ((v * 17)/16) - ((v*17)%16/16),
560 expected: clause_type !== 'string' ? 'ok-' + v : undefined
561 };
562 });
563 }
564
565 pairs.forEach(function(pair) {
566 assertEquals(fn(pair.value), pair.expected);
567 });
568};
569
570// test_switch(clause_type, test_type, feedback, optimize);
571

Callers 1

testFunction · 0.85

Calls 6

switch_genFunction · 0.85
fnFunction · 0.70
mapMethod · 0.65
sliceMethod · 0.65
forEachMethod · 0.65
assertEqualsFunction · 0.50

Tested by 1

testFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…