blob: 2fa7438619cb7b12d3dfbee69b6bd359d65eff2a [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) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000109 \
110 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100111 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100113 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000114 F(NumberToJSUint32, 1, 1) \
115 F(NumberToJSInt32, 1, 1) \
116 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100117 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 \
119 /* Arithmetic operations */ \
120 F(NumberAdd, 2, 1) \
121 F(NumberSub, 2, 1) \
122 F(NumberMul, 2, 1) \
123 F(NumberDiv, 2, 1) \
124 F(NumberMod, 2, 1) \
125 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100126 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 \
128 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000129 F(StringBuilderConcat, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 \
131 /* Bit operations */ \
132 F(NumberOr, 2, 1) \
133 F(NumberAnd, 2, 1) \
134 F(NumberXor, 2, 1) \
135 F(NumberNot, 1, 1) \
136 \
137 F(NumberShl, 2, 1) \
138 F(NumberShr, 2, 1) \
139 F(NumberSar, 2, 1) \
140 \
141 /* Comparisons */ \
142 F(NumberEquals, 2, 1) \
143 F(StringEquals, 2, 1) \
144 \
145 F(NumberCompare, 3, 1) \
146 F(SmiLexicographicCompare, 2, 1) \
147 F(StringCompare, 2, 1) \
148 \
149 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000150 F(Math_acos, 1, 1) \
151 F(Math_asin, 1, 1) \
152 F(Math_atan, 1, 1) \
153 F(Math_atan2, 2, 1) \
154 F(Math_ceil, 1, 1) \
155 F(Math_cos, 1, 1) \
156 F(Math_exp, 1, 1) \
157 F(Math_floor, 1, 1) \
158 F(Math_log, 1, 1) \
159 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100160 F(Math_pow_cfunction, 2, 1) \
161 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000162 F(Math_sin, 1, 1) \
163 F(Math_sqrt, 1, 1) \
164 F(Math_tan, 1, 1) \
165 \
166 /* Regular expressions */ \
167 F(RegExpCompile, 3, 1) \
168 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100169 F(RegExpExecMultiple, 4, 1) \
170 F(RegExpInitializeObject, 5, 1) \
171 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800172 \
173 /* JSON */ \
174 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000175 \
176 /* Strings */ \
177 F(StringCharCodeAt, 2, 1) \
178 F(StringIndexOf, 3, 1) \
179 F(StringLastIndexOf, 3, 1) \
180 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000181 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000182 F(StringReplaceRegExpWithString, 4, 1) \
183 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000184 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800185 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100186 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 \
188 /* Numbers */ \
189 F(NumberToRadixString, 2, 1) \
190 F(NumberToFixed, 2, 1) \
191 F(NumberToExponential, 2, 1) \
192 F(NumberToPrecision, 2, 1)
193
194#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
195 /* Reflection */ \
196 F(FunctionSetInstanceClassName, 2, 1) \
197 F(FunctionSetLength, 2, 1) \
198 F(FunctionSetPrototype, 2, 1) \
199 F(FunctionGetName, 1, 1) \
200 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100201 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000202 F(FunctionGetSourceCode, 1, 1) \
203 F(FunctionGetScript, 1, 1) \
204 F(FunctionGetScriptSourcePosition, 1, 1) \
205 F(FunctionGetPositionForOffset, 2, 1) \
206 F(FunctionIsAPIFunction, 1, 1) \
207 F(FunctionIsBuiltin, 1, 1) \
208 F(GetScript, 1, 1) \
209 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000210 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000211 \
212 F(ClassOf, 1, 1) \
213 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100214 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 \
216 F(CreateApiFunction, 1, 1) \
217 F(IsTemplate, 1, 1) \
218 F(GetTemplateField, 2, 1) \
219 F(DisableAccessChecks, 1, 1) \
220 F(EnableAccessChecks, 1, 1) \
221 \
222 /* Dates */ \
223 F(DateCurrentTime, 0, 1) \
224 F(DateParseString, 2, 1) \
225 F(DateLocalTimezone, 1, 1) \
226 F(DateLocalTimeOffset, 0, 1) \
227 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100228 F(DateMakeDay, 3, 1) \
229 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 \
231 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000232 \
233 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800234 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 F(GlobalPrint, 1, 1) \
236 \
237 /* Eval */ \
238 F(GlobalReceiver, 1, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000239 F(ResolvePossiblyDirectEval, 3, 2) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100240 F(ResolvePossiblyDirectEvalNoLookup, 3, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000241 \
242 F(SetProperty, -1 /* 3 or 4 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000243 F(DefineOrRedefineDataProperty, 4, 1) \
244 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000245 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
246 \
247 /* Arrays */ \
248 F(RemoveArrayHoles, 2, 1) \
249 F(GetArrayKeys, 2, 1) \
250 F(MoveArrayContents, 2, 1) \
251 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100252 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000253 \
254 /* Getters and Setters */ \
255 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
256 F(LookupAccessor, 3, 1) \
257 \
258 /* Literals */ \
259 F(MaterializeRegExpLiteral, 4, 1)\
260 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000261 F(CloneLiteralBoilerplate, 1, 1) \
262 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100263 F(CreateObjectLiteral, 4, 1) \
264 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000265 F(CreateArrayLiteral, 3, 1) \
266 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000267 \
268 /* Catch context extension objects */ \
269 F(CreateCatchExtensionObject, 2, 1) \
270 \
271 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800272 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000273 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100274 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100275 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000276 F(Throw, 1, 1) \
277 F(ReThrow, 1, 1) \
278 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100279 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000280 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 \
282 /* Contexts */ \
283 F(NewContext, 1, 1) \
284 F(PushContext, 1, 1) \
285 F(PushCatchContext, 1, 1) \
286 F(LookupContext, 2, 1) \
287 F(LoadContextSlot, 2, 2) \
288 F(LoadContextSlotNoReferenceError, 2, 2) \
289 F(StoreContextSlot, 3, 1) \
290 \
291 /* Declarations and initialization */ \
292 F(DeclareGlobals, 3, 1) \
293 F(DeclareContextSlot, 4, 1) \
294 F(InitializeVarGlobal, -1 /* 1 or 2 */, 1) \
295 F(InitializeConstGlobal, 2, 1) \
296 F(InitializeConstContextSlot, 3, 1) \
297 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 \
299 /* Debugging */ \
300 F(DebugPrint, 1, 1) \
301 F(DebugTrace, 0, 1) \
302 F(TraceEnter, 0, 1) \
303 F(TraceExit, 1, 1) \
304 F(Abort, 2, 1) \
305 /* Logging */ \
306 F(Log, 2, 1) \
307 /* ES5 */ \
308 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100309 /* Cache suport */ \
310 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000311 \
312 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000313 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000314
315#ifdef ENABLE_DEBUGGER_SUPPORT
316#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
317 /* Debugger support*/ \
318 F(DebugBreak, 0, 1) \
319 F(SetDebugEventListener, 2, 1) \
320 F(Break, 0, 1) \
321 F(DebugGetPropertyDetails, 2, 1) \
322 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 F(DebugPropertyTypeFromDetails, 1, 1) \
324 F(DebugPropertyAttributesFromDetails, 1, 1) \
325 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 F(DebugNamedInterceptorPropertyValue, 2, 1) \
327 F(DebugIndexedInterceptorElementValue, 2, 1) \
328 F(CheckExecutionState, 1, 1) \
329 F(GetFrameCount, 1, 1) \
330 F(GetFrameDetails, 2, 1) \
331 F(GetScopeCount, 2, 1) \
332 F(GetScopeDetails, 3, 1) \
333 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000334 F(GetThreadCount, 1, 1) \
335 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100336 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 F(GetBreakLocations, 1, 1) \
338 F(SetFunctionBreakPoint, 3, 1) \
339 F(SetScriptBreakPoint, 3, 1) \
340 F(ClearBreakPoint, 1, 1) \
341 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100342 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 F(PrepareStep, 3, 1) \
344 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100345 F(DebugEvaluate, 5, 1) \
346 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000347 F(DebugGetLoadedScripts, 0, 1) \
348 F(DebugReferencedBy, 3, 1) \
349 F(DebugConstructedBy, 2, 1) \
350 F(DebugGetPrototype, 1, 1) \
351 F(SystemBreak, 0, 1) \
352 F(DebugDisassembleFunction, 1, 1) \
353 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100354 F(FunctionGetInferredName, 1, 1) \
355 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
356 F(LiveEditGatherCompileInfo, 2, 1) \
357 F(LiveEditReplaceScript, 3, 1) \
358 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100359 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100360 F(LiveEditFunctionSetScript, 2, 1) \
361 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
362 F(LiveEditPatchFunctionPositions, 2, 1) \
363 F(LiveEditCheckAndDropActivations, 2, 1) \
364 F(LiveEditCompareStringsLinewise, 2, 1) \
365 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100366 F(ExecuteInDebugContext, 2, 1) \
367 \
368 F(SetFlags, 1, 1) \
369 F(CollectGarbage, 1, 1) \
370 F(GetHeapUsage, 0, 1)
371
Steve Blocka7e24c12009-10-30 11:49:00 +0000372#else
373#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
374#endif
375
Steve Blockd0582a62009-12-15 09:54:21 +0000376#ifdef ENABLE_LOGGING_AND_PROFILING
377#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000378 F(ProfilerResume, 2, 1) \
379 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000380#else
381#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
382#endif
383
Steve Blocka7e24c12009-10-30 11:49:00 +0000384#ifdef DEBUG
385#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
386 /* Testing */ \
387 F(ListNatives, 0, 1)
388#else
389#define RUNTIME_FUNCTION_LIST_DEBUG(F)
390#endif
391
392
393// ----------------------------------------------------------------------------
394// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
395// either directly by id (via the code generator), or indirectly
396// via a native call by name (from within JS code).
397
398#define RUNTIME_FUNCTION_LIST(F) \
399 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
400 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
401 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000402 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
403 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000404
405// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100406// INLINE_FUNCTION_LIST defines all inlined functions accessed
407// with a native call of the form %_name from within JS code.
408// Entries have the form F(name, number of arguments, number of return values).
409#define INLINE_FUNCTION_LIST(F) \
410 F(IsSmi, 1, 1) \
411 F(IsNonNegativeSmi, 1, 1) \
412 F(IsArray, 1, 1) \
413 F(IsRegExp, 1, 1) \
414 F(CallFunction, -1 /* receiver + n args + function */, 1) \
415 F(ArgumentsLength, 0, 1) \
416 F(Arguments, 1, 1) \
417 F(ValueOf, 1, 1) \
418 F(SetValueOf, 2, 1) \
419 F(StringCharFromCode, 1, 1) \
420 F(StringCharAt, 2, 1) \
421 F(ObjectEquals, 2, 1) \
422 F(RandomHeapNumber, 0, 1) \
423 F(IsObject, 1, 1) \
424 F(IsFunction, 1, 1) \
425 F(IsUndetectableObject, 1, 1) \
426 F(IsSpecObject, 1, 1) \
427 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
428 F(MathPow, 2, 1) \
429 F(MathSin, 1, 1) \
430 F(MathCos, 1, 1) \
431 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100432 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100433 F(IsRegExpEquivalent, 2, 1) \
434 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800435 F(GetCachedArrayIndex, 1, 1) \
436 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100437
438
439// ----------------------------------------------------------------------------
440// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
441// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800442// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100443// Entries have the form F(name, number of arguments, number of return values).
444#define INLINE_RUNTIME_FUNCTION_LIST(F) \
445 F(IsConstructCall, 0, 1) \
446 F(ClassOf, 1, 1) \
447 F(StringCharCodeAt, 2, 1) \
448 F(Log, 3, 1) \
449 F(StringAdd, 2, 1) \
450 F(SubString, 3, 1) \
451 F(StringCompare, 2, 1) \
452 F(RegExpExec, 4, 1) \
453 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100454 F(GetFromCache, 2, 1) \
455 F(NumberToString, 1, 1) \
456 F(SwapElements, 3, 1)
457
458
459//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000460// Runtime provides access to all C++ runtime functions.
461
462class Runtime : public AllStatic {
463 public:
464 enum FunctionId {
465#define F(name, nargs, ressize) k##name,
466 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000467#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100468#define F(name, nargs, ressize) kInline##name,
469 INLINE_FUNCTION_LIST(F)
470 INLINE_RUNTIME_FUNCTION_LIST(F)
471#undef F
472 kNumFunctions,
473 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000474 };
475
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100476 enum IntrinsicType {
477 RUNTIME,
478 INLINE
479 };
480
481 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000482 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100483 FunctionId function_id;
484 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000485 // The JS name of the function.
486 const char* name;
487
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100488 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000489 byte* entry;
490
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100491 // The number of arguments expected. nargs is -1 if the function takes
492 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100494 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000495 int result_size;
496 };
497
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100498 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000499
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100500 // Add symbols for all the intrinsic function names to a StringDictionary.
501 // Returns failure if an allocation fails. In this case, it must be
502 // retried with a new, empty StringDictionary, not with the same one.
503 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700504 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
505 Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000506
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100507 // Get the intrinsic function with the given name, which must be a symbol.
508 static Function* FunctionForSymbol(Handle<String> name);
509
510 // Get the intrinsic function with the given FunctionId.
511 static Function* FunctionForId(FunctionId id);
512
513 // General-purpose helper functions for runtime system.
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 static int StringMatch(Handle<String> sub, Handle<String> pat, int index);
515
516 static bool IsUpperCaseChar(uint16_t ch);
517
518 // TODO(1240886): The following three methods are *not* handle safe,
519 // but accept handle arguments. This seems fragile.
520
521 // Support getting the characters in a string using [] notation as
522 // in Firefox/SpiderMonkey, Safari and Opera.
John Reck59135872010-11-02 12:39:01 -0700523 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Handle<Object> object,
524 uint32_t index);
525 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
526 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000527
John Reck59135872010-11-02 12:39:01 -0700528 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
529 Handle<Object> object,
530 Handle<Object> key,
531 Handle<Object> value,
532 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000533
John Reck59135872010-11-02 12:39:01 -0700534 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
535 Handle<JSObject> object,
536 Handle<Object> key,
537 Handle<Object> value,
538 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000539
John Reck59135872010-11-02 12:39:01 -0700540 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
541 Handle<JSObject> object,
542 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000543
John Reck59135872010-11-02 12:39:01 -0700544 MUST_USE_RESULT static MaybeObject* GetObjectProperty(Handle<Object> object,
545 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000546
547 // This function is used in FunctionNameUsing* tests.
548 static Object* FindSharedFunctionInfoInScript(Handle<Script> script,
549 int position);
550
551 // Helper functions used stubs.
552 static void PerformGC(Object* result);
553};
554
555
556} } // namespace v8::internal
557
558#endif // V8_RUNTIME_H_