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 | |
| 30 | function makeArguments() { |
| 31 | var result = [ ]; |
| 32 | result.push(17); |
| 33 | result.push(-31); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 34 | result.push(new Array(100)); |
| 35 | result.push(new Array(100003)); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 36 | result.push(Number.MIN_VALUE); |
| 37 | result.push("whoops"); |
| 38 | result.push("x"); |
| 39 | result.push({"x": 1, "y": 2}); |
| 40 | var slowCaseObj = {"a": 3, "b": 4, "c": 5}; |
| 41 | delete slowCaseObj.c; |
| 42 | result.push(slowCaseObj); |
| 43 | result.push(function () { return 8; }); |
| 44 | return result; |
| 45 | } |
| 46 | |
| 47 | var kArgObjects = makeArguments().length; |
| 48 | |
| 49 | function makeFunction(name, argc) { |
| 50 | var args = []; |
| 51 | for (var i = 0; i < argc; i++) |
| 52 | args.push("x" + i); |
| 53 | var argsStr = args.join(", "); |
| 54 | return new Function(args.join(", "), "return %" + name + "(" + argsStr + ");"); |
| 55 | } |
| 56 | |
| 57 | function testArgumentCount(name) { |
| 58 | for (var i = 0; i < 10; i++) { |
| 59 | var func = makeFunction(name, i); |
| 60 | var args = [ ]; |
| 61 | for (var j = 0; j < i; j++) |
| 62 | args.push(0); |
| 63 | try { |
| 64 | func.apply(void 0, args); |
| 65 | } catch (e) { |
| 66 | // we don't care what happens as long as we don't crash |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | function testArgumentTypes(name, argc) { |
| 72 | var type = 0; |
| 73 | var hasMore = true; |
| 74 | var func = makeFunction(name, argc); |
| 75 | while (hasMore) { |
| 76 | var argPool = makeArguments(); |
| 77 | var current = type; |
| 78 | var hasMore = false; |
| 79 | var argList = [ ]; |
| 80 | for (var i = 0; i < argc; i++) { |
| 81 | var index = current % kArgObjects; |
| 82 | current = (current / kArgObjects) << 0; |
| 83 | if (index != (kArgObjects - 1)) |
| 84 | hasMore = true; |
| 85 | argList.push(argPool[index]); |
| 86 | } |
| 87 | try { |
| 88 | func.apply(void 0, argList); |
| 89 | } catch (e) { |
| 90 | // we don't care what happens as long as we don't crash |
| 91 | } |
| 92 | type++; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | var knownProblems = { |
| 97 | "Abort": true, |
| 98 | |
| 99 | // These functions use pseudo-stack-pointers and are not robust |
| 100 | // to unexpected integer values. |
| 101 | "DebugEvaluate": true, |
| 102 | |
| 103 | // These functions do nontrivial error checking in recursive calls, |
| 104 | // which means that we have to propagate errors back. |
| 105 | "SetFunctionBreakPoint": true, |
| 106 | "SetScriptBreakPoint": true, |
| 107 | "ChangeBreakOnException": true, |
| 108 | "PrepareStep": true, |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 109 | |
| 110 | // Too slow. |
| 111 | "DebugReferencedBy": true, |
| 112 | |
| 113 | // Calling disable/enable access checks may interfere with the |
| 114 | // the rest of the tests. |
| 115 | "DisableAccessChecks": true, |
| 116 | "EnableAccessChecks": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 117 | |
| 118 | // These functions should not be callable as runtime functions. |
| 119 | "NewContext": true, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 120 | "NewArgumentsFast": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 121 | "PushContext": true, |
| 122 | "LazyCompile": true, |
| 123 | "CreateObjectLiteralBoilerplate": true, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 124 | "CloneLiteralBoilerplate": true, |
| 125 | "CloneShallowLiteralBoilerplate": true, |
| 126 | "CreateArrayLiteralBoilerplate": true, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 127 | "IS_VAR": true, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 128 | "ResolvePossiblyDirectEval": true, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame^] | 129 | "Log": true, |
| 130 | |
| 131 | "CollectStackTrace": true |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | var currentlyUncallable = { |
| 135 | // We need to find a way to test this without breaking the system. |
| 136 | "SystemBreak": true |
| 137 | }; |
| 138 | |
| 139 | function testNatives() { |
| 140 | var allNatives = %ListNatives(); |
| 141 | for (var i = 0; i < allNatives.length; i++) { |
| 142 | var nativeInfo = allNatives[i]; |
| 143 | var name = nativeInfo[0]; |
| 144 | if (name in knownProblems || name in currentlyUncallable) |
| 145 | continue; |
| 146 | print(name); |
| 147 | var argc = nativeInfo[1]; |
| 148 | testArgumentCount(name); |
| 149 | testArgumentTypes(name, argc); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | testNatives(); |