blob: fb2ff93c6f745db6c8f2ecbe617b717e7be781b0 [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) \
Steve Block1e0659c2011-05-24 12:43:12 +0100240 F(ResolvePossiblyDirectEval, 4, 2) \
241 F(ResolvePossiblyDirectEvalNoLookup, 4, 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) \
Steve Block1e0659c2011-05-24 12:43:12 +0100287 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 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 \
Steve Block1e0659c2011-05-24 12:43:12 +0100313 /* Message objects */ \
314 F(NewMessageObject, 2, 1) \
315 F(MessageGetType, 1, 1) \
316 F(MessageGetArguments, 1, 1) \
317 F(MessageGetStartPosition, 1, 1) \
318 F(MessageGetScript, 1, 1) \
319 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000321 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000322
323#ifdef ENABLE_DEBUGGER_SUPPORT
324#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
325 /* Debugger support*/ \
326 F(DebugBreak, 0, 1) \
327 F(SetDebugEventListener, 2, 1) \
328 F(Break, 0, 1) \
329 F(DebugGetPropertyDetails, 2, 1) \
330 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000331 F(DebugPropertyTypeFromDetails, 1, 1) \
332 F(DebugPropertyAttributesFromDetails, 1, 1) \
333 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 F(DebugNamedInterceptorPropertyValue, 2, 1) \
335 F(DebugIndexedInterceptorElementValue, 2, 1) \
336 F(CheckExecutionState, 1, 1) \
337 F(GetFrameCount, 1, 1) \
338 F(GetFrameDetails, 2, 1) \
339 F(GetScopeCount, 2, 1) \
340 F(GetScopeDetails, 3, 1) \
341 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000342 F(GetThreadCount, 1, 1) \
343 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100344 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 F(GetBreakLocations, 1, 1) \
346 F(SetFunctionBreakPoint, 3, 1) \
347 F(SetScriptBreakPoint, 3, 1) \
348 F(ClearBreakPoint, 1, 1) \
349 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100350 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000351 F(PrepareStep, 3, 1) \
352 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100353 F(DebugEvaluate, 5, 1) \
354 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000355 F(DebugGetLoadedScripts, 0, 1) \
356 F(DebugReferencedBy, 3, 1) \
357 F(DebugConstructedBy, 2, 1) \
358 F(DebugGetPrototype, 1, 1) \
359 F(SystemBreak, 0, 1) \
360 F(DebugDisassembleFunction, 1, 1) \
361 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100362 F(FunctionGetInferredName, 1, 1) \
363 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
364 F(LiveEditGatherCompileInfo, 2, 1) \
365 F(LiveEditReplaceScript, 3, 1) \
366 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100367 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100368 F(LiveEditFunctionSetScript, 2, 1) \
369 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
370 F(LiveEditPatchFunctionPositions, 2, 1) \
371 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100372 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100373 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100374 F(ExecuteInDebugContext, 2, 1) \
375 \
376 F(SetFlags, 1, 1) \
377 F(CollectGarbage, 1, 1) \
378 F(GetHeapUsage, 0, 1)
379
Steve Blocka7e24c12009-10-30 11:49:00 +0000380#else
381#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
382#endif
383
Steve Blockd0582a62009-12-15 09:54:21 +0000384#ifdef ENABLE_LOGGING_AND_PROFILING
385#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000386 F(ProfilerResume, 2, 1) \
387 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000388#else
389#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
390#endif
391
Steve Blocka7e24c12009-10-30 11:49:00 +0000392#ifdef DEBUG
393#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
394 /* Testing */ \
395 F(ListNatives, 0, 1)
396#else
397#define RUNTIME_FUNCTION_LIST_DEBUG(F)
398#endif
399
400
401// ----------------------------------------------------------------------------
402// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
403// either directly by id (via the code generator), or indirectly
404// via a native call by name (from within JS code).
405
406#define RUNTIME_FUNCTION_LIST(F) \
407 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
408 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
409 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000410 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
411 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000412
413// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100414// INLINE_FUNCTION_LIST defines all inlined functions accessed
415// with a native call of the form %_name from within JS code.
416// Entries have the form F(name, number of arguments, number of return values).
417#define INLINE_FUNCTION_LIST(F) \
418 F(IsSmi, 1, 1) \
419 F(IsNonNegativeSmi, 1, 1) \
420 F(IsArray, 1, 1) \
421 F(IsRegExp, 1, 1) \
422 F(CallFunction, -1 /* receiver + n args + function */, 1) \
423 F(ArgumentsLength, 0, 1) \
424 F(Arguments, 1, 1) \
425 F(ValueOf, 1, 1) \
426 F(SetValueOf, 2, 1) \
427 F(StringCharFromCode, 1, 1) \
428 F(StringCharAt, 2, 1) \
429 F(ObjectEquals, 2, 1) \
430 F(RandomHeapNumber, 0, 1) \
431 F(IsObject, 1, 1) \
432 F(IsFunction, 1, 1) \
433 F(IsUndetectableObject, 1, 1) \
434 F(IsSpecObject, 1, 1) \
435 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
436 F(MathPow, 2, 1) \
437 F(MathSin, 1, 1) \
438 F(MathCos, 1, 1) \
439 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100440 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100441 F(IsRegExpEquivalent, 2, 1) \
442 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800443 F(GetCachedArrayIndex, 1, 1) \
444 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100445
446
447// ----------------------------------------------------------------------------
448// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
449// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800450// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100451// Entries have the form F(name, number of arguments, number of return values).
452#define INLINE_RUNTIME_FUNCTION_LIST(F) \
453 F(IsConstructCall, 0, 1) \
454 F(ClassOf, 1, 1) \
455 F(StringCharCodeAt, 2, 1) \
456 F(Log, 3, 1) \
457 F(StringAdd, 2, 1) \
458 F(SubString, 3, 1) \
459 F(StringCompare, 2, 1) \
460 F(RegExpExec, 4, 1) \
461 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100462 F(GetFromCache, 2, 1) \
463 F(NumberToString, 1, 1) \
464 F(SwapElements, 3, 1)
465
466
467//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000468// Runtime provides access to all C++ runtime functions.
469
470class Runtime : public AllStatic {
471 public:
472 enum FunctionId {
473#define F(name, nargs, ressize) k##name,
474 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000475#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100476#define F(name, nargs, ressize) kInline##name,
477 INLINE_FUNCTION_LIST(F)
478 INLINE_RUNTIME_FUNCTION_LIST(F)
479#undef F
480 kNumFunctions,
481 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000482 };
483
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100484 enum IntrinsicType {
485 RUNTIME,
486 INLINE
487 };
488
489 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100491 FunctionId function_id;
492 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 // The JS name of the function.
494 const char* name;
495
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100496 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000497 byte* entry;
498
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100499 // The number of arguments expected. nargs is -1 if the function takes
500 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000501 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100502 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000503 int result_size;
504 };
505
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100506 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000507
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100508 // Add symbols for all the intrinsic function names to a StringDictionary.
509 // Returns failure if an allocation fails. In this case, it must be
510 // retried with a new, empty StringDictionary, not with the same one.
511 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700512 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
513 Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000514
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100515 // Get the intrinsic function with the given name, which must be a symbol.
516 static Function* FunctionForSymbol(Handle<String> name);
517
518 // Get the intrinsic function with the given FunctionId.
519 static Function* FunctionForId(FunctionId id);
520
521 // General-purpose helper functions for runtime system.
Steve Blocka7e24c12009-10-30 11:49:00 +0000522 static int StringMatch(Handle<String> sub, Handle<String> pat, int index);
523
524 static bool IsUpperCaseChar(uint16_t ch);
525
526 // TODO(1240886): The following three methods are *not* handle safe,
527 // but accept handle arguments. This seems fragile.
528
529 // Support getting the characters in a string using [] notation as
530 // in Firefox/SpiderMonkey, Safari and Opera.
John Reck59135872010-11-02 12:39:01 -0700531 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Handle<Object> object,
532 uint32_t index);
533 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
534 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000535
John Reck59135872010-11-02 12:39:01 -0700536 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
537 Handle<Object> object,
538 Handle<Object> key,
539 Handle<Object> value,
540 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000541
John Reck59135872010-11-02 12:39:01 -0700542 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
543 Handle<JSObject> object,
544 Handle<Object> key,
545 Handle<Object> value,
546 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000547
John Reck59135872010-11-02 12:39:01 -0700548 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
549 Handle<JSObject> object,
550 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000551
John Reck59135872010-11-02 12:39:01 -0700552 MUST_USE_RESULT static MaybeObject* GetObjectProperty(Handle<Object> object,
553 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000554
555 // This function is used in FunctionNameUsing* tests.
556 static Object* FindSharedFunctionInfoInScript(Handle<Script> script,
557 int position);
558
559 // Helper functions used stubs.
560 static void PerformGC(Object* result);
561};
562
563
564} } // namespace v8::internal
565
566#endif // V8_RUNTIME_H_