• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // 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 
31 #include "zone.h"
32 
33 namespace v8 {
34 namespace internal {
35 
36 // The interface to C++ runtime functions.
37 
38 // ----------------------------------------------------------------------------
39 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
40 // release and debug mode.
41 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
42 
43 // WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
44 // MSVC Intellisense to crash.  It was broken into two macros to work around
45 // this problem. Please avoid large recursive macros whenever possible.
46 #define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
47   /* Property access */ \
48   F(GetProperty, 2, 1) \
49   F(KeyedGetProperty, 2, 1) \
50   F(DeleteProperty, 3, 1) \
51   F(HasLocalProperty, 2, 1) \
52   F(HasProperty, 2, 1) \
53   F(HasElement, 2, 1) \
54   F(IsPropertyEnumerable, 2, 1) \
55   F(GetPropertyNames, 1, 1) \
56   F(GetPropertyNamesFast, 1, 1) \
57   F(GetLocalPropertyNames, 1, 1) \
58   F(GetLocalElementNames, 1, 1) \
59   F(GetInterceptorInfo, 1, 1) \
60   F(GetNamedInterceptorPropertyNames, 1, 1) \
61   F(GetIndexedInterceptorElementNames, 1, 1) \
62   F(GetArgumentsProperty, 1, 1) \
63   F(ToFastProperties, 1, 1) \
64   F(ToSlowProperties, 1, 1) \
65   F(FinishArrayPrototypeSetup, 1, 1) \
66   F(SpecialArrayFunctions, 1, 1) \
67   F(GetGlobalReceiver, 0, 1) \
68   \
69   F(IsInPrototypeChain, 2, 1) \
70   F(SetHiddenPrototype, 2, 1) \
71   \
72   F(IsConstructCall, 0, 1) \
73   \
74   F(GetOwnProperty, 2, 1) \
75   \
76   F(IsExtensible, 1, 1) \
77   F(PreventExtensions, 1, 1)\
78   \
79   /* Utilities */ \
80   F(GetFunctionDelegate, 1, 1) \
81   F(GetConstructorDelegate, 1, 1) \
82   F(NewArgumentsFast, 3, 1) \
83   F(LazyCompile, 1, 1) \
84   F(LazyRecompile, 1, 1) \
85   F(NotifyDeoptimized, 1, 1) \
86   F(NotifyOSR, 0, 1) \
87   F(DeoptimizeFunction, 1, 1) \
88   F(OptimizeFunctionOnNextCall, 1, 1) \
89   F(CompileForOnStackReplacement, 1, 1) \
90   F(SetNewFunctionAttributes, 1, 1) \
91   F(AllocateInNewSpace, 1, 1) \
92   \
93   /* Array join support */ \
94   F(PushIfAbsent, 2, 1) \
95   F(ArrayConcat, 1, 1) \
96   \
97   /* Conversions */ \
98   F(ToBool, 1, 1) \
99   F(Typeof, 1, 1) \
100   \
101   F(StringToNumber, 1, 1) \
102   F(StringFromCharCodeArray, 1, 1) \
103   F(StringParseInt, 2, 1) \
104   F(StringParseFloat, 1, 1) \
105   F(StringToLowerCase, 1, 1) \
106   F(StringToUpperCase, 1, 1) \
107   F(StringSplit, 3, 1) \
108   F(CharFromCode, 1, 1) \
109   F(URIEscape, 1, 1) \
110   F(URIUnescape, 1, 1) \
111   F(QuoteJSONString, 1, 1) \
112   F(QuoteJSONStringComma, 1, 1) \
113   \
114   F(NumberToString, 1, 1) \
115   F(NumberToStringSkipCache, 1, 1) \
116   F(NumberToInteger, 1, 1) \
117   F(NumberToIntegerMapMinusZero, 1, 1) \
118   F(NumberToJSUint32, 1, 1) \
119   F(NumberToJSInt32, 1, 1) \
120   F(NumberToSmi, 1, 1) \
121   F(AllocateHeapNumber, 0, 1) \
122   \
123   /* Arithmetic operations */ \
124   F(NumberAdd, 2, 1) \
125   F(NumberSub, 2, 1) \
126   F(NumberMul, 2, 1) \
127   F(NumberDiv, 2, 1) \
128   F(NumberMod, 2, 1) \
129   F(NumberUnaryMinus, 1, 1) \
130   F(NumberAlloc, 0, 1) \
131   \
132   F(StringAdd, 2, 1) \
133   F(StringBuilderConcat, 3, 1) \
134   F(StringBuilderJoin, 3, 1) \
135   \
136   /* Bit operations */ \
137   F(NumberOr, 2, 1) \
138   F(NumberAnd, 2, 1) \
139   F(NumberXor, 2, 1) \
140   F(NumberNot, 1, 1) \
141   \
142   F(NumberShl, 2, 1) \
143   F(NumberShr, 2, 1) \
144   F(NumberSar, 2, 1) \
145   \
146   /* Comparisons */ \
147   F(NumberEquals, 2, 1) \
148   F(StringEquals, 2, 1) \
149   \
150   F(NumberCompare, 3, 1) \
151   F(SmiLexicographicCompare, 2, 1) \
152   F(StringCompare, 2, 1) \
153   \
154   /* Math */ \
155   F(Math_acos, 1, 1) \
156   F(Math_asin, 1, 1) \
157   F(Math_atan, 1, 1) \
158   F(Math_atan2, 2, 1) \
159   F(Math_ceil, 1, 1) \
160   F(Math_cos, 1, 1) \
161   F(Math_exp, 1, 1) \
162   F(Math_floor, 1, 1) \
163   F(Math_log, 1, 1) \
164   F(Math_pow, 2, 1) \
165   F(Math_pow_cfunction, 2, 1) \
166   F(RoundNumber, 1, 1) \
167   F(Math_sin, 1, 1) \
168   F(Math_sqrt, 1, 1) \
169   F(Math_tan, 1, 1) \
170   \
171   /* Regular expressions */ \
172   F(RegExpCompile, 3, 1) \
173   F(RegExpExec, 4, 1) \
174   F(RegExpExecMultiple, 4, 1) \
175   F(RegExpInitializeObject, 5, 1) \
176   F(RegExpConstructResult, 3, 1) \
177   \
178   /* JSON */ \
179   F(ParseJson, 1, 1) \
180   \
181   /* Strings */ \
182   F(StringCharCodeAt, 2, 1) \
183   F(StringIndexOf, 3, 1) \
184   F(StringLastIndexOf, 3, 1) \
185   F(StringLocaleCompare, 2, 1) \
186   F(SubString, 3, 1) \
187   F(StringReplaceRegExpWithString, 4, 1) \
188   F(StringMatch, 3, 1) \
189   F(StringTrim, 3, 1) \
190   F(StringToArray, 2, 1) \
191   F(NewStringWrapper, 1, 1) \
192   \
193   /* Numbers */ \
194   F(NumberToRadixString, 2, 1) \
195   F(NumberToFixed, 2, 1) \
196   F(NumberToExponential, 2, 1) \
197   F(NumberToPrecision, 2, 1)
198 
199 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
200   /* Reflection */ \
201   F(FunctionSetInstanceClassName, 2, 1) \
202   F(FunctionSetLength, 2, 1) \
203   F(FunctionSetPrototype, 2, 1) \
204   F(FunctionGetName, 1, 1) \
205   F(FunctionSetName, 2, 1) \
206   F(FunctionRemovePrototype, 1, 1) \
207   F(FunctionGetSourceCode, 1, 1) \
208   F(FunctionGetScript, 1, 1) \
209   F(FunctionGetScriptSourcePosition, 1, 1) \
210   F(FunctionGetPositionForOffset, 2, 1) \
211   F(FunctionIsAPIFunction, 1, 1) \
212   F(FunctionIsBuiltin, 1, 1) \
213   F(GetScript, 1, 1) \
214   F(CollectStackTrace, 2, 1) \
215   F(GetV8Version, 0, 1) \
216   \
217   F(ClassOf, 1, 1) \
218   F(SetCode, 2, 1) \
219   F(SetExpectedNumberOfProperties, 2, 1) \
220   \
221   F(CreateApiFunction, 1, 1) \
222   F(IsTemplate, 1, 1) \
223   F(GetTemplateField, 2, 1) \
224   F(DisableAccessChecks, 1, 1) \
225   F(EnableAccessChecks, 1, 1) \
226   \
227   /* Dates */ \
228   F(DateCurrentTime, 0, 1) \
229   F(DateParseString, 2, 1) \
230   F(DateLocalTimezone, 1, 1) \
231   F(DateLocalTimeOffset, 0, 1) \
232   F(DateDaylightSavingsOffset, 1, 1) \
233   F(DateMakeDay, 3, 1) \
234   F(DateYMDFromTime, 2, 1) \
235   \
236   /* Numbers */ \
237   \
238   /* Globals */ \
239   F(CompileString, 1, 1) \
240   F(GlobalPrint, 1, 1) \
241   \
242   /* Eval */ \
243   F(GlobalReceiver, 1, 1) \
244   F(ResolvePossiblyDirectEval, 4, 2) \
245   F(ResolvePossiblyDirectEvalNoLookup, 4, 2) \
246   \
247   F(SetProperty, -1 /* 4 or 5 */, 1) \
248   F(DefineOrRedefineDataProperty, 4, 1) \
249   F(DefineOrRedefineAccessorProperty, 5, 1) \
250   F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
251   \
252   /* Arrays */ \
253   F(RemoveArrayHoles, 2, 1) \
254   F(GetArrayKeys, 2, 1) \
255   F(MoveArrayContents, 2, 1) \
256   F(EstimateNumberOfElements, 1, 1) \
257   F(SwapElements, 3, 1) \
258   \
259   /* Getters and Setters */ \
260   F(DefineAccessor, -1 /* 4 or 5 */, 1) \
261   F(LookupAccessor, 3, 1) \
262   \
263   /* Literals */ \
264   F(MaterializeRegExpLiteral, 4, 1)\
265   F(CreateArrayLiteralBoilerplate, 3, 1) \
266   F(CloneLiteralBoilerplate, 1, 1) \
267   F(CloneShallowLiteralBoilerplate, 1, 1) \
268   F(CreateObjectLiteral, 4, 1) \
269   F(CreateObjectLiteralShallow, 4, 1) \
270   F(CreateArrayLiteral, 3, 1) \
271   F(CreateArrayLiteralShallow, 3, 1) \
272   \
273   /* Catch context extension objects */ \
274   F(CreateCatchExtensionObject, 2, 1) \
275   \
276   /* Statements */ \
277   F(NewClosure, 3, 1) \
278   F(NewObject, 1, 1) \
279   F(NewObjectFromBound, 2, 1) \
280   F(FinalizeInstanceSize, 1, 1) \
281   F(Throw, 1, 1) \
282   F(ReThrow, 1, 1) \
283   F(ThrowReferenceError, 1, 1) \
284   F(StackGuard, 0, 1) \
285   F(PromoteScheduledException, 0, 1) \
286   \
287   /* Contexts */ \
288   F(NewContext, 1, 1) \
289   F(PushContext, 1, 1) \
290   F(PushCatchContext, 1, 1) \
291   F(DeleteContextSlot, 2, 1) \
292   F(LoadContextSlot, 2, 2) \
293   F(LoadContextSlotNoReferenceError, 2, 2) \
294   F(StoreContextSlot, 4, 1) \
295   \
296   /* Declarations and initialization */ \
297   F(DeclareGlobals, 4, 1) \
298   F(DeclareContextSlot, 4, 1) \
299   F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
300   F(InitializeConstGlobal, 2, 1) \
301   F(InitializeConstContextSlot, 3, 1) \
302   F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
303   \
304   /* Debugging */ \
305   F(DebugPrint, 1, 1) \
306   F(DebugTrace, 0, 1) \
307   F(TraceEnter, 0, 1) \
308   F(TraceExit, 1, 1) \
309   F(Abort, 2, 1) \
310   /* Logging */ \
311   F(Log, 2, 1) \
312   /* ES5 */ \
313   F(LocalKeys, 1, 1) \
314   /* Cache suport */ \
315   F(GetFromCache, 2, 1) \
316   \
317   /* Message objects */ \
318   F(NewMessageObject, 2, 1) \
319   F(MessageGetType, 1, 1) \
320   F(MessageGetArguments, 1, 1) \
321   F(MessageGetStartPosition, 1, 1) \
322   F(MessageGetScript, 1, 1) \
323   \
324   /* Pseudo functions - handled as macros by parser */ \
325   F(IS_VAR, 1, 1)
326 
327 #ifdef ENABLE_DEBUGGER_SUPPORT
328 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
329   /* Debugger support*/ \
330   F(DebugBreak, 0, 1) \
331   F(SetDebugEventListener, 2, 1) \
332   F(Break, 0, 1) \
333   F(DebugGetPropertyDetails, 2, 1) \
334   F(DebugGetProperty, 2, 1) \
335   F(DebugPropertyTypeFromDetails, 1, 1) \
336   F(DebugPropertyAttributesFromDetails, 1, 1) \
337   F(DebugPropertyIndexFromDetails, 1, 1) \
338   F(DebugNamedInterceptorPropertyValue, 2, 1) \
339   F(DebugIndexedInterceptorElementValue, 2, 1) \
340   F(CheckExecutionState, 1, 1) \
341   F(GetFrameCount, 1, 1) \
342   F(GetFrameDetails, 2, 1) \
343   F(GetScopeCount, 2, 1) \
344   F(GetScopeDetails, 3, 1) \
345   F(DebugPrintScopes, 0, 1) \
346   F(GetThreadCount, 1, 1) \
347   F(GetThreadDetails, 2, 1) \
348   F(SetDisableBreak, 1, 1) \
349   F(GetBreakLocations, 1, 1) \
350   F(SetFunctionBreakPoint, 3, 1) \
351   F(SetScriptBreakPoint, 3, 1) \
352   F(ClearBreakPoint, 1, 1) \
353   F(ChangeBreakOnException, 2, 1) \
354   F(IsBreakOnException, 1, 1) \
355   F(PrepareStep, 3, 1) \
356   F(ClearStepping, 0, 1) \
357   F(DebugEvaluate, 5, 1) \
358   F(DebugEvaluateGlobal, 4, 1) \
359   F(DebugGetLoadedScripts, 0, 1) \
360   F(DebugReferencedBy, 3, 1) \
361   F(DebugConstructedBy, 2, 1) \
362   F(DebugGetPrototype, 1, 1) \
363   F(SystemBreak, 0, 1) \
364   F(DebugDisassembleFunction, 1, 1) \
365   F(DebugDisassembleConstructor, 1, 1) \
366   F(FunctionGetInferredName, 1, 1) \
367   F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
368   F(LiveEditGatherCompileInfo, 2, 1) \
369   F(LiveEditReplaceScript, 3, 1) \
370   F(LiveEditReplaceFunctionCode, 2, 1) \
371   F(LiveEditFunctionSourceUpdated, 1, 1) \
372   F(LiveEditFunctionSetScript, 2, 1) \
373   F(LiveEditReplaceRefToNestedFunction, 3, 1) \
374   F(LiveEditPatchFunctionPositions, 2, 1) \
375   F(LiveEditCheckAndDropActivations, 2, 1) \
376   F(LiveEditCompareStrings, 2, 1) \
377   F(GetFunctionCodePositionFromSource, 2, 1) \
378   F(ExecuteInDebugContext, 2, 1) \
379   \
380   F(SetFlags, 1, 1) \
381   F(CollectGarbage, 1, 1) \
382   F(GetHeapUsage, 0, 1) \
383   \
384   /* LiveObjectList support*/ \
385   F(HasLOLEnabled, 0, 1) \
386   F(CaptureLOL, 0, 1) \
387   F(DeleteLOL, 1, 1) \
388   F(DumpLOL, 5, 1) \
389   F(GetLOLObj, 1, 1) \
390   F(GetLOLObjId, 1, 1) \
391   F(GetLOLObjRetainers, 6, 1) \
392   F(GetLOLPath, 3, 1) \
393   F(InfoLOL, 2, 1) \
394   F(PrintLOLObj, 1, 1) \
395   F(ResetLOL, 0, 1) \
396   F(SummarizeLOL, 3, 1)
397 
398 #else
399 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
400 #endif
401 
402 #ifdef ENABLE_LOGGING_AND_PROFILING
403 #define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F) \
404   F(ProfilerResume, 2, 1) \
405   F(ProfilerPause, 2, 1)
406 #else
407 #define RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
408 #endif
409 
410 #ifdef DEBUG
411 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
412   /* Testing */ \
413   F(ListNatives, 0, 1)
414 #else
415 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
416 #endif
417 
418 // ----------------------------------------------------------------------------
419 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
420 // either directly by id (via the code generator), or indirectly
421 // via a native call by name (from within JS code).
422 
423 #define RUNTIME_FUNCTION_LIST(F) \
424   RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
425   RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
426   RUNTIME_FUNCTION_LIST_DEBUG(F) \
427   RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
428   RUNTIME_FUNCTION_LIST_PROFILER_SUPPORT(F)
429 
430 // ----------------------------------------------------------------------------
431 // INLINE_FUNCTION_LIST defines all inlined functions accessed
432 // with a native call of the form %_name from within JS code.
433 // Entries have the form F(name, number of arguments, number of return values).
434 #define INLINE_FUNCTION_LIST(F) \
435   F(IsSmi, 1, 1)                                                             \
436   F(IsNonNegativeSmi, 1, 1)                                                  \
437   F(IsArray, 1, 1)                                                           \
438   F(IsRegExp, 1, 1)                                                          \
439   F(CallFunction, -1 /* receiver + n args + function */, 1)                  \
440   F(ArgumentsLength, 0, 1)                                                   \
441   F(Arguments, 1, 1)                                                         \
442   F(ValueOf, 1, 1)                                                           \
443   F(SetValueOf, 2, 1)                                                        \
444   F(StringCharFromCode, 1, 1)                                                \
445   F(StringCharAt, 2, 1)                                                      \
446   F(ObjectEquals, 2, 1)                                                      \
447   F(RandomHeapNumber, 0, 1)                                                  \
448   F(IsObject, 1, 1)                                                          \
449   F(IsFunction, 1, 1)                                                        \
450   F(IsUndetectableObject, 1, 1)                                              \
451   F(IsSpecObject, 1, 1)                                                      \
452   F(IsStringWrapperSafeForDefaultValueOf, 1, 1)                              \
453   F(MathPow, 2, 1)                                                           \
454   F(MathSin, 1, 1)                                                           \
455   F(MathCos, 1, 1)                                                           \
456   F(MathSqrt, 1, 1)                                                          \
457   F(MathLog, 1, 1)                                                           \
458   F(IsRegExpEquivalent, 2, 1)                                                \
459   F(HasCachedArrayIndex, 1, 1)                                               \
460   F(GetCachedArrayIndex, 1, 1)                                               \
461   F(FastAsciiArrayJoin, 2, 1)
462 
463 
464 // ----------------------------------------------------------------------------
465 // INLINE_AND_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
466 // with a native call of the form %_name from within JS code that also have
467 // a corresponding runtime function, that is called for slow cases.
468 // Entries have the form F(name, number of arguments, number of return values).
469 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
470   F(IsConstructCall, 0, 1)                                                   \
471   F(ClassOf, 1, 1)                                                           \
472   F(StringCharCodeAt, 2, 1)                                                  \
473   F(Log, 3, 1)                                                               \
474   F(StringAdd, 2, 1)                                                         \
475   F(SubString, 3, 1)                                                         \
476   F(StringCompare, 2, 1)                                                     \
477   F(RegExpExec, 4, 1)                                                        \
478   F(RegExpConstructResult, 3, 1)                                             \
479   F(GetFromCache, 2, 1)                                                      \
480   F(NumberToString, 1, 1)                                                    \
481   F(SwapElements, 3, 1)
482 
483 
484 //---------------------------------------------------------------------------
485 // Runtime provides access to all C++ runtime functions.
486 
487 class RuntimeState {
488  public:
489 
string_input_buffer()490   StaticResource<StringInputBuffer>* string_input_buffer() {
491     return &string_input_buffer_;
492   }
to_upper_mapping()493   unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
494     return &to_upper_mapping_;
495   }
to_lower_mapping()496   unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
497     return &to_lower_mapping_;
498   }
string_input_buffer_compare_bufx()499   StringInputBuffer* string_input_buffer_compare_bufx() {
500     return &string_input_buffer_compare_bufx_;
501   }
string_input_buffer_compare_bufy()502   StringInputBuffer* string_input_buffer_compare_bufy() {
503     return &string_input_buffer_compare_bufy_;
504   }
string_locale_compare_buf1()505   StringInputBuffer* string_locale_compare_buf1() {
506     return &string_locale_compare_buf1_;
507   }
string_locale_compare_buf2()508   StringInputBuffer* string_locale_compare_buf2() {
509     return &string_locale_compare_buf2_;
510   }
smi_lexicographic_compare_x_elms()511   int* smi_lexicographic_compare_x_elms() {
512     return smi_lexicographic_compare_x_elms_;
513   }
smi_lexicographic_compare_y_elms()514   int* smi_lexicographic_compare_y_elms() {
515     return smi_lexicographic_compare_y_elms_;
516   }
517 
518  private:
RuntimeState()519   RuntimeState() {}
520   // Non-reentrant string buffer for efficient general use in the runtime.
521   StaticResource<StringInputBuffer> string_input_buffer_;
522   unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
523   unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
524   StringInputBuffer string_input_buffer_compare_bufx_;
525   StringInputBuffer string_input_buffer_compare_bufy_;
526   StringInputBuffer string_locale_compare_buf1_;
527   StringInputBuffer string_locale_compare_buf2_;
528   int smi_lexicographic_compare_x_elms_[10];
529   int smi_lexicographic_compare_y_elms_[10];
530 
531   friend class Isolate;
532   friend class Runtime;
533 
534   DISALLOW_COPY_AND_ASSIGN(RuntimeState);
535 };
536 
537 
538 class Runtime : public AllStatic {
539  public:
540   enum FunctionId {
541 #define F(name, nargs, ressize) k##name,
542     RUNTIME_FUNCTION_LIST(F)
543 #undef F
544 #define F(name, nargs, ressize) kInline##name,
545     INLINE_FUNCTION_LIST(F)
546     INLINE_RUNTIME_FUNCTION_LIST(F)
547 #undef F
548     kNumFunctions,
549     kFirstInlineFunction = kInlineIsSmi
550   };
551 
552   enum IntrinsicType {
553     RUNTIME,
554     INLINE
555   };
556 
557   // Intrinsic function descriptor.
558   struct Function {
559     FunctionId function_id;
560     IntrinsicType intrinsic_type;
561     // The JS name of the function.
562     const char* name;
563 
564     // The C++ (native) entry point.  NULL if the function is inlined.
565     byte* entry;
566 
567     // The number of arguments expected. nargs is -1 if the function takes
568     // a variable number of arguments.
569     int nargs;
570     // Size of result.  Most functions return a single pointer, size 1.
571     int result_size;
572   };
573 
574   static const int kNotFound = -1;
575 
576   // Add symbols for all the intrinsic function names to a StringDictionary.
577   // Returns failure if an allocation fails.  In this case, it must be
578   // retried with a new, empty StringDictionary, not with the same one.
579   // Alternatively, heap initialization can be completely restarted.
580   MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
581       Heap* heap, Object* dictionary);
582 
583   // Get the intrinsic function with the given name, which must be a symbol.
584   static const Function* FunctionForSymbol(Handle<String> name);
585 
586   // Get the intrinsic function with the given FunctionId.
587   static const Function* FunctionForId(FunctionId id);
588 
589   // General-purpose helper functions for runtime system.
590   static int StringMatch(Isolate* isolate,
591                          Handle<String> sub,
592                          Handle<String> pat,
593                          int index);
594 
595   static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
596 
597   // TODO(1240886): The following three methods are *not* handle safe,
598   // but accept handle arguments. This seems fragile.
599 
600   // Support getting the characters in a string using [] notation as
601   // in Firefox/SpiderMonkey, Safari and Opera.
602   MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
603                                                          Handle<Object> object,
604                                                          uint32_t index);
605   MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object,
606                                                  uint32_t index);
607 
608   MUST_USE_RESULT static MaybeObject* SetObjectProperty(
609       Isolate* isolate,
610       Handle<Object> object,
611       Handle<Object> key,
612       Handle<Object> value,
613       PropertyAttributes attr,
614       StrictModeFlag strict_mode);
615 
616   MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
617       Isolate* isolate,
618       Handle<JSObject> object,
619       Handle<Object> key,
620       Handle<Object> value,
621       PropertyAttributes attr);
622 
623   MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty(
624       Isolate* isolate,
625       Handle<JSObject> object,
626       Handle<Object> key);
627 
628   MUST_USE_RESULT static MaybeObject* GetObjectProperty(
629       Isolate* isolate,
630       Handle<Object> object,
631       Handle<Object> key);
632 
633   // This function is used in FunctionNameUsing* tests.
634   static Object* FindSharedFunctionInfoInScript(Isolate* isolate,
635                                                 Handle<Script> script,
636                                                 int position);
637 
638   // Helper functions used stubs.
639   static void PerformGC(Object* result);
640 };
641 
642 } }  // namespace v8::internal
643 
644 #endif  // V8_RUNTIME_H_
645