blob: 91a19dfd453d592aec932b884862a06e3ff14ce0 [file] [log] [blame]
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001// Copyright 2011 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) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +000068 F(GetDefaultReceiver, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000069 \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000070 F(GetPrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000071 F(IsInPrototypeChain, 2, 1) \
72 F(SetHiddenPrototype, 2, 1) \
73 \
74 F(IsConstructCall, 0, 1) \
75 \
Leon Clarkee46be812010-01-19 14:06:41 +000076 F(GetOwnProperty, 2, 1) \
77 \
78 F(IsExtensible, 1, 1) \
Steve Block8defd9f2010-07-08 12:39:36 +010079 F(PreventExtensions, 1, 1)\
Leon Clarkee46be812010-01-19 14:06:41 +000080 \
Steve Blocka7e24c12009-10-30 11:49:00 +000081 /* Utilities */ \
Steve Blocka7e24c12009-10-30 11:49:00 +000082 F(GetFunctionDelegate, 1, 1) \
83 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000084 F(NewArgumentsFast, 3, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000085 F(NewStrictArgumentsFast, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000086 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010087 F(LazyRecompile, 1, 1) \
88 F(NotifyDeoptimized, 1, 1) \
89 F(NotifyOSR, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010090 F(DeoptimizeFunction, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000091 F(RunningInSimulator, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010092 F(OptimizeFunctionOnNextCall, 1, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +000093 F(GetOptimizationStatus, 1, 1) \
94 F(GetOptimizationCount, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010095 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000096 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010097 F(AllocateInNewSpace, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000098 F(SetNativeFlag, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000099 \
100 /* Array join support */ \
101 F(PushIfAbsent, 2, 1) \
102 F(ArrayConcat, 1, 1) \
103 \
104 /* Conversions */ \
105 F(ToBool, 1, 1) \
106 F(Typeof, 1, 1) \
107 \
108 F(StringToNumber, 1, 1) \
109 F(StringFromCharCodeArray, 1, 1) \
110 F(StringParseInt, 2, 1) \
111 F(StringParseFloat, 1, 1) \
112 F(StringToLowerCase, 1, 1) \
113 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100114 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000115 F(CharFromCode, 1, 1) \
116 F(URIEscape, 1, 1) \
117 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100118 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100119 F(QuoteJSONStringComma, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000120 F(QuoteJSONStringArray, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 \
122 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100123 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100125 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000126 F(NumberToJSUint32, 1, 1) \
127 F(NumberToJSInt32, 1, 1) \
128 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100129 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 \
131 /* Arithmetic operations */ \
132 F(NumberAdd, 2, 1) \
133 F(NumberSub, 2, 1) \
134 F(NumberMul, 2, 1) \
135 F(NumberDiv, 2, 1) \
136 F(NumberMod, 2, 1) \
137 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100138 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000139 \
140 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000141 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100142 F(StringBuilderJoin, 3, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000143 F(SparseJoinWithSeparator, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000144 \
145 /* Bit operations */ \
146 F(NumberOr, 2, 1) \
147 F(NumberAnd, 2, 1) \
148 F(NumberXor, 2, 1) \
149 F(NumberNot, 1, 1) \
150 \
151 F(NumberShl, 2, 1) \
152 F(NumberShr, 2, 1) \
153 F(NumberSar, 2, 1) \
154 \
155 /* Comparisons */ \
156 F(NumberEquals, 2, 1) \
157 F(StringEquals, 2, 1) \
158 \
159 F(NumberCompare, 3, 1) \
160 F(SmiLexicographicCompare, 2, 1) \
161 F(StringCompare, 2, 1) \
162 \
163 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 F(Math_acos, 1, 1) \
165 F(Math_asin, 1, 1) \
166 F(Math_atan, 1, 1) \
167 F(Math_atan2, 2, 1) \
168 F(Math_ceil, 1, 1) \
169 F(Math_cos, 1, 1) \
170 F(Math_exp, 1, 1) \
171 F(Math_floor, 1, 1) \
172 F(Math_log, 1, 1) \
173 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100174 F(Math_pow_cfunction, 2, 1) \
175 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000176 F(Math_sin, 1, 1) \
177 F(Math_sqrt, 1, 1) \
178 F(Math_tan, 1, 1) \
179 \
180 /* Regular expressions */ \
181 F(RegExpCompile, 3, 1) \
182 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100183 F(RegExpExecMultiple, 4, 1) \
184 F(RegExpInitializeObject, 5, 1) \
185 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800186 \
187 /* JSON */ \
188 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000189 \
190 /* Strings */ \
191 F(StringCharCodeAt, 2, 1) \
192 F(StringIndexOf, 3, 1) \
193 F(StringLastIndexOf, 3, 1) \
194 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000195 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000196 F(StringReplaceRegExpWithString, 4, 1) \
197 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000198 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800199 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100200 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000201 \
202 /* Numbers */ \
203 F(NumberToRadixString, 2, 1) \
204 F(NumberToFixed, 2, 1) \
205 F(NumberToExponential, 2, 1) \
206 F(NumberToPrecision, 2, 1)
207
208#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
209 /* Reflection */ \
210 F(FunctionSetInstanceClassName, 2, 1) \
211 F(FunctionSetLength, 2, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000212 F(BoundFunctionSetLength, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 F(FunctionSetPrototype, 2, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000214 F(FunctionSetReadOnlyPrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 F(FunctionGetName, 1, 1) \
216 F(FunctionSetName, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000217 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
218 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
219 F(FunctionSetBound, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100220 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000221 F(FunctionGetSourceCode, 1, 1) \
222 F(FunctionGetScript, 1, 1) \
223 F(FunctionGetScriptSourcePosition, 1, 1) \
224 F(FunctionGetPositionForOffset, 2, 1) \
225 F(FunctionIsAPIFunction, 1, 1) \
226 F(FunctionIsBuiltin, 1, 1) \
227 F(GetScript, 1, 1) \
228 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000229 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000230 \
231 F(ClassOf, 1, 1) \
232 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100233 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 \
235 F(CreateApiFunction, 1, 1) \
236 F(IsTemplate, 1, 1) \
237 F(GetTemplateField, 2, 1) \
238 F(DisableAccessChecks, 1, 1) \
239 F(EnableAccessChecks, 1, 1) \
240 \
241 /* Dates */ \
242 F(DateCurrentTime, 0, 1) \
243 F(DateParseString, 2, 1) \
244 F(DateLocalTimezone, 1, 1) \
245 F(DateLocalTimeOffset, 0, 1) \
246 F(DateDaylightSavingsOffset, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100247 F(DateMakeDay, 3, 1) \
248 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000249 \
250 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000251 \
252 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800253 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000254 F(GlobalPrint, 1, 1) \
255 \
256 /* Eval */ \
257 F(GlobalReceiver, 1, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100258 F(ResolvePossiblyDirectEval, 4, 2) \
259 F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000260 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100261 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000262 F(DefineOrRedefineDataProperty, 4, 1) \
263 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000264 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
265 \
266 /* Arrays */ \
267 F(RemoveArrayHoles, 2, 1) \
268 F(GetArrayKeys, 2, 1) \
269 F(MoveArrayContents, 2, 1) \
270 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100271 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000272 \
273 /* Getters and Setters */ \
274 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
275 F(LookupAccessor, 3, 1) \
276 \
277 /* Literals */ \
278 F(MaterializeRegExpLiteral, 4, 1)\
279 F(CreateArrayLiteralBoilerplate, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 F(CloneLiteralBoilerplate, 1, 1) \
281 F(CloneShallowLiteralBoilerplate, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100282 F(CreateObjectLiteral, 4, 1) \
283 F(CreateObjectLiteralShallow, 4, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000284 F(CreateArrayLiteral, 3, 1) \
285 F(CreateArrayLiteralShallow, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000286 \
Ben Murdoch257744e2011-11-30 15:57:28 +0000287 /* Harmony proxies */ \
288 F(CreateJSProxy, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000289 F(IsJSProxy, 1, 1) \
290 F(GetHandler, 1, 1) \
291 F(Fix, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000292 \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000293 /* Harmony weakmaps */ \
294 F(WeakMapInitialize, 1, 1) \
295 F(WeakMapGet, 2, 1) \
296 F(WeakMapSet, 3, 1) \
297 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000298 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800299 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 F(NewObject, 1, 1) \
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100301 F(NewObjectFromBound, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100302 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 F(Throw, 1, 1) \
304 F(ReThrow, 1, 1) \
305 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100306 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000307 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000308 \
309 /* Contexts */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000310 F(NewFunctionContext, 1, 1) \
311 F(PushWithContext, 2, 1) \
312 F(PushCatchContext, 3, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000313 F(PushBlockContext, 2, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100314 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 F(LoadContextSlot, 2, 2) \
316 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100317 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000318 \
319 /* Declarations and initialization */ \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100320 F(DeclareGlobals, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000321 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100322 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 F(InitializeConstGlobal, 2, 1) \
324 F(InitializeConstContextSlot, 3, 1) \
325 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 \
327 /* Debugging */ \
328 F(DebugPrint, 1, 1) \
329 F(DebugTrace, 0, 1) \
330 F(TraceEnter, 0, 1) \
331 F(TraceExit, 1, 1) \
332 F(Abort, 2, 1) \
333 /* Logging */ \
334 F(Log, 2, 1) \
335 /* ES5 */ \
336 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100337 /* Cache suport */ \
338 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 \
Steve Block1e0659c2011-05-24 12:43:12 +0100340 /* Message objects */ \
341 F(NewMessageObject, 2, 1) \
342 F(MessageGetType, 1, 1) \
343 F(MessageGetArguments, 1, 1) \
344 F(MessageGetStartPosition, 1, 1) \
345 F(MessageGetScript, 1, 1) \
346 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000347 /* Pseudo functions - handled as macros by parser */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000348 F(IS_VAR, 1, 1) \
349 \
350 /* expose boolean functions from objects-inl.h */ \
351 F(HasFastElements, 1, 1) \
352 F(HasFastDoubleElements, 1, 1) \
353 F(HasDictionaryElements, 1, 1) \
354 F(HasExternalPixelElements, 1, 1) \
355 F(HasExternalArrayElements, 1, 1) \
356 F(HasExternalByteElements, 1, 1) \
357 F(HasExternalUnsignedByteElements, 1, 1) \
358 F(HasExternalShortElements, 1, 1) \
359 F(HasExternalUnsignedShortElements, 1, 1) \
360 F(HasExternalIntElements, 1, 1) \
361 F(HasExternalUnsignedIntElements, 1, 1) \
362 F(HasExternalFloatElements, 1, 1) \
363 F(HasExternalDoubleElements, 1, 1) \
364 /* profiler */ \
365 F(ProfilerResume, 0, 1) \
366 F(ProfilerPause, 0, 1)
367
Steve Blocka7e24c12009-10-30 11:49:00 +0000368
369#ifdef ENABLE_DEBUGGER_SUPPORT
370#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
371 /* Debugger support*/ \
372 F(DebugBreak, 0, 1) \
373 F(SetDebugEventListener, 2, 1) \
374 F(Break, 0, 1) \
375 F(DebugGetPropertyDetails, 2, 1) \
376 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 F(DebugPropertyTypeFromDetails, 1, 1) \
378 F(DebugPropertyAttributesFromDetails, 1, 1) \
379 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 F(DebugNamedInterceptorPropertyValue, 2, 1) \
381 F(DebugIndexedInterceptorElementValue, 2, 1) \
382 F(CheckExecutionState, 1, 1) \
383 F(GetFrameCount, 1, 1) \
384 F(GetFrameDetails, 2, 1) \
385 F(GetScopeCount, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000386 F(GetScopeDetails, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000387 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 F(GetThreadCount, 1, 1) \
389 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100390 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 F(GetBreakLocations, 1, 1) \
392 F(SetFunctionBreakPoint, 3, 1) \
393 F(SetScriptBreakPoint, 3, 1) \
394 F(ClearBreakPoint, 1, 1) \
395 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100396 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000397 F(PrepareStep, 3, 1) \
398 F(ClearStepping, 0, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000399 F(DebugEvaluate, 6, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100400 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000401 F(DebugGetLoadedScripts, 0, 1) \
402 F(DebugReferencedBy, 3, 1) \
403 F(DebugConstructedBy, 2, 1) \
404 F(DebugGetPrototype, 1, 1) \
405 F(SystemBreak, 0, 1) \
406 F(DebugDisassembleFunction, 1, 1) \
407 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100408 F(FunctionGetInferredName, 1, 1) \
409 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
410 F(LiveEditGatherCompileInfo, 2, 1) \
411 F(LiveEditReplaceScript, 3, 1) \
412 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100413 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100414 F(LiveEditFunctionSetScript, 2, 1) \
415 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
416 F(LiveEditPatchFunctionPositions, 2, 1) \
417 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100418 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100419 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100420 F(ExecuteInDebugContext, 2, 1) \
421 \
422 F(SetFlags, 1, 1) \
423 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100424 F(GetHeapUsage, 0, 1) \
425 \
426 /* LiveObjectList support*/ \
427 F(HasLOLEnabled, 0, 1) \
428 F(CaptureLOL, 0, 1) \
429 F(DeleteLOL, 1, 1) \
430 F(DumpLOL, 5, 1) \
431 F(GetLOLObj, 1, 1) \
432 F(GetLOLObjId, 1, 1) \
433 F(GetLOLObjRetainers, 6, 1) \
434 F(GetLOLPath, 3, 1) \
435 F(InfoLOL, 2, 1) \
436 F(PrintLOLObj, 1, 1) \
437 F(ResetLOL, 0, 1) \
438 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100439
Steve Blocka7e24c12009-10-30 11:49:00 +0000440#else
441#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
442#endif
443
444#ifdef DEBUG
445#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
446 /* Testing */ \
447 F(ListNatives, 0, 1)
448#else
449#define RUNTIME_FUNCTION_LIST_DEBUG(F)
450#endif
451
Steve Blocka7e24c12009-10-30 11:49:00 +0000452// ----------------------------------------------------------------------------
453// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
454// either directly by id (via the code generator), or indirectly
455// via a native call by name (from within JS code).
456
457#define RUNTIME_FUNCTION_LIST(F) \
458 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
459 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
460 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000461 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000462
463// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100464// INLINE_FUNCTION_LIST defines all inlined functions accessed
465// with a native call of the form %_name from within JS code.
466// Entries have the form F(name, number of arguments, number of return values).
467#define INLINE_FUNCTION_LIST(F) \
468 F(IsSmi, 1, 1) \
469 F(IsNonNegativeSmi, 1, 1) \
470 F(IsArray, 1, 1) \
471 F(IsRegExp, 1, 1) \
472 F(CallFunction, -1 /* receiver + n args + function */, 1) \
473 F(ArgumentsLength, 0, 1) \
474 F(Arguments, 1, 1) \
475 F(ValueOf, 1, 1) \
476 F(SetValueOf, 2, 1) \
477 F(StringCharFromCode, 1, 1) \
478 F(StringCharAt, 2, 1) \
479 F(ObjectEquals, 2, 1) \
480 F(RandomHeapNumber, 0, 1) \
481 F(IsObject, 1, 1) \
482 F(IsFunction, 1, 1) \
483 F(IsUndetectableObject, 1, 1) \
484 F(IsSpecObject, 1, 1) \
485 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
486 F(MathPow, 2, 1) \
487 F(MathSin, 1, 1) \
488 F(MathCos, 1, 1) \
489 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100490 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100491 F(IsRegExpEquivalent, 2, 1) \
492 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800493 F(GetCachedArrayIndex, 1, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000494 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100495
496
497// ----------------------------------------------------------------------------
498// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
499// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800500// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100501// Entries have the form F(name, number of arguments, number of return values).
502#define INLINE_RUNTIME_FUNCTION_LIST(F) \
503 F(IsConstructCall, 0, 1) \
504 F(ClassOf, 1, 1) \
505 F(StringCharCodeAt, 2, 1) \
506 F(Log, 3, 1) \
507 F(StringAdd, 2, 1) \
508 F(SubString, 3, 1) \
509 F(StringCompare, 2, 1) \
510 F(RegExpExec, 4, 1) \
511 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100512 F(GetFromCache, 2, 1) \
513 F(NumberToString, 1, 1) \
514 F(SwapElements, 3, 1)
515
516
517//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000518// Runtime provides access to all C++ runtime functions.
519
Steve Block44f0eee2011-05-26 01:26:41 +0100520class RuntimeState {
521 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100522 StaticResource<StringInputBuffer>* string_input_buffer() {
523 return &string_input_buffer_;
524 }
525 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
526 return &to_upper_mapping_;
527 }
528 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
529 return &to_lower_mapping_;
530 }
531 StringInputBuffer* string_input_buffer_compare_bufx() {
532 return &string_input_buffer_compare_bufx_;
533 }
534 StringInputBuffer* string_input_buffer_compare_bufy() {
535 return &string_input_buffer_compare_bufy_;
536 }
537 StringInputBuffer* string_locale_compare_buf1() {
538 return &string_locale_compare_buf1_;
539 }
540 StringInputBuffer* string_locale_compare_buf2() {
541 return &string_locale_compare_buf2_;
542 }
Steve Block44f0eee2011-05-26 01:26:41 +0100543
544 private:
545 RuntimeState() {}
546 // Non-reentrant string buffer for efficient general use in the runtime.
547 StaticResource<StringInputBuffer> string_input_buffer_;
548 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
549 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
550 StringInputBuffer string_input_buffer_compare_bufx_;
551 StringInputBuffer string_input_buffer_compare_bufy_;
552 StringInputBuffer string_locale_compare_buf1_;
553 StringInputBuffer string_locale_compare_buf2_;
Steve Block44f0eee2011-05-26 01:26:41 +0100554
555 friend class Isolate;
556 friend class Runtime;
557
558 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
559};
560
561
Steve Blocka7e24c12009-10-30 11:49:00 +0000562class Runtime : public AllStatic {
563 public:
564 enum FunctionId {
565#define F(name, nargs, ressize) k##name,
566 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000567#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100568#define F(name, nargs, ressize) kInline##name,
569 INLINE_FUNCTION_LIST(F)
570 INLINE_RUNTIME_FUNCTION_LIST(F)
571#undef F
572 kNumFunctions,
573 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000574 };
575
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100576 enum IntrinsicType {
577 RUNTIME,
578 INLINE
579 };
580
581 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000582 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100583 FunctionId function_id;
584 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000585 // The JS name of the function.
586 const char* name;
587
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100588 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000589 byte* entry;
590
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100591 // The number of arguments expected. nargs is -1 if the function takes
592 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000593 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100594 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 int result_size;
596 };
597
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100598 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000599
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100600 // Add symbols for all the intrinsic function names to a StringDictionary.
601 // Returns failure if an allocation fails. In this case, it must be
602 // retried with a new, empty StringDictionary, not with the same one.
603 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700604 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100605 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100607 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100608 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100609
610 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100611 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100612
613 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100614 static int StringMatch(Isolate* isolate,
615 Handle<String> sub,
616 Handle<String> pat,
617 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000618
Steve Block44f0eee2011-05-26 01:26:41 +0100619 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000620
621 // TODO(1240886): The following three methods are *not* handle safe,
622 // but accept handle arguments. This seems fragile.
623
624 // Support getting the characters in a string using [] notation as
625 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100626 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
627 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700628 uint32_t index);
629 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
630 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000631
John Reck59135872010-11-02 12:39:01 -0700632 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100633 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700634 Handle<Object> object,
635 Handle<Object> key,
636 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100637 PropertyAttributes attr,
638 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000639
John Reck59135872010-11-02 12:39:01 -0700640 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100641 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700642 Handle<JSObject> object,
643 Handle<Object> key,
644 Handle<Object> value,
645 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000646
John Reck59135872010-11-02 12:39:01 -0700647 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100648 Isolate* isolate,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000649 Handle<JSReceiver> object,
John Reck59135872010-11-02 12:39:01 -0700650 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000651
Steve Block44f0eee2011-05-26 01:26:41 +0100652 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
653 Isolate* isolate,
654 Handle<Object> object,
655 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000656
657 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100658 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
659 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000660 int position);
661
662 // Helper functions used stubs.
663 static void PerformGC(Object* result);
664};
665
Steve Blocka7e24c12009-10-30 11:49:00 +0000666} } // namespace v8::internal
667
668#endif // V8_RUNTIME_H_