blob: d3223d1a8223f9b5b860b27698b17aff035b76fa [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
Ben Murdoch257744e2011-11-30 15:57:28 +000031#include "allocation.h"
Steve Block44f0eee2011-05-26 01:26:41 +010032#include "zone.h"
33
Steve Blocka7e24c12009-10-30 11:49:00 +000034namespace v8 {
35namespace internal {
36
37// The interface to C++ runtime functions.
38
39// ----------------------------------------------------------------------------
40// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
41// release and debug mode.
42// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
43
44// WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
45// MSVC Intellisense to crash. It was broken into two macros to work around
46// this problem. Please avoid large recursive macros whenever possible.
47#define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
48 /* Property access */ \
49 F(GetProperty, 2, 1) \
50 F(KeyedGetProperty, 2, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +010051 F(DeleteProperty, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000052 F(HasLocalProperty, 2, 1) \
53 F(HasProperty, 2, 1) \
54 F(HasElement, 2, 1) \
55 F(IsPropertyEnumerable, 2, 1) \
56 F(GetPropertyNames, 1, 1) \
57 F(GetPropertyNamesFast, 1, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +000058 F(GetLocalPropertyNames, 1, 1) \
59 F(GetLocalElementNames, 1, 1) \
60 F(GetInterceptorInfo, 1, 1) \
61 F(GetNamedInterceptorPropertyNames, 1, 1) \
62 F(GetIndexedInterceptorElementNames, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000063 F(GetArgumentsProperty, 1, 1) \
64 F(ToFastProperties, 1, 1) \
65 F(ToSlowProperties, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +010066 F(FinishArrayPrototypeSetup, 1, 1) \
67 F(SpecialArrayFunctions, 1, 1) \
68 F(GetGlobalReceiver, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000069 \
70 F(IsInPrototypeChain, 2, 1) \
71 F(SetHiddenPrototype, 2, 1) \
72 \
73 F(IsConstructCall, 0, 1) \
74 \
Leon Clarkee46be812010-01-19 14:06:41 +000075 F(GetOwnProperty, 2, 1) \
76 \
77 F(IsExtensible, 1, 1) \
Steve Block8defd9f2010-07-08 12:39:36 +010078 F(PreventExtensions, 1, 1)\
Leon Clarkee46be812010-01-19 14:06:41 +000079 \
Steve Blocka7e24c12009-10-30 11:49:00 +000080 /* Utilities */ \
Steve Blocka7e24c12009-10-30 11:49:00 +000081 F(GetFunctionDelegate, 1, 1) \
82 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000083 F(NewArgumentsFast, 3, 1) \
84 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010085 F(LazyRecompile, 1, 1) \
86 F(NotifyDeoptimized, 1, 1) \
87 F(NotifyOSR, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010088 F(DeoptimizeFunction, 1, 1) \
89 F(OptimizeFunctionOnNextCall, 1, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +000090 F(GetOptimizationStatus, 1, 1) \
91 F(GetOptimizationCount, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010092 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000093 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010094 F(AllocateInNewSpace, 1, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +000095 F(SetES5Flag, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000096 \
97 /* Array join support */ \
98 F(PushIfAbsent, 2, 1) \
99 F(ArrayConcat, 1, 1) \
100 \
101 /* Conversions */ \
102 F(ToBool, 1, 1) \
103 F(Typeof, 1, 1) \
104 \
105 F(StringToNumber, 1, 1) \
106 F(StringFromCharCodeArray, 1, 1) \
107 F(StringParseInt, 2, 1) \
108 F(StringParseFloat, 1, 1) \
109 F(StringToLowerCase, 1, 1) \
110 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100111 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 F(CharFromCode, 1, 1) \
113 F(URIEscape, 1, 1) \
114 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100115 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100116 F(QuoteJSONStringComma, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000117 \
118 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100119 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000120 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100121 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000122 F(NumberToJSUint32, 1, 1) \
123 F(NumberToJSInt32, 1, 1) \
124 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100125 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000126 \
127 /* Arithmetic operations */ \
128 F(NumberAdd, 2, 1) \
129 F(NumberSub, 2, 1) \
130 F(NumberMul, 2, 1) \
131 F(NumberDiv, 2, 1) \
132 F(NumberMod, 2, 1) \
133 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100134 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000135 \
136 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000137 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100138 F(StringBuilderJoin, 3, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000139 F(SparseJoinWithSeparator, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000140 \
141 /* Bit operations */ \
142 F(NumberOr, 2, 1) \
143 F(NumberAnd, 2, 1) \
144 F(NumberXor, 2, 1) \
145 F(NumberNot, 1, 1) \
146 \
147 F(NumberShl, 2, 1) \
148 F(NumberShr, 2, 1) \
149 F(NumberSar, 2, 1) \
150 \
151 /* Comparisons */ \
152 F(NumberEquals, 2, 1) \
153 F(StringEquals, 2, 1) \
154 \
155 F(NumberCompare, 3, 1) \
156 F(SmiLexicographicCompare, 2, 1) \
157 F(StringCompare, 2, 1) \
158 \
159 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000160 F(Math_acos, 1, 1) \
161 F(Math_asin, 1, 1) \
162 F(Math_atan, 1, 1) \
163 F(Math_atan2, 2, 1) \
164 F(Math_ceil, 1, 1) \
165 F(Math_cos, 1, 1) \
166 F(Math_exp, 1, 1) \
167 F(Math_floor, 1, 1) \
168 F(Math_log, 1, 1) \
169 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100170 F(Math_pow_cfunction, 2, 1) \
171 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000172 F(Math_sin, 1, 1) \
173 F(Math_sqrt, 1, 1) \
174 F(Math_tan, 1, 1) \
175 \
176 /* Regular expressions */ \
177 F(RegExpCompile, 3, 1) \
178 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100179 F(RegExpExecMultiple, 4, 1) \
180 F(RegExpInitializeObject, 5, 1) \
181 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800182 \
183 /* JSON */ \
184 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000185 \
186 /* Strings */ \
187 F(StringCharCodeAt, 2, 1) \
188 F(StringIndexOf, 3, 1) \
189 F(StringLastIndexOf, 3, 1) \
190 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000191 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000192 F(StringReplaceRegExpWithString, 4, 1) \
193 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000194 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800195 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100196 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000197 \
198 /* Numbers */ \
199 F(NumberToRadixString, 2, 1) \
200 F(NumberToFixed, 2, 1) \
201 F(NumberToExponential, 2, 1) \
202 F(NumberToPrecision, 2, 1)
203
204#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
205 /* Reflection */ \
206 F(FunctionSetInstanceClassName, 2, 1) \
207 F(FunctionSetLength, 2, 1) \
208 F(FunctionSetPrototype, 2, 1) \
209 F(FunctionGetName, 1, 1) \
210 F(FunctionSetName, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100211 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000212 F(FunctionGetSourceCode, 1, 1) \
213 F(FunctionGetScript, 1, 1) \
214 F(FunctionGetScriptSourcePosition, 1, 1) \
215 F(FunctionGetPositionForOffset, 2, 1) \
216 F(FunctionIsAPIFunction, 1, 1) \
217 F(FunctionIsBuiltin, 1, 1) \
218 F(GetScript, 1, 1) \
219 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000220 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 \
222 F(ClassOf, 1, 1) \
223 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100224 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 \
226 F(CreateApiFunction, 1, 1) \
227 F(IsTemplate, 1, 1) \
228 F(GetTemplateField, 2, 1) \
229 F(DisableAccessChecks, 1, 1) \
230 F(EnableAccessChecks, 1, 1) \
231 \
232 /* Dates */ \
233 F(DateCurrentTime, 0, 1) \
234 F(DateParseString, 2, 1) \
235 F(DateLocalTimezone, 1, 1) \
236 F(DateLocalTimeOffset, 0, 1) \
237 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100238 F(DateMakeDay, 3, 1) \
239 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000240 \
241 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000242 \
243 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800244 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000245 F(GlobalPrint, 1, 1) \
246 \
247 /* Eval */ \
248 F(GlobalReceiver, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100249 F(ResolvePossiblyDirectEval, 4, 2) \
250 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000251 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100252 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000253 F(DefineOrRedefineDataProperty, 4, 1) \
254 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000255 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
256 \
257 /* Arrays */ \
258 F(RemoveArrayHoles, 2, 1) \
259 F(GetArrayKeys, 2, 1) \
260 F(MoveArrayContents, 2, 1) \
261 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100262 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 \
264 /* Getters and Setters */ \
265 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
266 F(LookupAccessor, 3, 1) \
267 \
268 /* Literals */ \
269 F(MaterializeRegExpLiteral, 4, 1)\
270 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000271 F(CloneLiteralBoilerplate, 1, 1) \
272 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100273 F(CreateObjectLiteral, 4, 1) \
274 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000275 F(CreateArrayLiteral, 3, 1) \
276 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000277 \
Ben Murdoch257744e2011-11-30 15:57:28 +0000278 /* Harmony proxies */ \
279 F(CreateJSProxy, 2, 1) \
280 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 /* Catch context extension objects */ \
282 F(CreateCatchExtensionObject, 2, 1) \
283 \
284 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800285 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100287 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100288 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000289 F(Throw, 1, 1) \
290 F(ReThrow, 1, 1) \
291 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100292 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000293 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000294 \
295 /* Contexts */ \
296 F(NewContext, 1, 1) \
297 F(PushContext, 1, 1) \
298 F(PushCatchContext, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100299 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 F(LoadContextSlot, 2, 2) \
301 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100302 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 \
304 /* Declarations and initialization */ \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100305 F(DeclareGlobals, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100307 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000308 F(InitializeConstGlobal, 2, 1) \
309 F(InitializeConstContextSlot, 3, 1) \
310 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000311 \
312 /* Debugging */ \
313 F(DebugPrint, 1, 1) \
314 F(DebugTrace, 0, 1) \
315 F(TraceEnter, 0, 1) \
316 F(TraceExit, 1, 1) \
317 F(Abort, 2, 1) \
318 /* Logging */ \
319 F(Log, 2, 1) \
320 /* ES5 */ \
321 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100322 /* Cache suport */ \
323 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000324 \
Steve Block1e0659c2011-05-24 12:43:12 +0100325 /* Message objects */ \
326 F(NewMessageObject, 2, 1) \
327 F(MessageGetType, 1, 1) \
328 F(MessageGetArguments, 1, 1) \
329 F(MessageGetStartPosition, 1, 1) \
330 F(MessageGetScript, 1, 1) \
331 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 /* Pseudo functions - handled as macros by parser */ \
Andrei Popescu402d9372010-02-26 13:31:12 +0000333 F(IS_VAR, 1, 1)
Steve Blocka7e24c12009-10-30 11:49:00 +0000334
335#ifdef ENABLE_DEBUGGER_SUPPORT
336#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
337 /* Debugger support*/ \
338 F(DebugBreak, 0, 1) \
339 F(SetDebugEventListener, 2, 1) \
340 F(Break, 0, 1) \
341 F(DebugGetPropertyDetails, 2, 1) \
342 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000343 F(DebugPropertyTypeFromDetails, 1, 1) \
344 F(DebugPropertyAttributesFromDetails, 1, 1) \
345 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 F(DebugNamedInterceptorPropertyValue, 2, 1) \
347 F(DebugIndexedInterceptorElementValue, 2, 1) \
348 F(CheckExecutionState, 1, 1) \
349 F(GetFrameCount, 1, 1) \
350 F(GetFrameDetails, 2, 1) \
351 F(GetScopeCount, 2, 1) \
352 F(GetScopeDetails, 3, 1) \
353 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 F(GetThreadCount, 1, 1) \
355 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100356 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000357 F(GetBreakLocations, 1, 1) \
358 F(SetFunctionBreakPoint, 3, 1) \
359 F(SetScriptBreakPoint, 3, 1) \
360 F(ClearBreakPoint, 1, 1) \
361 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100362 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000363 F(PrepareStep, 3, 1) \
364 F(ClearStepping, 0, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100365 F(DebugEvaluate, 5, 1) \
366 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 F(DebugGetLoadedScripts, 0, 1) \
368 F(DebugReferencedBy, 3, 1) \
369 F(DebugConstructedBy, 2, 1) \
370 F(DebugGetPrototype, 1, 1) \
371 F(SystemBreak, 0, 1) \
372 F(DebugDisassembleFunction, 1, 1) \
373 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100374 F(FunctionGetInferredName, 1, 1) \
375 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
376 F(LiveEditGatherCompileInfo, 2, 1) \
377 F(LiveEditReplaceScript, 3, 1) \
378 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100379 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100380 F(LiveEditFunctionSetScript, 2, 1) \
381 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
382 F(LiveEditPatchFunctionPositions, 2, 1) \
383 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100384 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100385 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100386 F(ExecuteInDebugContext, 2, 1) \
387 \
388 F(SetFlags, 1, 1) \
389 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100390 F(GetHeapUsage, 0, 1) \
391 \
392 /* LiveObjectList support*/ \
393 F(HasLOLEnabled, 0, 1) \
394 F(CaptureLOL, 0, 1) \
395 F(DeleteLOL, 1, 1) \
396 F(DumpLOL, 5, 1) \
397 F(GetLOLObj, 1, 1) \
398 F(GetLOLObjId, 1, 1) \
399 F(GetLOLObjRetainers, 6, 1) \
400 F(GetLOLPath, 3, 1) \
401 F(InfoLOL, 2, 1) \
402 F(PrintLOLObj, 1, 1) \
403 F(ResetLOL, 0, 1) \
404 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100405
Steve Blocka7e24c12009-10-30 11:49:00 +0000406#else
407#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
408#endif
409
Steve Blockd0582a62009-12-15 09:54:21 +0000410#ifdef ENABLE_LOGGING_AND_PROFILING
411#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
Andrei Popescu402d9372010-02-26 13:31:12 +0000412 F(ProfilerResume, 2, 1) \
413 F(ProfilerPause, 2, 1)
Steve Blockd0582a62009-12-15 09:54:21 +0000414#else
415#define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
416#endif
417
Steve Blocka7e24c12009-10-30 11:49:00 +0000418#ifdef DEBUG
419#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
420 /* Testing */ \
421 F(ListNatives, 0, 1)
422#else
423#define RUNTIME_FUNCTION_LIST_DEBUG(F)
424#endif
425
Steve Blocka7e24c12009-10-30 11:49:00 +0000426// ----------------------------------------------------------------------------
427// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
428// either directly by id (via the code generator), or indirectly
429// via a native call by name (from within JS code).
430
431#define RUNTIME_FUNCTION_LIST(F) \
432 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
433 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
434 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Steve Blockd0582a62009-12-15 09:54:21 +0000435 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
436 RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000437
438// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100439// INLINE_FUNCTION_LIST defines all inlined functions accessed
440// with a native call of the form %_name from within JS code.
441// Entries have the form F(name, number of arguments, number of return values).
442#define INLINE_FUNCTION_LIST(F) \
443 F(IsSmi, 1, 1) \
444 F(IsNonNegativeSmi, 1, 1) \
445 F(IsArray, 1, 1) \
446 F(IsRegExp, 1, 1) \
447 F(CallFunction, -1 /* receiver + n args + function */, 1) \
448 F(ArgumentsLength, 0, 1) \
449 F(Arguments, 1, 1) \
450 F(ValueOf, 1, 1) \
451 F(SetValueOf, 2, 1) \
452 F(StringCharFromCode, 1, 1) \
453 F(StringCharAt, 2, 1) \
454 F(ObjectEquals, 2, 1) \
455 F(RandomHeapNumber, 0, 1) \
456 F(IsObject, 1, 1) \
457 F(IsFunction, 1, 1) \
458 F(IsUndetectableObject, 1, 1) \
459 F(IsSpecObject, 1, 1) \
460 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
461 F(MathPow, 2, 1) \
462 F(MathSin, 1, 1) \
463 F(MathCos, 1, 1) \
464 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100465 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100466 F(IsRegExpEquivalent, 2, 1) \
467 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800468 F(GetCachedArrayIndex, 1, 1) \
469 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100470
471
472// ----------------------------------------------------------------------------
473// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
474// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800475// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100476// Entries have the form F(name, number of arguments, number of return values).
477#define INLINE_RUNTIME_FUNCTION_LIST(F) \
478 F(IsConstructCall, 0, 1) \
479 F(ClassOf, 1, 1) \
480 F(StringCharCodeAt, 2, 1) \
481 F(Log, 3, 1) \
482 F(StringAdd, 2, 1) \
483 F(SubString, 3, 1) \
484 F(StringCompare, 2, 1) \
485 F(RegExpExec, 4, 1) \
486 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100487 F(GetFromCache, 2, 1) \
488 F(NumberToString, 1, 1) \
489 F(SwapElements, 3, 1)
490
491
492//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000493// Runtime provides access to all C++ runtime functions.
494
Steve Block44f0eee2011-05-26 01:26:41 +0100495class RuntimeState {
496 public:
497
498 StaticResource<StringInputBuffer>* string_input_buffer() {
499 return &string_input_buffer_;
500 }
501 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
502 return &to_upper_mapping_;
503 }
504 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
505 return &to_lower_mapping_;
506 }
507 StringInputBuffer* string_input_buffer_compare_bufx() {
508 return &string_input_buffer_compare_bufx_;
509 }
510 StringInputBuffer* string_input_buffer_compare_bufy() {
511 return &string_input_buffer_compare_bufy_;
512 }
513 StringInputBuffer* string_locale_compare_buf1() {
514 return &string_locale_compare_buf1_;
515 }
516 StringInputBuffer* string_locale_compare_buf2() {
517 return &string_locale_compare_buf2_;
518 }
519 int* smi_lexicographic_compare_x_elms() {
520 return smi_lexicographic_compare_x_elms_;
521 }
522 int* smi_lexicographic_compare_y_elms() {
523 return smi_lexicographic_compare_y_elms_;
524 }
525
526 private:
527 RuntimeState() {}
528 // Non-reentrant string buffer for efficient general use in the runtime.
529 StaticResource<StringInputBuffer> string_input_buffer_;
530 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
531 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
532 StringInputBuffer string_input_buffer_compare_bufx_;
533 StringInputBuffer string_input_buffer_compare_bufy_;
534 StringInputBuffer string_locale_compare_buf1_;
535 StringInputBuffer string_locale_compare_buf2_;
536 int smi_lexicographic_compare_x_elms_[10];
537 int smi_lexicographic_compare_y_elms_[10];
538
539 friend class Isolate;
540 friend class Runtime;
541
542 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
543};
544
545
Steve Blocka7e24c12009-10-30 11:49:00 +0000546class Runtime : public AllStatic {
547 public:
548 enum FunctionId {
549#define F(name, nargs, ressize) k##name,
550 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000551#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100552#define F(name, nargs, ressize) kInline##name,
553 INLINE_FUNCTION_LIST(F)
554 INLINE_RUNTIME_FUNCTION_LIST(F)
555#undef F
556 kNumFunctions,
557 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 };
559
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100560 enum IntrinsicType {
561 RUNTIME,
562 INLINE
563 };
564
565 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100567 FunctionId function_id;
568 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000569 // The JS name of the function.
570 const char* name;
571
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100572 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000573 byte* entry;
574
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100575 // The number of arguments expected. nargs is -1 if the function takes
576 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000577 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100578 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 int result_size;
580 };
581
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100582 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000583
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100584 // Add symbols for all the intrinsic function names to a StringDictionary.
585 // Returns failure if an allocation fails. In this case, it must be
586 // retried with a new, empty StringDictionary, not with the same one.
587 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700588 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100589 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000590
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100591 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100592 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100593
594 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100595 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100596
597 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100598 static int StringMatch(Isolate* isolate,
599 Handle<String> sub,
600 Handle<String> pat,
601 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000602
Steve Block44f0eee2011-05-26 01:26:41 +0100603 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000604
605 // TODO(1240886): The following three methods are *not* handle safe,
606 // but accept handle arguments. This seems fragile.
607
608 // Support getting the characters in a string using [] notation as
609 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100610 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
611 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700612 uint32_t index);
613 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
614 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000615
John Reck59135872010-11-02 12:39:01 -0700616 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100617 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700618 Handle<Object> object,
619 Handle<Object> key,
620 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100621 PropertyAttributes attr,
622 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000623
John Reck59135872010-11-02 12:39:01 -0700624 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100625 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700626 Handle<JSObject> object,
627 Handle<Object> key,
628 Handle<Object> value,
629 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000630
John Reck59135872010-11-02 12:39:01 -0700631 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100632 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700633 Handle<JSObject> object,
634 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000635
Steve Block44f0eee2011-05-26 01:26:41 +0100636 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
637 Isolate* isolate,
638 Handle<Object> object,
639 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000640
641 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100642 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
643 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000644 int position);
645
646 // Helper functions used stubs.
647 static void PerformGC(Object* result);
648};
649
Steve Blocka7e24c12009-10-30 11:49:00 +0000650} } // namespace v8::internal
651
652#endif // V8_RUNTIME_H_