MCPcopy Create free account
hub / github.com/nodejs/node / switch_gen

Function switch_gen

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

Source from the content-addressed store, hash-verified

480 };
481
482function switch_gen(clause_type, feedback, optimize) {
483 var values = clause_values[clause_type];
484
485 function opt(fn) {
486 if (optimize) %PrepareFunctionForOptimization(fn);
487 if (feedback === 'all') {
488 values.forEach(fn);
489 } else if (Array.isArray(feedback)) {
490 // Non-target
491 values.filter(function(v) {
492 return feedback.indexOf(v) === -1;
493 }).forEach(fn);
494 } else if (feedback !== undefined) {
495 // Target
496 fn(feedback);
497 } else {
498 // None
499 }
500
501 if (optimize) %OptimizeFunctionOnNextCall(fn);
502
503 return fn;
504 };
505
506 return opt(new Function(
507 'tag',
508 '"' + (test_id++) + '";' +
509 'switch(tag) {' +
510 values.map(function(value) {
511 return 'case ' + JSON.stringify(value) + ': return' +
512 JSON.stringify('ok-' + value);
513 }).join(';') +
514 '}'
515 ));
516};
517
518function test_switch(clause_type, test_type, feedback, optimize) {
519 var pairs = [],

Callers 1

test_switchFunction · 0.85

Calls 3

optFunction · 0.70
mapMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected