blob: 8e73d5c4a23bf5ab21c32644800bf7715f7cbd6b [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
31namespace v8 {
32namespace internal {
33
34// The interface to C++ runtime functions.
35
36// ----------------------------------------------------------------------------
37// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
38// release and debug mode.
39// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
40
41// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
42// MSVC Intellisense to crash. It was broken into two macros to work around
43// this problem. Please avoid large recursive macros whenever possible.
44#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
45 /* Property access */ \
46 F(GetProperty, 2, 1) \
47 F(KeyedGetProperty, 2, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +010048 F(DeleteProperty, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000049 F(HasLocalProperty, 2, 1) \
50 F(HasProperty, 2, 1) \
51 F(HasElement, 2, 1) \
52 F(IsPropertyEnumerable, 2, 1) \
53 F(GetPropertyNames, 1, 1) \
54 F(GetPropertyNamesFast, 1, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +000055 F(GetLocalPropertyNames, 1, 1) \
56 F(GetLocalElementNames, 1, 1) \
57 F(GetInterceptorInfo, 1, 1) \
58 F(GetNamedInterceptorPropertyNames, 1, 1) \
59 F(GetIndexedInterceptorElementNames, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000060 F(GetArgumentsProperty, 1, 1) \
61 F(ToFastProperties, 1, 1) \
62 F(ToSlowProperties, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +010063 F(FinishArrayPrototypeSetup, 1, 1) \
64 F(SpecialArrayFunctions, 1, 1) \
65 F(GetGlobalReceiver, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000066 \
67 F(IsInPrototypeChain, 2, 1) \
68 F(SetHiddenPrototype, 2, 1) \
69 \
70 F(IsConstructCall, 0, 1) \
71 \
Leon Clarkee46be812010-01-19 14:06:41 +000072 F(GetOwnProperty, 2, 1) \
73 \
74 F(IsExtensible, 1, 1) \
Steve Block8defd9f2010-07-08 12:39:36 +010075 F(PreventExtensions, 1, 1)\
Leon Clarkee46be812010-01-19 14:06:41 +000076 \
Steve Blocka7e24c12009-10-30 11:49:00 +000077 /* Utilities */ \
Steve Blocka7e24c12009-10-30 11:49:00 +000078 F(GetFunctionDelegate, 1, 1) \
79 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000080 F(NewArgumentsFast, 3, 1) \
81 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010082 F(LazyRecompile, 1, 1) \
83 F(NotifyDeoptimized, 1, 1) \
84 F(NotifyOSR, 0, 1) \
85 F(DeoptimizeFunction, 1, 1) \
86 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000087 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010088 F(AllocateInNewSpace, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000089 \
90 /* Array join support */ \
91 F(PushIfAbsent, 2, 1) \
92 F(ArrayConcat, 1, 1) \
93 \
94 /* Conversions */ \
95 F(ToBool, 1, 1) \
96 F(Typeof, 1, 1) \
97 \
98 F(StringToNumber, 1, 1) \
99 F(StringFromCharCodeArray, 1, 1) \
100 F(StringParseInt, 2, 1) \
101 F(StringParseFloat, 1, 1) \
102 F(StringToLowerCase, 1, 1) \
103 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100104 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000105 F(CharFromCode, 1, 1) \
106 F(URIEscape, 1, 1) \
107 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100108 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100109 F(QuoteJSONStringComma, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000110 \
111 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100112 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000113 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100114 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 F(NumberToJSUint32, 1, 1) \
116 F(NumberToJSInt32, 1, 1) \
117 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100118 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000119 \
120 /* Arithmetic operations */ \
121 F(NumberAdd, 2, 1) \
122 F(NumberSub, 2, 1) \
123 F(NumberMul, 2, 1) \
124 F(NumberDiv, 2, 1) \
125 F(NumberMod, 2, 1) \
126 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100127 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000128 \
129 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000130 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100131 F(StringBuilderJoin, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000132 \
133 /* Bit operations */ \
134 F(NumberOr, 2, 1) \
135 F(NumberAnd, 2, 1) \
136 F(NumberXor, 2, 1) \
137 F(NumberNot, 1, 1) \
138 \
139 F(NumberShl, 2, 1) \
140 F(NumberShr, 2, 1) \
141 F(NumberSar, 2, 1) \
142 \
143 /* Comparisons */ \
144 F(NumberEquals, 2, 1) \
145 F(StringEquals, 2, 1) \
146 \
147 F(NumberCompare, 3, 1) \
148 F(SmiLexicographicCompare, 2, 1) \
149 F(StringCompare, 2, 1) \
150 \
151 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000152 F(Math_acos, 1, 1) \
153 F(Math_asin, 1, 1) \
154 F(Math_atan, 1, 1) \
155 F(Math_atan2, 2, 1) \
156 F(Math_ceil, 1, 1) \
157 F(Math_cos, 1, 1) \
158 F(Math_exp, 1, 1) \
159 F(Math_floor, 1, 1) \
160 F(Math_log, 1, 1) \
161 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100162 F(Math_pow_cfunction, 2, 1) \
163 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 F(Math_sin, 1, 1) \
165 F(Math_sqrt, 1, 1) \
166 F(Math_tan, 1, 1) \
167 \
168 /* Regular expressions */ \
169 F(RegExpCompile, 3, 1) \
170 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100171 F(RegExpExecMultiple, 4, 1) \
172 F(RegExpInitializeObject, 5, 1) \
173 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800174 \
175 /* JSON */ \
176 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000177 \
178 /* Strings */ \
179 F(StringCharCodeAt, 2, 1) \
180 F(StringIndexOf, 3, 1) \
181 F(StringLastIndexOf, 3, 1) \
182 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000183 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 F(StringReplaceRegExpWithString, 4, 1) \
185 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000186 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800187 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100188 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000189 \
190 /* Numbers */ \
191 F(NumberToRadixString, 2, 1) \
192 F(NumberToFixed, 2, 1) \
193 F(NumberToExponential, 2, 1) \
194 F(NumberToPrecision, 2, 1)
195
196#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
197 /* Reflection */ \
198 F(FunctionSetInstanceClassName, 2, 1) \
199 F(FunctionSetLength, 2, 1) \
200 F(FunctionSetPrototype, 2, 1) \
201 F(FunctionGetName, 1, 1) \
202 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100203 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000204 F(FunctionGetSourceCode, 1, 1) \
205 F(FunctionGetScript, 1, 1) \
206 F(FunctionGetScriptSourcePosition, 1, 1) \
207 F(FunctionGetPositionForOffset, 2, 1) \
208 F(FunctionIsAPIFunction, 1, 1) \
209 F(FunctionIsBuiltin, 1, 1) \
210 F(GetScript, 1, 1) \
211 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000212 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 \
214 F(ClassOf, 1, 1) \
215 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100216 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000217 \
218 F(CreateApiFunction, 1, 1) \
219 F(IsTemplate, 1, 1) \
220 F(GetTemplateField, 2, 1) \
221 F(DisableAccessChecks, 1, 1) \
222 F(EnableAccessChecks, 1, 1) \
223 \
224 /* Dates */ \
225 F(DateCurrentTime, 0, 1) \
226 F(DateParseString, 2, 1) \
227 F(DateLocalTimezone, 1, 1) \
228 F(DateLocalTimeOffset, 0, 1) \
229 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100230 F(DateMakeDay, 3, 1) \
231 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 \
233 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 \
235 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800236 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 F(GlobalPrint, 1, 1) \
238 \
239 /* Eval */ \
240 F(GlobalReceiver, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100241 F(ResolvePossiblyDirectEval, 4, 2) \
242 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000243 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100244 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000245 F(DefineOrRedefineDataProperty, 4, 1) \
246 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000247 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
248 \
249 /* Arrays */ \
250 F(RemoveArrayHoles, 2, 1) \
251 F(GetArrayKeys, 2, 1) \
252 F(MoveArrayContents, 2, 1) \
253 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100254 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000255 \
256 /* Getters and Setters */ \
257 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
258 F(LookupAccessor, 3, 1) \
259 \
260 /* Literals */ \
261 F(MaterializeRegExpLiteral, 4, 1)\
262 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 F(CloneLiteralBoilerplate, 1, 1) \
264 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100265 F(CreateObjectLiteral, 4, 1) \
266 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000267 F(CreateArrayLiteral, 3, 1) \
268 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000269 \
270 /* Catch context extension objects */ \
271 F(CreateCatchExtensionObject, 2, 1) \
272 \
273 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800274 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100276 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100277 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 F(Throw, 1, 1) \
279 F(ReThrow, 1, 1) \
280 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100281 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000282 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000283 \
284 /* Contexts */ \
285 F(NewContext, 1, 1) \
286 F(PushContext, 1, 1) \
287 F(PushCatchContext, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100288 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000289 F(LoadContextSlot, 2, 2) \
290 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100291 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000292 \
293 /* Declarations and initialization */ \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100294 F(DeclareGlobals, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100296 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000297 F(InitializeConstGlobal, 2, 1) \
298 F(InitializeConstContextSlot, 3, 1) \
299 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 \
301 /* Debugging */ \
302 F(DebugPrint, 1, 1) \
303 F(DebugTrace, 0, 1) \
304 F(TraceEnter, 0, 1) \
305 F(TraceExit, 1, 1) \
306 F(Abort, 2, 1) \
307 /* Logging */ \
308 F(Log, 2, 1) \
309 /* ES5 */ \
310 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100311 /* Cache suport */ \
312 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000313 \
Steve Block1e0659c2011-05-24 12:43:12 +0100314 /* Message objects */ \
315 F(NewMessageObject, 2, 1) \
316 F(MessageGetType, 1, 1) \
317 F(MessageGetArguments, 1, 1) \
318 F(MessageGetStartPosition, 1, 1) \
319 F(MessageGetScript, 1, 1) \
320 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000321 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000322 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000323
324#ifdef ENABLE_DEBUGGER_SUPPORT
325#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
326 /* Debugger support*/ \
327 F(DebugBreak, 0, 1) \
328 F(SetDebugEventListener, 2, 1) \
329 F(Break, 0, 1) \
330 F(DebugGetPropertyDetails, 2, 1) \
331 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 F(DebugPropertyTypeFromDetails, 1, 1) \
333 F(DebugPropertyAttributesFromDetails, 1, 1) \
334 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 F(DebugNamedInterceptorPropertyValue, 2, 1) \
336 F(DebugIndexedInterceptorElementValue, 2, 1) \
337 F(CheckExecutionState, 1, 1) \
338 F(GetFrameCount, 1, 1) \
339 F(GetFrameDetails, 2, 1) \
340 F(GetScopeCount, 2, 1) \
341 F(GetScopeDetails, 3, 1) \
342 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 F(GetThreadCount, 1, 1) \
344 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100345 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 F(GetBreakLocations, 1, 1) \
347 F(SetFunctionBreakPoint, 3, 1) \
348 F(SetScriptBreakPoint, 3, 1) \
349 F(ClearBreakPoint, 1, 1) \
350 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100351 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000352 F(PrepareStep, 3, 1) \
353 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100354 F(DebugEvaluate, 5, 1) \
355 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000356 F(DebugGetLoadedScripts, 0, 1) \
357 F(DebugReferencedBy, 3, 1) \
358 F(DebugConstructedBy, 2, 1) \
359 F(DebugGetPrototype, 1, 1) \
360 F(SystemBreak, 0, 1) \
361 F(DebugDisassembleFunction, 1, 1) \
362 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100363 F(FunctionGetInferredName, 1, 1) \
364 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
365 F(LiveEditGatherCompileInfo, 2, 1) \
366 F(LiveEditReplaceScript, 3, 1) \
367 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100368 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100369 F(LiveEditFunctionSetScript, 2, 1) \
370 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
371 F(LiveEditPatchFunctionPositions, 2, 1) \
372 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100373 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100374 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100375 F(ExecuteInDebugContext, 2, 1) \
376 \
377 F(SetFlags, 1, 1) \
378 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100379 F(GetHeapUsage, 0, 1) \
380 \
381 /* LiveObjectList support*/ \
382 F(HasLOLEnabled, 0, 1) \
383 F(CaptureLOL, 0, 1) \
384 F(DeleteLOL, 1, 1) \
385 F(DumpLOL, 5, 1) \
386 F(GetLOLObj, 1, 1) \
387 F(GetLOLObjId, 1, 1) \
388 F(GetLOLObjRetainers, 6, 1) \
389 F(GetLOLPath, 3, 1) \
390 F(InfoLOL, 2, 1) \
391 F(PrintLOLObj, 1, 1) \
392 F(ResetLOL, 0, 1) \
393 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100394
Steve Blocka7e24c12009-10-30 11:49:00 +0000395#else
396#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
397#endif
398
Steve Blockd0582a62009-12-15 09:54:21 +0000399#ifdef ENABLE_LOGGING_AND_PROFILING
400#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000401 F(ProfilerResume, 2, 1) \
402 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000403#else
404#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
405#endif
406
Steve Blocka7e24c12009-10-30 11:49:00 +0000407#ifdef DEBUG
408#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
409 /* Testing */ \
410 F(ListNatives, 0, 1)
411#else
412#define RUNTIME_FUNCTION_LIST_DEBUG(F)
413#endif
414
415
416// ----------------------------------------------------------------------------
417// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
418// either directly by id (via the code generator), or indirectly
419// via a native call by name (from within JS code).
420
421#define RUNTIME_FUNCTION_LIST(F) \
422 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
423 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
424 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000425 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
426 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000427
428// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100429// INLINE_FUNCTION_LIST defines all inlined functions accessed
430// with a native call of the form %_name from within JS code.
431// Entries have the form F(name, number of arguments, number of return values).
432#define INLINE_FUNCTION_LIST(F) \
433 F(IsSmi, 1, 1) \
434 F(IsNonNegativeSmi, 1, 1) \
435 F(IsArray, 1, 1) \
436 F(IsRegExp, 1, 1) \
437 F(CallFunction, -1 /* receiver + n args + function */, 1) \
438 F(ArgumentsLength, 0, 1) \
439 F(Arguments, 1, 1) \
440 F(ValueOf, 1, 1) \
441 F(SetValueOf, 2, 1) \
442 F(StringCharFromCode, 1, 1) \
443 F(StringCharAt, 2, 1) \
444 F(ObjectEquals, 2, 1) \
445 F(RandomHeapNumber, 0, 1) \
446 F(IsObject, 1, 1) \
447 F(IsFunction, 1, 1) \
448 F(IsUndetectableObject, 1, 1) \
449 F(IsSpecObject, 1, 1) \
450 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
451 F(MathPow, 2, 1) \
452 F(MathSin, 1, 1) \
453 F(MathCos, 1, 1) \
454 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100455 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100456 F(IsRegExpEquivalent, 2, 1) \
457 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800458 F(GetCachedArrayIndex, 1, 1) \
459 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100460
461
462// ----------------------------------------------------------------------------
463// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
464// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800465// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100466// Entries have the form F(name, number of arguments, number of return values).
467#define INLINE_RUNTIME_FUNCTION_LIST(F) \
468 F(IsConstructCall, 0, 1) \
469 F(ClassOf, 1, 1) \
470 F(StringCharCodeAt, 2, 1) \
471 F(Log, 3, 1) \
472 F(StringAdd, 2, 1) \
473 F(SubString, 3, 1) \
474 F(StringCompare, 2, 1) \
475 F(RegExpExec, 4, 1) \
476 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100477 F(GetFromCache, 2, 1) \
478 F(NumberToString, 1, 1) \
479 F(SwapElements, 3, 1)
480
481
482//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000483// Runtime provides access to all C++ runtime functions.
484
485class Runtime : public AllStatic {
486 public:
487 enum FunctionId {
488#define F(name, nargs, ressize) k##name,
489 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000490#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100491#define F(name, nargs, ressize) kInline##name,
492 INLINE_FUNCTION_LIST(F)
493 INLINE_RUNTIME_FUNCTION_LIST(F)
494#undef F
495 kNumFunctions,
496 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000497 };
498
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100499 enum IntrinsicType {
500 RUNTIME,
501 INLINE
502 };
503
504 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000505 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100506 FunctionId function_id;
507 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000508 // The JS name of the function.
509 const char* name;
510
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100511 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000512 byte* entry;
513
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100514 // The number of arguments expected. nargs is -1 if the function takes
515 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000516 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100517 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000518 int result_size;
519 };
520
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100521 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000522
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100523 // Add symbols for all the intrinsic function names to a StringDictionary.
524 // Returns failure if an allocation fails. In this case, it must be
525 // retried with a new, empty StringDictionary, not with the same one.
526 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700527 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
528 Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000529
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100530 // Get the intrinsic function with the given name, which must be a symbol.
531 static Function* FunctionForSymbol(Handle<String> name);
532
533 // Get the intrinsic function with the given FunctionId.
534 static Function* FunctionForId(FunctionId id);
535
536 // General-purpose helper functions for runtime system.
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 static int StringMatch(Handle<String> sub, Handle<String> pat, int index);
538
539 static bool IsUpperCaseChar(uint16_t ch);
540
541 // TODO(1240886): The following three methods are *not* handle safe,
542 // but accept handle arguments. This seems fragile.
543
544 // Support getting the characters in a string using [] notation as
545 // in Firefox/SpiderMonkey, Safari and Opera.
John Reck59135872010-11-02 12:39:01 -0700546 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Handle<Object> object,
547 uint32_t index);
548 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
549 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000550
John Reck59135872010-11-02 12:39:01 -0700551 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
552 Handle<Object> object,
553 Handle<Object> key,
554 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100555 PropertyAttributes attr,
556 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000557
John Reck59135872010-11-02 12:39:01 -0700558 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
559 Handle<JSObject> object,
560 Handle<Object> key,
561 Handle<Object> value,
562 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000563
John Reck59135872010-11-02 12:39:01 -0700564 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
565 Handle<JSObject> object,
566 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000567
John Reck59135872010-11-02 12:39:01 -0700568 MUST_USE_RESULT static MaybeObject* GetObjectProperty(Handle<Object> object,
569 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000570
571 // This function is used in FunctionNameUsing* tests.
572 static Object* FindSharedFunctionInfoInScript(Handle<Script> script,
573 int position);
574
575 // Helper functions used stubs.
576 static void PerformGC(Object* result);
577};
578
579
580} } // namespace v8::internal
581
582#endif // V8_RUNTIME_H_