blob: 58062ca404935d802c4e8328ffedeed80491f976 [file] [log] [blame]
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001// Copyright 2010 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
Steve Block44f0eee2011-05-26 01:26:41 +010031#include "zone.h"
32
Steve Blocka7e24c12009-10-30 11:49:00 +000033namespace v8 {
34namespace internal {
35
36// The interface to C++ runtime functions.
37
38// ----------------------------------------------------------------------------
39// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
40// release and debug mode.
41// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
42
43// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
44// MSVC Intellisense to crash. It was broken into two macros to work around
45// this problem. Please avoid large recursive macros whenever possible.
46#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
47 /* Property access */ \
48 F(GetProperty, 2, 1) \
49 F(KeyedGetProperty, 2, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +010050 F(DeleteProperty, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000051 F(HasLocalProperty, 2, 1) \
52 F(HasProperty, 2, 1) \
53 F(HasElement, 2, 1) \
54 F(IsPropertyEnumerable, 2, 1) \
55 F(GetPropertyNames, 1, 1) \
56 F(GetPropertyNamesFast, 1, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +000057 F(GetLocalPropertyNames, 1, 1) \
58 F(GetLocalElementNames, 1, 1) \
59 F(GetInterceptorInfo, 1, 1) \
60 F(GetNamedInterceptorPropertyNames, 1, 1) \
61 F(GetIndexedInterceptorElementNames, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000062 F(GetArgumentsProperty, 1, 1) \
63 F(ToFastProperties, 1, 1) \
64 F(ToSlowProperties, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +010065 F(FinishArrayPrototypeSetup, 1, 1) \
66 F(SpecialArrayFunctions, 1, 1) \
67 F(GetGlobalReceiver, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000068 \
69 F(IsInPrototypeChain, 2, 1) \
70 F(SetHiddenPrototype, 2, 1) \
71 \
72 F(IsConstructCall, 0, 1) \
73 \
Leon Clarkee46be812010-01-19 14:06:41 +000074 F(GetOwnProperty, 2, 1) \
75 \
76 F(IsExtensible, 1, 1) \
Steve Block8defd9f2010-07-08 12:39:36 +010077 F(PreventExtensions, 1, 1)\
Leon Clarkee46be812010-01-19 14:06:41 +000078 \
Steve Blocka7e24c12009-10-30 11:49:00 +000079 /* Utilities */ \
Steve Blocka7e24c12009-10-30 11:49:00 +000080 F(GetFunctionDelegate, 1, 1) \
81 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000082 F(NewArgumentsFast, 3, 1) \
83 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010084 F(LazyRecompile, 1, 1) \
85 F(NotifyDeoptimized, 1, 1) \
86 F(NotifyOSR, 0, 1) \
87 F(DeoptimizeFunction, 1, 1) \
88 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000089 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010090 F(AllocateInNewSpace, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000091 \
92 /* Array join support */ \
93 F(PushIfAbsent, 2, 1) \
94 F(ArrayConcat, 1, 1) \
95 \
96 /* Conversions */ \
97 F(ToBool, 1, 1) \
98 F(Typeof, 1, 1) \
99 \
100 F(StringToNumber, 1, 1) \
101 F(StringFromCharCodeArray, 1, 1) \
102 F(StringParseInt, 2, 1) \
103 F(StringParseFloat, 1, 1) \
104 F(StringToLowerCase, 1, 1) \
105 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100106 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000107 F(CharFromCode, 1, 1) \
108 F(URIEscape, 1, 1) \
109 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100110 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100111 F(QuoteJSONStringComma, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 \
113 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100114 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100116 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 F(NumberToJSUint32, 1, 1) \
118 F(NumberToJSInt32, 1, 1) \
119 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100120 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 \
122 /* Arithmetic operations */ \
123 F(NumberAdd, 2, 1) \
124 F(NumberSub, 2, 1) \
125 F(NumberMul, 2, 1) \
126 F(NumberDiv, 2, 1) \
127 F(NumberMod, 2, 1) \
128 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100129 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 \
131 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000132 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100133 F(StringBuilderJoin, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000134 \
135 /* Bit operations */ \
136 F(NumberOr, 2, 1) \
137 F(NumberAnd, 2, 1) \
138 F(NumberXor, 2, 1) \
139 F(NumberNot, 1, 1) \
140 \
141 F(NumberShl, 2, 1) \
142 F(NumberShr, 2, 1) \
143 F(NumberSar, 2, 1) \
144 \
145 /* Comparisons */ \
146 F(NumberEquals, 2, 1) \
147 F(StringEquals, 2, 1) \
148 \
149 F(NumberCompare, 3, 1) \
150 F(SmiLexicographicCompare, 2, 1) \
151 F(StringCompare, 2, 1) \
152 \
153 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000154 F(Math_acos, 1, 1) \
155 F(Math_asin, 1, 1) \
156 F(Math_atan, 1, 1) \
157 F(Math_atan2, 2, 1) \
158 F(Math_ceil, 1, 1) \
159 F(Math_cos, 1, 1) \
160 F(Math_exp, 1, 1) \
161 F(Math_floor, 1, 1) \
162 F(Math_log, 1, 1) \
163 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100164 F(Math_pow_cfunction, 2, 1) \
165 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000166 F(Math_sin, 1, 1) \
167 F(Math_sqrt, 1, 1) \
168 F(Math_tan, 1, 1) \
169 \
170 /* Regular expressions */ \
171 F(RegExpCompile, 3, 1) \
172 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100173 F(RegExpExecMultiple, 4, 1) \
174 F(RegExpInitializeObject, 5, 1) \
175 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800176 \
177 /* JSON */ \
178 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000179 \
180 /* Strings */ \
181 F(StringCharCodeAt, 2, 1) \
182 F(StringIndexOf, 3, 1) \
183 F(StringLastIndexOf, 3, 1) \
184 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000185 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000186 F(StringReplaceRegExpWithString, 4, 1) \
187 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000188 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800189 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100190 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000191 \
192 /* Numbers */ \
193 F(NumberToRadixString, 2, 1) \
194 F(NumberToFixed, 2, 1) \
195 F(NumberToExponential, 2, 1) \
196 F(NumberToPrecision, 2, 1)
197
198#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
199 /* Reflection */ \
200 F(FunctionSetInstanceClassName, 2, 1) \
201 F(FunctionSetLength, 2, 1) \
202 F(FunctionSetPrototype, 2, 1) \
203 F(FunctionGetName, 1, 1) \
204 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100205 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000206 F(FunctionGetSourceCode, 1, 1) \
207 F(FunctionGetScript, 1, 1) \
208 F(FunctionGetScriptSourcePosition, 1, 1) \
209 F(FunctionGetPositionForOffset, 2, 1) \
210 F(FunctionIsAPIFunction, 1, 1) \
211 F(FunctionIsBuiltin, 1, 1) \
212 F(GetScript, 1, 1) \
213 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000214 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 \
216 F(ClassOf, 1, 1) \
217 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100218 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000219 \
220 F(CreateApiFunction, 1, 1) \
221 F(IsTemplate, 1, 1) \
222 F(GetTemplateField, 2, 1) \
223 F(DisableAccessChecks, 1, 1) \
224 F(EnableAccessChecks, 1, 1) \
225 \
226 /* Dates */ \
227 F(DateCurrentTime, 0, 1) \
228 F(DateParseString, 2, 1) \
229 F(DateLocalTimezone, 1, 1) \
230 F(DateLocalTimeOffset, 0, 1) \
231 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100232 F(DateMakeDay, 3, 1) \
233 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 \
235 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 \
237 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800238 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000239 F(GlobalPrint, 1, 1) \
240 \
241 /* Eval */ \
242 F(GlobalReceiver, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100243 F(ResolvePossiblyDirectEval, 4, 2) \
244 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000245 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100246 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000247 F(DefineOrRedefineDataProperty, 4, 1) \
248 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
250 \
251 /* Arrays */ \
252 F(RemoveArrayHoles, 2, 1) \
253 F(GetArrayKeys, 2, 1) \
254 F(MoveArrayContents, 2, 1) \
255 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100256 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000257 \
258 /* Getters and Setters */ \
259 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
260 F(LookupAccessor, 3, 1) \
261 \
262 /* Literals */ \
263 F(MaterializeRegExpLiteral, 4, 1)\
264 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000265 F(CloneLiteralBoilerplate, 1, 1) \
266 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100267 F(CreateObjectLiteral, 4, 1) \
268 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000269 F(CreateArrayLiteral, 3, 1) \
270 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000271 \
272 /* Catch context extension objects */ \
273 F(CreateCatchExtensionObject, 2, 1) \
274 \
275 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800276 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100278 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100279 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 F(Throw, 1, 1) \
281 F(ReThrow, 1, 1) \
282 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100283 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000284 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000285 \
286 /* Contexts */ \
287 F(NewContext, 1, 1) \
288 F(PushContext, 1, 1) \
289 F(PushCatchContext, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100290 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000291 F(LoadContextSlot, 2, 2) \
292 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100293 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000294 \
295 /* Declarations and initialization */ \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100296 F(DeclareGlobals, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000297 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100298 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 F(InitializeConstGlobal, 2, 1) \
300 F(InitializeConstContextSlot, 3, 1) \
301 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000302 \
303 /* Debugging */ \
304 F(DebugPrint, 1, 1) \
305 F(DebugTrace, 0, 1) \
306 F(TraceEnter, 0, 1) \
307 F(TraceExit, 1, 1) \
308 F(Abort, 2, 1) \
309 /* Logging */ \
310 F(Log, 2, 1) \
311 /* ES5 */ \
312 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100313 /* Cache suport */ \
314 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 \
Steve Block1e0659c2011-05-24 12:43:12 +0100316 /* Message objects */ \
317 F(NewMessageObject, 2, 1) \
318 F(MessageGetType, 1, 1) \
319 F(MessageGetArguments, 1, 1) \
320 F(MessageGetStartPosition, 1, 1) \
321 F(MessageGetScript, 1, 1) \
322 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000324 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
326#ifdef ENABLE_DEBUGGER_SUPPORT
327#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
328 /* Debugger support*/ \
329 F(DebugBreak, 0, 1) \
330 F(SetDebugEventListener, 2, 1) \
331 F(Break, 0, 1) \
332 F(DebugGetPropertyDetails, 2, 1) \
333 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 F(DebugPropertyTypeFromDetails, 1, 1) \
335 F(DebugPropertyAttributesFromDetails, 1, 1) \
336 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 F(DebugNamedInterceptorPropertyValue, 2, 1) \
338 F(DebugIndexedInterceptorElementValue, 2, 1) \
339 F(CheckExecutionState, 1, 1) \
340 F(GetFrameCount, 1, 1) \
341 F(GetFrameDetails, 2, 1) \
342 F(GetScopeCount, 2, 1) \
343 F(GetScopeDetails, 3, 1) \
344 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 F(GetThreadCount, 1, 1) \
346 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100347 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000348 F(GetBreakLocations, 1, 1) \
349 F(SetFunctionBreakPoint, 3, 1) \
350 F(SetScriptBreakPoint, 3, 1) \
351 F(ClearBreakPoint, 1, 1) \
352 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100353 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 F(PrepareStep, 3, 1) \
355 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100356 F(DebugEvaluate, 5, 1) \
357 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000358 F(DebugGetLoadedScripts, 0, 1) \
359 F(DebugReferencedBy, 3, 1) \
360 F(DebugConstructedBy, 2, 1) \
361 F(DebugGetPrototype, 1, 1) \
362 F(SystemBreak, 0, 1) \
363 F(DebugDisassembleFunction, 1, 1) \
364 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100365 F(FunctionGetInferredName, 1, 1) \
366 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
367 F(LiveEditGatherCompileInfo, 2, 1) \
368 F(LiveEditReplaceScript, 3, 1) \
369 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100370 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100371 F(LiveEditFunctionSetScript, 2, 1) \
372 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
373 F(LiveEditPatchFunctionPositions, 2, 1) \
374 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100375 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100376 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100377 F(ExecuteInDebugContext, 2, 1) \
378 \
379 F(SetFlags, 1, 1) \
380 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100381 F(GetHeapUsage, 0, 1) \
382 \
383 /* LiveObjectList support*/ \
384 F(HasLOLEnabled, 0, 1) \
385 F(CaptureLOL, 0, 1) \
386 F(DeleteLOL, 1, 1) \
387 F(DumpLOL, 5, 1) \
388 F(GetLOLObj, 1, 1) \
389 F(GetLOLObjId, 1, 1) \
390 F(GetLOLObjRetainers, 6, 1) \
391 F(GetLOLPath, 3, 1) \
392 F(InfoLOL, 2, 1) \
393 F(PrintLOLObj, 1, 1) \
394 F(ResetLOL, 0, 1) \
395 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100396
Steve Blocka7e24c12009-10-30 11:49:00 +0000397#else
398#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
399#endif
400
Steve Blockd0582a62009-12-15 09:54:21 +0000401#ifdef ENABLE_LOGGING_AND_PROFILING
402#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000403 F(ProfilerResume, 2, 1) \
404 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000405#else
406#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
407#endif
408
Steve Blocka7e24c12009-10-30 11:49:00 +0000409#ifdef DEBUG
410#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
411 /* Testing */ \
412 F(ListNatives, 0, 1)
413#else
414#define RUNTIME_FUNCTION_LIST_DEBUG(F)
415#endif
416
Steve Blocka7e24c12009-10-30 11:49:00 +0000417// ----------------------------------------------------------------------------
418// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
419// either directly by id (via the code generator), or indirectly
420// via a native call by name (from within JS code).
421
422#define RUNTIME_FUNCTION_LIST(F) \
423 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
424 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
425 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000426 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
427 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000428
429// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100430// INLINE_FUNCTION_LIST defines all inlined functions accessed
431// with a native call of the form %_name from within JS code.
432// Entries have the form F(name, number of arguments, number of return values).
433#define INLINE_FUNCTION_LIST(F) \
434 F(IsSmi, 1, 1) \
435 F(IsNonNegativeSmi, 1, 1) \
436 F(IsArray, 1, 1) \
437 F(IsRegExp, 1, 1) \
438 F(CallFunction, -1 /* receiver + n args + function */, 1) \
439 F(ArgumentsLength, 0, 1) \
440 F(Arguments, 1, 1) \
441 F(ValueOf, 1, 1) \
442 F(SetValueOf, 2, 1) \
443 F(StringCharFromCode, 1, 1) \
444 F(StringCharAt, 2, 1) \
445 F(ObjectEquals, 2, 1) \
446 F(RandomHeapNumber, 0, 1) \
447 F(IsObject, 1, 1) \
448 F(IsFunction, 1, 1) \
449 F(IsUndetectableObject, 1, 1) \
450 F(IsSpecObject, 1, 1) \
451 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
452 F(MathPow, 2, 1) \
453 F(MathSin, 1, 1) \
454 F(MathCos, 1, 1) \
455 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100456 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100457 F(IsRegExpEquivalent, 2, 1) \
458 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800459 F(GetCachedArrayIndex, 1, 1) \
460 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100461
462
463// ----------------------------------------------------------------------------
464// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
465// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800466// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100467// Entries have the form F(name, number of arguments, number of return values).
468#define INLINE_RUNTIME_FUNCTION_LIST(F) \
469 F(IsConstructCall, 0, 1) \
470 F(ClassOf, 1, 1) \
471 F(StringCharCodeAt, 2, 1) \
472 F(Log, 3, 1) \
473 F(StringAdd, 2, 1) \
474 F(SubString, 3, 1) \
475 F(StringCompare, 2, 1) \
476 F(RegExpExec, 4, 1) \
477 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100478 F(GetFromCache, 2, 1) \
479 F(NumberToString, 1, 1) \
480 F(SwapElements, 3, 1)
481
482
483//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000484// Runtime provides access to all C++ runtime functions.
485
Steve Block44f0eee2011-05-26 01:26:41 +0100486class RuntimeState {
487 public:
488
489 StaticResource<StringInputBuffer>* string_input_buffer() {
490 return &string_input_buffer_;
491 }
492 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
493 return &to_upper_mapping_;
494 }
495 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
496 return &to_lower_mapping_;
497 }
498 StringInputBuffer* string_input_buffer_compare_bufx() {
499 return &string_input_buffer_compare_bufx_;
500 }
501 StringInputBuffer* string_input_buffer_compare_bufy() {
502 return &string_input_buffer_compare_bufy_;
503 }
504 StringInputBuffer* string_locale_compare_buf1() {
505 return &string_locale_compare_buf1_;
506 }
507 StringInputBuffer* string_locale_compare_buf2() {
508 return &string_locale_compare_buf2_;
509 }
510 int* smi_lexicographic_compare_x_elms() {
511 return smi_lexicographic_compare_x_elms_;
512 }
513 int* smi_lexicographic_compare_y_elms() {
514 return smi_lexicographic_compare_y_elms_;
515 }
516
517 private:
518 RuntimeState() {}
519 // Non-reentrant string buffer for efficient general use in the runtime.
520 StaticResource<StringInputBuffer> string_input_buffer_;
521 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
522 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
523 StringInputBuffer string_input_buffer_compare_bufx_;
524 StringInputBuffer string_input_buffer_compare_bufy_;
525 StringInputBuffer string_locale_compare_buf1_;
526 StringInputBuffer string_locale_compare_buf2_;
527 int smi_lexicographic_compare_x_elms_[10];
528 int smi_lexicographic_compare_y_elms_[10];
529
530 friend class Isolate;
531 friend class Runtime;
532
533 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
534};
535
536
Steve Blocka7e24c12009-10-30 11:49:00 +0000537class Runtime : public AllStatic {
538 public:
539 enum FunctionId {
540#define F(name, nargs, ressize) k##name,
541 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000542#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100543#define F(name, nargs, ressize) kInline##name,
544 INLINE_FUNCTION_LIST(F)
545 INLINE_RUNTIME_FUNCTION_LIST(F)
546#undef F
547 kNumFunctions,
548 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000549 };
550
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100551 enum IntrinsicType {
552 RUNTIME,
553 INLINE
554 };
555
556 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000557 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100558 FunctionId function_id;
559 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000560 // The JS name of the function.
561 const char* name;
562
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100563 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000564 byte* entry;
565
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100566 // The number of arguments expected. nargs is -1 if the function takes
567 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000568 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100569 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000570 int result_size;
571 };
572
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100573 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000574
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100575 // Add symbols for all the intrinsic function names to a StringDictionary.
576 // Returns failure if an allocation fails. In this case, it must be
577 // retried with a new, empty StringDictionary, not with the same one.
578 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700579 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100580 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000581
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100582 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100583 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100584
585 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100586 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100587
588 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100589 static int StringMatch(Isolate* isolate,
590 Handle<String> sub,
591 Handle<String> pat,
592 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
Steve Block44f0eee2011-05-26 01:26:41 +0100594 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000595
596 // TODO(1240886): The following three methods are *not* handle safe,
597 // but accept handle arguments. This seems fragile.
598
599 // Support getting the characters in a string using [] notation as
600 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100601 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
602 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700603 uint32_t index);
604 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
605 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
John Reck59135872010-11-02 12:39:01 -0700607 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100608 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700609 Handle<Object> object,
610 Handle<Object> key,
611 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100612 PropertyAttributes attr,
613 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000614
John Reck59135872010-11-02 12:39:01 -0700615 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100616 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700617 Handle<JSObject> object,
618 Handle<Object> key,
619 Handle<Object> value,
620 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000621
John Reck59135872010-11-02 12:39:01 -0700622 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100623 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700624 Handle<JSObject> object,
625 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000626
Steve Block44f0eee2011-05-26 01:26:41 +0100627 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
628 Isolate* isolate,
629 Handle<Object> object,
630 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000631
632 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100633 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
634 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000635 int position);
636
637 // Helper functions used stubs.
638 static void PerformGC(Object* result);
639};
640
Steve Blocka7e24c12009-10-30 11:49:00 +0000641} } // namespace v8::internal
642
643#endif // V8_RUNTIME_H_