blob: 1538b7d84656579659f09c33974016c79ed1d309 [file] [log] [blame]
Ben Murdoch85b71792012-04-11 18:30:58 +01001// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +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
Ben Murdoch257744e2011-11-30 15:57:28 +000031#include "allocation.h"
Steve Block44f0eee2011-05-26 01:26:41 +010032#include "zone.h"
33
Steve Blocka7e24c12009-10-30 11:49:00 +000034namespace v8 {
35namespace internal {
36
37// The interface to C++ runtime functions.
38
39// ----------------------------------------------------------------------------
40// 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.
43
44// 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) \
48 /* Property access */ \
49 F(GetProperty, 2, 1) \
50 F(KeyedGetProperty, 2, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +010051 F(DeleteProperty, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +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) \
Leon Clarkee46be812010-01-19 14:06:41 +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) \
Steve Blocka7e24c12009-10-30 11:49:00 +000063 F(GetArgumentsProperty, 1, 1) \
64 F(ToFastProperties, 1, 1) \
65 F(ToSlowProperties, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +010066 F(FinishArrayPrototypeSetup, 1, 1) \
67 F(SpecialArrayFunctions, 1, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +000068 F(GetDefaultReceiver, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000069 \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000070 F(GetPrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000071 F(IsInPrototypeChain, 2, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +010072 F(SetHiddenPrototype, 2, 1) \
73 \
74 F(IsConstructCall, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000075 \
Leon Clarkee46be812010-01-19 14:06:41 +000076 F(GetOwnProperty, 2, 1) \
77 \
78 F(IsExtensible, 1, 1) \
Steve Block8defd9f2010-07-08 12:39:36 +010079 F(PreventExtensions, 1, 1)\
Leon Clarkee46be812010-01-19 14:06:41 +000080 \
Steve Blocka7e24c12009-10-30 11:49:00 +000081 /* Utilities */ \
Ben Murdoch589d6972011-11-30 16:04:58 +000082 F(CheckIsBootstrapping, 0, 1) \
83 F(Apply, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000084 F(GetFunctionDelegate, 1, 1) \
85 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000086 F(NewArgumentsFast, 3, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000087 F(NewStrictArgumentsFast, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000088 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010089 F(LazyRecompile, 1, 1) \
90 F(NotifyDeoptimized, 1, 1) \
91 F(NotifyOSR, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010092 F(DeoptimizeFunction, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000093 F(RunningInSimulator, 0, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +010094 F(OptimizeFunctionOnNextCall, 1, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +000095 F(GetOptimizationStatus, 1, 1) \
96 F(GetOptimizationCount, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010097 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000098 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010099 F(AllocateInNewSpace, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000100 F(SetNativeFlag, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000101 \
102 /* Array join support */ \
103 F(PushIfAbsent, 2, 1) \
104 F(ArrayConcat, 1, 1) \
105 \
106 /* Conversions */ \
107 F(ToBool, 1, 1) \
108 F(Typeof, 1, 1) \
109 \
110 F(StringToNumber, 1, 1) \
111 F(StringFromCharCodeArray, 1, 1) \
112 F(StringParseInt, 2, 1) \
113 F(StringParseFloat, 1, 1) \
114 F(StringToLowerCase, 1, 1) \
115 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100116 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 F(CharFromCode, 1, 1) \
118 F(URIEscape, 1, 1) \
119 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100120 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100121 F(QuoteJSONStringComma, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000122 F(QuoteJSONStringArray, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000123 \
124 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100125 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000126 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100127 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000128 F(NumberToJSUint32, 1, 1) \
129 F(NumberToJSInt32, 1, 1) \
130 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100131 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000132 \
133 /* Arithmetic operations */ \
134 F(NumberAdd, 2, 1) \
135 F(NumberSub, 2, 1) \
136 F(NumberMul, 2, 1) \
137 F(NumberDiv, 2, 1) \
138 F(NumberMod, 2, 1) \
139 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100140 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000141 \
142 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000143 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100144 F(StringBuilderJoin, 3, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100145 F(SparseJoinWithSeparator, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000146 \
147 /* Bit operations */ \
148 F(NumberOr, 2, 1) \
149 F(NumberAnd, 2, 1) \
150 F(NumberXor, 2, 1) \
151 F(NumberNot, 1, 1) \
152 \
153 F(NumberShl, 2, 1) \
154 F(NumberShr, 2, 1) \
155 F(NumberSar, 2, 1) \
156 \
157 /* Comparisons */ \
158 F(NumberEquals, 2, 1) \
159 F(StringEquals, 2, 1) \
160 \
161 F(NumberCompare, 3, 1) \
162 F(SmiLexicographicCompare, 2, 1) \
163 F(StringCompare, 2, 1) \
164 \
165 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000166 F(Math_acos, 1, 1) \
167 F(Math_asin, 1, 1) \
168 F(Math_atan, 1, 1) \
169 F(Math_atan2, 2, 1) \
170 F(Math_ceil, 1, 1) \
171 F(Math_cos, 1, 1) \
172 F(Math_exp, 1, 1) \
173 F(Math_floor, 1, 1) \
174 F(Math_log, 1, 1) \
175 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100176 F(Math_pow_cfunction, 2, 1) \
177 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000178 F(Math_sin, 1, 1) \
179 F(Math_sqrt, 1, 1) \
180 F(Math_tan, 1, 1) \
181 \
182 /* Regular expressions */ \
183 F(RegExpCompile, 3, 1) \
184 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100185 F(RegExpExecMultiple, 4, 1) \
186 F(RegExpInitializeObject, 5, 1) \
187 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800188 \
189 /* JSON */ \
190 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000191 \
192 /* Strings */ \
193 F(StringCharCodeAt, 2, 1) \
194 F(StringIndexOf, 3, 1) \
195 F(StringLastIndexOf, 3, 1) \
196 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000197 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000198 F(StringReplaceRegExpWithString, 4, 1) \
199 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000200 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800201 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100202 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 \
204 /* Numbers */ \
205 F(NumberToRadixString, 2, 1) \
206 F(NumberToFixed, 2, 1) \
207 F(NumberToExponential, 2, 1) \
208 F(NumberToPrecision, 2, 1)
209
210#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
211 /* Reflection */ \
212 F(FunctionSetInstanceClassName, 2, 1) \
213 F(FunctionSetLength, 2, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100214 F(BoundFunctionSetLength, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 F(FunctionSetPrototype, 2, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000216 F(FunctionSetReadOnlyPrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000217 F(FunctionGetName, 1, 1) \
218 F(FunctionSetName, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000219 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
220 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100221 F(FunctionSetBound, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100222 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000223 F(FunctionGetSourceCode, 1, 1) \
224 F(FunctionGetScript, 1, 1) \
225 F(FunctionGetScriptSourcePosition, 1, 1) \
226 F(FunctionGetPositionForOffset, 2, 1) \
227 F(FunctionIsAPIFunction, 1, 1) \
228 F(FunctionIsBuiltin, 1, 1) \
229 F(GetScript, 1, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100230 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000231 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 \
233 F(ClassOf, 1, 1) \
234 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100235 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 \
237 F(CreateApiFunction, 1, 1) \
238 F(IsTemplate, 1, 1) \
239 F(GetTemplateField, 2, 1) \
240 F(DisableAccessChecks, 1, 1) \
241 F(EnableAccessChecks, 1, 1) \
242 \
243 /* Dates */ \
244 F(DateCurrentTime, 0, 1) \
245 F(DateParseString, 2, 1) \
246 F(DateLocalTimezone, 1, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100247 F(DateLocalTimeOffset, 0, 1) \
248 F(DateDaylightSavingsOffset, 1, 1) \
249 F(DateMakeDay, 3, 1) \
250 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000251 \
252 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000253 \
254 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800255 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000256 F(GlobalPrint, 1, 1) \
257 \
258 /* Eval */ \
259 F(GlobalReceiver, 1, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100260 F(ResolvePossiblyDirectEval, 4, 2) \
261 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100263 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000264 F(DefineOrRedefineDataProperty, 4, 1) \
265 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000266 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
267 \
268 /* Arrays */ \
269 F(RemoveArrayHoles, 2, 1) \
270 F(GetArrayKeys, 2, 1) \
271 F(MoveArrayContents, 2, 1) \
272 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100273 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000274 \
275 /* Getters and Setters */ \
Ben Murdoch85b71792012-04-11 18:30:58 +0100276 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 F(LookupAccessor, 3, 1) \
278 \
279 /* Literals */ \
280 F(MaterializeRegExpLiteral, 4, 1)\
Ben Murdoch85b71792012-04-11 18:30:58 +0100281 F(CreateArrayLiteralBoilerplate, 3, 1) \
282 F(CloneLiteralBoilerplate, 1, 1) \
283 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100284 F(CreateObjectLiteral, 4, 1) \
285 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000286 F(CreateArrayLiteral, 3, 1) \
287 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 \
Ben Murdoch257744e2011-11-30 15:57:28 +0000289 /* Harmony proxies */ \
290 F(CreateJSProxy, 2, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +0000291 F(CreateJSFunctionProxy, 4, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000292 F(IsJSProxy, 1, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +0000293 F(IsJSFunctionProxy, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000294 F(GetHandler, 1, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +0000295 F(GetCallTrap, 1, 1) \
296 F(GetConstructTrap, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000297 F(Fix, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000299 /* Harmony weakmaps */ \
300 F(WeakMapInitialize, 1, 1) \
301 F(WeakMapGet, 2, 1) \
302 F(WeakMapSet, 3, 1) \
303 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000304 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800305 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 F(NewObject, 1, 1) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100307 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100308 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000309 F(Throw, 1, 1) \
310 F(ReThrow, 1, 1) \
311 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100312 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000313 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000314 \
315 /* Contexts */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000316 F(NewFunctionContext, 1, 1) \
317 F(PushWithContext, 2, 1) \
318 F(PushCatchContext, 3, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000319 F(PushBlockContext, 2, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100320 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000321 F(LoadContextSlot, 2, 2) \
322 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100323 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 \
325 /* Declarations and initialization */ \
Ben Murdoch589d6972011-11-30 16:04:58 +0000326 F(DeclareGlobals, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100328 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000329 F(InitializeConstGlobal, 2, 1) \
330 F(InitializeConstContextSlot, 3, 1) \
331 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 \
333 /* Debugging */ \
334 F(DebugPrint, 1, 1) \
335 F(DebugTrace, 0, 1) \
336 F(TraceEnter, 0, 1) \
337 F(TraceExit, 1, 1) \
338 F(Abort, 2, 1) \
339 /* Logging */ \
340 F(Log, 2, 1) \
341 /* ES5 */ \
342 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100343 /* Cache suport */ \
344 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 \
Steve Block1e0659c2011-05-24 12:43:12 +0100346 /* Message objects */ \
347 F(NewMessageObject, 2, 1) \
348 F(MessageGetType, 1, 1) \
349 F(MessageGetArguments, 1, 1) \
350 F(MessageGetStartPosition, 1, 1) \
351 F(MessageGetScript, 1, 1) \
352 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000353 /* Pseudo functions - handled as macros by parser */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000354 F(IS_VAR, 1, 1) \
355 \
356 /* expose boolean functions from objects-inl.h */ \
357 F(HasFastElements, 1, 1) \
358 F(HasFastDoubleElements, 1, 1) \
359 F(HasDictionaryElements, 1, 1) \
360 F(HasExternalPixelElements, 1, 1) \
361 F(HasExternalArrayElements, 1, 1) \
362 F(HasExternalByteElements, 1, 1) \
363 F(HasExternalUnsignedByteElements, 1, 1) \
364 F(HasExternalShortElements, 1, 1) \
365 F(HasExternalUnsignedShortElements, 1, 1) \
366 F(HasExternalIntElements, 1, 1) \
367 F(HasExternalUnsignedIntElements, 1, 1) \
368 F(HasExternalFloatElements, 1, 1) \
369 F(HasExternalDoubleElements, 1, 1) \
370 /* profiler */ \
371 F(ProfilerResume, 0, 1) \
372 F(ProfilerPause, 0, 1)
373
Steve Blocka7e24c12009-10-30 11:49:00 +0000374
375#ifdef ENABLE_DEBUGGER_SUPPORT
376#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
377 /* Debugger support*/ \
378 F(DebugBreak, 0, 1) \
379 F(SetDebugEventListener, 2, 1) \
380 F(Break, 0, 1) \
381 F(DebugGetPropertyDetails, 2, 1) \
382 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000383 F(DebugPropertyTypeFromDetails, 1, 1) \
384 F(DebugPropertyAttributesFromDetails, 1, 1) \
385 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000386 F(DebugNamedInterceptorPropertyValue, 2, 1) \
387 F(DebugIndexedInterceptorElementValue, 2, 1) \
388 F(CheckExecutionState, 1, 1) \
389 F(GetFrameCount, 1, 1) \
390 F(GetFrameDetails, 2, 1) \
391 F(GetScopeCount, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000392 F(GetScopeDetails, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000393 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000394 F(GetThreadCount, 1, 1) \
395 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100396 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000397 F(GetBreakLocations, 1, 1) \
398 F(SetFunctionBreakPoint, 3, 1) \
399 F(SetScriptBreakPoint, 3, 1) \
400 F(ClearBreakPoint, 1, 1) \
401 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100402 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 F(PrepareStep, 3, 1) \
404 F(ClearStepping, 0, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000405 F(DebugEvaluate, 6, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100406 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000407 F(DebugGetLoadedScripts, 0, 1) \
408 F(DebugReferencedBy, 3, 1) \
409 F(DebugConstructedBy, 2, 1) \
410 F(DebugGetPrototype, 1, 1) \
411 F(SystemBreak, 0, 1) \
412 F(DebugDisassembleFunction, 1, 1) \
413 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100414 F(FunctionGetInferredName, 1, 1) \
415 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
416 F(LiveEditGatherCompileInfo, 2, 1) \
417 F(LiveEditReplaceScript, 3, 1) \
418 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100419 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100420 F(LiveEditFunctionSetScript, 2, 1) \
421 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
422 F(LiveEditPatchFunctionPositions, 2, 1) \
423 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100424 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100425 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100426 F(ExecuteInDebugContext, 2, 1) \
427 \
428 F(SetFlags, 1, 1) \
429 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100430 F(GetHeapUsage, 0, 1) \
431 \
432 /* LiveObjectList support*/ \
433 F(HasLOLEnabled, 0, 1) \
434 F(CaptureLOL, 0, 1) \
435 F(DeleteLOL, 1, 1) \
436 F(DumpLOL, 5, 1) \
437 F(GetLOLObj, 1, 1) \
438 F(GetLOLObjId, 1, 1) \
439 F(GetLOLObjRetainers, 6, 1) \
440 F(GetLOLPath, 3, 1) \
441 F(InfoLOL, 2, 1) \
442 F(PrintLOLObj, 1, 1) \
443 F(ResetLOL, 0, 1) \
444 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100445
Steve Blocka7e24c12009-10-30 11:49:00 +0000446#else
447#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
448#endif
449
450#ifdef DEBUG
451#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
452 /* Testing */ \
453 F(ListNatives, 0, 1)
454#else
455#define RUNTIME_FUNCTION_LIST_DEBUG(F)
456#endif
457
Steve Blocka7e24c12009-10-30 11:49:00 +0000458// ----------------------------------------------------------------------------
459// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
460// either directly by id (via the code generator), or indirectly
461// via a native call by name (from within JS code).
462
463#define RUNTIME_FUNCTION_LIST(F) \
464 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
465 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
466 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000467 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000468
469// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100470// INLINE_FUNCTION_LIST defines all inlined functions accessed
471// with a native call of the form %_name from within JS code.
472// Entries have the form F(name, number of arguments, number of return values).
473#define INLINE_FUNCTION_LIST(F) \
474 F(IsSmi, 1, 1) \
475 F(IsNonNegativeSmi, 1, 1) \
476 F(IsArray, 1, 1) \
477 F(IsRegExp, 1, 1) \
478 F(CallFunction, -1 /* receiver + n args + function */, 1) \
479 F(ArgumentsLength, 0, 1) \
480 F(Arguments, 1, 1) \
481 F(ValueOf, 1, 1) \
482 F(SetValueOf, 2, 1) \
483 F(StringCharFromCode, 1, 1) \
484 F(StringCharAt, 2, 1) \
485 F(ObjectEquals, 2, 1) \
486 F(RandomHeapNumber, 0, 1) \
487 F(IsObject, 1, 1) \
488 F(IsFunction, 1, 1) \
489 F(IsUndetectableObject, 1, 1) \
490 F(IsSpecObject, 1, 1) \
491 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
492 F(MathPow, 2, 1) \
493 F(MathSin, 1, 1) \
494 F(MathCos, 1, 1) \
495 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100496 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100497 F(IsRegExpEquivalent, 2, 1) \
498 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800499 F(GetCachedArrayIndex, 1, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000500 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100501
502
503// ----------------------------------------------------------------------------
504// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
505// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800506// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100507// Entries have the form F(name, number of arguments, number of return values).
508#define INLINE_RUNTIME_FUNCTION_LIST(F) \
Ben Murdoch85b71792012-04-11 18:30:58 +0100509 F(IsConstructCall, 0, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100510 F(ClassOf, 1, 1) \
511 F(StringCharCodeAt, 2, 1) \
512 F(Log, 3, 1) \
513 F(StringAdd, 2, 1) \
514 F(SubString, 3, 1) \
515 F(StringCompare, 2, 1) \
516 F(RegExpExec, 4, 1) \
517 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100518 F(GetFromCache, 2, 1) \
519 F(NumberToString, 1, 1) \
520 F(SwapElements, 3, 1)
521
522
523//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000524// Runtime provides access to all C++ runtime functions.
525
Steve Block44f0eee2011-05-26 01:26:41 +0100526class RuntimeState {
527 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100528 StaticResource<StringInputBuffer>* string_input_buffer() {
529 return &string_input_buffer_;
530 }
531 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
532 return &to_upper_mapping_;
533 }
534 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
535 return &to_lower_mapping_;
536 }
537 StringInputBuffer* string_input_buffer_compare_bufx() {
538 return &string_input_buffer_compare_bufx_;
539 }
540 StringInputBuffer* string_input_buffer_compare_bufy() {
541 return &string_input_buffer_compare_bufy_;
542 }
543 StringInputBuffer* string_locale_compare_buf1() {
544 return &string_locale_compare_buf1_;
545 }
546 StringInputBuffer* string_locale_compare_buf2() {
547 return &string_locale_compare_buf2_;
548 }
Steve Block44f0eee2011-05-26 01:26:41 +0100549
550 private:
551 RuntimeState() {}
552 // Non-reentrant string buffer for efficient general use in the runtime.
553 StaticResource<StringInputBuffer> string_input_buffer_;
554 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
555 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
556 StringInputBuffer string_input_buffer_compare_bufx_;
557 StringInputBuffer string_input_buffer_compare_bufy_;
558 StringInputBuffer string_locale_compare_buf1_;
559 StringInputBuffer string_locale_compare_buf2_;
Steve Block44f0eee2011-05-26 01:26:41 +0100560
561 friend class Isolate;
562 friend class Runtime;
563
564 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
565};
566
567
Steve Blocka7e24c12009-10-30 11:49:00 +0000568class Runtime : public AllStatic {
569 public:
570 enum FunctionId {
571#define F(name, nargs, ressize) k##name,
572 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000573#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100574#define F(name, nargs, ressize) kInline##name,
575 INLINE_FUNCTION_LIST(F)
576 INLINE_RUNTIME_FUNCTION_LIST(F)
577#undef F
578 kNumFunctions,
579 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000580 };
581
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100582 enum IntrinsicType {
583 RUNTIME,
584 INLINE
585 };
586
587 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000588 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100589 FunctionId function_id;
590 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000591 // The JS name of the function.
592 const char* name;
593
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100594 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 byte* entry;
596
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100597 // The number of arguments expected. nargs is -1 if the function takes
598 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000599 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100600 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000601 int result_size;
602 };
603
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100604 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000605
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100606 // Add symbols for all the intrinsic function names to a StringDictionary.
607 // Returns failure if an allocation fails. In this case, it must be
608 // retried with a new, empty StringDictionary, not with the same one.
609 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700610 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100611 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000612
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100613 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100614 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100615
616 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100617 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100618
619 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100620 static int StringMatch(Isolate* isolate,
621 Handle<String> sub,
622 Handle<String> pat,
623 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000624
Steve Block44f0eee2011-05-26 01:26:41 +0100625 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000626
Ben Murdoch85b71792012-04-11 18:30:58 +0100627 // TODO(1240886): The following three methods are *not* handle safe,
628 // but accept handle arguments. This seems fragile.
Steve Blocka7e24c12009-10-30 11:49:00 +0000629
630 // Support getting the characters in a string using [] notation as
631 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100632 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
633 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700634 uint32_t index);
Ben Murdoch85b71792012-04-11 18:30:58 +0100635 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
636 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000637
John Reck59135872010-11-02 12:39:01 -0700638 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100639 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700640 Handle<Object> object,
641 Handle<Object> key,
642 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100643 PropertyAttributes attr,
644 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000645
John Reck59135872010-11-02 12:39:01 -0700646 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100647 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700648 Handle<JSObject> object,
649 Handle<Object> key,
650 Handle<Object> value,
651 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000652
John Reck59135872010-11-02 12:39:01 -0700653 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100654 Isolate* isolate,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000655 Handle<JSReceiver> object,
John Reck59135872010-11-02 12:39:01 -0700656 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000657
Steve Block44f0eee2011-05-26 01:26:41 +0100658 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
659 Isolate* isolate,
660 Handle<Object> object,
661 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000662
663 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100664 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
665 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000666 int position);
667
668 // Helper functions used stubs.
669 static void PerformGC(Object* result);
670};
671
Ben Murdoch589d6972011-11-30 16:04:58 +0000672
673//---------------------------------------------------------------------------
674// Constants used by interface to runtime functions.
675
Ben Murdoch85b71792012-04-11 18:30:58 +0100676enum kDeclareGlobalsFlags {
677 kDeclareGlobalsEvalFlag = 1 << 0,
678 kDeclareGlobalsStrictModeFlag = 1 << 1,
679 kDeclareGlobalsNativeFlag = 1 << 2
680};
Ben Murdoch589d6972011-11-30 16:04:58 +0000681
Steve Blocka7e24c12009-10-30 11:49:00 +0000682} } // namespace v8::internal
683
684#endif // V8_RUNTIME_H_