blob: bf1ba68b02a4af604f5f1782039cf61acdcd1cb7 [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) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010087 F(DeoptimizeFunction, 1, 1) \
88 F(OptimizeFunctionOnNextCall, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010089 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000090 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010091 F(AllocateInNewSpace, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000092 \
93 /* Array join support */ \
94 F(PushIfAbsent, 2, 1) \
95 F(ArrayConcat, 1, 1) \
96 \
97 /* Conversions */ \
98 F(ToBool, 1, 1) \
99 F(Typeof, 1, 1) \
100 \
101 F(StringToNumber, 1, 1) \
102 F(StringFromCharCodeArray, 1, 1) \
103 F(StringParseInt, 2, 1) \
104 F(StringParseFloat, 1, 1) \
105 F(StringToLowerCase, 1, 1) \
106 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100107 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000108 F(CharFromCode, 1, 1) \
109 F(URIEscape, 1, 1) \
110 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100111 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100112 F(QuoteJSONStringComma, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000113 \
114 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100115 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000116 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100117 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 F(NumberToJSUint32, 1, 1) \
119 F(NumberToJSInt32, 1, 1) \
120 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100121 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 \
123 /* Arithmetic operations */ \
124 F(NumberAdd, 2, 1) \
125 F(NumberSub, 2, 1) \
126 F(NumberMul, 2, 1) \
127 F(NumberDiv, 2, 1) \
128 F(NumberMod, 2, 1) \
129 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100130 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000131 \
132 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000133 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100134 F(StringBuilderJoin, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000135 \
136 /* Bit operations */ \
137 F(NumberOr, 2, 1) \
138 F(NumberAnd, 2, 1) \
139 F(NumberXor, 2, 1) \
140 F(NumberNot, 1, 1) \
141 \
142 F(NumberShl, 2, 1) \
143 F(NumberShr, 2, 1) \
144 F(NumberSar, 2, 1) \
145 \
146 /* Comparisons */ \
147 F(NumberEquals, 2, 1) \
148 F(StringEquals, 2, 1) \
149 \
150 F(NumberCompare, 3, 1) \
151 F(SmiLexicographicCompare, 2, 1) \
152 F(StringCompare, 2, 1) \
153 \
154 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000155 F(Math_acos, 1, 1) \
156 F(Math_asin, 1, 1) \
157 F(Math_atan, 1, 1) \
158 F(Math_atan2, 2, 1) \
159 F(Math_ceil, 1, 1) \
160 F(Math_cos, 1, 1) \
161 F(Math_exp, 1, 1) \
162 F(Math_floor, 1, 1) \
163 F(Math_log, 1, 1) \
164 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100165 F(Math_pow_cfunction, 2, 1) \
166 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 F(Math_sin, 1, 1) \
168 F(Math_sqrt, 1, 1) \
169 F(Math_tan, 1, 1) \
170 \
171 /* Regular expressions */ \
172 F(RegExpCompile, 3, 1) \
173 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100174 F(RegExpExecMultiple, 4, 1) \
175 F(RegExpInitializeObject, 5, 1) \
176 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800177 \
178 /* JSON */ \
179 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000180 \
181 /* Strings */ \
182 F(StringCharCodeAt, 2, 1) \
183 F(StringIndexOf, 3, 1) \
184 F(StringLastIndexOf, 3, 1) \
185 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000186 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 F(StringReplaceRegExpWithString, 4, 1) \
188 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000189 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800190 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100191 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000192 \
193 /* Numbers */ \
194 F(NumberToRadixString, 2, 1) \
195 F(NumberToFixed, 2, 1) \
196 F(NumberToExponential, 2, 1) \
197 F(NumberToPrecision, 2, 1)
198
199#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
200 /* Reflection */ \
201 F(FunctionSetInstanceClassName, 2, 1) \
202 F(FunctionSetLength, 2, 1) \
203 F(FunctionSetPrototype, 2, 1) \
204 F(FunctionGetName, 1, 1) \
205 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100206 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000207 F(FunctionGetSourceCode, 1, 1) \
208 F(FunctionGetScript, 1, 1) \
209 F(FunctionGetScriptSourcePosition, 1, 1) \
210 F(FunctionGetPositionForOffset, 2, 1) \
211 F(FunctionIsAPIFunction, 1, 1) \
212 F(FunctionIsBuiltin, 1, 1) \
213 F(GetScript, 1, 1) \
214 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000215 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 \
217 F(ClassOf, 1, 1) \
218 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100219 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000220 \
221 F(CreateApiFunction, 1, 1) \
222 F(IsTemplate, 1, 1) \
223 F(GetTemplateField, 2, 1) \
224 F(DisableAccessChecks, 1, 1) \
225 F(EnableAccessChecks, 1, 1) \
226 \
227 /* Dates */ \
228 F(DateCurrentTime, 0, 1) \
229 F(DateParseString, 2, 1) \
230 F(DateLocalTimezone, 1, 1) \
231 F(DateLocalTimeOffset, 0, 1) \
232 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100233 F(DateMakeDay, 3, 1) \
234 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 \
236 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 \
238 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800239 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000240 F(GlobalPrint, 1, 1) \
241 \
242 /* Eval */ \
243 F(GlobalReceiver, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100244 F(ResolvePossiblyDirectEval, 4, 2) \
245 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100247 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000248 F(DefineOrRedefineDataProperty, 4, 1) \
249 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000250 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
251 \
252 /* Arrays */ \
253 F(RemoveArrayHoles, 2, 1) \
254 F(GetArrayKeys, 2, 1) \
255 F(MoveArrayContents, 2, 1) \
256 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100257 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000258 \
259 /* Getters and Setters */ \
260 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
261 F(LookupAccessor, 3, 1) \
262 \
263 /* Literals */ \
264 F(MaterializeRegExpLiteral, 4, 1)\
265 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000266 F(CloneLiteralBoilerplate, 1, 1) \
267 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100268 F(CreateObjectLiteral, 4, 1) \
269 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000270 F(CreateArrayLiteral, 3, 1) \
271 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000272 \
273 /* Catch context extension objects */ \
274 F(CreateCatchExtensionObject, 2, 1) \
275 \
276 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800277 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100279 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100280 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 F(Throw, 1, 1) \
282 F(ReThrow, 1, 1) \
283 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100284 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000285 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 \
287 /* Contexts */ \
288 F(NewContext, 1, 1) \
289 F(PushContext, 1, 1) \
290 F(PushCatchContext, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100291 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000292 F(LoadContextSlot, 2, 2) \
293 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100294 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 \
296 /* Declarations and initialization */ \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100297 F(DeclareGlobals, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100299 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 F(InitializeConstGlobal, 2, 1) \
301 F(InitializeConstContextSlot, 3, 1) \
302 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 \
304 /* Debugging */ \
305 F(DebugPrint, 1, 1) \
306 F(DebugTrace, 0, 1) \
307 F(TraceEnter, 0, 1) \
308 F(TraceExit, 1, 1) \
309 F(Abort, 2, 1) \
310 /* Logging */ \
311 F(Log, 2, 1) \
312 /* ES5 */ \
313 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100314 /* Cache suport */ \
315 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000316 \
Steve Block1e0659c2011-05-24 12:43:12 +0100317 /* Message objects */ \
318 F(NewMessageObject, 2, 1) \
319 F(MessageGetType, 1, 1) \
320 F(MessageGetArguments, 1, 1) \
321 F(MessageGetStartPosition, 1, 1) \
322 F(MessageGetScript, 1, 1) \
323 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000325 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000326
327#ifdef ENABLE_DEBUGGER_SUPPORT
328#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
329 /* Debugger support*/ \
330 F(DebugBreak, 0, 1) \
331 F(SetDebugEventListener, 2, 1) \
332 F(Break, 0, 1) \
333 F(DebugGetPropertyDetails, 2, 1) \
334 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 F(DebugPropertyTypeFromDetails, 1, 1) \
336 F(DebugPropertyAttributesFromDetails, 1, 1) \
337 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 F(DebugNamedInterceptorPropertyValue, 2, 1) \
339 F(DebugIndexedInterceptorElementValue, 2, 1) \
340 F(CheckExecutionState, 1, 1) \
341 F(GetFrameCount, 1, 1) \
342 F(GetFrameDetails, 2, 1) \
343 F(GetScopeCount, 2, 1) \
344 F(GetScopeDetails, 3, 1) \
345 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 F(GetThreadCount, 1, 1) \
347 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100348 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000349 F(GetBreakLocations, 1, 1) \
350 F(SetFunctionBreakPoint, 3, 1) \
351 F(SetScriptBreakPoint, 3, 1) \
352 F(ClearBreakPoint, 1, 1) \
353 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100354 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000355 F(PrepareStep, 3, 1) \
356 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100357 F(DebugEvaluate, 5, 1) \
358 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000359 F(DebugGetLoadedScripts, 0, 1) \
360 F(DebugReferencedBy, 3, 1) \
361 F(DebugConstructedBy, 2, 1) \
362 F(DebugGetPrototype, 1, 1) \
363 F(SystemBreak, 0, 1) \
364 F(DebugDisassembleFunction, 1, 1) \
365 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100366 F(FunctionGetInferredName, 1, 1) \
367 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
368 F(LiveEditGatherCompileInfo, 2, 1) \
369 F(LiveEditReplaceScript, 3, 1) \
370 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100371 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100372 F(LiveEditFunctionSetScript, 2, 1) \
373 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
374 F(LiveEditPatchFunctionPositions, 2, 1) \
375 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100376 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100377 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100378 F(ExecuteInDebugContext, 2, 1) \
379 \
380 F(SetFlags, 1, 1) \
381 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100382 F(GetHeapUsage, 0, 1) \
383 \
384 /* LiveObjectList support*/ \
385 F(HasLOLEnabled, 0, 1) \
386 F(CaptureLOL, 0, 1) \
387 F(DeleteLOL, 1, 1) \
388 F(DumpLOL, 5, 1) \
389 F(GetLOLObj, 1, 1) \
390 F(GetLOLObjId, 1, 1) \
391 F(GetLOLObjRetainers, 6, 1) \
392 F(GetLOLPath, 3, 1) \
393 F(InfoLOL, 2, 1) \
394 F(PrintLOLObj, 1, 1) \
395 F(ResetLOL, 0, 1) \
396 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100397
Steve Blocka7e24c12009-10-30 11:49:00 +0000398#else
399#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
400#endif
401
Steve Blockd0582a62009-12-15 09:54:21 +0000402#ifdef ENABLE_LOGGING_AND_PROFILING
403#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000404 F(ProfilerResume, 2, 1) \
405 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000406#else
407#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
408#endif
409
Steve Blocka7e24c12009-10-30 11:49:00 +0000410#ifdef DEBUG
411#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
412 /* Testing */ \
413 F(ListNatives, 0, 1)
414#else
415#define RUNTIME_FUNCTION_LIST_DEBUG(F)
416#endif
417
Steve Blocka7e24c12009-10-30 11:49:00 +0000418// ----------------------------------------------------------------------------
419// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
420// either directly by id (via the code generator), or indirectly
421// via a native call by name (from within JS code).
422
423#define RUNTIME_FUNCTION_LIST(F) \
424 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
425 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
426 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000427 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
428 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000429
430// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100431// INLINE_FUNCTION_LIST defines all inlined functions accessed
432// with a native call of the form %_name from within JS code.
433// Entries have the form F(name, number of arguments, number of return values).
434#define INLINE_FUNCTION_LIST(F) \
435 F(IsSmi, 1, 1) \
436 F(IsNonNegativeSmi, 1, 1) \
437 F(IsArray, 1, 1) \
438 F(IsRegExp, 1, 1) \
439 F(CallFunction, -1 /* receiver + n args + function */, 1) \
440 F(ArgumentsLength, 0, 1) \
441 F(Arguments, 1, 1) \
442 F(ValueOf, 1, 1) \
443 F(SetValueOf, 2, 1) \
444 F(StringCharFromCode, 1, 1) \
445 F(StringCharAt, 2, 1) \
446 F(ObjectEquals, 2, 1) \
447 F(RandomHeapNumber, 0, 1) \
448 F(IsObject, 1, 1) \
449 F(IsFunction, 1, 1) \
450 F(IsUndetectableObject, 1, 1) \
451 F(IsSpecObject, 1, 1) \
452 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
453 F(MathPow, 2, 1) \
454 F(MathSin, 1, 1) \
455 F(MathCos, 1, 1) \
456 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100457 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100458 F(IsRegExpEquivalent, 2, 1) \
459 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800460 F(GetCachedArrayIndex, 1, 1) \
461 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100462
463
464// ----------------------------------------------------------------------------
465// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
466// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800467// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100468// Entries have the form F(name, number of arguments, number of return values).
469#define INLINE_RUNTIME_FUNCTION_LIST(F) \
470 F(IsConstructCall, 0, 1) \
471 F(ClassOf, 1, 1) \
472 F(StringCharCodeAt, 2, 1) \
473 F(Log, 3, 1) \
474 F(StringAdd, 2, 1) \
475 F(SubString, 3, 1) \
476 F(StringCompare, 2, 1) \
477 F(RegExpExec, 4, 1) \
478 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100479 F(GetFromCache, 2, 1) \
480 F(NumberToString, 1, 1) \
481 F(SwapElements, 3, 1)
482
483
484//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000485// Runtime provides access to all C++ runtime functions.
486
Steve Block44f0eee2011-05-26 01:26:41 +0100487class RuntimeState {
488 public:
489
490 StaticResource<StringInputBuffer>* string_input_buffer() {
491 return &string_input_buffer_;
492 }
493 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
494 return &to_upper_mapping_;
495 }
496 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
497 return &to_lower_mapping_;
498 }
499 StringInputBuffer* string_input_buffer_compare_bufx() {
500 return &string_input_buffer_compare_bufx_;
501 }
502 StringInputBuffer* string_input_buffer_compare_bufy() {
503 return &string_input_buffer_compare_bufy_;
504 }
505 StringInputBuffer* string_locale_compare_buf1() {
506 return &string_locale_compare_buf1_;
507 }
508 StringInputBuffer* string_locale_compare_buf2() {
509 return &string_locale_compare_buf2_;
510 }
511 int* smi_lexicographic_compare_x_elms() {
512 return smi_lexicographic_compare_x_elms_;
513 }
514 int* smi_lexicographic_compare_y_elms() {
515 return smi_lexicographic_compare_y_elms_;
516 }
517
518 private:
519 RuntimeState() {}
520 // Non-reentrant string buffer for efficient general use in the runtime.
521 StaticResource<StringInputBuffer> string_input_buffer_;
522 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
523 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
524 StringInputBuffer string_input_buffer_compare_bufx_;
525 StringInputBuffer string_input_buffer_compare_bufy_;
526 StringInputBuffer string_locale_compare_buf1_;
527 StringInputBuffer string_locale_compare_buf2_;
528 int smi_lexicographic_compare_x_elms_[10];
529 int smi_lexicographic_compare_y_elms_[10];
530
531 friend class Isolate;
532 friend class Runtime;
533
534 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
535};
536
537
Steve Blocka7e24c12009-10-30 11:49:00 +0000538class Runtime : public AllStatic {
539 public:
540 enum FunctionId {
541#define F(name, nargs, ressize) k##name,
542 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000543#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100544#define F(name, nargs, ressize) kInline##name,
545 INLINE_FUNCTION_LIST(F)
546 INLINE_RUNTIME_FUNCTION_LIST(F)
547#undef F
548 kNumFunctions,
549 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000550 };
551
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100552 enum IntrinsicType {
553 RUNTIME,
554 INLINE
555 };
556
557 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100559 FunctionId function_id;
560 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000561 // The JS name of the function.
562 const char* name;
563
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100564 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000565 byte* entry;
566
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100567 // The number of arguments expected. nargs is -1 if the function takes
568 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000569 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100570 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000571 int result_size;
572 };
573
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100574 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000575
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100576 // Add symbols for all the intrinsic function names to a StringDictionary.
577 // Returns failure if an allocation fails. In this case, it must be
578 // retried with a new, empty StringDictionary, not with the same one.
579 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700580 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100581 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000582
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100583 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100584 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100585
586 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100587 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100588
589 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100590 static int StringMatch(Isolate* isolate,
591 Handle<String> sub,
592 Handle<String> pat,
593 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000594
Steve Block44f0eee2011-05-26 01:26:41 +0100595 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000596
597 // TODO(1240886): The following three methods are *not* handle safe,
598 // but accept handle arguments. This seems fragile.
599
600 // Support getting the characters in a string using [] notation as
601 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100602 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
603 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700604 uint32_t index);
605 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
606 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000607
John Reck59135872010-11-02 12:39:01 -0700608 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100609 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700610 Handle<Object> object,
611 Handle<Object> key,
612 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100613 PropertyAttributes attr,
614 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000615
John Reck59135872010-11-02 12:39:01 -0700616 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100617 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700618 Handle<JSObject> object,
619 Handle<Object> key,
620 Handle<Object> value,
621 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000622
John Reck59135872010-11-02 12:39:01 -0700623 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100624 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700625 Handle<JSObject> object,
626 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000627
Steve Block44f0eee2011-05-26 01:26:41 +0100628 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
629 Isolate* isolate,
630 Handle<Object> object,
631 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000632
633 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100634 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
635 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000636 int position);
637
638 // Helper functions used stubs.
639 static void PerformGC(Object* result);
640};
641
Steve Blocka7e24c12009-10-30 11:49:00 +0000642} } // namespace v8::internal
643
644#endif // V8_RUNTIME_H_