blob: dbd8d644b77ccd8dc7bb579cdc5cdef641d8c13b [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) \
48 F(DeleteProperty, 2, 1) \
49 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) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000131 \
132 /* Bit operations */ \
133 F(NumberOr, 2, 1) \
134 F(NumberAnd, 2, 1) \
135 F(NumberXor, 2, 1) \
136 F(NumberNot, 1, 1) \
137 \
138 F(NumberShl, 2, 1) \
139 F(NumberShr, 2, 1) \
140 F(NumberSar, 2, 1) \
141 \
142 /* Comparisons */ \
143 F(NumberEquals, 2, 1) \
144 F(StringEquals, 2, 1) \
145 \
146 F(NumberCompare, 3, 1) \
147 F(SmiLexicographicCompare, 2, 1) \
148 F(StringCompare, 2, 1) \
149 \
150 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000151 F(Math_acos, 1, 1) \
152 F(Math_asin, 1, 1) \
153 F(Math_atan, 1, 1) \
154 F(Math_atan2, 2, 1) \
155 F(Math_ceil, 1, 1) \
156 F(Math_cos, 1, 1) \
157 F(Math_exp, 1, 1) \
158 F(Math_floor, 1, 1) \
159 F(Math_log, 1, 1) \
160 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100161 F(Math_pow_cfunction, 2, 1) \
162 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000163 F(Math_sin, 1, 1) \
164 F(Math_sqrt, 1, 1) \
165 F(Math_tan, 1, 1) \
166 \
167 /* Regular expressions */ \
168 F(RegExpCompile, 3, 1) \
169 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100170 F(RegExpExecMultiple, 4, 1) \
171 F(RegExpInitializeObject, 5, 1) \
172 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800173 \
174 /* JSON */ \
175 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000176 \
177 /* Strings */ \
178 F(StringCharCodeAt, 2, 1) \
179 F(StringIndexOf, 3, 1) \
180 F(StringLastIndexOf, 3, 1) \
181 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000182 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000183 F(StringReplaceRegExpWithString, 4, 1) \
184 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000185 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800186 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100187 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000188 \
189 /* Numbers */ \
190 F(NumberToRadixString, 2, 1) \
191 F(NumberToFixed, 2, 1) \
192 F(NumberToExponential, 2, 1) \
193 F(NumberToPrecision, 2, 1)
194
195#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
196 /* Reflection */ \
197 F(FunctionSetInstanceClassName, 2, 1) \
198 F(FunctionSetLength, 2, 1) \
199 F(FunctionSetPrototype, 2, 1) \
200 F(FunctionGetName, 1, 1) \
201 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100202 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 F(FunctionGetSourceCode, 1, 1) \
204 F(FunctionGetScript, 1, 1) \
205 F(FunctionGetScriptSourcePosition, 1, 1) \
206 F(FunctionGetPositionForOffset, 2, 1) \
207 F(FunctionIsAPIFunction, 1, 1) \
208 F(FunctionIsBuiltin, 1, 1) \
209 F(GetScript, 1, 1) \
210 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000211 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000212 \
213 F(ClassOf, 1, 1) \
214 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100215 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000216 \
217 F(CreateApiFunction, 1, 1) \
218 F(IsTemplate, 1, 1) \
219 F(GetTemplateField, 2, 1) \
220 F(DisableAccessChecks, 1, 1) \
221 F(EnableAccessChecks, 1, 1) \
222 \
223 /* Dates */ \
224 F(DateCurrentTime, 0, 1) \
225 F(DateParseString, 2, 1) \
226 F(DateLocalTimezone, 1, 1) \
227 F(DateLocalTimeOffset, 0, 1) \
228 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100229 F(DateMakeDay, 3, 1) \
230 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000231 \
232 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000233 \
234 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800235 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000236 F(GlobalPrint, 1, 1) \
237 \
238 /* Eval */ \
239 F(GlobalReceiver, 1, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000240 F(ResolvePossiblyDirectEval, 3, 2) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100241 F(ResolvePossiblyDirectEvalNoLookup, 3, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000242 \
243 F(SetProperty, -1 /* 3 or 4 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000244 F(DefineOrRedefineDataProperty, 4, 1) \
245 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
247 \
248 /* Arrays */ \
249 F(RemoveArrayHoles, 2, 1) \
250 F(GetArrayKeys, 2, 1) \
251 F(MoveArrayContents, 2, 1) \
252 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100253 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000254 \
255 /* Getters and Setters */ \
256 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
257 F(LookupAccessor, 3, 1) \
258 \
259 /* Literals */ \
260 F(MaterializeRegExpLiteral, 4, 1)\
261 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 F(CloneLiteralBoilerplate, 1, 1) \
263 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100264 F(CreateObjectLiteral, 4, 1) \
265 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000266 F(CreateArrayLiteral, 3, 1) \
267 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000268 \
269 /* Catch context extension objects */ \
270 F(CreateCatchExtensionObject, 2, 1) \
271 \
272 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800273 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000274 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100275 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100276 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 F(Throw, 1, 1) \
278 F(ReThrow, 1, 1) \
279 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100280 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000281 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000282 \
283 /* Contexts */ \
284 F(NewContext, 1, 1) \
285 F(PushContext, 1, 1) \
286 F(PushCatchContext, 1, 1) \
287 F(LookupContext, 2, 1) \
288 F(LoadContextSlot, 2, 2) \
289 F(LoadContextSlotNoReferenceError, 2, 2) \
290 F(StoreContextSlot, 3, 1) \
291 \
292 /* Declarations and initialization */ \
293 F(DeclareGlobals, 3, 1) \
294 F(DeclareContextSlot, 4, 1) \
295 F(InitializeVarGlobal, -1 /* 1 or 2 */, 1) \
296 F(InitializeConstGlobal, 2, 1) \
297 F(InitializeConstContextSlot, 3, 1) \
298 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 \
300 /* Debugging */ \
301 F(DebugPrint, 1, 1) \
302 F(DebugTrace, 0, 1) \
303 F(TraceEnter, 0, 1) \
304 F(TraceExit, 1, 1) \
305 F(Abort, 2, 1) \
306 /* Logging */ \
307 F(Log, 2, 1) \
308 /* ES5 */ \
309 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100310 /* Cache suport */ \
311 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000312 \
313 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000314 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
316#ifdef ENABLE_DEBUGGER_SUPPORT
317#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
318 /* Debugger support*/ \
319 F(DebugBreak, 0, 1) \
320 F(SetDebugEventListener, 2, 1) \
321 F(Break, 0, 1) \
322 F(DebugGetPropertyDetails, 2, 1) \
323 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 F(DebugPropertyTypeFromDetails, 1, 1) \
325 F(DebugPropertyAttributesFromDetails, 1, 1) \
326 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 F(DebugNamedInterceptorPropertyValue, 2, 1) \
328 F(DebugIndexedInterceptorElementValue, 2, 1) \
329 F(CheckExecutionState, 1, 1) \
330 F(GetFrameCount, 1, 1) \
331 F(GetFrameDetails, 2, 1) \
332 F(GetScopeCount, 2, 1) \
333 F(GetScopeDetails, 3, 1) \
334 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000335 F(GetThreadCount, 1, 1) \
336 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100337 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 F(GetBreakLocations, 1, 1) \
339 F(SetFunctionBreakPoint, 3, 1) \
340 F(SetScriptBreakPoint, 3, 1) \
341 F(ClearBreakPoint, 1, 1) \
342 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100343 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000344 F(PrepareStep, 3, 1) \
345 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100346 F(DebugEvaluate, 5, 1) \
347 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000348 F(DebugGetLoadedScripts, 0, 1) \
349 F(DebugReferencedBy, 3, 1) \
350 F(DebugConstructedBy, 2, 1) \
351 F(DebugGetPrototype, 1, 1) \
352 F(SystemBreak, 0, 1) \
353 F(DebugDisassembleFunction, 1, 1) \
354 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100355 F(FunctionGetInferredName, 1, 1) \
356 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
357 F(LiveEditGatherCompileInfo, 2, 1) \
358 F(LiveEditReplaceScript, 3, 1) \
359 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100360 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100361 F(LiveEditFunctionSetScript, 2, 1) \
362 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
363 F(LiveEditPatchFunctionPositions, 2, 1) \
364 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100365 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100366 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100367 F(ExecuteInDebugContext, 2, 1) \
368 \
369 F(SetFlags, 1, 1) \
370 F(CollectGarbage, 1, 1) \
371 F(GetHeapUsage, 0, 1)
372
Steve Blocka7e24c12009-10-30 11:49:00 +0000373#else
374#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
375#endif
376
Steve Blockd0582a62009-12-15 09:54:21 +0000377#ifdef ENABLE_LOGGING_AND_PROFILING
378#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000379 F(ProfilerResume, 2, 1) \
380 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000381#else
382#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
383#endif
384
Steve Blocka7e24c12009-10-30 11:49:00 +0000385#ifdef DEBUG
386#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
387 /* Testing */ \
388 F(ListNatives, 0, 1)
389#else
390#define RUNTIME_FUNCTION_LIST_DEBUG(F)
391#endif
392
393
394// ----------------------------------------------------------------------------
395// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
396// either directly by id (via the code generator), or indirectly
397// via a native call by name (from within JS code).
398
399#define RUNTIME_FUNCTION_LIST(F) \
400 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
401 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
402 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000403 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
404 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000405
406// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100407// INLINE_FUNCTION_LIST defines all inlined functions accessed
408// with a native call of the form %_name from within JS code.
409// Entries have the form F(name, number of arguments, number of return values).
410#define INLINE_FUNCTION_LIST(F) \
411 F(IsSmi, 1, 1) \
412 F(IsNonNegativeSmi, 1, 1) \
413 F(IsArray, 1, 1) \
414 F(IsRegExp, 1, 1) \
415 F(CallFunction, -1 /* receiver + n args + function */, 1) \
416 F(ArgumentsLength, 0, 1) \
417 F(Arguments, 1, 1) \
418 F(ValueOf, 1, 1) \
419 F(SetValueOf, 2, 1) \
420 F(StringCharFromCode, 1, 1) \
421 F(StringCharAt, 2, 1) \
422 F(ObjectEquals, 2, 1) \
423 F(RandomHeapNumber, 0, 1) \
424 F(IsObject, 1, 1) \
425 F(IsFunction, 1, 1) \
426 F(IsUndetectableObject, 1, 1) \
427 F(IsSpecObject, 1, 1) \
428 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
429 F(MathPow, 2, 1) \
430 F(MathSin, 1, 1) \
431 F(MathCos, 1, 1) \
432 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100433 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100434 F(IsRegExpEquivalent, 2, 1) \
435 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800436 F(GetCachedArrayIndex, 1, 1) \
437 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100438
439
440// ----------------------------------------------------------------------------
441// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
442// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800443// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100444// Entries have the form F(name, number of arguments, number of return values).
445#define INLINE_RUNTIME_FUNCTION_LIST(F) \
446 F(IsConstructCall, 0, 1) \
447 F(ClassOf, 1, 1) \
448 F(StringCharCodeAt, 2, 1) \
449 F(Log, 3, 1) \
450 F(StringAdd, 2, 1) \
451 F(SubString, 3, 1) \
452 F(StringCompare, 2, 1) \
453 F(RegExpExec, 4, 1) \
454 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100455 F(GetFromCache, 2, 1) \
456 F(NumberToString, 1, 1) \
457 F(SwapElements, 3, 1)
458
459
460//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000461// Runtime provides access to all C++ runtime functions.
462
463class Runtime : public AllStatic {
464 public:
465 enum FunctionId {
466#define F(name, nargs, ressize) k##name,
467 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000468#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100469#define F(name, nargs, ressize) kInline##name,
470 INLINE_FUNCTION_LIST(F)
471 INLINE_RUNTIME_FUNCTION_LIST(F)
472#undef F
473 kNumFunctions,
474 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000475 };
476
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100477 enum IntrinsicType {
478 RUNTIME,
479 INLINE
480 };
481
482 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000483 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100484 FunctionId function_id;
485 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000486 // The JS name of the function.
487 const char* name;
488
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100489 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 byte* entry;
491
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100492 // The number of arguments expected. nargs is -1 if the function takes
493 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000494 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100495 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000496 int result_size;
497 };
498
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100499 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000500
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100501 // Add symbols for all the intrinsic function names to a StringDictionary.
502 // Returns failure if an allocation fails. In this case, it must be
503 // retried with a new, empty StringDictionary, not with the same one.
504 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700505 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
506 Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000507
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100508 // Get the intrinsic function with the given name, which must be a symbol.
509 static Function* FunctionForSymbol(Handle<String> name);
510
511 // Get the intrinsic function with the given FunctionId.
512 static Function* FunctionForId(FunctionId id);
513
514 // General-purpose helper functions for runtime system.
Steve Blocka7e24c12009-10-30 11:49:00 +0000515 static int StringMatch(Handle<String> sub, Handle<String> pat, int index);
516
517 static bool IsUpperCaseChar(uint16_t ch);
518
519 // TODO(1240886): The following three methods are *not* handle safe,
520 // but accept handle arguments. This seems fragile.
521
522 // Support getting the characters in a string using [] notation as
523 // in Firefox/SpiderMonkey, Safari and Opera.
John Reck59135872010-11-02 12:39:01 -0700524 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Handle<Object> object,
525 uint32_t index);
526 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
527 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000528
John Reck59135872010-11-02 12:39:01 -0700529 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
530 Handle<Object> object,
531 Handle<Object> key,
532 Handle<Object> value,
533 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000534
John Reck59135872010-11-02 12:39:01 -0700535 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
536 Handle<JSObject> object,
537 Handle<Object> key,
538 Handle<Object> value,
539 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000540
John Reck59135872010-11-02 12:39:01 -0700541 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
542 Handle<JSObject> object,
543 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000544
John Reck59135872010-11-02 12:39:01 -0700545 MUST_USE_RESULT static MaybeObject* GetObjectProperty(Handle<Object> object,
546 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000547
548 // This function is used in FunctionNameUsing* tests.
549 static Object* FindSharedFunctionInfoInScript(Handle<Script> script,
550 int position);
551
552 // Helper functions used stubs.
553 static void PerformGC(Object* result);
554};
555
556
557} } // namespace v8::internal
558
559#endif // V8_RUNTIME_H_