blob: 98559d44747c78fc9924088fe09a44f934c9b381 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_RUNTIME_H_
29#define V8_RUNTIME_H_
30
31namespace v8 { namespace internal {
32
33// The interface to C++ runtime functions.
34
35// ----------------------------------------------------------------------------
kasper.lund44510672008-07-25 07:37:58 +000036// RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
37// release and debug mode.
38// This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039
kasper.lund44510672008-07-25 07:37:58 +000040#define RUNTIME_FUNCTION_LIST_ALWAYS(F) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000041 /* Property access */ \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000042 F(GetProperty, 2) \
ager@chromium.org7c537e22008-10-16 08:43:32 +000043 F(KeyedGetProperty, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000044 F(DeleteProperty, 2) \
45 F(HasLocalProperty, 2) \
46 F(HasProperty, 2) \
47 F(HasElement, 2) \
48 F(IsPropertyEnumerable, 2) \
49 F(GetPropertyNames, 1) \
50 F(GetPropertyNamesFast, 1) \
51 F(GetArgumentsProperty, 1) \
52 \
53 F(IsInPrototypeChain, 2) \
54 \
mads.s.ager31e71382008-08-13 09:32:07 +000055 F(IsConstructCall, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000056 \
57 /* Utilities */ \
mads.s.ager31e71382008-08-13 09:32:07 +000058 F(GetCalledFunction, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000059 F(GetFunctionDelegate, 1) \
60 F(NewArguments, 1) \
kasperl@chromium.org41044eb2008-10-06 08:24:46 +000061 F(NewArgumentsFast, 3) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000062 F(LazyCompile, 1) \
63 F(SetNewFunctionAttributes, 1) \
64 \
ager@chromium.org9258b6b2008-09-11 09:11:10 +000065 /* Array join support */ \
66 F(PushIfAbsent, 2) \
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +000067 F(ArrayConcat, 1) \
ager@chromium.org9258b6b2008-09-11 09:11:10 +000068 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000069 /* Conversions */ \
70 F(ToBool, 1) \
71 F(Typeof, 1) \
72 \
73 F(StringToNumber, 1) \
74 F(StringFromCharCodeArray, 1) \
75 F(StringParseInt, 2) \
76 F(StringParseFloat, 1) \
77 F(StringToLowerCase, 1) \
78 F(StringToUpperCase, 1) \
79 F(CharFromCode, 1) \
80 F(URIEscape, 1) \
81 F(URIUnescape, 1) \
82 \
83 F(NumberToString, 1) \
84 F(NumberToInteger, 1) \
85 F(NumberToJSUint32, 1) \
86 F(NumberToJSInt32, 1) \
ager@chromium.org870a0b62008-11-04 11:43:05 +000087 F(NumberToSmi, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000088 \
89 /* Arithmetic operations */ \
90 F(NumberAdd, 2) \
91 F(NumberSub, 2) \
92 F(NumberMul, 2) \
93 F(NumberDiv, 2) \
94 F(NumberMod, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000095 F(NumberUnaryMinus, 1) \
96 \
97 F(StringAdd, 2) \
98 F(StringBuilderConcat, 2) \
99 \
100 /* Bit operations */ \
101 F(NumberOr, 2) \
102 F(NumberAnd, 2) \
103 F(NumberXor, 2) \
104 F(NumberNot, 1) \
105 \
106 F(NumberShl, 2) \
107 F(NumberShr, 2) \
108 F(NumberSar, 2) \
109 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000110 /* Comparisons */ \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000111 F(NumberEquals, 2) \
112 F(StringEquals, 2) \
113 \
114 F(NumberCompare, 3) \
ager@chromium.org9258b6b2008-09-11 09:11:10 +0000115 F(SmiLexicographicCompare, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000116 F(StringCompare, 2) \
117 \
118 /* Math */ \
119 F(Math_abs, 1) \
120 F(Math_acos, 1) \
121 F(Math_asin, 1) \
122 F(Math_atan, 1) \
123 F(Math_atan2, 2) \
124 F(Math_ceil, 1) \
125 F(Math_cos, 1) \
126 F(Math_exp, 1) \
127 F(Math_floor, 1) \
128 F(Math_log, 1) \
129 F(Math_pow, 2) \
mads.s.ager31e71382008-08-13 09:32:07 +0000130 F(Math_random, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000131 F(Math_round, 1) \
132 F(Math_sin, 1) \
133 F(Math_sqrt, 1) \
134 F(Math_tan, 1) \
135 \
136 /* Regular expressions */ \
137 F(RegExpCompile, 3) \
138 F(RegExpExec, 3) \
139 F(RegExpExecGlobal, 2) \
140 \
141 /* Strings */ \
142 F(StringCharCodeAt, 2) \
143 F(StringIndexOf, 3) \
144 F(StringLastIndexOf, 3) \
145 F(StringLocaleCompare, 2) \
146 F(StringSlice, 3) \
147 \
148 /* Numbers */ \
149 F(NumberToRadixString, 2) \
150 F(NumberToFixed, 2) \
151 F(NumberToExponential, 2) \
152 F(NumberToPrecision, 2) \
153 \
154 /* Reflection */ \
155 F(FunctionSetInstanceClassName, 2) \
156 F(FunctionSetLength, 2) \
157 F(FunctionSetPrototype, 2) \
158 F(FunctionGetName, 1) \
ager@chromium.org236ad962008-09-25 09:45:57 +0000159 F(FunctionSetName, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000160 F(FunctionGetSourceCode, 1) \
161 F(FunctionGetScript, 1) \
162 F(FunctionGetScriptSourcePosition, 1) \
163 F(GetScript, 1) \
164 \
165 F(ClassOf, 1) \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000166 F(HasDateClass, 1) \
167 F(HasStringClass, 1) \
168 F(HasArrayClass, 1) \
169 F(HasFunctionClass, 1) \
170 F(HasNumberClass, 1) \
171 F(HasBooleanClass, 1) \
172 F(HasArgumentsClass, 1) \
173 F(HasRegExpClass, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000174 F(SetCode, 2) \
175 \
176 F(CreateApiFunction, 1) \
177 F(IsTemplate, 1) \
178 F(GetTemplateField, 2) \
ager@chromium.org870a0b62008-11-04 11:43:05 +0000179 F(DisableAccessChecks, 1) \
180 F(EnableAccessChecks, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000181 \
182 /* Dates */ \
mads.s.ager31e71382008-08-13 09:32:07 +0000183 F(DateCurrentTime, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184 F(DateParseString, 1) \
185 F(DateLocalTimezone, 1) \
mads.s.ager31e71382008-08-13 09:32:07 +0000186 F(DateLocalTimeOffset, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187 F(DateDaylightSavingsOffset, 1) \
188 \
189 /* Numbers */ \
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000190 F(NumberIsFinite, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000191 \
192 /* Globals */ \
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000193 F(CompileString, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000194 F(CompileScript, 4) \
195 F(GlobalPrint, 1) \
196 \
197 /* Eval */ \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000198 F(GlobalReceiver, 1) \
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000199 F(ResolvePossiblyDirectEval, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000200 \
201 F(SetProperty, -1 /* 3 or 4 */) \
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000202 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000203 \
204 /* Arrays */ \
205 F(RemoveArrayHoles, 1) \
206 F(GetArrayKeys, 2) \
207 F(MoveArrayContents, 2) \
208 F(EstimateNumberOfElements, 1) \
209 \
210 /* Getters and Setters */ \
211 F(DefineAccessor, -1 /* 4 or 5 */) \
212 F(LookupAccessor, 3) \
213 \
214 /* Debugging */ \
215 F(AddDebugEventListener, 2) \
216 F(RemoveDebugEventListener, 1) \
mads.s.ager31e71382008-08-13 09:32:07 +0000217 F(Break, 0) \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000218 F(DebugGetPropertyDetails, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000219 F(DebugGetProperty, 2) \
220 F(DebugLocalPropertyNames, 1) \
221 F(DebugLocalElementNames, 1) \
222 F(DebugPropertyTypeFromDetails, 1) \
223 F(DebugPropertyAttributesFromDetails, 1) \
224 F(DebugPropertyIndexFromDetails, 1) \
225 F(DebugInterceptorInfo, 1) \
226 F(DebugNamedInterceptorPropertyNames, 1) \
227 F(DebugIndexedInterceptorElementNames, 1) \
228 F(DebugNamedInterceptorPropertyValue, 2) \
229 F(DebugIndexedInterceptorElementValue, 2) \
230 F(CheckExecutionState, 1) \
231 F(GetFrameCount, 1) \
232 F(GetFrameDetails, 2) \
233 F(GetCFrames, 1) \
234 F(GetBreakLocations, 1) \
235 F(SetFunctionBreakPoint, 3) \
236 F(SetScriptBreakPoint, 3) \
237 F(ClearBreakPoint, 1) \
238 F(ChangeBreakOnException, 2) \
239 F(PrepareStep, 3) \
mads.s.ager31e71382008-08-13 09:32:07 +0000240 F(ClearStepping, 0) \
kasper.lundbd3ec4e2008-07-09 11:06:54 +0000241 F(DebugEvaluate, 4) \
242 F(DebugEvaluateGlobal, 3) \
mads.s.ager31e71382008-08-13 09:32:07 +0000243 F(DebugGetLoadedScripts, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000244 F(DebugReferencedBy, 3) \
245 F(DebugConstructedBy, 2) \
246 F(GetPrototype, 1) \
mads.s.ager31e71382008-08-13 09:32:07 +0000247 F(SystemBreak, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000248 \
249 /* Literals */ \
250 F(MaterializeRegExpLiteral, 4)\
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000251 F(CreateArrayLiteral, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000252 F(CreateObjectLiteralBoilerplate, 3) \
253 F(CloneObjectLiteralBoilerplate, 1) \
254 \
255 /* Statements */ \
256 F(NewClosure, 2) \
257 F(NewObject, 1) \
258 F(Throw, 1) \
259 F(ReThrow, 1) \
260 F(ThrowReferenceError, 1) \
261 F(StackGuard, 1) \
262 \
263 /* Contexts */ \
kasper.lund7276f142008-07-30 08:49:36 +0000264 F(NewContext, 1) \
265 F(PushContext, 1) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000266 F(LookupContext, 2) \
267 F(LoadContextSlot, 2) \
268 F(LoadContextSlotNoReferenceError, 2) \
269 F(StoreContextSlot, 3) \
270 \
271 /* Declarations and initialization */ \
272 F(DeclareGlobals, 3) \
ager@chromium.org7c537e22008-10-16 08:43:32 +0000273 F(DeclareContextSlot, 4) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000274 F(InitializeVarGlobal, -1 /* 1 or 2 */) \
mads.s.ager31e71382008-08-13 09:32:07 +0000275 F(InitializeConstGlobal, 2) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276 F(InitializeConstContextSlot, 3) \
277 \
278 /* Debugging */ \
279 F(DebugPrint, 1) \
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000280 F(DebugTrace, 0) \
281 F(TraceEnter, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000282 F(TraceExit, 1) \
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000283 F(DebugBreak, 0) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000284 F(FunctionGetAssemblerCode, 1) \
285 F(Abort, 2) \
286 \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000287 /* Pseudo functions - handled as macros by parser */ \
288 F(IS_VAR, 1)
289
290
kasper.lund44510672008-07-25 07:37:58 +0000291#ifdef DEBUG
292#define RUNTIME_FUNCTION_LIST_DEBUG(F) \
293 /* Testing */ \
mads.s.ager31e71382008-08-13 09:32:07 +0000294 F(ListNatives, 0)
kasper.lund44510672008-07-25 07:37:58 +0000295#else
296#define RUNTIME_FUNCTION_LIST_DEBUG(F)
297#endif
298
299
300// ----------------------------------------------------------------------------
301// RUNTIME_FUNCTION_LIST defines all runtime functions accessed
302// either directly by id (via the code generator), or indirectly
303// via a native call by name (from within JS code).
304
305#define RUNTIME_FUNCTION_LIST(F) \
306 RUNTIME_FUNCTION_LIST_ALWAYS(F) \
307 RUNTIME_FUNCTION_LIST_DEBUG(F)
308
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000309// ----------------------------------------------------------------------------
310// Runtime provides access to all C++ runtime functions.
311
312class Runtime : public AllStatic {
313 public:
314 enum FunctionId {
315#define F(name, nargs) k##name,
316 RUNTIME_FUNCTION_LIST(F)
317 kNofFunctions
318#undef F
319 };
320 static Object* CreateArrayLiteral(Arguments args);
321
322 // Runtime function descriptor.
323 struct Function {
324 // The JS name of the function.
325 const char* name;
326
327 // The name of the stub that calls the runtime function.
328 const char* stub_name;
329
330 // The C++ (native) entry point.
331 byte* entry;
332
333 // The number of arguments expected; nargs < 0 if variable no. of
334 // arguments.
335 int nargs;
336 int stub_id;
337 };
338
339 // Get the runtime function with the given function id.
340 static Function* FunctionForId(FunctionId fid);
341
342 // Get the runtime function with the given name.
343 static Function* FunctionForName(const char* name);
344
ager@chromium.org7c537e22008-10-16 08:43:32 +0000345 static int StringMatch(Handle<String> sub, Handle<String> pat, int index);
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000346
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000347 // TODO(1240886): The following three methods are *not* handle safe,
348 // but accept handle arguments. This seems fragile.
349
350 // Support getting the characters in a string using [] notation as
351 // in Firefox/SpiderMonkey, Safari and Opera.
352 static Object* GetElementOrCharAt(Handle<Object> object, uint32_t index);
353
354 static Object* SetObjectProperty(Handle<Object> object,
355 Handle<Object> key,
356 Handle<Object> value,
357 PropertyAttributes attr);
358
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +0000359 static Object* GetObjectProperty(Handle<Object> object, Handle<Object> key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000360
361 // Helper functions used stubs.
362 static void PerformGC(Object* result);
363};
364
365
366} } // namespace v8::internal
367
368#endif // V8_RUNTIME_H_