blob: d906eb8a41ea9d00b870b8966b7a0d8c75fbb819 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2008 the V8 project authors. All rights reserved.
ager@chromium.orgc27e4e72008-09-04 13:52:27 +00002// 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
30function makeArguments() {
31 var result = [ ];
32 result.push(17);
33 result.push(-31);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +000034 result.push(new Array(100));
35 result.push(new Array(100003));
ager@chromium.orgc27e4e72008-09-04 13:52:27 +000036 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
47var kArgObjects = makeArguments().length;
48
49function 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
57function 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
71function 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
96var knownProblems = {
97 "Abort": true,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000098
99 // Avoid calling the concat operation, because weird lengths
100 // may lead to out-of-memory.
101 "StringBuilderConcat": true,
102
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000103 // These functions use pseudo-stack-pointers and are not robust
104 // to unexpected integer values.
105 "DebugEvaluate": true,
106
107 // These functions do nontrivial error checking in recursive calls,
108 // which means that we have to propagate errors back.
109 "SetFunctionBreakPoint": true,
110 "SetScriptBreakPoint": true,
111 "ChangeBreakOnException": true,
112 "PrepareStep": true,
ager@chromium.org870a0b62008-11-04 11:43:05 +0000113
114 // Too slow.
115 "DebugReferencedBy": true,
116
117 // Calling disable/enable access checks may interfere with the
118 // the rest of the tests.
119 "DisableAccessChecks": true,
120 "EnableAccessChecks": true,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000121
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000122 // These functions should not be callable as runtime functions.
123 "NewContext": true,
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000124 "NewArgumentsFast": true,
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000125 "PushContext": true,
126 "LazyCompile": true,
127 "CreateObjectLiteralBoilerplate": true,
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000128 "CloneLiteralBoilerplate": true,
129 "CloneShallowLiteralBoilerplate": true,
130 "CreateArrayLiteralBoilerplate": true,
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000131 "IS_VAR": true,
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000132 "ResolvePossiblyDirectEval": true,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000133 "Log": true,
ager@chromium.org3811b432009-10-28 14:53:37 +0000134 "DeclareGlobals": true,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000135
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000136 "PromoteScheduledException": true,
137 "DeleteHandleScopeExtensions": true
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000138};
139
140var currentlyUncallable = {
141 // We need to find a way to test this without breaking the system.
142 "SystemBreak": true
143};
144
145function testNatives() {
146 var allNatives = %ListNatives();
147 for (var i = 0; i < allNatives.length; i++) {
148 var nativeInfo = allNatives[i];
149 var name = nativeInfo[0];
150 if (name in knownProblems || name in currentlyUncallable)
151 continue;
152 print(name);
153 var argc = nativeInfo[1];
154 testArgumentCount(name);
155 testArgumentTypes(name, argc);
156 }
157}
158
159testNatives();