ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2008 the V8 project authors. All rights reserved. |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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. |
| 27 | |
| 28 | // Flags: --allow-natives-syntax |
| 29 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 30 | var RUN_WITH_ALL_ARGUMENT_ENTRIES = false; |
| 31 | var kOnManyArgumentsRemove = 5; |
| 32 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 33 | function makeArguments() { |
| 34 | var result = [ ]; |
| 35 | result.push(17); |
| 36 | result.push(-31); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 37 | result.push(new Array(100)); |
| 38 | result.push(new Array(100003)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 39 | result.push(Number.MIN_VALUE); |
| 40 | result.push("whoops"); |
| 41 | result.push("x"); |
| 42 | result.push({"x": 1, "y": 2}); |
| 43 | var slowCaseObj = {"a": 3, "b": 4, "c": 5}; |
| 44 | delete slowCaseObj.c; |
| 45 | result.push(slowCaseObj); |
| 46 | result.push(function () { return 8; }); |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | var kArgObjects = makeArguments().length; |
| 51 | |
| 52 | function makeFunction(name, argc) { |
| 53 | var args = []; |
| 54 | for (var i = 0; i < argc; i++) |
| 55 | args.push("x" + i); |
| 56 | var argsStr = args.join(", "); |
| 57 | return new Function(args.join(", "), "return %" + name + "(" + argsStr + ");"); |
| 58 | } |
| 59 | |
| 60 | function testArgumentCount(name) { |
| 61 | for (var i = 0; i < 10; i++) { |
| 62 | var func = makeFunction(name, i); |
| 63 | var args = [ ]; |
| 64 | for (var j = 0; j < i; j++) |
| 65 | args.push(0); |
| 66 | try { |
| 67 | func.apply(void 0, args); |
| 68 | } catch (e) { |
| 69 | // we don't care what happens as long as we don't crash |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | function testArgumentTypes(name, argc) { |
| 75 | var type = 0; |
| 76 | var hasMore = true; |
| 77 | var func = makeFunction(name, argc); |
| 78 | while (hasMore) { |
| 79 | var argPool = makeArguments(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 80 | // When we have 5 or more arguments we lower the amount of tests cases |
| 81 | // by randomly removing kOnManyArgumentsRemove entries |
| 82 | var numArguments = RUN_WITH_ALL_ARGUMENT_ENTRIES ? |
| 83 | kArgObjects : kArgObjects-kOnManyArgumentsRemove; |
| 84 | if (argc >= 5 && !RUN_WITH_ALL_ARGUMENT_ENTRIES) { |
| 85 | for (var i = 0; i < kOnManyArgumentsRemove; i++) { |
| 86 | var rand = Math.floor(Math.random() * (kArgObjects - i)); |
| 87 | argPool.splice(rand,1); |
| 88 | } |
| 89 | } |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 90 | var current = type; |
| 91 | var hasMore = false; |
| 92 | var argList = [ ]; |
| 93 | for (var i = 0; i < argc; i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame^] | 94 | var index = current % numArguments; |
| 95 | current = (current / numArguments) << 0; |
| 96 | if (index != (numArguments - 1)) |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 97 | hasMore = true; |
| 98 | argList.push(argPool[index]); |
| 99 | } |
| 100 | try { |
| 101 | func.apply(void 0, argList); |
| 102 | } catch (e) { |
| 103 | // we don't care what happens as long as we don't crash |
| 104 | } |
| 105 | type++; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | var knownProblems = { |
| 110 | "Abort": true, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 111 | |
| 112 | // Avoid calling the concat operation, because weird lengths |
| 113 | // may lead to out-of-memory. |
| 114 | "StringBuilderConcat": true, |
| 115 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 116 | // These functions use pseudo-stack-pointers and are not robust |
| 117 | // to unexpected integer values. |
| 118 | "DebugEvaluate": true, |
| 119 | |
| 120 | // These functions do nontrivial error checking in recursive calls, |
| 121 | // which means that we have to propagate errors back. |
| 122 | "SetFunctionBreakPoint": true, |
| 123 | "SetScriptBreakPoint": true, |
| 124 | "ChangeBreakOnException": true, |
| 125 | "PrepareStep": true, |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 126 | |
| 127 | // Too slow. |
| 128 | "DebugReferencedBy": true, |
| 129 | |
| 130 | // Calling disable/enable access checks may interfere with the |
| 131 | // the rest of the tests. |
| 132 | "DisableAccessChecks": true, |
| 133 | "EnableAccessChecks": true, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 134 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 135 | // These functions should not be callable as runtime functions. |
| 136 | "NewContext": true, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 137 | "NewArgumentsFast": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 138 | "PushContext": true, |
| 139 | "LazyCompile": true, |
| 140 | "CreateObjectLiteralBoilerplate": true, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 141 | "CloneLiteralBoilerplate": true, |
| 142 | "CloneShallowLiteralBoilerplate": true, |
| 143 | "CreateArrayLiteralBoilerplate": true, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 144 | "IS_VAR": true, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 145 | "ResolvePossiblyDirectEval": true, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 146 | "Log": true, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 147 | "DeclareGlobals": true, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 148 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 149 | "PromoteScheduledException": true, |
| 150 | "DeleteHandleScopeExtensions": true |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | var currentlyUncallable = { |
| 154 | // We need to find a way to test this without breaking the system. |
| 155 | "SystemBreak": true |
| 156 | }; |
| 157 | |
| 158 | function testNatives() { |
| 159 | var allNatives = %ListNatives(); |
| 160 | for (var i = 0; i < allNatives.length; i++) { |
| 161 | var nativeInfo = allNatives[i]; |
| 162 | var name = nativeInfo[0]; |
| 163 | if (name in knownProblems || name in currentlyUncallable) |
| 164 | continue; |
| 165 | print(name); |
| 166 | var argc = nativeInfo[1]; |
| 167 | testArgumentCount(name); |
| 168 | testArgumentTypes(name, argc); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | testNatives(); |