1 // Copyright 2012 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
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.
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.
31 #include "allocation.h"
37 // The interface to C++ runtime functions.
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.
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) \
51 F(DeleteProperty, 3, 1) \
52 F(HasLocalProperty, 2, 1) \
53 F(HasProperty, 2, 1) \
55 F(IsPropertyEnumerable, 2, 1) \
56 F(GetPropertyNames, 1, 1) \
57 F(GetPropertyNamesFast, 1, 1) \
58 F(GetLocalPropertyNames, 2, 1) \
59 F(GetLocalElementNames, 1, 1) \
60 F(GetInterceptorInfo, 1, 1) \
61 F(GetNamedInterceptorPropertyNames, 1, 1) \
62 F(GetIndexedInterceptorElementNames, 1, 1) \
63 F(GetArgumentsProperty, 1, 1) \
64 F(ToFastProperties, 1, 1) \
65 F(FinishArrayPrototypeSetup, 1, 1) \
66 F(SpecialArrayFunctions, 1, 1) \
67 F(IsClassicModeFunction, 1, 1) \
68 F(GetDefaultReceiver, 1, 1) \
70 F(GetPrototype, 1, 1) \
71 F(SetPrototype, 2, 1) \
72 F(IsInPrototypeChain, 2, 1) \
74 F(GetOwnProperty, 2, 1) \
76 F(IsExtensible, 1, 1) \
77 F(PreventExtensions, 1, 1)\
80 F(CheckIsBootstrapping, 0, 1) \
82 F(Call, -1 /* >= 2 */, 1) \
84 F(GetFunctionDelegate, 1, 1) \
85 F(GetConstructorDelegate, 1, 1) \
86 F(NewArgumentsFast, 3, 1) \
87 F(NewStrictArgumentsFast, 3, 1) \
88 F(LazyCompile, 1, 1) \
89 F(LazyRecompile, 1, 1) \
90 F(ConcurrentRecompile, 1, 1) \
91 F(TryInstallRecompiledCode, 1, 1) \
92 F(NotifyDeoptimized, 1, 1) \
93 F(NotifyStubFailure, 0, 1) \
94 F(DeoptimizeFunction, 1, 1) \
95 F(ClearFunctionTypeFeedback, 1, 1) \
96 F(RunningInSimulator, 0, 1) \
97 F(IsConcurrentRecompilationSupported, 0, 1) \
98 F(OptimizeFunctionOnNextCall, -1, 1) \
99 F(NeverOptimizeFunction, 1, 1) \
100 F(GetOptimizationStatus, -1, 1) \
101 F(GetOptimizationCount, 1, 1) \
102 F(UnblockConcurrentRecompilation, 0, 1) \
103 F(CompileForOnStackReplacement, 2, 1) \
104 F(SetAllocationTimeout, 2, 1) \
105 F(AllocateInNewSpace, 1, 1) \
106 F(AllocateInOldPointerSpace, 1, 1) \
107 F(AllocateInOldDataSpace, 1, 1) \
108 F(SetNativeFlag, 1, 1) \
109 F(StoreArrayLiteralElement, 5, 1) \
110 F(DebugCallbackSupportsStepping, 1, 1) \
111 F(DebugPrepareStepInIfStepping, 1, 1) \
112 F(FlattenString, 1, 1) \
113 F(MigrateInstance, 1, 1) \
114 F(NotifyContextDisposed, 0, 1) \
116 /* Array join support */ \
117 F(PushIfAbsent, 2, 1) \
118 F(ArrayConcat, 1, 1) \
124 F(StringToNumber, 1, 1) \
125 F(StringParseInt, 2, 1) \
126 F(StringParseFloat, 1, 1) \
127 F(StringToLowerCase, 1, 1) \
128 F(StringToUpperCase, 1, 1) \
129 F(StringSplit, 3, 1) \
130 F(CharFromCode, 1, 1) \
132 F(URIUnescape, 1, 1) \
134 F(NumberToString, 1, 1) \
135 F(NumberToStringSkipCache, 1, 1) \
136 F(NumberToInteger, 1, 1) \
137 F(NumberToPositiveInteger, 1, 1) \
138 F(NumberToIntegerMapMinusZero, 1, 1) \
139 F(NumberToJSUint32, 1, 1) \
140 F(NumberToJSInt32, 1, 1) \
141 F(NumberToSmi, 1, 1) \
142 F(AllocateHeapNumber, 0, 1) \
144 /* Arithmetic operations */ \
150 F(NumberUnaryMinus, 1, 1) \
151 F(NumberAlloc, 0, 1) \
152 F(NumberImul, 2, 1) \
155 F(StringBuilderConcat, 3, 1) \
156 F(StringBuilderJoin, 3, 1) \
157 F(SparseJoinWithSeparator, 3, 1) \
159 /* Bit operations */ \
169 F(NumberEquals, 2, 1) \
170 F(StringEquals, 2, 1) \
172 F(NumberCompare, 3, 1) \
173 F(SmiLexicographicCompare, 2, 1) \
174 F(StringCompare, 2, 1) \
180 F(Math_atan2, 2, 1) \
184 F(Math_floor, 1, 1) \
187 F(Math_pow_cfunction, 2, 1) \
188 F(RoundNumber, 1, 1) \
193 /* Regular expressions */ \
194 F(RegExpCompile, 3, 1) \
195 F(RegExpExec, 4, 1) \
196 F(RegExpExecMultiple, 4, 1) \
197 F(RegExpInitializeObject, 5, 1) \
198 F(RegExpConstructResult, 3, 1) \
202 F(BasicJSONStringify, 1, 1) \
203 F(QuoteJSONString, 1, 1) \
206 F(StringCharCodeAt, 2, 1) \
207 F(StringIndexOf, 3, 1) \
208 F(StringLastIndexOf, 3, 1) \
209 F(StringLocaleCompare, 2, 1) \
211 F(StringReplaceGlobalRegExpWithString, 4, 1) \
212 F(StringReplaceOneCharWithString, 3, 1) \
213 F(StringMatch, 3, 1) \
214 F(StringTrim, 3, 1) \
215 F(StringToArray, 2, 1) \
216 F(NewStringWrapper, 1, 1) \
218 F(TruncateString, 2, 1) \
221 F(NumberToRadixString, 2, 1) \
222 F(NumberToFixed, 2, 1) \
223 F(NumberToExponential, 2, 1) \
224 F(NumberToPrecision, 2, 1) \
228 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
230 F(FunctionSetInstanceClassName, 2, 1) \
231 F(FunctionSetLength, 2, 1) \
232 F(FunctionSetPrototype, 2, 1) \
233 F(FunctionSetReadOnlyPrototype, 1, 1) \
234 F(FunctionGetName, 1, 1) \
235 F(FunctionSetName, 2, 1) \
236 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
237 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
238 F(FunctionIsGenerator, 1, 1) \
239 F(FunctionBindArguments, 4, 1) \
240 F(BoundFunctionGetBindings, 1, 1) \
241 F(FunctionRemovePrototype, 1, 1) \
242 F(FunctionGetSourceCode, 1, 1) \
243 F(FunctionGetScript, 1, 1) \
244 F(FunctionGetScriptSourcePosition, 1, 1) \
245 F(FunctionGetPositionForOffset, 2, 1) \
246 F(FunctionIsAPIFunction, 1, 1) \
247 F(FunctionIsBuiltin, 1, 1) \
249 F(CollectStackTrace, 3, 1) \
250 F(GetAndClearOverflowedStackTrace, 1, 1) \
251 F(GetV8Version, 0, 1) \
255 F(SetExpectedNumberOfProperties, 2, 1) \
257 F(CreateApiFunction, 1, 1) \
258 F(IsTemplate, 1, 1) \
259 F(GetTemplateField, 2, 1) \
260 F(DisableAccessChecks, 1, 1) \
261 F(EnableAccessChecks, 1, 1) \
262 F(SetAccessorProperty, 6, 1) \
265 F(DateCurrentTime, 0, 1) \
266 F(DateParseString, 2, 1) \
267 F(DateLocalTimezone, 1, 1) \
269 F(DateMakeDay, 2, 1) \
270 F(DateSetValue, 3, 1) \
275 F(CompileString, 2, 1) \
276 F(GlobalPrint, 1, 1) \
279 F(GlobalReceiver, 1, 1) \
280 F(ResolvePossiblyDirectEval, 5, 2) \
282 F(SetProperty, -1 /* 4 or 5 */, 1) \
283 F(DefineOrRedefineDataProperty, 4, 1) \
284 F(DefineOrRedefineAccessorProperty, 5, 1) \
285 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
286 F(GetDataProperty, 2, 1) \
289 F(RemoveArrayHoles, 2, 1) \
290 F(GetArrayKeys, 2, 1) \
291 F(MoveArrayContents, 2, 1) \
292 F(EstimateNumberOfElements, 1, 1) \
293 F(ArrayConstructor, -1, 1) \
294 F(InternalArrayConstructor, -1, 1) \
296 /* Getters and Setters */ \
297 F(LookupAccessor, 3, 1) \
300 F(MaterializeRegExpLiteral, 4, 1)\
301 F(CreateObjectLiteral, 4, 1) \
302 F(CreateArrayLiteral, 3, 1) \
303 F(CreateArrayLiteralShallow, 3, 1) \
305 /* Harmony generators */ \
306 F(CreateJSGeneratorObject, 0, 1) \
307 F(SuspendJSGeneratorObject, 1, 1) \
308 F(ResumeJSGeneratorObject, 3, 1) \
309 F(ThrowGeneratorStateError, 1, 1) \
312 F(ObjectFreeze, 1, 1) \
314 /* Harmony modules */ \
315 F(IsJSModule, 1, 1) \
317 /* Harmony symbols */ \
318 F(CreateSymbol, 1, 1) \
319 F(SymbolName, 1, 1) \
321 /* Harmony proxies */ \
322 F(CreateJSProxy, 2, 1) \
323 F(CreateJSFunctionProxy, 4, 1) \
325 F(IsJSFunctionProxy, 1, 1) \
326 F(GetHandler, 1, 1) \
327 F(GetCallTrap, 1, 1) \
328 F(GetConstructTrap, 1, 1) \
332 F(SetInitialize, 1, 1) \
336 F(SetGetSize, 1, 1) \
339 F(MapInitialize, 1, 1) \
344 F(MapGetSize, 1, 1) \
346 /* Harmony weak maps and sets */ \
347 F(WeakCollectionInitialize, 1, 1) \
348 F(WeakCollectionGet, 2, 1) \
349 F(WeakCollectionHas, 2, 1) \
350 F(WeakCollectionDelete, 2, 1) \
351 F(WeakCollectionSet, 3, 1) \
353 /* Harmony observe */ \
354 F(IsObserved, 1, 1) \
355 F(SetIsObserved, 1, 1) \
356 F(SetObserverDeliveryPending, 0, 1) \
357 F(GetObservationState, 0, 1) \
358 F(ObservationWeakMapCreate, 0, 1) \
359 F(UnwrapGlobalProxy, 1, 1) \
360 F(IsAccessAllowedForObserver, 3, 1) \
362 /* Harmony typed arrays */ \
363 F(ArrayBufferInitialize, 2, 1)\
364 F(ArrayBufferGetByteLength, 1, 1)\
365 F(ArrayBufferSliceImpl, 3, 1) \
366 F(ArrayBufferIsView, 1, 1) \
368 F(TypedArrayInitialize, 5, 1) \
369 F(TypedArrayInitializeFromArrayLike, 4, 1) \
370 F(TypedArrayGetBuffer, 1, 1) \
371 F(TypedArrayGetByteLength, 1, 1) \
372 F(TypedArrayGetByteOffset, 1, 1) \
373 F(TypedArrayGetLength, 1, 1) \
374 F(TypedArraySetFastCases, 3, 1) \
376 F(DataViewInitialize, 4, 1) \
377 F(DataViewGetBuffer, 1, 1) \
378 F(DataViewGetByteLength, 1, 1) \
379 F(DataViewGetByteOffset, 1, 1) \
380 F(DataViewGetInt8, 3, 1) \
381 F(DataViewGetUint8, 3, 1) \
382 F(DataViewGetInt16, 3, 1) \
383 F(DataViewGetUint16, 3, 1) \
384 F(DataViewGetInt32, 3, 1) \
385 F(DataViewGetUint32, 3, 1) \
386 F(DataViewGetFloat32, 3, 1) \
387 F(DataViewGetFloat64, 3, 1) \
389 F(DataViewSetInt8, 4, 1) \
390 F(DataViewSetUint8, 4, 1) \
391 F(DataViewSetInt16, 4, 1) \
392 F(DataViewSetUint16, 4, 1) \
393 F(DataViewSetInt32, 4, 1) \
394 F(DataViewSetUint32, 4, 1) \
395 F(DataViewSetFloat32, 4, 1) \
396 F(DataViewSetFloat64, 4, 1) \
399 F(NewClosure, 3, 1) \
400 F(NewClosureFromStubFailure, 1, 1) \
402 F(NewObjectFromBound, 1, 1) \
403 F(FinalizeInstanceSize, 1, 1) \
406 F(ThrowReferenceError, 1, 1) \
407 F(ThrowNotDateError, 0, 1) \
408 F(StackGuard, 0, 1) \
410 F(PromoteScheduledException, 0, 1) \
413 F(NewGlobalContext, 2, 1) \
414 F(NewFunctionContext, 1, 1) \
415 F(PushWithContext, 2, 1) \
416 F(PushCatchContext, 3, 1) \
417 F(PushBlockContext, 2, 1) \
418 F(PushModuleContext, 2, 1) \
419 F(DeleteContextSlot, 2, 1) \
420 F(LoadContextSlot, 2, 2) \
421 F(LoadContextSlotNoReferenceError, 2, 2) \
422 F(StoreContextSlot, 4, 1) \
424 /* Declarations and initialization */ \
425 F(DeclareGlobals, 3, 1) \
426 F(DeclareModules, 1, 1) \
427 F(DeclareContextSlot, 4, 1) \
428 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
429 F(InitializeConstGlobal, 2, 1) \
430 F(InitializeConstContextSlot, 3, 1) \
431 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
434 F(DebugPrint, 1, 1) \
435 F(DebugTrace, 0, 1) \
436 F(TraceEnter, 0, 1) \
444 F(GetFromCache, 2, 1) \
446 /* Message objects */ \
447 F(MessageGetStartPosition, 1, 1) \
448 F(MessageGetScript, 1, 1) \
450 /* Pseudo functions - handled as macros by parser */ \
453 /* expose boolean functions from objects-inl.h */ \
454 F(HasFastSmiElements, 1, 1) \
455 F(HasFastSmiOrObjectElements, 1, 1) \
456 F(HasFastObjectElements, 1, 1) \
457 F(HasFastDoubleElements, 1, 1) \
458 F(HasFastHoleyElements, 1, 1) \
459 F(HasDictionaryElements, 1, 1) \
460 F(HasNonStrictArgumentsElements, 1, 1) \
461 F(HasExternalPixelElements, 1, 1) \
462 F(HasExternalArrayElements, 1, 1) \
463 F(HasExternalByteElements, 1, 1) \
464 F(HasExternalUnsignedByteElements, 1, 1) \
465 F(HasExternalShortElements, 1, 1) \
466 F(HasExternalUnsignedShortElements, 1, 1) \
467 F(HasExternalIntElements, 1, 1) \
468 F(HasExternalUnsignedIntElements, 1, 1) \
469 F(HasExternalFloatElements, 1, 1) \
470 F(HasExternalDoubleElements, 1, 1) \
471 F(HasFastProperties, 1, 1) \
472 F(TransitionElementsKind, 2, 1) \
473 F(HaveSameMap, 2, 1) \
474 F(IsAccessCheckNeeded, 1, 1)
477 #ifdef ENABLE_DEBUGGER_SUPPORT
478 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
479 /* Debugger support*/ \
480 F(DebugBreak, 0, 1) \
481 F(SetDebugEventListener, 2, 1) \
483 F(DebugGetPropertyDetails, 2, 1) \
484 F(DebugGetProperty, 2, 1) \
485 F(DebugPropertyTypeFromDetails, 1, 1) \
486 F(DebugPropertyAttributesFromDetails, 1, 1) \
487 F(DebugPropertyIndexFromDetails, 1, 1) \
488 F(DebugNamedInterceptorPropertyValue, 2, 1) \
489 F(DebugIndexedInterceptorElementValue, 2, 1) \
490 F(CheckExecutionState, 1, 1) \
491 F(GetFrameCount, 1, 1) \
492 F(GetFrameDetails, 2, 1) \
493 F(GetScopeCount, 2, 1) \
494 F(GetStepInPositions, 2, 1) \
495 F(GetScopeDetails, 4, 1) \
496 F(GetFunctionScopeCount, 1, 1) \
497 F(GetFunctionScopeDetails, 2, 1) \
498 F(SetScopeVariableValue, 6, 1) \
499 F(DebugPrintScopes, 0, 1) \
500 F(GetThreadCount, 1, 1) \
501 F(GetThreadDetails, 2, 1) \
502 F(SetDisableBreak, 1, 1) \
503 F(GetBreakLocations, 2, 1) \
504 F(SetFunctionBreakPoint, 3, 1) \
505 F(SetScriptBreakPoint, 4, 1) \
506 F(ClearBreakPoint, 1, 1) \
507 F(ChangeBreakOnException, 2, 1) \
508 F(IsBreakOnException, 1, 1) \
509 F(PrepareStep, 4, 1) \
510 F(ClearStepping, 0, 1) \
511 F(DebugEvaluate, 6, 1) \
512 F(DebugEvaluateGlobal, 4, 1) \
513 F(DebugGetLoadedScripts, 0, 1) \
514 F(DebugReferencedBy, 3, 1) \
515 F(DebugConstructedBy, 2, 1) \
516 F(DebugGetPrototype, 1, 1) \
517 F(DebugSetScriptSource, 2, 1) \
518 F(SystemBreak, 0, 1) \
519 F(DebugDisassembleFunction, 1, 1) \
520 F(DebugDisassembleConstructor, 1, 1) \
521 F(FunctionGetInferredName, 1, 1) \
522 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
523 F(LiveEditGatherCompileInfo, 2, 1) \
524 F(LiveEditReplaceScript, 3, 1) \
525 F(LiveEditReplaceFunctionCode, 2, 1) \
526 F(LiveEditFunctionSourceUpdated, 1, 1) \
527 F(LiveEditFunctionSetScript, 2, 1) \
528 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
529 F(LiveEditPatchFunctionPositions, 2, 1) \
530 F(LiveEditCheckAndDropActivations, 2, 1) \
531 F(LiveEditCompareStrings, 2, 1) \
532 F(LiveEditRestartFrame, 2, 1) \
533 F(GetFunctionCodePositionFromSource, 2, 1) \
534 F(ExecuteInDebugContext, 2, 1) \
537 F(CollectGarbage, 1, 1) \
538 F(GetHeapUsage, 0, 1) \
541 #define RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F)
545 #ifdef V8_I18N_SUPPORT
546 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
548 /* Standalone, helper methods. */ \
549 F(CanonicalizeLanguageTag, 1, 1) \
550 F(AvailableLocalesOf, 1, 1) \
551 F(GetDefaultICULocale, 0, 1) \
552 F(GetLanguageTagVariants, 1, 1) \
554 /* Date format and parse. */ \
555 F(CreateDateTimeFormat, 3, 1) \
556 F(InternalDateFormat, 2, 1) \
557 F(InternalDateParse, 2, 1) \
559 /* Number format and parse. */ \
560 F(CreateNumberFormat, 3, 1) \
561 F(InternalNumberFormat, 2, 1) \
562 F(InternalNumberParse, 2, 1) \
565 F(CreateCollator, 3, 1) \
566 F(InternalCompare, 3, 1) \
568 /* Break iterator. */ \
569 F(CreateBreakIterator, 3, 1) \
570 F(BreakIteratorAdoptText, 2, 1) \
571 F(BreakIteratorFirst, 1, 1) \
572 F(BreakIteratorNext, 1, 1) \
573 F(BreakIteratorCurrent, 1, 1) \
574 F(BreakIteratorBreakType, 1, 1) \
577 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
582 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
586 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
589 // ----------------------------------------------------------------------------
590 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
591 // either directly by id (via the code generator), or indirectly
592 // via a native call by name (from within JS code).
594 #define RUNTIME_FUNCTION_LIST(F) \
595 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
596 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
597 RUNTIME_FUNCTION_LIST_DEBUG(F) \
598 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \
599 RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
601 // ----------------------------------------------------------------------------
602 // INLINE_FUNCTION_LIST defines all inlined functions accessed
603 // with a native call of the form %_name from within JS code.
604 // Entries have the form F(name, number of arguments, number of return values).
605 #define INLINE_FUNCTION_LIST(F) \
607 F(IsNonNegativeSmi, 1, 1) \
610 F(IsConstructCall, 0, 1) \
611 F(CallFunction, -1 /* receiver + n args + function */, 1) \
612 F(ArgumentsLength, 0, 1) \
615 F(SetValueOf, 2, 1) \
616 F(DateField, 2 /* date object, field index */, 1) \
617 F(StringCharFromCode, 1, 1) \
618 F(StringCharAt, 2, 1) \
619 F(OneByteSeqStringSetChar, 3, 1) \
620 F(TwoByteSeqStringSetChar, 3, 1) \
621 F(ObjectEquals, 2, 1) \
622 F(RandomHeapNumber, 0, 1) \
624 F(IsFunction, 1, 1) \
625 F(IsUndetectableObject, 1, 1) \
626 F(IsSpecObject, 1, 1) \
627 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
634 F(IsRegExpEquivalent, 2, 1) \
635 F(HasCachedArrayIndex, 1, 1) \
636 F(GetCachedArrayIndex, 1, 1) \
637 F(FastAsciiArrayJoin, 2, 1) \
638 F(GeneratorNext, 2, 1) \
639 F(GeneratorThrow, 2, 1) \
640 F(DebugBreakInOptimizedCode, 0, 1)
643 // ----------------------------------------------------------------------------
644 // INLINE_RUNTIME_FUNCTION_LIST defines all inlined functions accessed
645 // with a native call of the form %_name from within JS code that also have
646 // a corresponding runtime function, that is called for slow cases.
647 // Entries have the form F(name, number of arguments, number of return values).
648 #define INLINE_RUNTIME_FUNCTION_LIST(F) \
650 F(StringCharCodeAt, 2, 1) \
654 F(StringCompare, 2, 1) \
655 F(RegExpExec, 4, 1) \
656 F(RegExpConstructResult, 3, 1) \
657 F(GetFromCache, 2, 1) \
658 F(NumberToString, 1, 1)
661 //---------------------------------------------------------------------------
662 // Runtime provides access to all C++ runtime functions.
666 StaticResource<ConsStringIteratorOp>* string_iterator() {
667 return &string_iterator_;
669 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
670 return &to_upper_mapping_;
672 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
673 return &to_lower_mapping_;
675 ConsStringIteratorOp* string_iterator_compare_x() {
676 return &string_iterator_compare_x_;
678 ConsStringIteratorOp* string_iterator_compare_y() {
679 return &string_iterator_compare_y_;
681 ConsStringIteratorOp* string_locale_compare_it1() {
682 return &string_locale_compare_it1_;
684 ConsStringIteratorOp* string_locale_compare_it2() {
685 return &string_locale_compare_it2_;
690 // Non-reentrant string buffer for efficient general use in the runtime.
691 StaticResource<ConsStringIteratorOp> string_iterator_;
692 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
693 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
694 ConsStringIteratorOp string_iterator_compare_x_;
695 ConsStringIteratorOp string_iterator_compare_y_;
696 ConsStringIteratorOp string_locale_compare_it1_;
697 ConsStringIteratorOp string_locale_compare_it2_;
699 friend class Isolate;
700 friend class Runtime;
702 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
706 class Runtime : public AllStatic {
709 #define F(name, nargs, ressize) k##name,
710 RUNTIME_FUNCTION_LIST(F)
712 #define F(name, nargs, ressize) kInline##name,
713 INLINE_FUNCTION_LIST(F)
714 INLINE_RUNTIME_FUNCTION_LIST(F)
717 kFirstInlineFunction = kInlineIsSmi
725 // Intrinsic function descriptor.
727 FunctionId function_id;
728 IntrinsicType intrinsic_type;
729 // The JS name of the function.
732 // The C++ (native) entry point. NULL if the function is inlined.
735 // The number of arguments expected. nargs is -1 if the function takes
736 // a variable number of arguments.
738 // Size of result. Most functions return a single pointer, size 1.
742 static const int kNotFound = -1;
744 // Add internalized strings for all the intrinsic function names to a
746 // Returns failure if an allocation fails. In this case, it must be
747 // retried with a new, empty StringDictionary, not with the same one.
748 // Alternatively, heap initialization can be completely restarted.
749 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames(
750 Heap* heap, Object* dictionary);
752 // Get the intrinsic function with the given name, which must be internalized.
753 static const Function* FunctionForName(Handle<String> name);
755 // Get the intrinsic function with the given FunctionId.
756 static const Function* FunctionForId(FunctionId id);
758 // General-purpose helper functions for runtime system.
759 static int StringMatch(Isolate* isolate,
764 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
766 // TODO(1240886): Some of the following methods are *not* handle safe, but
767 // accept handle arguments. This seems fragile.
769 // Support getting the characters in a string using [] notation as
770 // in Firefox/SpiderMonkey, Safari and Opera.
771 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate,
772 Handle<Object> object,
775 MUST_USE_RESULT static MaybeObject* GetElementOrCharAtOrFail(
777 Handle<Object> object,
780 MUST_USE_RESULT static MaybeObject* SetObjectProperty(
782 Handle<Object> object,
784 Handle<Object> value,
785 PropertyAttributes attr,
786 StrictModeFlag strict_mode);
788 MUST_USE_RESULT static MaybeObject* SetObjectPropertyOrFail(
790 Handle<Object> object,
792 Handle<Object> value,
793 PropertyAttributes attr,
794 StrictModeFlag strict_mode);
796 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty(
798 Handle<JSObject> object,
800 Handle<Object> value,
801 PropertyAttributes attr);
803 MUST_USE_RESULT static MaybeObject* DeleteObjectProperty(
805 Handle<JSReceiver> object,
807 JSReceiver::DeleteMode mode);
809 MUST_USE_RESULT static MaybeObject* HasObjectProperty(
811 Handle<JSReceiver> object,
814 MUST_USE_RESULT static MaybeObject* GetObjectProperty(
816 Handle<Object> object,
819 MUST_USE_RESULT static MaybeObject* GetObjectPropertyOrFail(
821 Handle<Object> object,
824 static void SetupArrayBuffer(Isolate* isolate,
825 Handle<JSArrayBuffer> array_buffer,
828 size_t allocated_length);
830 static bool SetupArrayBufferAllocatingData(
832 Handle<JSArrayBuffer> array_buffer,
833 size_t allocated_length,
834 bool initialize = true);
836 static void FreeArrayBuffer(
838 JSArrayBuffer* phantom_array_buffer);
840 // Helper functions used stubs.
841 static void PerformGC(Object* result, Isolate* isolate);
843 // Used in runtime.cc and hydrogen's VisitArrayLiteral.
844 static Handle<Object> CreateArrayLiteralBoilerplate(
846 Handle<FixedArray> literals,
847 Handle<FixedArray> elements);
851 //---------------------------------------------------------------------------
852 // Constants used by interface to runtime functions.
854 class DeclareGlobalsEvalFlag: public BitField<bool, 0, 1> {};
855 class DeclareGlobalsNativeFlag: public BitField<bool, 1, 1> {};
856 class DeclareGlobalsLanguageMode: public BitField<LanguageMode, 2, 2> {};
858 } } // namespace v8::internal
860 #endif // V8_RUNTIME_H_