svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1 | // Copyright 2011 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 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 28 | // Flags: --allow-natives-syntax |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 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 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 60 | function testArgumentCount(name, argc) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 61 | for (var i = 0; i < 10; i++) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 62 | var func = null; |
| 63 | try { |
| 64 | func = makeFunction(name, i); |
| 65 | } catch (e) { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 66 | if (e != "SyntaxError: Illegal access") throw e; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 67 | } |
| 68 | if (func === null && i == argc) { |
| 69 | throw "unexpected exception"; |
| 70 | } |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 71 | var args = [ ]; |
| 72 | for (var j = 0; j < i; j++) |
| 73 | args.push(0); |
| 74 | try { |
| 75 | func.apply(void 0, args); |
| 76 | } catch (e) { |
| 77 | // we don't care what happens as long as we don't crash |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | function testArgumentTypes(name, argc) { |
| 83 | var type = 0; |
| 84 | var hasMore = true; |
| 85 | var func = makeFunction(name, argc); |
| 86 | while (hasMore) { |
| 87 | var argPool = makeArguments(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 88 | // When we have 5 or more arguments we lower the amount of tests cases |
| 89 | // by randomly removing kOnManyArgumentsRemove entries |
| 90 | var numArguments = RUN_WITH_ALL_ARGUMENT_ENTRIES ? |
| 91 | kArgObjects : kArgObjects-kOnManyArgumentsRemove; |
| 92 | if (argc >= 5 && !RUN_WITH_ALL_ARGUMENT_ENTRIES) { |
| 93 | for (var i = 0; i < kOnManyArgumentsRemove; i++) { |
| 94 | var rand = Math.floor(Math.random() * (kArgObjects - i)); |
| 95 | argPool.splice(rand,1); |
| 96 | } |
| 97 | } |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 98 | var current = type; |
| 99 | var hasMore = false; |
| 100 | var argList = [ ]; |
| 101 | for (var i = 0; i < argc; i++) { |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 102 | var index = current % numArguments; |
| 103 | current = (current / numArguments) << 0; |
| 104 | if (index != (numArguments - 1)) |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 105 | hasMore = true; |
| 106 | argList.push(argPool[index]); |
| 107 | } |
| 108 | try { |
| 109 | func.apply(void 0, argList); |
| 110 | } catch (e) { |
| 111 | // we don't care what happens as long as we don't crash |
| 112 | } |
| 113 | type++; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | var knownProblems = { |
| 118 | "Abort": true, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 119 | |
| 120 | // Avoid calling the concat operation, because weird lengths |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 121 | // may lead to out-of-memory. Ditto for StringBuilderJoin. |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 122 | "StringBuilderConcat": true, |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 123 | "StringBuilderJoin": true, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 124 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 125 | // These functions use pseudo-stack-pointers and are not robust |
| 126 | // to unexpected integer values. |
| 127 | "DebugEvaluate": true, |
| 128 | |
| 129 | // These functions do nontrivial error checking in recursive calls, |
| 130 | // which means that we have to propagate errors back. |
| 131 | "SetFunctionBreakPoint": true, |
| 132 | "SetScriptBreakPoint": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 133 | "PrepareStep": true, |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 134 | |
| 135 | // Too slow. |
| 136 | "DebugReferencedBy": true, |
| 137 | |
| 138 | // Calling disable/enable access checks may interfere with the |
| 139 | // the rest of the tests. |
| 140 | "DisableAccessChecks": true, |
| 141 | "EnableAccessChecks": true, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 142 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 143 | // These functions should not be callable as runtime functions. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 144 | "NewFunctionContext": true, |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 145 | "NewArgumentsFast": true, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 146 | "NewStrictArgumentsFast": true, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 147 | "PushWithContext": true, |
| 148 | "PushCatchContext": true, |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 149 | "PushBlockContext": true, |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 150 | "PushModuleContext": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 151 | "LazyCompile": true, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 152 | "LazyRecompile": true, |
rossberg@chromium.org | 9259716 | 2013-08-23 13:28:00 +0000 | [diff] [blame] | 153 | "ConcurrentRecompile": true, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 154 | "NotifyDeoptimized": true, |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 155 | "NotifyStubFailure": true, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 156 | "NotifyOSR": true, |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 157 | "CreateObjectLiteralBoilerplate": true, |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 158 | "CloneLiteralBoilerplate": true, |
| 159 | "CloneShallowLiteralBoilerplate": true, |
| 160 | "CreateArrayLiteralBoilerplate": true, |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 161 | "IS_VAR": true, |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 162 | "ResolvePossiblyDirectEval": true, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 163 | "Log": true, |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 164 | "DeclareGlobals": true, |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 165 | "ArrayConstructor": true, |
| 166 | "InternalArrayConstructor": true, |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 167 | "SetAccessorProperty": true, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 168 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 169 | "PromoteScheduledException": true, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 170 | "DeleteHandleScopeExtensions": true, |
| 171 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 172 | // Vararg with minimum number > 0. |
| 173 | "Call": true, |
| 174 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 175 | // Requires integer arguments to be non-negative. |
| 176 | "Apply": true, |
| 177 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 178 | // That can only be invoked on Array.prototype. |
| 179 | "FinishArrayPrototypeSetup": true, |
| 180 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 181 | "_SwapElements": true, |
| 182 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 183 | // Performance critical functions which cannot afford type checks. |
| 184 | "_IsNativeOrStrictMode": true, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame] | 185 | "_CallFunction": true, |
| 186 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 187 | // Tries to allocate based on argument, and (correctly) throws |
| 188 | // out-of-memory if the request is too large. In practice, the |
| 189 | // size will be the number of captures of a RegExp. |
| 190 | "RegExpConstructResult": true, |
| 191 | "_RegExpConstructResult": true, |
| 192 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 193 | // This functions perform some checks compile time (they require one of their |
| 194 | // arguments to be a compile time smi). |
| 195 | "_DateField": true, |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 196 | "_GetFromCache": true, |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 197 | |
| 198 | // This function expects its first argument to be a non-smi. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 199 | "_IsStringWrapperSafeForDefaultValueOf" : true, |
| 200 | |
| 201 | // Only applicable to strings. |
| 202 | "_HasCachedArrayIndex": true, |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 203 | "_GetCachedArrayIndex": true, |
| 204 | "_OneByteSeqStringSetChar": true, |
| 205 | "_TwoByteSeqStringSetChar": true, |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 206 | |
| 207 | // Only applicable to generators. |
| 208 | "_GeneratorNext": true, |
| 209 | "_GeneratorThrow": true, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 210 | |
| 211 | // Only applicable to DataViews. |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 212 | "DataViewInitialize": true, |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 213 | "DataViewGetBuffer": true, |
| 214 | "DataViewGetByteLength": true, |
| 215 | "DataViewGetByteOffset": true |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | var currentlyUncallable = { |
| 219 | // We need to find a way to test this without breaking the system. |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 220 | "SystemBreak": true, |
| 221 | // Inserts an int3/stop instruction when run with --always-opt. |
| 222 | "_DebugBreakInOptimizedCode": true |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 223 | }; |
| 224 | |
| 225 | function testNatives() { |
| 226 | var allNatives = %ListNatives(); |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 227 | var start = allNatives.length >> 2; |
| 228 | var stop = (allNatives.length >> 2)*2; |
| 229 | for (var i = start; i < stop; i++) { |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 230 | var nativeInfo = allNatives[i]; |
| 231 | var name = nativeInfo[0]; |
| 232 | if (name in knownProblems || name in currentlyUncallable) |
| 233 | continue; |
| 234 | print(name); |
| 235 | var argc = nativeInfo[1]; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 236 | testArgumentCount(name, argc); |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 237 | testArgumentTypes(name, argc); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | testNatives(); |