blob: c0c7b13bc212527d0a8019c3ba58ec57a5ed4498 [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) \
Steve Blocka7e24c12009-10-30 11:49:00 +000072 \
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 */ \
Ben Murdoch589d6972011-11-30 16:04:58 +000081 F(CheckIsBootstrapping, 0, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +000082 F(Call, -1 /* >= 2 */, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +000083 F(Apply, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000084 F(GetFunctionDelegate, 1, 1) \
85 F(GetConstructorDelegate, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000086 F(NewArgumentsFast, 3, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000087 F(NewStrictArgumentsFast, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000088 F(LazyCompile, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010089 F(LazyRecompile, 1, 1) \
90 F(NotifyDeoptimized, 1, 1) \
91 F(NotifyOSR, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010092 F(DeoptimizeFunction, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000093 F(RunningInSimulator, 0, 1) \
Ben Murdoch8b112d22011-06-08 16:22:53 +010094 F(OptimizeFunctionOnNextCall, 1, 1) \
Ben Murdoch257744e2011-11-30 15:57:28 +000095 F(GetOptimizationStatus, 1, 1) \
96 F(GetOptimizationCount, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +010097 F(CompileForOnStackReplacement, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +000098 F(SetNewFunctionAttributes, 1, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +010099 F(AllocateInNewSpace, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000100 F(SetNativeFlag, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000101 F(StoreArrayLiteralElement, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000102 \
103 /* Array join support */ \
104 F(PushIfAbsent, 2, 1) \
105 F(ArrayConcat, 1, 1) \
106 \
107 /* Conversions */ \
108 F(ToBool, 1, 1) \
109 F(Typeof, 1, 1) \
110 \
111 F(StringToNumber, 1, 1) \
112 F(StringFromCharCodeArray, 1, 1) \
113 F(StringParseInt, 2, 1) \
114 F(StringParseFloat, 1, 1) \
115 F(StringToLowerCase, 1, 1) \
116 F(StringToUpperCase, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100117 F(StringSplit, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 F(CharFromCode, 1, 1) \
119 F(URIEscape, 1, 1) \
120 F(URIUnescape, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100121 F(QuoteJSONString, 1, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100122 F(QuoteJSONStringComma, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000123 F(QuoteJSONStringArray, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 \
125 F(NumberToString, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100126 F(NumberToStringSkipCache, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 F(NumberToInteger, 1, 1) \
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100128 F(NumberToIntegerMapMinusZero, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000129 F(NumberToJSUint32, 1, 1) \
130 F(NumberToJSInt32, 1, 1) \
131 F(NumberToSmi, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100132 F(AllocateHeapNumber, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000133 \
134 /* Arithmetic operations */ \
135 F(NumberAdd, 2, 1) \
136 F(NumberSub, 2, 1) \
137 F(NumberMul, 2, 1) \
138 F(NumberDiv, 2, 1) \
139 F(NumberMod, 2, 1) \
140 F(NumberUnaryMinus, 1, 1) \
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100141 F(NumberAlloc, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000142 \
143 F(StringAdd, 2, 1) \
Leon Clarkee46be812010-01-19 14:06:41 +0000144 F(StringBuilderConcat, 3, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100145 F(StringBuilderJoin, 3, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000146 F(SparseJoinWithSeparator, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000147 \
148 /* Bit operations */ \
149 F(NumberOr, 2, 1) \
150 F(NumberAnd, 2, 1) \
151 F(NumberXor, 2, 1) \
152 F(NumberNot, 1, 1) \
153 \
154 F(NumberShl, 2, 1) \
155 F(NumberShr, 2, 1) \
156 F(NumberSar, 2, 1) \
157 \
158 /* Comparisons */ \
159 F(NumberEquals, 2, 1) \
160 F(StringEquals, 2, 1) \
161 \
162 F(NumberCompare, 3, 1) \
163 F(SmiLexicographicCompare, 2, 1) \
164 F(StringCompare, 2, 1) \
165 \
166 /* Math */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000167 F(Math_acos, 1, 1) \
168 F(Math_asin, 1, 1) \
169 F(Math_atan, 1, 1) \
170 F(Math_atan2, 2, 1) \
171 F(Math_ceil, 1, 1) \
172 F(Math_cos, 1, 1) \
173 F(Math_exp, 1, 1) \
174 F(Math_floor, 1, 1) \
175 F(Math_log, 1, 1) \
176 F(Math_pow, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100177 F(Math_pow_cfunction, 2, 1) \
178 F(RoundNumber, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000179 F(Math_sin, 1, 1) \
180 F(Math_sqrt, 1, 1) \
181 F(Math_tan, 1, 1) \
182 \
183 /* Regular expressions */ \
184 F(RegExpCompile, 3, 1) \
185 F(RegExpExec, 4, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100186 F(RegExpExecMultiple, 4, 1) \
187 F(RegExpInitializeObject, 5, 1) \
188 F(RegExpConstructResult, 3, 1) \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800189 \
190 /* JSON */ \
191 F(ParseJson, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000192 \
193 /* Strings */ \
194 F(StringCharCodeAt, 2, 1) \
195 F(StringIndexOf, 3, 1) \
196 F(StringLastIndexOf, 3, 1) \
197 F(StringLocaleCompare, 2, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000198 F(SubString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000199 F(StringReplaceRegExpWithString, 4, 1) \
Ben Murdochc7cc0282012-03-05 14:35:55 +0000200 F(StringReplaceOneCharWithString, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000201 F(StringMatch, 3, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000202 F(StringTrim, 3, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800203 F(StringToArray, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100204 F(NewStringWrapper, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000205 \
206 /* Numbers */ \
207 F(NumberToRadixString, 2, 1) \
208 F(NumberToFixed, 2, 1) \
209 F(NumberToExponential, 2, 1) \
210 F(NumberToPrecision, 2, 1)
211
212#define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
213 /* Reflection */ \
214 F(FunctionSetInstanceClassName, 2, 1) \
215 F(FunctionSetLength, 2, 1) \
216 F(FunctionSetPrototype, 2, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000217 F(FunctionSetReadOnlyPrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000218 F(FunctionGetName, 1, 1) \
219 F(FunctionSetName, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000220 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
221 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000222 F(FunctionBindArguments, 4, 1) \
223 F(BoundFunctionGetBindings, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100224 F(FunctionRemovePrototype, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 F(FunctionGetSourceCode, 1, 1) \
226 F(FunctionGetScript, 1, 1) \
227 F(FunctionGetScriptSourcePosition, 1, 1) \
228 F(FunctionGetPositionForOffset, 2, 1) \
229 F(FunctionIsAPIFunction, 1, 1) \
230 F(FunctionIsBuiltin, 1, 1) \
231 F(GetScript, 1, 1) \
232 F(CollectStackTrace, 2, 1) \
Steve Block3ce2e202009-11-05 08:53:23 +0000233 F(GetV8Version, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000234 \
235 F(ClassOf, 1, 1) \
236 F(SetCode, 2, 1) \
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100237 F(SetExpectedNumberOfProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000238 \
239 F(CreateApiFunction, 1, 1) \
240 F(IsTemplate, 1, 1) \
241 F(GetTemplateField, 2, 1) \
242 F(DisableAccessChecks, 1, 1) \
243 F(EnableAccessChecks, 1, 1) \
244 \
245 /* Dates */ \
246 F(DateCurrentTime, 0, 1) \
247 F(DateParseString, 2, 1) \
248 F(DateLocalTimezone, 1, 1) \
249 F(DateLocalTimeOffset, 0, 1) \
250 F(DateDaylightSavingsOffset, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000251 F(DateMakeDay, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100252 F(DateYMDFromTime, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000253 \
254 /* Numbers */ \
Steve Blocka7e24c12009-10-30 11:49:00 +0000255 \
256 /* Globals */ \
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800257 F(CompileString, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000258 F(GlobalPrint, 1, 1) \
259 \
260 /* Eval */ \
261 F(GlobalReceiver, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000262 F(ResolvePossiblyDirectEval, 5, 2) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100264 F(SetProperty, -1 /* 4 or 5 */, 1) \
Andrei Popescu31002712010-02-23 13:46:05 +0000265 F(DefineOrRedefineDataProperty, 4, 1) \
266 F(DefineOrRedefineAccessorProperty, 5, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000267 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
268 \
269 /* Arrays */ \
270 F(RemoveArrayHoles, 2, 1) \
271 F(GetArrayKeys, 2, 1) \
272 F(MoveArrayContents, 2, 1) \
273 F(EstimateNumberOfElements, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100274 F(SwapElements, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 \
276 /* Getters and Setters */ \
277 F(DefineAccessor, -1 /* 4 or 5 */, 1) \
278 F(LookupAccessor, 3, 1) \
279 \
280 /* Literals */ \
281 F(MaterializeRegExpLiteral, 4, 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 Murdoch589d6972011-11-30 16:04:58 +0000289 F(CreateJSFunctionProxy, 4, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000290 F(IsJSProxy, 1, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +0000291 F(IsJSFunctionProxy, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000292 F(GetHandler, 1, 1) \
Ben Murdoch589d6972011-11-30 16:04:58 +0000293 F(GetCallTrap, 1, 1) \
294 F(GetConstructTrap, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000295 F(Fix, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000296 \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000297 /* Harmony sets */ \
298 F(SetInitialize, 1, 1) \
299 F(SetAdd, 2, 1) \
300 F(SetHas, 2, 1) \
301 F(SetDelete, 2, 1) \
302 \
303 /* Harmony maps */ \
304 F(MapInitialize, 1, 1) \
305 F(MapGet, 2, 1) \
306 F(MapSet, 3, 1) \
307 \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000308 /* Harmony weakmaps */ \
309 F(WeakMapInitialize, 1, 1) \
310 F(WeakMapGet, 2, 1) \
311 F(WeakMapSet, 3, 1) \
312 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000313 /* Statements */ \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800314 F(NewClosure, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 F(NewObject, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000316 F(NewObjectFromBound, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100317 F(FinalizeInstanceSize, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000318 F(Throw, 1, 1) \
319 F(ReThrow, 1, 1) \
320 F(ThrowReferenceError, 1, 1) \
Ben Murdochf87a2032010-10-22 12:50:53 +0100321 F(StackGuard, 0, 1) \
Steve Blockd0582a62009-12-15 09:54:21 +0000322 F(PromoteScheduledException, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 \
324 /* Contexts */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000325 F(NewFunctionContext, 1, 1) \
326 F(PushWithContext, 2, 1) \
327 F(PushCatchContext, 3, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000328 F(PushBlockContext, 2, 1) \
Steve Block1e0659c2011-05-24 12:43:12 +0100329 F(DeleteContextSlot, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000330 F(LoadContextSlot, 2, 2) \
331 F(LoadContextSlotNoReferenceError, 2, 2) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100332 F(StoreContextSlot, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000333 \
334 /* Declarations and initialization */ \
Ben Murdoch589d6972011-11-30 16:04:58 +0000335 F(DeclareGlobals, 3, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000336 F(DeclareContextSlot, 4, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100337 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000338 F(InitializeConstGlobal, 2, 1) \
339 F(InitializeConstContextSlot, 3, 1) \
340 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 \
342 /* Debugging */ \
343 F(DebugPrint, 1, 1) \
344 F(DebugTrace, 0, 1) \
345 F(TraceEnter, 0, 1) \
346 F(TraceExit, 1, 1) \
347 F(Abort, 2, 1) \
348 /* Logging */ \
349 F(Log, 2, 1) \
350 /* ES5 */ \
351 F(LocalKeys, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100352 /* Cache suport */ \
353 F(GetFromCache, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000354 \
Steve Block1e0659c2011-05-24 12:43:12 +0100355 /* Message objects */ \
356 F(NewMessageObject, 2, 1) \
357 F(MessageGetType, 1, 1) \
358 F(MessageGetArguments, 1, 1) \
359 F(MessageGetStartPosition, 1, 1) \
360 F(MessageGetScript, 1, 1) \
361 \
Steve Blocka7e24c12009-10-30 11:49:00 +0000362 /* Pseudo functions - handled as macros by parser */ \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000363 F(IS_VAR, 1, 1) \
364 \
365 /* expose boolean functions from objects-inl.h */ \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000366 F(HasFastSmiOnlyElements, 1, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000367 F(HasFastElements, 1, 1) \
368 F(HasFastDoubleElements, 1, 1) \
369 F(HasDictionaryElements, 1, 1) \
370 F(HasExternalPixelElements, 1, 1) \
371 F(HasExternalArrayElements, 1, 1) \
372 F(HasExternalByteElements, 1, 1) \
373 F(HasExternalUnsignedByteElements, 1, 1) \
374 F(HasExternalShortElements, 1, 1) \
375 F(HasExternalUnsignedShortElements, 1, 1) \
376 F(HasExternalIntElements, 1, 1) \
377 F(HasExternalUnsignedIntElements, 1, 1) \
378 F(HasExternalFloatElements, 1, 1) \
379 F(HasExternalDoubleElements, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000380 F(TransitionElementsSmiToDouble, 1, 1) \
381 F(TransitionElementsDoubleToObject, 1, 1) \
382 F(HaveSameMap, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000383 /* profiler */ \
384 F(ProfilerResume, 0, 1) \
385 F(ProfilerPause, 0, 1)
386
Steve Blocka7e24c12009-10-30 11:49:00 +0000387
388#ifdef ENABLE_DEBUGGER_SUPPORT
389#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
390 /* Debugger support*/ \
391 F(DebugBreak, 0, 1) \
392 F(SetDebugEventListener, 2, 1) \
393 F(Break, 0, 1) \
394 F(DebugGetPropertyDetails, 2, 1) \
395 F(DebugGetProperty, 2, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000396 F(DebugPropertyTypeFromDetails, 1, 1) \
397 F(DebugPropertyAttributesFromDetails, 1, 1) \
398 F(DebugPropertyIndexFromDetails, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000399 F(DebugNamedInterceptorPropertyValue, 2, 1) \
400 F(DebugIndexedInterceptorElementValue, 2, 1) \
401 F(CheckExecutionState, 1, 1) \
402 F(GetFrameCount, 1, 1) \
403 F(GetFrameDetails, 2, 1) \
404 F(GetScopeCount, 2, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000405 F(GetScopeDetails, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000406 F(DebugPrintScopes, 0, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000407 F(GetThreadCount, 1, 1) \
408 F(GetThreadDetails, 2, 1) \
Ben Murdochbb769b22010-08-11 14:56:33 +0100409 F(SetDisableBreak, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000410 F(GetBreakLocations, 1, 1) \
411 F(SetFunctionBreakPoint, 3, 1) \
412 F(SetScriptBreakPoint, 3, 1) \
413 F(ClearBreakPoint, 1, 1) \
414 F(ChangeBreakOnException, 2, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100415 F(IsBreakOnException, 1, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 F(PrepareStep, 3, 1) \
417 F(ClearStepping, 0, 1) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000418 F(DebugEvaluate, 6, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100419 F(DebugEvaluateGlobal, 4, 1) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000420 F(DebugGetLoadedScripts, 0, 1) \
421 F(DebugReferencedBy, 3, 1) \
422 F(DebugConstructedBy, 2, 1) \
423 F(DebugGetPrototype, 1, 1) \
424 F(SystemBreak, 0, 1) \
425 F(DebugDisassembleFunction, 1, 1) \
426 F(DebugDisassembleConstructor, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100427 F(FunctionGetInferredName, 1, 1) \
428 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
429 F(LiveEditGatherCompileInfo, 2, 1) \
430 F(LiveEditReplaceScript, 3, 1) \
431 F(LiveEditReplaceFunctionCode, 2, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100432 F(LiveEditFunctionSourceUpdated, 1, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100433 F(LiveEditFunctionSetScript, 2, 1) \
434 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
435 F(LiveEditPatchFunctionPositions, 2, 1) \
436 F(LiveEditCheckAndDropActivations, 2, 1) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100437 F(LiveEditCompareStrings, 2, 1) \
Steve Block6ded16b2010-05-10 14:33:55 +0100438 F(GetFunctionCodePositionFromSource, 2, 1) \
Ben Murdoch086aeea2011-05-13 15:57:08 +0100439 F(ExecuteInDebugContext, 2, 1) \
440 \
441 F(SetFlags, 1, 1) \
442 F(CollectGarbage, 1, 1) \
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100443 F(GetHeapUsage, 0, 1) \
444 \
445 /* LiveObjectList support*/ \
446 F(HasLOLEnabled, 0, 1) \
447 F(CaptureLOL, 0, 1) \
448 F(DeleteLOL, 1, 1) \
449 F(DumpLOL, 5, 1) \
450 F(GetLOLObj, 1, 1) \
451 F(GetLOLObjId, 1, 1) \
452 F(GetLOLObjRetainers, 6, 1) \
453 F(GetLOLPath, 3, 1) \
454 F(InfoLOL, 2, 1) \
455 F(PrintLOLObj, 1, 1) \
456 F(ResetLOL, 0, 1) \
457 F(SummarizeLOL, 3, 1)
Ben Murdoch086aeea2011-05-13 15:57:08 +0100458
Steve Blocka7e24c12009-10-30 11:49:00 +0000459#else
460#define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
461#endif
462
463#ifdef DEBUG
464#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
465 /* Testing */ \
466 F(ListNatives, 0, 1)
467#else
468#define RUNTIME_FUNCTION_LIST_DEBUG(F)
469#endif
470
Steve Blocka7e24c12009-10-30 11:49:00 +0000471// ----------------------------------------------------------------------------
472// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
473// either directly by id (via the code generator), or indirectly
474// via a native call by name (from within JS code).
475
476#define RUNTIME_FUNCTION_LIST(F) \
477 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
478 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
479 RUNTIME_FUNCTION_LIST_DEBUG(F) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000480 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000481
482// ----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100483// INLINE_FUNCTION_LIST defines all inlined functions accessed
484// with a native call of the form %_name from within JS code.
485// Entries have the form F(name, number of arguments, number of return values).
486#define INLINE_FUNCTION_LIST(F) \
487 F(IsSmi, 1, 1) \
488 F(IsNonNegativeSmi, 1, 1) \
489 F(IsArray, 1, 1) \
490 F(IsRegExp, 1, 1) \
491 F(CallFunction, -1 /* receiver + n args + function */, 1) \
492 F(ArgumentsLength, 0, 1) \
493 F(Arguments, 1, 1) \
494 F(ValueOf, 1, 1) \
495 F(SetValueOf, 2, 1) \
496 F(StringCharFromCode, 1, 1) \
497 F(StringCharAt, 2, 1) \
498 F(ObjectEquals, 2, 1) \
499 F(RandomHeapNumber, 0, 1) \
500 F(IsObject, 1, 1) \
501 F(IsFunction, 1, 1) \
502 F(IsUndetectableObject, 1, 1) \
503 F(IsSpecObject, 1, 1) \
504 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
505 F(MathPow, 2, 1) \
506 F(MathSin, 1, 1) \
507 F(MathCos, 1, 1) \
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000508 F(MathTan, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100509 F(MathSqrt, 1, 1) \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100510 F(MathLog, 1, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100511 F(IsRegExpEquivalent, 2, 1) \
512 F(HasCachedArrayIndex, 1, 1) \
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800513 F(GetCachedArrayIndex, 1, 1) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000514 F(FastAsciiArrayJoin, 2, 1)
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100515
516
517// ----------------------------------------------------------------------------
518// INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
519// with a native call of the form %_name from within JS code that also have
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800520// a corresponding runtime function, that is called for slow cases.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100521// Entries have the form F(name, number of arguments, number of return values).
522#define INLINE_RUNTIME_FUNCTION_LIST(F) \
523 F(IsConstructCall, 0, 1) \
524 F(ClassOf, 1, 1) \
525 F(StringCharCodeAt, 2, 1) \
526 F(Log, 3, 1) \
527 F(StringAdd, 2, 1) \
528 F(SubString, 3, 1) \
529 F(StringCompare, 2, 1) \
530 F(RegExpExec, 4, 1) \
531 F(RegExpConstructResult, 3, 1) \
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100532 F(GetFromCache, 2, 1) \
533 F(NumberToString, 1, 1) \
534 F(SwapElements, 3, 1)
535
536
537//---------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000538// Runtime provides access to all C++ runtime functions.
539
Steve Block44f0eee2011-05-26 01:26:41 +0100540class RuntimeState {
541 public:
Steve Block44f0eee2011-05-26 01:26:41 +0100542 StaticResource<StringInputBuffer>* string_input_buffer() {
543 return &string_input_buffer_;
544 }
545 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
546 return &to_upper_mapping_;
547 }
548 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
549 return &to_lower_mapping_;
550 }
551 StringInputBuffer* string_input_buffer_compare_bufx() {
552 return &string_input_buffer_compare_bufx_;
553 }
554 StringInputBuffer* string_input_buffer_compare_bufy() {
555 return &string_input_buffer_compare_bufy_;
556 }
557 StringInputBuffer* string_locale_compare_buf1() {
558 return &string_locale_compare_buf1_;
559 }
560 StringInputBuffer* string_locale_compare_buf2() {
561 return &string_locale_compare_buf2_;
562 }
Steve Block44f0eee2011-05-26 01:26:41 +0100563
564 private:
565 RuntimeState() {}
566 // Non-reentrant string buffer for efficient general use in the runtime.
567 StaticResource<StringInputBuffer> string_input_buffer_;
568 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
569 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
570 StringInputBuffer string_input_buffer_compare_bufx_;
571 StringInputBuffer string_input_buffer_compare_bufy_;
572 StringInputBuffer string_locale_compare_buf1_;
573 StringInputBuffer string_locale_compare_buf2_;
Steve Block44f0eee2011-05-26 01:26:41 +0100574
575 friend class Isolate;
576 friend class Runtime;
577
578 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
579};
580
581
Steve Blocka7e24c12009-10-30 11:49:00 +0000582class Runtime : public AllStatic {
583 public:
584 enum FunctionId {
585#define F(name, nargs, ressize) k##name,
586 RUNTIME_FUNCTION_LIST(F)
Steve Blocka7e24c12009-10-30 11:49:00 +0000587#undef F
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100588#define F(name, nargs, ressize) kInline##name,
589 INLINE_FUNCTION_LIST(F)
590 INLINE_RUNTIME_FUNCTION_LIST(F)
591#undef F
592 kNumFunctions,
593 kFirstInlineFunction = kInlineIsSmi
Steve Blocka7e24c12009-10-30 11:49:00 +0000594 };
595
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100596 enum IntrinsicType {
597 RUNTIME,
598 INLINE
599 };
600
601 // Intrinsic function descriptor.
Steve Blocka7e24c12009-10-30 11:49:00 +0000602 struct Function {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100603 FunctionId function_id;
604 IntrinsicType intrinsic_type;
Steve Blocka7e24c12009-10-30 11:49:00 +0000605 // The JS name of the function.
606 const char* name;
607
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100608 // The C++ (native) entry point. NULL if the function is inlined.
Steve Blocka7e24c12009-10-30 11:49:00 +0000609 byte* entry;
610
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100611 // The number of arguments expected. nargs is -1 if the function takes
612 // a variable number of arguments.
Steve Blocka7e24c12009-10-30 11:49:00 +0000613 int nargs;
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100614 // Size of result. Most functions return a single pointer, size 1.
Steve Blocka7e24c12009-10-30 11:49:00 +0000615 int result_size;
616 };
617
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100618 static const int kNotFound = -1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000619
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100620 // Add symbols for all the intrinsic function names to a StringDictionary.
621 // Returns failure if an allocation fails. In this case, it must be
622 // retried with a new, empty StringDictionary, not with the same one.
623 // Alternatively, heap initialization can be completely restarted.
John Reck59135872010-11-02 12:39:01 -0700624 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
Steve Block44f0eee2011-05-26 01:26:41 +0100625 Heap* heap, Object* dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +0000626
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100627 // Get the intrinsic function with the given name, which must be a symbol.
Steve Block44f0eee2011-05-26 01:26:41 +0100628 static const Function* FunctionForSymbol(Handle<String> name);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100629
630 // Get the intrinsic function with the given FunctionId.
Steve Block44f0eee2011-05-26 01:26:41 +0100631 static const Function* FunctionForId(FunctionId id);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100632
Ben Murdochc7cc0282012-03-05 14:35:55 +0000633 static Handle<String> StringReplaceOneCharWithString(Isolate* isolate,
634 Handle<String> subject,
635 Handle<String> search,
636 Handle<String> replace,
637 bool* found,
638 int recursion_limit);
639
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100640 // General-purpose helper functions for runtime system.
Steve Block44f0eee2011-05-26 01:26:41 +0100641 static int StringMatch(Isolate* isolate,
642 Handle<String> sub,
643 Handle<String> pat,
644 int index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000645
Steve Block44f0eee2011-05-26 01:26:41 +0100646 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
Steve Blocka7e24c12009-10-30 11:49:00 +0000647
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000648 // TODO(1240886): Some of the following methods are *not* handle safe, but
649 // accept handle arguments. This seems fragile.
Steve Blocka7e24c12009-10-30 11:49:00 +0000650
651 // Support getting the characters in a string using [] notation as
652 // in Firefox/SpiderMonkey, Safari and Opera.
Steve Block44f0eee2011-05-26 01:26:41 +0100653 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
654 Handle<Object> object,
John Reck59135872010-11-02 12:39:01 -0700655 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000656
John Reck59135872010-11-02 12:39:01 -0700657 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100658 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700659 Handle<Object> object,
660 Handle<Object> key,
661 Handle<Object> value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100662 PropertyAttributes attr,
663 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000664
John Reck59135872010-11-02 12:39:01 -0700665 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100666 Isolate* isolate,
John Reck59135872010-11-02 12:39:01 -0700667 Handle<JSObject> object,
668 Handle<Object> key,
669 Handle<Object> value,
670 PropertyAttributes attr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000671
John Reck59135872010-11-02 12:39:01 -0700672 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
Steve Block44f0eee2011-05-26 01:26:41 +0100673 Isolate* isolate,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000674 Handle<JSReceiver> object,
John Reck59135872010-11-02 12:39:01 -0700675 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000676
Steve Block44f0eee2011-05-26 01:26:41 +0100677 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
678 Isolate* isolate,
679 Handle<Object> object,
680 Handle<Object> key);
Steve Blocka7e24c12009-10-30 11:49:00 +0000681
682 // This function is used in FunctionNameUsing* tests.
Steve Block44f0eee2011-05-26 01:26:41 +0100683 static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
684 Handle<Script> script,
Steve Blocka7e24c12009-10-30 11:49:00 +0000685 int position);
686
687 // Helper functions used stubs.
688 static void PerformGC(Object* result);
Ben Murdochc7cc0282012-03-05 14:35:55 +0000689
690 // Used in runtime.cc and hydrogen's VisitArrayLiteral.
691 static Handle<Object> CreateArrayLiteralBoilerplate(
692 Isolate* isolate,
693 Handle<FixedArray> literals,
694 Handle<FixedArray> elements);
Steve Blocka7e24c12009-10-30 11:49:00 +0000695};
696
Ben Murdoch589d6972011-11-30 16:04:58 +0000697
698//---------------------------------------------------------------------------
699// Constants used by interface to runtime functions.
700
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000701class DeclareGlobalsEvalFlag: public BitField<bool, 0, 1> {};
702class DeclareGlobalsNativeFlag: public BitField<bool, 1, 1> {};
703class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
Ben Murdoch589d6972011-11-30 16:04:58 +0000704
Steve Blocka7e24c12009-10-30 11:49:00 +0000705} } // namespace v8::internal
706
707#endif // V8_RUNTIME_H_