Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var RUN_WITH_ALL_ARGUMENT_ENTRIES = false; | |
| 6 var kOnManyArgumentsRemove = 5; | |
| 7 | |
| 8 function makeArguments() { | |
| 9 var result = [ ]; | |
| 10 result.push(17); | |
| 11 result.push(-31); | |
| 12 result.push(new Array(100)); | |
| 13 result.push(new Array(100003)); | |
| 14 result.push(Number.MIN_VALUE); | |
| 15 result.push("whoops"); | |
| 16 result.push("x"); | |
| 17 result.push({"x": 1, "y": 2}); | |
| 18 var slowCaseObj = {"a": 3, "b": 4, "c": 5}; | |
| 19 delete slowCaseObj.c; | |
| 20 result.push(slowCaseObj); | |
| 21 result.push(function () { return 8; }); | |
| 22 return result; | |
| 23 } | |
| 24 | |
| 25 var kArgObjects = makeArguments().length; | |
| 26 | |
| 27 function makeFunction(name, argc) { | |
| 28 var args = []; | |
| 29 for (var i = 0; i < argc; i++) | |
| 30 args.push("x" + i); | |
| 31 var argsStr = args.join(", "); | |
| 32 return new Function(args.join(", "), | |
|
Michael Achenbach
2014/04/29 15:51:53
args.join(", ") == argsStr
Jakob Kummerow
2014/04/30 13:46:12
Done.
| |
| 33 "return %" + name + "(" + argsStr + ");"); | |
| 34 } | |
| 35 | |
| 36 function testArgumentCount(name, argc) { | |
| 37 for (var i = 0; i < 10; i++) { | |
|
Michael Achenbach
2014/04/29 15:51:53
Should we not better just loop until argc + 1?
| |
| 38 var func = null; | |
| 39 try { | |
| 40 func = makeFunction(name, i); | |
| 41 } catch (e) { | |
| 42 if (e != "SyntaxError: Illegal access") throw e; | |
| 43 } | |
| 44 if (func === null && i == argc) { | |
| 45 throw "unexpected exception"; | |
|
Michael Achenbach
2014/04/29 15:51:53
Could we not already "continue" in all other cases
| |
| 46 } | |
| 47 var args = [ ]; | |
| 48 for (var j = 0; j < i; j++) | |
| 49 args.push(0); | |
| 50 try { | |
| 51 func.apply(void 0, args); | |
| 52 } catch (e) { | |
| 53 // we don't care what happens as long as we don't crash | |
| 54 } | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 function testArgumentTypes(name, argc) { | |
| 59 var type = 0; | |
| 60 var hasMore = true; | |
| 61 var func = makeFunction(name, argc); | |
| 62 while (hasMore) { | |
| 63 var argPool = makeArguments(); | |
| 64 // When we have 5 or more arguments we lower the amount of tests cases | |
|
Michael Achenbach
2014/04/29 15:51:53
...which is always the case.
| |
| 65 // by randomly removing kOnManyArgumentsRemove entries | |
|
Michael Achenbach
2014/04/29 15:51:53
Wouldn't it be better to always choose, 5 instead
| |
| 66 var numArguments = RUN_WITH_ALL_ARGUMENT_ENTRIES ? | |
| 67 kArgObjects : kArgObjects-kOnManyArgumentsRemove; | |
|
Michael Achenbach
2014/04/29 15:51:53
nit: space around -
Jakob Kummerow
2014/04/30 13:46:12
Done.
| |
| 68 if (kArgObjects >= 5 && !RUN_WITH_ALL_ARGUMENT_ENTRIES) { | |
| 69 for (var i = 0; i < kOnManyArgumentsRemove; i++) { | |
| 70 var rand = Math.floor(Math.random() * (kArgObjects - i)); | |
|
Michael Achenbach
2014/04/29 15:51:53
Might be easier readable when calling repeatedly a
| |
| 71 argPool.splice(rand,1); | |
| 72 } | |
| 73 } | |
| 74 var current = type; | |
| 75 var hasMore = false; | |
|
Michael Achenbach
2014/04/29 15:51:53
var hasMore exists in the outer scope. Remove var?
Jakob Kummerow
2014/04/30 13:46:12
Done.
| |
| 76 var argList = [ ]; | |
| 77 for (var i = 0; i < argc; i++) { | |
|
Michael Achenbach
2014/04/29 15:51:53
Maybe add a TODO about improving the complexity, s
| |
| 78 var index = current % numArguments; | |
| 79 current = (current / numArguments) << 0; | |
| 80 if (index != (numArguments - 1)) | |
| 81 hasMore = true; | |
| 82 argList.push(argPool[index]); | |
| 83 } | |
| 84 try { | |
| 85 func.apply(void 0, argList); | |
| 86 } catch (e) { | |
| 87 // we don't care what happens as long as we don't crash | |
| 88 } | |
| 89 type++; | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 testArgumentCount(NAME, ARGC); | |
| 94 testArgumentTypes(NAME, ARGC); | |
| OLD | NEW |