1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "src/allocation.h"
14 // The interface to C++ runtime functions.
16 // ----------------------------------------------------------------------------
17 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both
18 // release and debug mode.
19 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST.
21 // WARNING: RUNTIME_FUNCTION_LIST_ALWAYS_* is a very large macro that caused
22 // MSVC Intellisense to crash. It was broken into two macros to work around
23 // this problem. Please avoid large recursive macros whenever possible.
24 #define RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
25 /* Property access */ \
26 F(GetProperty, 2, 1) \
27 F(KeyedGetProperty, 2, 1) \
28 F(DeleteProperty, 3, 1) \
29 F(HasOwnProperty, 2, 1) \
30 F(HasProperty, 2, 1) \
32 F(IsPropertyEnumerable, 2, 1) \
33 F(GetPropertyNames, 1, 1) \
34 F(GetPropertyNamesFast, 1, 1) \
35 F(GetOwnPropertyNames, 2, 1) \
36 F(GetOwnElementNames, 1, 1) \
37 F(GetInterceptorInfo, 1, 1) \
38 F(GetNamedInterceptorPropertyNames, 1, 1) \
39 F(GetIndexedInterceptorElementNames, 1, 1) \
40 F(GetArgumentsProperty, 1, 1) \
41 F(ToFastProperties, 1, 1) \
42 F(FinishArrayPrototypeSetup, 1, 1) \
43 F(SpecialArrayFunctions, 0, 1) \
44 F(IsSloppyModeFunction, 1, 1) \
45 F(GetDefaultReceiver, 1, 1) \
47 F(GetPrototype, 1, 1) \
48 F(SetPrototype, 2, 1) \
49 F(IsInPrototypeChain, 2, 1) \
51 F(GetOwnProperty, 2, 1) \
53 F(IsExtensible, 1, 1) \
54 F(PreventExtensions, 1, 1)\
57 F(CheckIsBootstrapping, 0, 1) \
59 F(Call, -1 /* >= 2 */, 1) \
61 F(GetFunctionDelegate, 1, 1) \
62 F(GetConstructorDelegate, 1, 1) \
63 F(DeoptimizeFunction, 1, 1) \
64 F(ClearFunctionTypeFeedback, 1, 1) \
65 F(RunningInSimulator, 0, 1) \
66 F(IsConcurrentRecompilationSupported, 0, 1) \
67 F(OptimizeFunctionOnNextCall, -1, 1) \
68 F(NeverOptimizeFunction, 1, 1) \
69 F(GetOptimizationStatus, -1, 1) \
70 F(GetOptimizationCount, 1, 1) \
71 F(UnblockConcurrentRecompilation, 0, 1) \
72 F(CompileForOnStackReplacement, 1, 1) \
73 F(SetAllocationTimeout, -1 /* 2 || 3 */, 1) \
74 F(SetNativeFlag, 1, 1) \
75 F(SetInlineBuiltinFlag, 1, 1) \
76 F(StoreArrayLiteralElement, 5, 1) \
77 F(DebugPrepareStepInIfStepping, 1, 1) \
78 F(DebugPromiseHandlePrologue, 1, 1) \
79 F(DebugPromiseHandleEpilogue, 0, 1) \
80 F(FlattenString, 1, 1) \
81 F(LoadMutableDouble, 2, 1) \
82 F(TryMigrateInstance, 1, 1) \
83 F(NotifyContextDisposed, 0, 1) \
85 /* Array join support */ \
86 F(PushIfAbsent, 2, 1) \
87 F(ArrayConcat, 1, 1) \
93 F(StringToNumber, 1, 1) \
94 F(StringParseInt, 2, 1) \
95 F(StringParseFloat, 1, 1) \
96 F(StringToLowerCase, 1, 1) \
97 F(StringToUpperCase, 1, 1) \
98 F(StringSplit, 3, 1) \
99 F(CharFromCode, 1, 1) \
101 F(URIUnescape, 1, 1) \
103 F(NumberToInteger, 1, 1) \
104 F(NumberToIntegerMapMinusZero, 1, 1) \
105 F(NumberToJSUint32, 1, 1) \
106 F(NumberToJSInt32, 1, 1) \
108 /* Arithmetic operations */ \
114 F(NumberUnaryMinus, 1, 1) \
115 F(NumberImul, 2, 1) \
117 F(StringBuilderConcat, 3, 1) \
118 F(StringBuilderJoin, 3, 1) \
119 F(SparseJoinWithSeparator, 3, 1) \
121 /* Bit operations */ \
131 F(NumberEquals, 2, 1) \
132 F(StringEquals, 2, 1) \
134 F(NumberCompare, 3, 1) \
135 F(SmiLexicographicCompare, 2, 1) \
141 F(MathFloorRT, 1, 1) \
144 F(RoundNumber, 1, 1) \
145 F(MathFround, 1, 1) \
147 /* Regular expressions */ \
148 F(RegExpCompile, 3, 1) \
149 F(RegExpExecMultiple, 4, 1) \
150 F(RegExpInitializeObject, 5, 1) \
154 F(BasicJSONStringify, 1, 1) \
155 F(QuoteJSONString, 1, 1) \
158 F(StringIndexOf, 3, 1) \
159 F(StringLastIndexOf, 3, 1) \
160 F(StringLocaleCompare, 2, 1) \
161 F(StringReplaceGlobalRegExpWithString, 4, 1) \
162 F(StringReplaceOneCharWithString, 3, 1) \
163 F(StringMatch, 3, 1) \
164 F(StringTrim, 3, 1) \
165 F(StringToArray, 2, 1) \
166 F(NewStringWrapper, 1, 1) \
168 F(TruncateString, 2, 1) \
171 F(NumberToRadixString, 2, 1) \
172 F(NumberToFixed, 2, 1) \
173 F(NumberToExponential, 2, 1) \
174 F(NumberToPrecision, 2, 1) \
178 #define RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
180 F(FunctionSetInstanceClassName, 2, 1) \
181 F(FunctionSetLength, 2, 1) \
182 F(FunctionSetPrototype, 2, 1) \
183 F(FunctionGetName, 1, 1) \
184 F(FunctionSetName, 2, 1) \
185 F(FunctionNameShouldPrintAsAnonymous, 1, 1) \
186 F(FunctionMarkNameShouldPrintAsAnonymous, 1, 1) \
187 F(FunctionIsGenerator, 1, 1) \
188 F(FunctionBindArguments, 4, 1) \
189 F(BoundFunctionGetBindings, 1, 1) \
190 F(FunctionRemovePrototype, 1, 1) \
191 F(FunctionGetSourceCode, 1, 1) \
192 F(FunctionGetScript, 1, 1) \
193 F(FunctionGetScriptSourcePosition, 1, 1) \
194 F(FunctionGetPositionForOffset, 2, 1) \
195 F(FunctionIsAPIFunction, 1, 1) \
196 F(FunctionIsBuiltin, 1, 1) \
198 F(CollectStackTrace, 3, 1) \
199 F(GetAndClearOverflowedStackTrace, 1, 1) \
200 F(GetV8Version, 0, 1) \
204 F(CreateApiFunction, 2, 1) \
205 F(IsTemplate, 1, 1) \
206 F(GetTemplateField, 2, 1) \
207 F(DisableAccessChecks, 1, 1) \
208 F(EnableAccessChecks, 1, 1) \
209 F(SetAccessorProperty, 6, 1) \
212 F(DateCurrentTime, 0, 1) \
213 F(DateParseString, 2, 1) \
214 F(DateLocalTimezone, 1, 1) \
216 F(DateMakeDay, 2, 1) \
217 F(DateSetValue, 3, 1) \
218 F(DateCacheVersion, 0, 1) \
221 F(CompileString, 2, 1) \
224 F(GlobalReceiver, 1, 1) \
225 F(IsAttachedGlobal, 1, 1) \
227 F(SetProperty, -1 /* 4 or 5 */, 1) \
228 F(DefineOrRedefineDataProperty, 4, 1) \
229 F(DefineOrRedefineAccessorProperty, 5, 1) \
230 F(IgnoreAttributesAndSetProperty, -1 /* 3 or 4 */, 1) \
231 F(GetDataProperty, 2, 1) \
232 F(SetHiddenProperty, 3, 1) \
235 F(RemoveArrayHoles, 2, 1) \
236 F(GetArrayKeys, 2, 1) \
237 F(MoveArrayContents, 2, 1) \
238 F(EstimateNumberOfElements, 1, 1) \
240 /* Getters and Setters */ \
241 F(LookupAccessor, 3, 1) \
244 F(ObjectFreeze, 1, 1) \
246 /* Harmony modules */ \
247 F(IsJSModule, 1, 1) \
249 /* Harmony symbols */ \
250 F(CreateSymbol, 1, 1) \
251 F(CreatePrivateSymbol, 1, 1) \
252 F(CreateGlobalPrivateSymbol, 1, 1) \
253 F(NewSymbolWrapper, 1, 1) \
254 F(SymbolDescription, 1, 1) \
255 F(SymbolRegistry, 0, 1) \
256 F(SymbolIsPrivate, 1, 1) \
258 /* Harmony proxies */ \
259 F(CreateJSProxy, 2, 1) \
260 F(CreateJSFunctionProxy, 4, 1) \
262 F(IsJSFunctionProxy, 1, 1) \
263 F(GetHandler, 1, 1) \
264 F(GetCallTrap, 1, 1) \
265 F(GetConstructTrap, 1, 1) \
269 F(SetInitialize, 1, 1) \
274 F(SetGetSize, 1, 1) \
276 F(SetIteratorInitialize, 3, 1) \
277 F(SetIteratorNext, 1, 1) \
280 F(MapInitialize, 1, 1) \
286 F(MapGetSize, 1, 1) \
288 F(MapIteratorInitialize, 3, 1) \
289 F(MapIteratorNext, 1, 1) \
291 /* Harmony weak maps and sets */ \
292 F(WeakCollectionInitialize, 1, 1) \
293 F(WeakCollectionGet, 2, 1) \
294 F(WeakCollectionHas, 2, 1) \
295 F(WeakCollectionDelete, 2, 1) \
296 F(WeakCollectionSet, 3, 1) \
298 /* Harmony events */ \
299 F(EnqueueMicrotask, 1, 1) \
300 F(RunMicrotasks, 0, 1) \
302 /* Harmony observe */ \
303 F(IsObserved, 1, 1) \
304 F(SetIsObserved, 1, 1) \
305 F(GetObservationState, 0, 1) \
306 F(ObservationWeakMapCreate, 0, 1) \
307 F(ObserverObjectAndRecordHaveSameOrigin, 3, 1) \
308 F(ObjectWasCreatedInCurrentOrigin, 1, 1) \
309 F(GetObjectContextObjectObserve, 1, 1) \
310 F(GetObjectContextObjectGetNotifier, 1, 1) \
311 F(GetObjectContextNotifierPerformChange, 1, 1) \
313 /* Harmony typed arrays */ \
314 F(ArrayBufferInitialize, 2, 1)\
315 F(ArrayBufferSliceImpl, 3, 1) \
316 F(ArrayBufferIsView, 1, 1) \
317 F(ArrayBufferNeuter, 1, 1) \
319 F(TypedArrayInitializeFromArrayLike, 4, 1) \
320 F(TypedArrayGetBuffer, 1, 1) \
321 F(TypedArraySetFastCases, 3, 1) \
323 F(DataViewGetBuffer, 1, 1) \
324 F(DataViewGetInt8, 3, 1) \
325 F(DataViewGetUint8, 3, 1) \
326 F(DataViewGetInt16, 3, 1) \
327 F(DataViewGetUint16, 3, 1) \
328 F(DataViewGetInt32, 3, 1) \
329 F(DataViewGetUint32, 3, 1) \
330 F(DataViewGetFloat32, 3, 1) \
331 F(DataViewGetFloat64, 3, 1) \
333 F(DataViewSetInt8, 4, 1) \
334 F(DataViewSetUint8, 4, 1) \
335 F(DataViewSetInt16, 4, 1) \
336 F(DataViewSetUint16, 4, 1) \
337 F(DataViewSetInt32, 4, 1) \
338 F(DataViewSetUint32, 4, 1) \
339 F(DataViewSetFloat32, 4, 1) \
340 F(DataViewSetFloat64, 4, 1) \
343 F(NewObjectFromBound, 1, 1) \
345 /* Declarations and initialization */ \
346 F(InitializeVarGlobal, -1 /* 2 or 3 */, 1) \
347 F(OptimizeObjectForAddingMultipleProperties, 2, 1) \
350 F(DebugPrint, 1, 1) \
351 F(GlobalPrint, 1, 1) \
352 F(DebugTrace, 0, 1) \
353 F(TraceEnter, 0, 1) \
360 /* Message objects */ \
361 F(MessageGetStartPosition, 1, 1) \
362 F(MessageGetScript, 1, 1) \
364 /* Pseudo functions - handled as macros by parser */ \
367 /* expose boolean functions from objects-inl.h */ \
368 F(HasFastSmiElements, 1, 1) \
369 F(HasFastSmiOrObjectElements, 1, 1) \
370 F(HasFastObjectElements, 1, 1) \
371 F(HasFastDoubleElements, 1, 1) \
372 F(HasFastHoleyElements, 1, 1) \
373 F(HasDictionaryElements, 1, 1) \
374 F(HasSloppyArgumentsElements, 1, 1) \
375 F(HasExternalUint8ClampedElements, 1, 1) \
376 F(HasExternalArrayElements, 1, 1) \
377 F(HasExternalInt8Elements, 1, 1) \
378 F(HasExternalUint8Elements, 1, 1) \
379 F(HasExternalInt16Elements, 1, 1) \
380 F(HasExternalUint16Elements, 1, 1) \
381 F(HasExternalInt32Elements, 1, 1) \
382 F(HasExternalUint32Elements, 1, 1) \
383 F(HasExternalFloat32Elements, 1, 1) \
384 F(HasExternalFloat64Elements, 1, 1) \
385 F(HasFixedUint8ClampedElements, 1, 1) \
386 F(HasFixedInt8Elements, 1, 1) \
387 F(HasFixedUint8Elements, 1, 1) \
388 F(HasFixedInt16Elements, 1, 1) \
389 F(HasFixedUint16Elements, 1, 1) \
390 F(HasFixedInt32Elements, 1, 1) \
391 F(HasFixedUint32Elements, 1, 1) \
392 F(HasFixedFloat32Elements, 1, 1) \
393 F(HasFixedFloat64Elements, 1, 1) \
394 F(HasFastProperties, 1, 1) \
395 F(TransitionElementsKind, 2, 1) \
396 F(HaveSameMap, 2, 1) \
397 F(IsJSGlobalProxy, 1, 1)
400 #define RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
401 /* Debugger support*/ \
402 F(DebugBreak, 0, 1) \
403 F(SetDebugEventListener, 2, 1) \
405 F(DebugGetPropertyDetails, 2, 1) \
406 F(DebugGetProperty, 2, 1) \
407 F(DebugPropertyTypeFromDetails, 1, 1) \
408 F(DebugPropertyAttributesFromDetails, 1, 1) \
409 F(DebugPropertyIndexFromDetails, 1, 1) \
410 F(DebugNamedInterceptorPropertyValue, 2, 1) \
411 F(DebugIndexedInterceptorElementValue, 2, 1) \
412 F(CheckExecutionState, 1, 1) \
413 F(GetFrameCount, 1, 1) \
414 F(GetFrameDetails, 2, 1) \
415 F(GetScopeCount, 2, 1) \
416 F(GetStepInPositions, 2, 1) \
417 F(GetScopeDetails, 4, 1) \
418 F(GetAllScopesDetails, 4, 1) \
419 F(GetFunctionScopeCount, 1, 1) \
420 F(GetFunctionScopeDetails, 2, 1) \
421 F(SetScopeVariableValue, 6, 1) \
422 F(DebugPrintScopes, 0, 1) \
423 F(GetThreadCount, 1, 1) \
424 F(GetThreadDetails, 2, 1) \
425 F(SetDisableBreak, 1, 1) \
426 F(GetBreakLocations, 2, 1) \
427 F(SetFunctionBreakPoint, 3, 1) \
428 F(SetScriptBreakPoint, 4, 1) \
429 F(ClearBreakPoint, 1, 1) \
430 F(ChangeBreakOnException, 2, 1) \
431 F(IsBreakOnException, 1, 1) \
432 F(PrepareStep, 4, 1) \
433 F(ClearStepping, 0, 1) \
434 F(DebugEvaluate, 6, 1) \
435 F(DebugEvaluateGlobal, 4, 1) \
436 F(DebugGetLoadedScripts, 0, 1) \
437 F(DebugReferencedBy, 3, 1) \
438 F(DebugConstructedBy, 2, 1) \
439 F(DebugGetPrototype, 1, 1) \
440 F(DebugSetScriptSource, 2, 1) \
441 F(SystemBreak, 0, 1) \
442 F(DebugDisassembleFunction, 1, 1) \
443 F(DebugDisassembleConstructor, 1, 1) \
444 F(FunctionGetInferredName, 1, 1) \
445 F(LiveEditFindSharedFunctionInfosForScript, 1, 1) \
446 F(LiveEditGatherCompileInfo, 2, 1) \
447 F(LiveEditReplaceScript, 3, 1) \
448 F(LiveEditReplaceFunctionCode, 2, 1) \
449 F(LiveEditFunctionSourceUpdated, 1, 1) \
450 F(LiveEditFunctionSetScript, 2, 1) \
451 F(LiveEditReplaceRefToNestedFunction, 3, 1) \
452 F(LiveEditPatchFunctionPositions, 2, 1) \
453 F(LiveEditCheckAndDropActivations, 2, 1) \
454 F(LiveEditCompareStrings, 2, 1) \
455 F(LiveEditRestartFrame, 2, 1) \
456 F(GetFunctionCodePositionFromSource, 2, 1) \
457 F(ExecuteInDebugContext, 2, 1) \
460 F(CollectGarbage, 1, 1) \
461 F(GetHeapUsage, 0, 1) \
464 #ifdef V8_I18N_SUPPORT
465 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F) \
467 /* Standalone, helper methods. */ \
468 F(CanonicalizeLanguageTag, 1, 1) \
469 F(AvailableLocalesOf, 1, 1) \
470 F(GetDefaultICULocale, 0, 1) \
471 F(GetLanguageTagVariants, 1, 1) \
472 F(IsInitializedIntlObject, 1, 1) \
473 F(IsInitializedIntlObjectOfType, 2, 1) \
474 F(MarkAsInitializedIntlObjectOfType, 3, 1) \
475 F(GetImplFromInitializedIntlObject, 1, 1) \
477 /* Date format and parse. */ \
478 F(CreateDateTimeFormat, 3, 1) \
479 F(InternalDateFormat, 2, 1) \
480 F(InternalDateParse, 2, 1) \
482 /* Number format and parse. */ \
483 F(CreateNumberFormat, 3, 1) \
484 F(InternalNumberFormat, 2, 1) \
485 F(InternalNumberParse, 2, 1) \
488 F(CreateCollator, 3, 1) \
489 F(InternalCompare, 3, 1) \
491 /* String.prototype.normalize. */ \
492 F(StringNormalize, 2, 1) \
494 /* Break iterator. */ \
495 F(CreateBreakIterator, 3, 1) \
496 F(BreakIteratorAdoptText, 2, 1) \
497 F(BreakIteratorFirst, 1, 1) \
498 F(BreakIteratorNext, 1, 1) \
499 F(BreakIteratorCurrent, 1, 1) \
500 F(BreakIteratorBreakType, 1, 1) \
503 #define RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
508 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \
512 #define RUNTIME_FUNCTION_LIST_DEBUG(F)
515 // ----------------------------------------------------------------------------
516 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed
517 // either directly by id (via the code generator), or indirectly
518 // via a native call by name (from within JS code).
519 // Entries have the form F(name, number of arguments, number of return values).
521 #define RUNTIME_FUNCTION_LIST(F) \
522 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \
523 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \
524 RUNTIME_FUNCTION_LIST_DEBUG(F) \
525 RUNTIME_FUNCTION_LIST_DEBUGGER(F) \
526 RUNTIME_FUNCTION_LIST_I18N_SUPPORT(F)
528 // RUNTIME_HIDDEN_FUNCTION_LIST defines all runtime functions accessed
529 // by id from code generator, but not via native call by name.
530 // Entries have the form F(name, number of arguments, number of return values).
531 #define RUNTIME_HIDDEN_FUNCTION_LIST(F) \
532 /* String and Regexp */ \
533 F(NumberToString, 1, 1) \
534 F(RegExpConstructResult, 3, 1) \
535 F(RegExpExec, 4, 1) \
538 F(StringCompare, 2, 1) \
539 F(StringCharCodeAt, 2, 1) \
540 F(GetFromCache, 2, 1) \
543 F(CompileUnoptimized, 1, 1) \
544 F(CompileOptimized, 2, 1) \
545 F(TryInstallOptimizedCode, 1, 1) \
546 F(NotifyDeoptimized, 1, 1) \
547 F(NotifyStubFailure, 0, 1) \
550 F(AllocateInNewSpace, 1, 1) \
551 F(AllocateInTargetSpace, 2, 1) \
552 F(AllocateHeapNumber, 0, 1) \
553 F(NumberToSmi, 1, 1) \
554 F(NumberToStringSkipCache, 1, 1) \
556 F(NewSloppyArguments, 3, 1) \
557 F(NewStrictArguments, 3, 1) \
559 /* Harmony generators */ \
560 F(CreateJSGeneratorObject, 0, 1) \
561 F(SuspendJSGeneratorObject, 1, 1) \
562 F(ResumeJSGeneratorObject, 3, 1) \
563 F(ThrowGeneratorStateError, 1, 1) \
566 F(ArrayConstructor, -1, 1) \
567 F(InternalArrayConstructor, -1, 1) \
570 F(MaterializeRegExpLiteral, 4, 1)\
571 F(CreateObjectLiteral, 4, 1) \
572 F(CreateArrayLiteral, 4, 1) \
573 F(CreateArrayLiteralStubBailout, 3, 1) \
576 F(NewClosure, 3, 1) \
577 F(NewClosureFromStubFailure, 1, 1) \
579 F(NewObjectWithAllocationSite, 2, 1) \
580 F(FinalizeInstanceSize, 1, 1) \
583 F(ThrowReferenceError, 1, 1) \
584 F(ThrowNotDateError, 0, 1) \
585 F(StackGuard, 0, 1) \
587 F(PromoteScheduledException, 0, 1) \
590 F(NewGlobalContext, 2, 1) \
591 F(NewFunctionContext, 1, 1) \
592 F(PushWithContext, 2, 1) \
593 F(PushCatchContext, 3, 1) \
594 F(PushBlockContext, 2, 1) \
595 F(PushModuleContext, 2, 1) \
596 F(DeleteContextSlot, 2, 1) \
597 F(LoadContextSlot, 2, 2) \
598 F(LoadContextSlotNoReferenceError, 2, 2) \
599 F(StoreContextSlot, 4, 1) \
601 /* Declarations and initialization */ \
602 F(DeclareGlobals, 3, 1) \
603 F(DeclareModules, 1, 1) \
604 F(DeclareContextSlot, 4, 1) \
605 F(InitializeConstGlobal, 2, 1) \
606 F(InitializeConstContextSlot, 3, 1) \
609 F(ResolvePossiblyDirectEval, 5, 2) \
612 F(MathPowSlow, 2, 1) \
615 // ----------------------------------------------------------------------------
616 // INLINE_FUNCTION_LIST defines all inlined functions accessed
617 // with a native call of the form %_name from within JS code.
618 // Entries have the form F(name, number of arguments, number of return values).
619 #define INLINE_FUNCTION_LIST(F) \
621 F(IsNonNegativeSmi, 1, 1) \
624 F(IsConstructCall, 0, 1) \
625 F(CallFunction, -1 /* receiver + n args + function */, 1) \
626 F(ArgumentsLength, 0, 1) \
629 F(SetValueOf, 2, 1) \
630 F(DateField, 2 /* date object, field index */, 1) \
631 F(StringCharFromCode, 1, 1) \
632 F(StringCharAt, 2, 1) \
633 F(OneByteSeqStringSetChar, 3, 1) \
634 F(TwoByteSeqStringSetChar, 3, 1) \
635 F(ObjectEquals, 2, 1) \
637 F(IsFunction, 1, 1) \
638 F(IsUndetectableObject, 1, 1) \
639 F(IsSpecObject, 1, 1) \
640 F(IsStringWrapperSafeForDefaultValueOf, 1, 1) \
642 F(IsMinusZero, 1, 1) \
643 F(HasCachedArrayIndex, 1, 1) \
644 F(GetCachedArrayIndex, 1, 1) \
645 F(FastAsciiArrayJoin, 2, 1) \
646 F(GeneratorNext, 2, 1) \
647 F(GeneratorThrow, 2, 1) \
648 F(DebugBreakInOptimizedCode, 0, 1) \
650 F(StringCharCodeAt, 2, 1) \
653 F(StringCompare, 2, 1) \
654 F(RegExpExec, 4, 1) \
655 F(RegExpConstructResult, 3, 1) \
656 F(GetFromCache, 2, 1) \
657 F(NumberToString, 1, 1)
660 // ----------------------------------------------------------------------------
661 // INLINE_OPTIMIZED_FUNCTION_LIST defines all inlined functions accessed
662 // with a native call of the form %_name from within JS code that also have
663 // a corresponding runtime function, that is called from non-optimized code.
664 // For the benefit of (fuzz) tests, the runtime version can also be called
665 // directly as %name (i.e. without the leading underscore).
666 // Entries have the form F(name, number of arguments, number of return values).
667 #define INLINE_OPTIMIZED_FUNCTION_LIST(F) \
669 F(TypedArrayInitialize, 5, 1) \
670 F(DataViewInitialize, 4, 1) \
672 F(TypedArrayMaxSizeInHeap, 0, 1) \
673 F(ArrayBufferViewGetByteLength, 1, 1) \
674 F(ArrayBufferViewGetByteOffset, 1, 1) \
675 F(TypedArrayGetLength, 1, 1) \
677 F(ArrayBufferGetByteLength, 1, 1) \
679 F(ConstructDouble, 2, 1) \
682 F(MathSqrtRT, 1, 1) \
685 F(DebugCallbackSupportsStepping, 1, 1)
688 //---------------------------------------------------------------------------
689 // Runtime provides access to all C++ runtime functions.
693 StaticResource<ConsStringIteratorOp>* string_iterator() {
694 return &string_iterator_;
696 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() {
697 return &to_upper_mapping_;
699 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() {
700 return &to_lower_mapping_;
702 ConsStringIteratorOp* string_iterator_compare_x() {
703 return &string_iterator_compare_x_;
705 ConsStringIteratorOp* string_iterator_compare_y() {
706 return &string_iterator_compare_y_;
708 ConsStringIteratorOp* string_locale_compare_it1() {
709 return &string_locale_compare_it1_;
711 ConsStringIteratorOp* string_locale_compare_it2() {
712 return &string_locale_compare_it2_;
717 // Non-reentrant string buffer for efficient general use in the runtime.
718 StaticResource<ConsStringIteratorOp> string_iterator_;
719 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_;
720 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_;
721 ConsStringIteratorOp string_iterator_compare_x_;
722 ConsStringIteratorOp string_iterator_compare_y_;
723 ConsStringIteratorOp string_locale_compare_it1_;
724 ConsStringIteratorOp string_locale_compare_it2_;
726 friend class Isolate;
727 friend class Runtime;
729 DISALLOW_COPY_AND_ASSIGN(RuntimeState);
733 class Runtime : public AllStatic {
736 #define F(name, nargs, ressize) k##name,
737 RUNTIME_FUNCTION_LIST(F)
738 INLINE_OPTIMIZED_FUNCTION_LIST(F)
740 #define F(name, nargs, ressize) kHidden##name,
741 RUNTIME_HIDDEN_FUNCTION_LIST(F)
743 #define F(name, nargs, ressize) kInline##name,
744 INLINE_FUNCTION_LIST(F)
746 #define F(name, nargs, ressize) kInlineOptimized##name,
747 INLINE_OPTIMIZED_FUNCTION_LIST(F)
750 kFirstInlineFunction = kInlineIsSmi
760 // Intrinsic function descriptor.
762 FunctionId function_id;
763 IntrinsicType intrinsic_type;
764 // The JS name of the function.
767 // The C++ (native) entry point. NULL if the function is inlined.
770 // The number of arguments expected. nargs is -1 if the function takes
771 // a variable number of arguments.
773 // Size of result. Most functions return a single pointer, size 1.
777 static const int kNotFound = -1;
779 // Add internalized strings for all the intrinsic function names to a
781 static void InitializeIntrinsicFunctionNames(Isolate* isolate,
782 Handle<NameDictionary> dict);
784 // Get the intrinsic function with the given name, which must be internalized.
785 static const Function* FunctionForName(Handle<String> name);
787 // Get the intrinsic function with the given FunctionId.
788 static const Function* FunctionForId(FunctionId id);
790 // General-purpose helper functions for runtime system.
791 static int StringMatch(Isolate* isolate,
796 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch);
798 // TODO(1240886): Some of the following methods are *not* handle safe, but
799 // accept handle arguments. This seems fragile.
801 // Support getting the characters in a string using [] notation as
802 // in Firefox/SpiderMonkey, Safari and Opera.
803 MUST_USE_RESULT static MaybeHandle<Object> GetElementOrCharAt(
805 Handle<Object> object,
808 MUST_USE_RESULT static MaybeHandle<Object> SetObjectProperty(
810 Handle<Object> object,
812 Handle<Object> value,
813 PropertyAttributes attr,
814 StrictMode strict_mode);
816 MUST_USE_RESULT static MaybeHandle<Object> ForceSetObjectProperty(
817 Handle<JSObject> object,
819 Handle<Object> value,
820 PropertyAttributes attr,
821 JSReceiver::StoreFromKeyed store_from_keyed
822 = JSReceiver::MAY_BE_STORE_FROM_KEYED);
824 MUST_USE_RESULT static MaybeHandle<Object> DeleteObjectProperty(
826 Handle<JSReceiver> object,
828 JSReceiver::DeleteMode mode);
830 MUST_USE_RESULT static MaybeHandle<Object> HasObjectProperty(
832 Handle<JSReceiver> object,
835 MUST_USE_RESULT static MaybeHandle<Object> GetObjectProperty(
837 Handle<Object> object,
840 static void SetupArrayBuffer(Isolate* isolate,
841 Handle<JSArrayBuffer> array_buffer,
844 size_t allocated_length);
846 static bool SetupArrayBufferAllocatingData(
848 Handle<JSArrayBuffer> array_buffer,
849 size_t allocated_length,
850 bool initialize = true);
852 static void NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer);
854 static void FreeArrayBuffer(
856 JSArrayBuffer* phantom_array_buffer);
859 // arrayIds below should be synchromized with typedarray.js natives.
866 ARRAY_ID_FLOAT32 = 7,
867 ARRAY_ID_FLOAT64 = 8,
868 ARRAY_ID_UINT8_CLAMPED = 9,
870 ARRAY_ID_FIRST = ARRAY_ID_UINT8,
871 ARRAY_ID_LAST = ARRAY_ID_UINT8_CLAMPED
874 static void ArrayIdToTypeAndSize(int array_id,
875 ExternalArrayType *type,
876 ElementsKind* external_elements_kind,
877 ElementsKind* fixed_elements_kind,
878 size_t *element_size);
880 // Used in runtime.cc and hydrogen's VisitArrayLiteral.
881 MUST_USE_RESULT static MaybeHandle<Object> CreateArrayLiteralBoilerplate(
883 Handle<FixedArray> literals,
884 Handle<FixedArray> elements);
888 //---------------------------------------------------------------------------
889 // Constants used by interface to runtime functions.
891 class AllocateDoubleAlignFlag: public BitField<bool, 0, 1> {};
892 class AllocateTargetSpace: public BitField<AllocationSpace, 1, 3> {};
894 class DeclareGlobalsEvalFlag: public BitField<bool, 0, 1> {};
895 class DeclareGlobalsNativeFlag: public BitField<bool, 1, 1> {};
896 class DeclareGlobalsStrictMode: public BitField<StrictMode, 2, 1> {};
898 } } // namespace v8::internal
900 #endif // V8_RUNTIME_H_