blob: cb5bb74f7a5c25235381a6362f9a684497deccaf [file] [log] [blame]
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001// Copyright 2011 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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#ifndef V8_RUNTIME_H_
29#define V8_RUNTIME_H_
30
lrn@chromium.org1c092762011-05-09 09:42:16 +000031#include "allocation.h"
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +000032#include "zone.h"
33
kasperl@chromium.org71affb52009-05-26 05:44:31 +000034namespace v8 {
35namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000036
37// The interface to C++ runtime functions.
38
39// ----------------------------------------------------------------------------
kasper.lund44510672008-07-25 07:37:58 +000040// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
41// release and debug mode.
42// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000043
ager@chromium.orgce58e172009-05-13 07:11:48 +000044// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
45// MSVC Intellisense to crash. It was broken into two macros to work around
46// this problem. Please avoid large recursive macros whenever possible.
47#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000048 /* Property access */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +000049 F(GetProperty, 2, 1) \
50 F(KeyedGetProperty, 2, 1) \
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +000051 F(DeleteProperty, 3, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +000052 F(HasLocalProperty, 2, 1) \
53 F(HasProperty, 2, 1) \
54 F(HasElement, 2, 1) \
55 F(IsPropertyEnumerable, 2, 1) \
56 F(GetPropertyNames, 1, 1) \
57 F(GetPropertyNamesFast, 1, 1) \
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000058 F(GetLocalPropertyNames, 1, 1) \
59 F(GetLocalElementNames, 1, 1) \
60 F(GetInterceptorInfo, 1, 1) \
61 F(GetNamedInterceptorPropertyNames, 1, 1) \
62 F(GetIndexedInterceptorElementNames, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +000063 F(GetArgumentsProperty, 1, 1) \
64 F(ToFastProperties, 1, 1) \
65 F(ToSlowProperties, 1, 1) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +000066 F(FinishArrayPrototypeSetup, 1, 1) \
vegorov@chromium.orgf8372902010-03-15 10:26:20 +000067 F(SpecialArrayFunctions, 1, 1) \
ager@chromium.org357bf652010-04-12 11:30:10 +000068 F(GetGlobalReceiver, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069 \
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +000070 F(GetPrototype, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +000071 F(IsInPrototypeChain, 2, 1) \
72 F(SetHiddenPrototype, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000073 \
ager@chromium.orga1645e22009-09-09 19:27:10 +000074 F(IsConstructCall, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000075 \
fschneider@chromium.org0c20e672010-01-14 15:28:53 +000076 F(GetOwnProperty, 2, 1) \
77 \
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000078 F(IsExtensible, 1, 1) \
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000079 F(PreventExtensions, 1, 1)\
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000080 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000081 /* Utilities */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +000082 F(GetFunctionDelegate, 1, 1) \
83 F(GetConstructorDelegate, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +000084 F(NewArgumentsFast, 3, 1) \
85 F(LazyCompile, 1, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +000086 F(LazyRecompile, 1, 1) \
87 F(NotifyDeoptimized, 1, 1) \
88 F(NotifyOSR, 0, 1) \
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +000089 F(DeoptimizeFunction, 1, 1) \
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000090 F(RunningInSimulator, 0, 1) \
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +000091 F(OptimizeFunctionOnNextCall, 1, 1) \
lrn@chromium.org1c092762011-05-09 09:42:16 +000092 F(GetOptimizationStatus, 1, 1) \
93 F(GetOptimizationCount, 1, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +000094 F(CompileForOnStackReplacement, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +000095 F(SetNewFunctionAttributes, 1, 1) \
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +000096 F(AllocateInNewSpace, 1, 1) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +000097 F(SetNativeFlag, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000098 \
ager@chromium.org9258b6b2008-09-11 09:11:10 +000099 /* Array join support */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000100 F(PushIfAbsent, 2, 1) \
101 F(ArrayConcat, 1, 1) \
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000102 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000103 /* Conversions */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000104 F(ToBool, 1, 1) \
105 F(Typeof, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000106 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000107 F(StringToNumber, 1, 1) \
108 F(StringFromCharCodeArray, 1, 1) \
109 F(StringParseInt, 2, 1) \
110 F(StringParseFloat, 1, 1) \
111 F(StringToLowerCase, 1, 1) \
112 F(StringToUpperCase, 1, 1) \
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000113 F(StringSplit, 3, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000114 F(CharFromCode, 1, 1) \
115 F(URIEscape, 1, 1) \
116 F(URIUnescape, 1, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000117 F(QuoteJSONString, 1, 1) \
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000118 F(QuoteJSONStringComma, 1, 1) \
ricow@chromium.orgc54d3652011-05-30 09:20:16 +0000119 F(QuoteJSONStringArray, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000120 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000121 F(NumberToString, 1, 1) \
ager@chromium.org357bf652010-04-12 11:30:10 +0000122 F(NumberToStringSkipCache, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000123 F(NumberToInteger, 1, 1) \
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000124 F(NumberToIntegerMapMinusZero, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000125 F(NumberToJSUint32, 1, 1) \
126 F(NumberToJSInt32, 1, 1) \
127 F(NumberToSmi, 1, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000128 F(AllocateHeapNumber, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000129 \
130 /* Arithmetic operations */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000131 F(NumberAdd, 2, 1) \
132 F(NumberSub, 2, 1) \
133 F(NumberMul, 2, 1) \
134 F(NumberDiv, 2, 1) \
135 F(NumberMod, 2, 1) \
136 F(NumberUnaryMinus, 1, 1) \
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000137 F(NumberAlloc, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000138 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000139 F(StringAdd, 2, 1) \
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000140 F(StringBuilderConcat, 3, 1) \
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +0000141 F(StringBuilderJoin, 3, 1) \
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000142 F(SparseJoinWithSeparator, 3, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000143 \
144 /* Bit operations */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000145 F(NumberOr, 2, 1) \
146 F(NumberAnd, 2, 1) \
147 F(NumberXor, 2, 1) \
148 F(NumberNot, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000149 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000150 F(NumberShl, 2, 1) \
151 F(NumberShr, 2, 1) \
152 F(NumberSar, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000153 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154 /* Comparisons */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000155 F(NumberEquals, 2, 1) \
156 F(StringEquals, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000157 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000158 F(NumberCompare, 3, 1) \
159 F(SmiLexicographicCompare, 2, 1) \
160 F(StringCompare, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000161 \
162 /* Math */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000163 F(Math_acos, 1, 1) \
164 F(Math_asin, 1, 1) \
165 F(Math_atan, 1, 1) \
166 F(Math_atan2, 2, 1) \
167 F(Math_ceil, 1, 1) \
168 F(Math_cos, 1, 1) \
169 F(Math_exp, 1, 1) \
170 F(Math_floor, 1, 1) \
171 F(Math_log, 1, 1) \
172 F(Math_pow, 2, 1) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000173 F(Math_pow_cfunction, 2, 1) \
whesse@chromium.orgcec079d2010-03-22 14:44:04 +0000174 F(RoundNumber, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000175 F(Math_sin, 1, 1) \
176 F(Math_sqrt, 1, 1) \
177 F(Math_tan, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000178 \
179 /* Regular expressions */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000180 F(RegExpCompile, 3, 1) \
181 F(RegExpExec, 4, 1) \
lrn@chromium.org25156de2010-04-06 13:10:27 +0000182 F(RegExpExecMultiple, 4, 1) \
183 F(RegExpInitializeObject, 5, 1) \
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000184 F(RegExpConstructResult, 3, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185 \
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000186 /* JSON */ \
187 F(ParseJson, 1, 1) \
188 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000189 /* Strings */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000190 F(StringCharCodeAt, 2, 1) \
191 F(StringIndexOf, 3, 1) \
192 F(StringLastIndexOf, 3, 1) \
193 F(StringLocaleCompare, 2, 1) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000194 F(SubString, 3, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000195 F(StringReplaceRegExpWithString, 4, 1) \
196 F(StringMatch, 3, 1) \
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000197 F(StringTrim, 3, 1) \
ager@chromium.orgbeb25712010-11-29 08:02:25 +0000198 F(StringToArray, 2, 1) \
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000199 F(NewStringWrapper, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000200 \
201 /* Numbers */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000202 F(NumberToRadixString, 2, 1) \
203 F(NumberToFixed, 2, 1) \
204 F(NumberToExponential, 2, 1) \
205 F(NumberToPrecision, 2, 1)
ager@chromium.orgce58e172009-05-13 07:11:48 +0000206
207#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000208 /* Reflection */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000209 F(FunctionSetInstanceClassName, 2, 1) \
210 F(FunctionSetLength, 2, 1) \
211 F(FunctionSetPrototype, 2, 1) \
212 F(FunctionGetName, 1, 1) \
213 F(FunctionSetName, 2, 1) \
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000214 F(FunctionRemovePrototype, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000215 F(FunctionGetSourceCode, 1, 1) \
216 F(FunctionGetScript, 1, 1) \
217 F(FunctionGetScriptSourcePosition, 1, 1) \
218 F(FunctionGetPositionForOffset, 2, 1) \
219 F(FunctionIsAPIFunction, 1, 1) \
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +0000220 F(FunctionIsBuiltin, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000221 F(GetScript, 1, 1) \
222 F(CollectStackTrace, 2, 1) \
ager@chromium.org3811b432009-10-28 14:53:37 +0000223 F(GetV8Version, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000224 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000225 F(ClassOf, 1, 1) \
226 F(SetCode, 2, 1) \
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000227 F(SetExpectedNumberOfProperties, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000228 \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000229 F(CreateApiFunction, 1, 1) \
230 F(IsTemplate, 1, 1) \
231 F(GetTemplateField, 2, 1) \
232 F(DisableAccessChecks, 1, 1) \
233 F(EnableAccessChecks, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000234 \
235 /* Dates */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000236 F(DateCurrentTime, 0, 1) \
237 F(DateParseString, 2, 1) \
238 F(DateLocalTimezone, 1, 1) \
239 F(DateLocalTimeOffset, 0, 1) \
240 F(DateDaylightSavingsOffset, 1, 1) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000241 F(DateMakeDay, 3, 1) \
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000242 F(DateYMDFromTime, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000243 \
244 /* Numbers */ \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000245 \
246 /* Globals */ \
fschneider@chromium.orge03fb642010-11-01 12:34:09 +0000247 F(CompileString, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000248 F(GlobalPrint, 1, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000249 \
250 /* Eval */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000251 F(GlobalReceiver, 1, 1) \
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000252 F(ResolvePossiblyDirectEval, 4, 2) \
253 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000254 \
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000255 F(SetProperty, -1 /* 4 or 5 */, 1) \
ager@chromium.org5c838252010-02-19 08:53:10 +0000256 F(DefineOrRedefineDataProperty, 4, 1) \
257 F(DefineOrRedefineAccessorProperty, 5, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000258 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000259 \
260 /* Arrays */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000261 F(RemoveArrayHoles, 2, 1) \
262 F(GetArrayKeys, 2, 1) \
263 F(MoveArrayContents, 2, 1) \
264 F(EstimateNumberOfElements, 1, 1) \
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000265 F(SwapElements, 3, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000266 \
267 /* Getters and Setters */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000268 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
269 F(LookupAccessor, 3, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000270 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000271 /* Literals */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000272 F(MaterializeRegExpLiteral, 4, 1)\
273 F(CreateArrayLiteralBoilerplate, 3, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000274 F(CloneLiteralBoilerplate, 1, 1) \
275 F(CloneShallowLiteralBoilerplate, 1, 1) \
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000276 F(CreateObjectLiteral, 4, 1) \
277 F(CreateObjectLiteralShallow, 4, 1) \
kmillikin@chromium.org13bd2942009-12-16 15:36:05 +0000278 F(CreateArrayLiteral, 3, 1) \
279 F(CreateArrayLiteralShallow, 3, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000280 \
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000281 /* Harmony proxies */ \
282 F(CreateJSProxy, 2, 1) \
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +0000283 F(IsJSProxy, 1, 1) \
284 F(GetHandler, 1, 1) \
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000285 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000286 /* Statements */ \
vegorov@chromium.org21b5e952010-11-23 10:24:40 +0000287 F(NewClosure, 3, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000288 F(NewObject, 1, 1) \
whesse@chromium.orgba5a61b2010-07-26 11:44:40 +0000289 F(NewObjectFromBound, 2, 1) \
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000290 F(FinalizeInstanceSize, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000291 F(Throw, 1, 1) \
292 F(ReThrow, 1, 1) \
293 F(ThrowReferenceError, 1, 1) \
whesse@chromium.org4a5224e2010-10-20 12:37:07 +0000294 F(StackGuard, 0, 1) \
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000295 F(PromoteScheduledException, 0, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000296 \
297 /* Contexts */ \
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000298 F(NewFunctionContext, 1, 1) \
299 F(PushWithContext, 1, 1) \
300 F(PushCatchContext, 2, 1) \
ager@chromium.org0ee099b2011-01-25 14:06:47 +0000301 F(DeleteContextSlot, 2, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000302 F(LoadContextSlot, 2, 2) \
303 F(LoadContextSlotNoReferenceError, 2, 2) \
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000304 F(StoreContextSlot, 4, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000305 \
306 /* Declarations and initialization */ \
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000307 F(DeclareGlobals, 4, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000308 F(DeclareContextSlot, 4, 1) \
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000309 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000310 F(InitializeConstGlobal, 2, 1) \
311 F(InitializeConstContextSlot, 3, 1) \
312 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000313 \
314 /* Debugging */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000315 F(DebugPrint, 1, 1) \
316 F(DebugTrace, 0, 1) \
317 F(TraceEnter, 0, 1) \
318 F(TraceExit, 1, 1) \
319 F(Abort, 2, 1) \
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000320 /* Logging */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000321 F(Log, 2, 1) \
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +0000322 /* ES5 */ \
323 F(LocalKeys, 1, 1) \
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000324 /* Cache suport */ \
325 F(GetFromCache, 2, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000326 \
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000327 /* Message objects */ \
328 F(NewMessageObject, 2, 1) \
329 F(MessageGetType, 1, 1) \
330 F(MessageGetArguments, 1, 1) \
331 F(MessageGetStartPosition, 1, 1) \
332 F(MessageGetScript, 1, 1) \
333 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000334 /* Pseudo functions - handled as macros by parser */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000335 F(IS_VAR, 1, 1)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000336
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000337#ifdef ENABLE_DEBUGGER_SUPPORT
338#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
339 /* Debugger support*/ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000340 F(DebugBreak, 0, 1) \
341 F(SetDebugEventListener, 2, 1) \
342 F(Break, 0, 1) \
343 F(DebugGetPropertyDetails, 2, 1) \
344 F(DebugGetProperty, 2, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000345 F(DebugPropertyTypeFromDetails, 1, 1) \
346 F(DebugPropertyAttributesFromDetails, 1, 1) \
347 F(DebugPropertyIndexFromDetails, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000348 F(DebugNamedInterceptorPropertyValue, 2, 1) \
349 F(DebugIndexedInterceptorElementValue, 2, 1) \
350 F(CheckExecutionState, 1, 1) \
351 F(GetFrameCount, 1, 1) \
352 F(GetFrameDetails, 2, 1) \
353 F(GetScopeCount, 2, 1) \
354 F(GetScopeDetails, 3, 1) \
355 F(DebugPrintScopes, 0, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000356 F(GetThreadCount, 1, 1) \
357 F(GetThreadDetails, 2, 1) \
whesse@chromium.orge90029b2010-08-02 11:52:17 +0000358 F(SetDisableBreak, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000359 F(GetBreakLocations, 1, 1) \
360 F(SetFunctionBreakPoint, 3, 1) \
361 F(SetScriptBreakPoint, 3, 1) \
362 F(ClearBreakPoint, 1, 1) \
363 F(ChangeBreakOnException, 2, 1) \
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +0000364 F(IsBreakOnException, 1, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000365 F(PrepareStep, 3, 1) \
366 F(ClearStepping, 0, 1) \
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000367 F(DebugEvaluate, 5, 1) \
368 F(DebugEvaluateGlobal, 4, 1) \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000369 F(DebugGetLoadedScripts, 0, 1) \
370 F(DebugReferencedBy, 3, 1) \
371 F(DebugConstructedBy, 2, 1) \
372 F(DebugGetPrototype, 1, 1) \
373 F(SystemBreak, 0, 1) \
374 F(DebugDisassembleFunction, 1, 1) \
375 F(DebugDisassembleConstructor, 1, 1) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000376 F(FunctionGetInferredName, 1, 1) \
377 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
378 F(LiveEditGatherCompileInfo, 2, 1) \
379 F(LiveEditReplaceScript, 3, 1) \
380 F(LiveEditReplaceFunctionCode, 2, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000381 F(LiveEditFunctionSourceUpdated, 1, 1) \
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000382 F(LiveEditFunctionSetScript, 2, 1) \
383 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000384 F(LiveEditPatchFunctionPositions, 2, 1) \
ager@chromium.org357bf652010-04-12 11:30:10 +0000385 F(LiveEditCheckAndDropActivations, 2, 1) \
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +0000386 F(LiveEditCompareStrings, 2, 1) \
ager@chromium.org357bf652010-04-12 11:30:10 +0000387 F(GetFunctionCodePositionFromSource, 2, 1) \
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000388 F(ExecuteInDebugContext, 2, 1) \
389 \
390 F(SetFlags, 1, 1) \
391 F(CollectGarbage, 1, 1) \
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000392 F(GetHeapUsage, 0, 1) \
393 \
394 /* LiveObjectList support*/ \
395 F(HasLOLEnabled, 0, 1) \
396 F(CaptureLOL, 0, 1) \
397 F(DeleteLOL, 1, 1) \
398 F(DumpLOL, 5, 1) \
399 F(GetLOLObj, 1, 1) \
400 F(GetLOLObjId, 1, 1) \
401 F(GetLOLObjRetainers, 6, 1) \
402 F(GetLOLPath, 3, 1) \
403 F(InfoLOL, 2, 1) \
404 F(PrintLOLObj, 1, 1) \
405 F(ResetLOL, 0, 1) \
406 F(SummarizeLOL, 3, 1)
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000407
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000408#else
409#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
410#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000411
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000412#ifdef ENABLE_LOGGING_AND_PROFILING
413#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
ager@chromium.org5c838252010-02-19 08:53:10 +0000414 F(ProfilerResume, 2, 1) \
415 F(ProfilerPause, 2, 1)
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000416#else
417#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
418#endif
419
kasper.lund44510672008-07-25 07:37:58 +0000420#ifdef DEBUG
421#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
422 /* Testing */ \
ager@chromium.orga1645e22009-09-09 19:27:10 +0000423 F(ListNatives, 0, 1)
kasper.lund44510672008-07-25 07:37:58 +0000424#else
425#define RUNTIME_FUNCTION_LIST_DEBUG(F)
426#endif
427
kasper.lund44510672008-07-25 07:37:58 +0000428// ----------------------------------------------------------------------------
429// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
430// either directly by id (via the code generator), or indirectly
431// via a native call by name (from within JS code).
432
433#define RUNTIME_FUNCTION_LIST(F) \
ager@chromium.orgce58e172009-05-13 07:11:48 +0000434 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
435 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000436 RUNTIME_FUNCTION_LIST_DEBUG(F) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000437 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
438 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
kasper.lund44510672008-07-25 07:37:58 +0000439
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000440// ----------------------------------------------------------------------------
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000441// INLINE_FUNCTION_LIST defines all inlined functions accessed
442// with a native call of the form %_name from within JS code.
443// Entries have the form F(name, number of arguments, number of return values).
444#define INLINE_FUNCTION_LIST(F) \
445 F(IsSmi, 1, 1) \
446 F(IsNonNegativeSmi, 1, 1) \
447 F(IsArray, 1, 1) \
448 F(IsRegExp, 1, 1) \
449 F(CallFunction, -1 /* receiver + n args + function */, 1) \
450 F(ArgumentsLength, 0, 1) \
451 F(Arguments, 1, 1) \
452 F(ValueOf, 1, 1) \
453 F(SetValueOf, 2, 1) \
454 F(StringCharFromCode, 1, 1) \
455 F(StringCharAt, 2, 1) \
456 F(ObjectEquals, 2, 1) \
457 F(RandomHeapNumber, 0, 1) \
458 F(IsObject, 1, 1) \
459 F(IsFunction, 1, 1) \
460 F(IsUndetectableObject, 1, 1) \
461 F(IsSpecObject, 1, 1) \
462 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
463 F(MathPow, 2, 1) \
464 F(MathSin, 1, 1) \
465 F(MathCos, 1, 1) \
466 F(MathSqrt, 1, 1) \
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000467 F(MathLog, 1, 1) \
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000468 F(IsRegExpEquivalent, 2, 1) \
469 F(HasCachedArrayIndex, 1, 1) \
vegorov@chromium.org21b5e952010-11-23 10:24:40 +0000470 F(GetCachedArrayIndex, 1, 1) \
471 F(FastAsciiArrayJoin, 2, 1)
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000472
473
474// ----------------------------------------------------------------------------
475// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
476// with a native call of the form %_name from within JS code that also have
lrn@chromium.orgfa943b72010-11-03 08:14:36 +0000477// a corresponding runtime function, that is called for slow cases.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000478// Entries have the form F(name, number of arguments, number of return values).
479#define INLINE_RUNTIME_FUNCTION_LIST(F) \
480 F(IsConstructCall, 0, 1) \
481 F(ClassOf, 1, 1) \
482 F(StringCharCodeAt, 2, 1) \
483 F(Log, 3, 1) \
484 F(StringAdd, 2, 1) \
485 F(SubString, 3, 1) \
486 F(StringCompare, 2, 1) \
487 F(RegExpExec, 4, 1) \
488 F(RegExpConstructResult, 3, 1) \
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000489 F(GetFromCache, 2, 1) \
490 F(NumberToString, 1, 1) \
491 F(SwapElements, 3, 1)
492
493
494//---------------------------------------------------------------------------
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000495// Runtime provides access to all C++ runtime functions.
496
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000497class RuntimeState {
498 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000499 StaticResource<StringInputBuffer>* string_input_buffer() {
500 return &string_input_buffer_;
501 }
502 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
503 return &to_upper_mapping_;
504 }
505 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
506 return &to_lower_mapping_;
507 }
508 StringInputBuffer* string_input_buffer_compare_bufx() {
509 return &string_input_buffer_compare_bufx_;
510 }
511 StringInputBuffer* string_input_buffer_compare_bufy() {
512 return &string_input_buffer_compare_bufy_;
513 }
514 StringInputBuffer* string_locale_compare_buf1() {
515 return &string_locale_compare_buf1_;
516 }
517 StringInputBuffer* string_locale_compare_buf2() {
518 return &string_locale_compare_buf2_;
519 }
520 int* smi_lexicographic_compare_x_elms() {
521 return smi_lexicographic_compare_x_elms_;
522 }
523 int* smi_lexicographic_compare_y_elms() {
524 return smi_lexicographic_compare_y_elms_;
525 }
526
527 private:
528 RuntimeState() {}
529 // Non-reentrant string buffer for efficient general use in the runtime.
530 StaticResource<StringInputBuffer> string_input_buffer_;
531 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
532 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
533 StringInputBuffer string_input_buffer_compare_bufx_;
534 StringInputBuffer string_input_buffer_compare_bufy_;
535 StringInputBuffer string_locale_compare_buf1_;
536 StringInputBuffer string_locale_compare_buf2_;
537 int smi_lexicographic_compare_x_elms_[10];
538 int smi_lexicographic_compare_y_elms_[10];
539
540 friend class Isolate;
541 friend class Runtime;
542
543 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
544};
545
546
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000547class Runtime : public AllStatic {
548 public:
549 enum FunctionId {
ager@chromium.orga1645e22009-09-09 19:27:10 +0000550#define F(name, nargs, ressize) k##name,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000551 RUNTIME_FUNCTION_LIST(F)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000552#undef F
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000553#define F(name, nargs, ressize) kInline##name,
554 INLINE_FUNCTION_LIST(F)
555 INLINE_RUNTIME_FUNCTION_LIST(F)
556#undef F
557 kNumFunctions,
558 kFirstInlineFunction = kInlineIsSmi
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000559 };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000560
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000561 enum IntrinsicType {
562 RUNTIME,
563 INLINE
564 };
565
566 // Intrinsic function descriptor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000567 struct Function {
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000568 FunctionId function_id;
569 IntrinsicType intrinsic_type;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000570 // The JS name of the function.
571 const char* name;
572
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000573 // The C++ (native) entry point. NULL if the function is inlined.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000574 byte* entry;
575
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000576 // The number of arguments expected. nargs is -1 if the function takes
577 // a variable number of arguments.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000578 int nargs;
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000579 // Size of result. Most functions return a single pointer, size 1.
ager@chromium.orga1645e22009-09-09 19:27:10 +0000580 int result_size;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000581 };
582
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000583 static const int kNotFound = -1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000584
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000585 // Add symbols for all the intrinsic function names to a StringDictionary.
586 // Returns failure if an allocation fails. In this case, it must be
587 // retried with a new, empty StringDictionary, not with the same one.
588 // Alternatively, heap initialization can be completely restarted.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000589 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000590 Heap* heap, Object* dictionary);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000591
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000592 // Get the intrinsic function with the given name, which must be a symbol.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000593 static const Function* FunctionForSymbol(Handle<String> name);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000594
595 // Get the intrinsic function with the given FunctionId.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000596 static const Function* FunctionForId(FunctionId id);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000597
598 // General-purpose helper functions for runtime system.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000599 static int StringMatch(Isolate* isolate,
600 Handle<String> sub,
601 Handle<String> pat,
602 int index);
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000603
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000604 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +0000605
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000606 // TODO(1240886): The following three methods are *not* handle safe,
607 // but accept handle arguments. This seems fragile.
608
609 // Support getting the characters in a string using [] notation as
610 // in Firefox/SpiderMonkey, Safari and Opera.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000611 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
612 Handle<Object> object,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000613 uint32_t index);
614 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
615 uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000616
lrn@chromium.org303ada72010-10-27 09:33:13 +0000617 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000618 Isolate* isolate,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000619 Handle<Object> object,
620 Handle<Object> key,
621 Handle<Object> value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000622 PropertyAttributes attr,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +0000623 StrictModeFlag strict_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000624
lrn@chromium.org303ada72010-10-27 09:33:13 +0000625 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000626 Isolate* isolate,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000627 Handle<JSObject> object,
628 Handle<Object> key,
629 Handle<Object> value,
630 PropertyAttributes attr);
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000631
lrn@chromium.org303ada72010-10-27 09:33:13 +0000632 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000633 Isolate* isolate,
lrn@chromium.org303ada72010-10-27 09:33:13 +0000634 Handle<JSObject> object,
635 Handle<Object> key);
ager@chromium.orge2902be2009-06-08 12:21:35 +0000636
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000637 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
638 Isolate* isolate,
639 Handle<Object> object,
640 Handle<Object> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000641
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +0000642 // This function is used in FunctionNameUsing* tests.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000643 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
644 Handle<Script> script,
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +0000645 int position);
646
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000647 // Helper functions used stubs.
648 static void PerformGC(Object* result);
649};
650
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000651} } // namespace v8::internal
652
653#endif // V8_RUNTIME_H_