v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
runtime-internal.cc
Go to the documentation of this file.
1// Copyright 2014 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.
4
5#include <memory>
6
7#include "src/api/api-inl.h"
8#include "src/api/api.h"
20#include "src/utils/ostreams.h"
21
22namespace v8 {
23namespace internal {
24
25RUNTIME_FUNCTION(Runtime_AccessCheck) {
26 HandleScope scope(isolate);
27 DCHECK_EQ(1, args.length());
28 DirectHandle<JSObject> object = args.at<JSObject>(0);
29 if (!isolate->MayAccess(isolate->native_context(), object)) {
31 isolate->ReportFailedAccessCheck(object));
33 }
34 return ReadOnlyRoots(isolate).undefined_value();
35}
36
37RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInAllocateRaw) {
38 HandleScope scope(isolate);
39 DCHECK_EQ(0, args.length());
40 isolate->heap()->FatalProcessOutOfMemory("CodeStubAssembler::AllocateRaw");
42}
43
44RUNTIME_FUNCTION(Runtime_FatalProcessOutOfMemoryInvalidArrayLength) {
45 HandleScope scope(isolate);
46 DCHECK_EQ(0, args.length());
47 isolate->heap()->FatalProcessOutOfMemory("invalid array length");
49}
50
51RUNTIME_FUNCTION(Runtime_FatalInvalidSize) {
52 HandleScope scope(isolate);
53 DCHECK_EQ(0, args.length());
54 FATAL("Invalid size");
56}
57
58RUNTIME_FUNCTION(Runtime_Throw) {
59 HandleScope scope(isolate);
60 DCHECK_EQ(1, args.length());
61 return isolate->Throw(args[0]);
62}
63
64RUNTIME_FUNCTION(Runtime_ReThrow) {
65 HandleScope scope(isolate);
66 DCHECK_EQ(1, args.length());
67 return isolate->ReThrow(args[0]);
68}
69
70RUNTIME_FUNCTION(Runtime_ReThrowWithMessage) {
71 HandleScope scope(isolate);
72 DCHECK_EQ(2, args.length());
73 return isolate->ReThrow(args[0], args[1]);
74}
75
76RUNTIME_FUNCTION(Runtime_ThrowStackOverflow) {
77 SealHandleScope shs(isolate);
78 DCHECK_LE(0, args.length());
79 return isolate->StackOverflow();
80}
81
82RUNTIME_FUNCTION(Runtime_ThrowSymbolAsyncIteratorInvalid) {
83 HandleScope scope(isolate);
84 DCHECK_EQ(0, args.length());
86 isolate, NewTypeError(MessageTemplate::kSymbolAsyncIteratorInvalid));
87}
88
89RUNTIME_FUNCTION(Runtime_TerminateExecution) {
90 HandleScope scope(isolate);
91 DCHECK_EQ(0, args.length());
92 return isolate->TerminateExecution();
93}
94
95namespace {
96
98 Handle<JSFunction> (Isolate::*constructor_fn)()) {
99 HandleScope scope(isolate);
100 DCHECK_LE(1, args.length());
101 int message_id_smi = args.smi_value_at(0);
102
103 constexpr int kMaxMessageArgs = 3;
104 DirectHandle<Object> message_args[kMaxMessageArgs];
105 int num_message_args = 0;
106 while (num_message_args < kMaxMessageArgs &&
107 args.length() > num_message_args + 1) {
108 message_args[num_message_args] = args.at(num_message_args + 1);
109 ++num_message_args;
110 }
111
112 MessageTemplate message_id = MessageTemplateFromInt(message_id_smi);
113
114 return *isolate->factory()->NewError(
115 (isolate->*constructor_fn)(), message_id,
116 base::VectorOf(message_args, num_message_args));
117}
118
119Tagged<Object> ThrowError(Isolate* isolate, RuntimeArguments args,
120 Handle<JSFunction> (Isolate::*constructor_fn)()) {
121 return isolate->Throw(NewError(isolate, args, constructor_fn));
122}
123
124} // namespace
125
126RUNTIME_FUNCTION(Runtime_ThrowRangeError) {
127 if (v8_flags.correctness_fuzzer_suppressions) {
128 DCHECK_LE(1, args.length());
129 int message_id_smi = args.smi_value_at(0);
130
131 // If the result of a BigInt computation is truncated to 64 bit, Turbofan
132 // can sometimes truncate intermediate results already, which can prevent
133 // those from exceeding the maximum length, effectively preventing a
134 // RangeError from being thrown. As this is a performance optimization, this
135 // behavior is accepted. To prevent the correctness fuzzer from detecting
136 // this difference, we crash the program.
137 if (MessageTemplateFromInt(message_id_smi) ==
138 MessageTemplate::kBigIntTooBig) {
139 FATAL("Aborting on invalid BigInt length");
140 }
141 }
142
143 return ThrowError(isolate, args, &Isolate::range_error_function);
144}
145
146RUNTIME_FUNCTION(Runtime_ThrowTypeError) {
147 return ThrowError(isolate, args, &Isolate::type_error_function);
148}
149
150RUNTIME_FUNCTION(Runtime_ThrowTypeErrorIfStrict) {
151 if (GetShouldThrow(isolate, Nothing<ShouldThrow>()) ==
153 return ReadOnlyRoots(isolate).undefined_value();
154 }
155 return ThrowError(isolate, args, &Isolate::type_error_function);
156}
157
158namespace {
159
160const char* ElementsKindToType(ElementsKind fixed_elements_kind) {
161 switch (fixed_elements_kind) {
162#define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype) \
163 case TYPE##_ELEMENTS: \
164 return #Type "Array";
165
168#undef ELEMENTS_KIND_CASE
169
170 default:
171 UNREACHABLE();
172 }
173}
174
175} // namespace
176
177RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
178 HandleScope scope(isolate);
179 DCHECK_EQ(2, args.length());
180 DirectHandle<Map> map = args.at<Map>(0);
181 Handle<String> problem_string = args.at<String>(1);
182
183 ElementsKind kind = map->elements_kind();
184
185 Handle<String> type =
186 isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
187
188 ExternalArrayType external_type;
189 size_t size;
190 Factory::TypeAndSizeForElementsKind(kind, &external_type, &size);
191 Handle<Object> element_size =
192 handle(Smi::FromInt(static_cast<int>(size)), isolate);
193
195 isolate, NewRangeError(MessageTemplate::kInvalidTypedArrayAlignment,
196 problem_string, type, element_size));
197}
198
199RUNTIME_FUNCTION(Runtime_UnwindAndFindExceptionHandler) {
200 SealHandleScope shs(isolate);
201 DCHECK_EQ(0, args.length());
202 return isolate->UnwindAndFindHandler();
203}
204
205RUNTIME_FUNCTION(Runtime_PropagateException) {
206 SealHandleScope shs(isolate);
207 DCHECK_EQ(0, args.length());
208 DCHECK(isolate->has_exception());
209 return ReadOnlyRoots(isolate).exception();
210}
211
212RUNTIME_FUNCTION(Runtime_ThrowReferenceError) {
213 HandleScope scope(isolate);
214 DCHECK_EQ(1, args.length());
215 Handle<Object> name = args.at(0);
217 isolate, NewReferenceError(MessageTemplate::kNotDefined, name));
218}
219
220RUNTIME_FUNCTION(Runtime_ThrowAccessedUninitializedVariable) {
221 HandleScope scope(isolate);
222 DCHECK_EQ(1, args.length());
223 Handle<Object> name = args.at(0);
225 isolate,
226 NewReferenceError(MessageTemplate::kAccessedUninitializedVariable, name));
227}
228
229RUNTIME_FUNCTION(Runtime_NewError) {
230 HandleScope scope(isolate);
231 DCHECK_EQ(2, args.length());
232 int template_index = args.smi_value_at(0);
233 Handle<Object> arg0 = args.at(1);
234 MessageTemplate message_template = MessageTemplateFromInt(template_index);
235 return *isolate->factory()->NewError(message_template, arg0);
236}
237
238RUNTIME_FUNCTION(Runtime_NewTypeError) {
239 return NewError(isolate, args, &Isolate::type_error_function);
240}
241
242RUNTIME_FUNCTION(Runtime_NewReferenceError) {
243 HandleScope scope(isolate);
244 DCHECK_EQ(2, args.length());
245 int template_index = args.smi_value_at(0);
246 Handle<Object> arg0 = args.at(1);
247 MessageTemplate message_template = MessageTemplateFromInt(template_index);
248 return *isolate->factory()->NewReferenceError(message_template, arg0);
249}
250
251RUNTIME_FUNCTION(Runtime_ThrowInvalidStringLength) {
252 HandleScope scope(isolate);
253 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewInvalidStringLengthError());
254}
255
256RUNTIME_FUNCTION(Runtime_ThrowIteratorResultNotAnObject) {
257 HandleScope scope(isolate);
258 DCHECK_EQ(1, args.length());
259 Handle<Object> value = args.at(0);
261 isolate,
262 NewTypeError(MessageTemplate::kIteratorResultNotAnObject, value));
263}
264
265RUNTIME_FUNCTION(Runtime_ThrowThrowMethodMissing) {
266 HandleScope scope(isolate);
267 DCHECK_EQ(0, args.length());
269 isolate, NewTypeError(MessageTemplate::kThrowMethodMissing));
270}
271
272RUNTIME_FUNCTION(Runtime_ThrowSymbolIteratorInvalid) {
273 HandleScope scope(isolate);
274 DCHECK_EQ(0, args.length());
276 isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
277}
278
279RUNTIME_FUNCTION(Runtime_ThrowNoAccess) {
280 HandleScope scope(isolate);
281 DCHECK_EQ(0, args.length());
282
283 // TODO(verwaest): We would like to throw using the calling context instead
284 // of the entered context but we don't currently have access to that.
285 HandleScopeImplementer* impl = isolate->handle_scope_implementer();
286 SaveAndSwitchContext save(isolate,
287 impl->LastEnteredContext()->native_context());
289 NewTypeError(MessageTemplate::kNoAccess));
290}
291
292RUNTIME_FUNCTION(Runtime_ThrowNotConstructor) {
293 HandleScope scope(isolate);
294 DCHECK_EQ(1, args.length());
295 Handle<Object> object = args.at(0);
297 isolate, NewTypeError(MessageTemplate::kNotConstructor, object));
298}
299
300RUNTIME_FUNCTION(Runtime_ThrowApplyNonFunction) {
301 HandleScope scope(isolate);
302 DCHECK_EQ(1, args.length());
303 Handle<Object> object = args.at(0);
304 Handle<String> type = Object::TypeOf(isolate, object);
305 Handle<String> msg;
306 if (IsNull(*object)) {
307 // "which is null"
308 msg = isolate->factory()->NewStringFromAsciiChecked("null");
309 } else if (isolate->factory()->object_string()->Equals(*type)) {
310 // "which is an object"
311 msg = isolate->factory()->NewStringFromAsciiChecked("an object");
312 } else {
313 // "which is a typeof arg"
314 msg = isolate->factory()
315 ->NewConsString(
316 isolate->factory()->NewStringFromAsciiChecked("a "), type)
317 .ToHandleChecked();
318 }
320 isolate, NewTypeError(MessageTemplate::kApplyNonFunction, object, msg));
321}
322
323RUNTIME_FUNCTION(Runtime_StackGuard) {
324 SealHandleScope shs(isolate);
325 DCHECK_EQ(0, args.length());
326 TRACE_EVENT0("v8.execute", "V8.StackGuard");
327
328 // First check if this is a real stack overflow.
329 StackLimitCheck check(isolate);
330 if (check.JsHasOverflowed()) {
331 return isolate->StackOverflow();
332 }
333
334 return isolate->stack_guard()->HandleInterrupts(
336}
337
338RUNTIME_FUNCTION(Runtime_HandleNoHeapWritesInterrupts) {
339 SealHandleScope shs(isolate);
340 DCHECK_EQ(0, args.length());
341 TRACE_EVENT0("v8.execute", "V8.StackGuard");
342
343 // First check if this is a real stack overflow.
344 StackLimitCheck check(isolate);
345 if (check.JsHasOverflowed()) {
346 return isolate->StackOverflow();
347 }
348
349 return isolate->stack_guard()->HandleInterrupts(
351}
352
353RUNTIME_FUNCTION(Runtime_StackGuardWithGap) {
354 SealHandleScope shs(isolate);
355 DCHECK_EQ(args.length(), 1);
356 uint32_t gap = args.positive_smi_value_at(0);
357 TRACE_EVENT0("v8.execute", "V8.StackGuard");
358
359 // First check if this is a real stack overflow.
360 StackLimitCheck check(isolate);
361 if (check.JsHasOverflowed(gap)) {
362 return isolate->StackOverflow();
363 }
364
365 return isolate->stack_guard()->HandleInterrupts(
367}
368
369namespace {
370
371Tagged<Object> BytecodeBudgetInterruptWithStackCheck(Isolate* isolate,
373 CodeKind code_kind) {
374 HandleScope scope(isolate);
375 DCHECK_EQ(1, args.length());
376 DirectHandle<JSFunction> function = args.at<JSFunction>(0);
377 TRACE_EVENT0("v8.execute", "V8.BytecodeBudgetInterruptWithStackCheck");
378
379 // Check for stack interrupts here so that we can fold the interrupt check
380 // into bytecode budget interrupts.
381 StackLimitCheck check(isolate);
382 if (check.JsHasOverflowed()) {
383 // We ideally wouldn't actually get StackOverflows here, since we stack
384 // check on bytecode entry, but it's possible that this check fires due to
385 // the runtime function call being what overflows the stack.
386 return isolate->StackOverflow();
387 } else if (check.InterruptRequested()) {
388 Tagged<Object> return_value = isolate->stack_guard()->HandleInterrupts();
389 if (!IsUndefined(return_value, isolate)) {
390 return return_value;
391 }
392 }
393
394 isolate->tiering_manager()->OnInterruptTick(function, code_kind);
395 return ReadOnlyRoots(isolate).undefined_value();
396}
397
398Tagged<Object> BytecodeBudgetInterrupt(Isolate* isolate, RuntimeArguments& args,
399 CodeKind code_kind) {
400 HandleScope scope(isolate);
401 DCHECK_EQ(1, args.length());
402 DirectHandle<JSFunction> function = args.at<JSFunction>(0);
403 function->TraceOptimizationStatus("budget from %s",
404 CodeKindToString(code_kind));
405 TRACE_EVENT0("v8.execute", "V8.BytecodeBudgetInterrupt");
406
407 isolate->tiering_manager()->OnInterruptTick(function, code_kind);
408 return ReadOnlyRoots(isolate).undefined_value();
409}
410
411} // namespace
412
413RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptWithStackCheck_Ignition) {
414 return BytecodeBudgetInterruptWithStackCheck(isolate, args,
415 CodeKind::INTERPRETED_FUNCTION);
416}
417
418RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterrupt_Ignition) {
419 return BytecodeBudgetInterrupt(isolate, args, CodeKind::INTERPRETED_FUNCTION);
420}
421
422RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptWithStackCheck_Sparkplug) {
423 return BytecodeBudgetInterruptWithStackCheck(isolate, args,
424 CodeKind::BASELINE);
425}
426
427RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterrupt_Sparkplug) {
428 return BytecodeBudgetInterrupt(isolate, args, CodeKind::BASELINE);
429}
430
431RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterrupt_Maglev) {
432 return BytecodeBudgetInterrupt(isolate, args, CodeKind::MAGLEV);
433}
434
435RUNTIME_FUNCTION(Runtime_BytecodeBudgetInterruptWithStackCheck_Maglev) {
436 return BytecodeBudgetInterruptWithStackCheck(isolate, args, CodeKind::MAGLEV);
437}
438
439RUNTIME_FUNCTION(Runtime_AllocateInYoungGeneration) {
440 HandleScope scope(isolate);
441 DCHECK(isolate->IsOnCentralStack());
442 DCHECK_EQ(2, args.length());
443 // TODO(v8:13070): Align allocations in the builtins that call this.
444 int size = ALIGN_TO_ALLOCATION_ALIGNMENT(args.smi_value_at(0));
445 int flags = args.smi_value_at(1);
446 AllocationAlignment alignment =
449 CHECK_GT(size, 0);
450
451 // When this is called from WasmGC code, clear the "thread in wasm" flag,
452 // which is important in case any GC needs to happen.
453 // TODO(40192807): Find a better fix, likely by replacing the global flag.
454 SaveAndClearThreadInWasmFlag clear_wasm_flag(isolate);
455
456 // TODO(v8:9472): Until double-aligned allocation is fixed for new-space
457 // allocations, don't request it.
458 alignment = kTaggedAligned;
459
460 return *isolate->factory()->NewFillerObject(size, alignment,
463}
464
465RUNTIME_FUNCTION(Runtime_AllocateInOldGeneration) {
466 HandleScope scope(isolate);
467 DCHECK_EQ(2, args.length());
468 // TODO(v8:13070): Align allocations in the builtins that call this.
469 int size = ALIGN_TO_ALLOCATION_ALIGNMENT(args.smi_value_at(0));
470 int flags = args.smi_value_at(1);
471
472 // When this is called from WasmGC code, clear the "thread in wasm" flag,
473 // which is important in case any GC needs to happen.
474 // TODO(40192807): Find a better fix, likely by replacing the global flag.
475 SaveAndClearThreadInWasmFlag clear_wasm_flag(isolate);
476
477 AllocationAlignment alignment =
480 CHECK_GT(size, 0);
481 return *isolate->factory()->NewFillerObject(
483}
484
485RUNTIME_FUNCTION(Runtime_AllocateByteArray) {
486 HandleScope scope(isolate);
487 DCHECK_EQ(1, args.length());
488 int length = args.smi_value_at(0);
489 DCHECK_LT(0, length);
490 return *isolate->factory()->NewByteArray(length);
491}
492
493RUNTIME_FUNCTION(Runtime_ThrowIteratorError) {
494 HandleScope scope(isolate);
495 DCHECK_EQ(1, args.length());
496 DirectHandle<Object> object = args.at(0);
497 return isolate->Throw(*ErrorUtils::NewIteratorError(isolate, object));
498}
499
500RUNTIME_FUNCTION(Runtime_ThrowSpreadArgError) {
501 HandleScope scope(isolate);
502 DCHECK_EQ(2, args.length());
503 int message_id_smi = args.smi_value_at(0);
504 MessageTemplate message_id = MessageTemplateFromInt(message_id_smi);
505 DirectHandle<Object> object = args.at(1);
506 return ErrorUtils::ThrowSpreadArgError(isolate, message_id, object);
507}
508
509RUNTIME_FUNCTION(Runtime_ThrowCalledNonCallable) {
510 HandleScope scope(isolate);
511 DCHECK_EQ(1, args.length());
512 DirectHandle<Object> object = args.at(0);
513 return isolate->Throw(
514 *ErrorUtils::NewCalledNonCallableError(isolate, object));
515}
516
517RUNTIME_FUNCTION(Runtime_ThrowConstructedNonConstructable) {
518 HandleScope scope(isolate);
519 DCHECK_EQ(1, args.length());
520 DirectHandle<Object> object = args.at(0);
521 return isolate->Throw(
523}
524
525RUNTIME_FUNCTION(Runtime_ThrowPatternAssignmentNonCoercible) {
526 HandleScope scope(isolate);
527 DCHECK_EQ(1, args.length());
528 DirectHandle<Object> object = args.at(0);
529 return ErrorUtils::ThrowLoadFromNullOrUndefined(isolate, object,
531}
532
533RUNTIME_FUNCTION(Runtime_ThrowConstructorReturnedNonObject) {
534 HandleScope scope(isolate);
535 DCHECK_EQ(0, args.length());
536
538 isolate,
539 NewTypeError(MessageTemplate::kDerivedConstructorReturnedNonObject));
540}
541
542// ES6 section 7.3.17 CreateListFromArrayLike (obj)
543RUNTIME_FUNCTION(Runtime_CreateListFromArrayLike) {
544 HandleScope scope(isolate);
545 DCHECK_EQ(1, args.length());
546 DirectHandle<Object> object = args.at(0);
548 isolate, object, ElementTypes::kAll));
549}
550
551RUNTIME_FUNCTION(Runtime_IncrementUseCounter) {
552 HandleScope scope(isolate);
553 DCHECK_EQ(1, args.length());
554 int counter = args.smi_value_at(0);
555 isolate->CountUsage(static_cast<v8::Isolate::UseCounterFeature>(counter));
556 return ReadOnlyRoots(isolate).undefined_value();
557}
558
559RUNTIME_FUNCTION(Runtime_GetAndResetTurboProfilingData) {
560 HandleScope scope(isolate);
561 DCHECK_LE(args.length(), 2);
562 if (!BasicBlockProfiler::Get()->HasData(isolate)) {
564 isolate,
565 NewTypeError(
566 MessageTemplate::kInvalid,
567 isolate->factory()->NewStringFromAsciiChecked("Runtime Call"),
568 isolate->factory()->NewStringFromAsciiChecked(
569 "V8 was not built with v8_enable_builtins_profiling=true")));
570 }
571
572 std::stringstream stats_stream;
573 BasicBlockProfiler::Get()->Log(isolate, stats_stream);
575 isolate->factory()->NewStringFromAsciiChecked(stats_stream.str().c_str());
577 return *result;
578}
579
580RUNTIME_FUNCTION(Runtime_GetAndResetRuntimeCallStats) {
581 HandleScope scope(isolate);
582 DCHECK_LE(args.length(), 2);
583#ifdef V8_RUNTIME_CALL_STATS
584 if (!v8_flags.runtime_call_stats) {
586 isolate, NewTypeError(MessageTemplate::kInvalid,
587 isolate->factory()->NewStringFromAsciiChecked(
588 "Runtime Call"),
589 isolate->factory()->NewStringFromAsciiChecked(
590 "--runtime-call-stats is not set")));
591 }
592 // Append any worker thread runtime call stats to the main table before
593 // printing.
594 isolate->counters()->worker_thread_runtime_call_stats()->AddToMainTable(
595 isolate->counters()->runtime_call_stats());
596
597 if (args.length() == 0) {
598 // Without arguments, the result is returned as a string.
599 std::stringstream stats_stream;
600 isolate->counters()->runtime_call_stats()->Print(stats_stream);
601 DirectHandle<String> result = isolate->factory()->NewStringFromAsciiChecked(
602 stats_stream.str().c_str());
603 isolate->counters()->runtime_call_stats()->Reset();
604 return *result;
605 }
606
607 std::FILE* f;
608 if (IsString(args[0])) {
609 // With a string argument, the results are appended to that file.
611 f = std::fopen(filename->ToCString().get(), "a");
613 } else {
614 // With an integer argument, the results are written to stdout/stderr.
615 int fd = args.smi_value_at(0);
616 DCHECK(fd == 1 || fd == 2);
617 f = fd == 1 ? stdout : stderr;
618 }
619 // The second argument (if any) is a message header to be printed.
620 if (args.length() >= 2) {
621 DirectHandle<String> message = args.at<String>(1);
622 message->PrintOn(f);
623 std::fputc('\n', f);
624 std::fflush(f);
625 }
626 OFStream stats_stream(f);
627 isolate->counters()->runtime_call_stats()->Print(stats_stream);
628 isolate->counters()->runtime_call_stats()->Reset();
629 if (IsString(args[0])) {
630 std::fclose(f);
631 } else {
632 std::fflush(f);
633 }
634 return ReadOnlyRoots(isolate).undefined_value();
635#else // V8_RUNTIME_CALL_STATS
637 isolate, NewTypeError(MessageTemplate::kInvalid,
638 isolate->factory()->NewStringFromAsciiChecked(
639 "Runtime Call"),
640 isolate->factory()->NewStringFromAsciiChecked(
641 "RCS was disabled at compile-time")));
642#endif // V8_RUNTIME_CALL_STATS
643}
644
645RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
646 HandleScope scope(isolate);
647 DCHECK_EQ(2, args.length());
648 DirectHandle<JSAny> callable = args.at<JSAny>(0);
649 DirectHandle<JSAny> object = args.at<JSAny>(1);
651 isolate, Object::OrdinaryHasInstance(isolate, callable, object));
652}
653
654RUNTIME_FUNCTION(Runtime_Typeof) {
655 HandleScope scope(isolate);
656 DCHECK_EQ(1, args.length());
657 DirectHandle<Object> object = args.at(0);
658 return *Object::TypeOf(isolate, object);
659}
660
661RUNTIME_FUNCTION(Runtime_AllowDynamicFunction) {
662 HandleScope scope(isolate);
663 DCHECK_EQ(1, args.length());
665 DirectHandle<JSObject> global_proxy(target->global_proxy(), isolate);
666 return *isolate->factory()->ToBoolean(
667 Builtins::AllowDynamicFunction(isolate, target, global_proxy));
668}
669
670RUNTIME_FUNCTION(Runtime_CreateAsyncFromSyncIterator) {
671 HandleScope scope(isolate);
672 DCHECK_EQ(1, args.length());
673
674 DirectHandle<JSAny> sync_iterator_any = args.at<JSAny>(0);
675 DirectHandle<JSReceiver> sync_iterator;
676 if (!TryCast<JSReceiver>(sync_iterator_any, &sync_iterator)) {
678 isolate, NewTypeError(MessageTemplate::kSymbolIteratorInvalid));
679 }
680
683 isolate, next,
684 Object::GetProperty(isolate, sync_iterator,
685 isolate->factory()->next_string()));
686
687 return *isolate->factory()->NewJSAsyncFromSyncIterator(sync_iterator, next);
688}
689
690RUNTIME_FUNCTION(Runtime_GetTemplateObject) {
691 HandleScope scope(isolate);
692 DCHECK_EQ(3, args.length());
696 int slot_id = args.smi_value_at(2);
697
699 isolate->context()->native_context(), isolate);
701 isolate, native_context, description, shared_info, slot_id);
702}
703
704RUNTIME_FUNCTION(Runtime_ReportMessageFromMicrotask) {
705 // Helper to report messages and continue JS execution. This is intended to
706 // behave similarly to reporting exceptions which reach the top-level, but
707 // allow the JS code to continue.
708 HandleScope scope(isolate);
709 DCHECK_EQ(1, args.length());
710
711 DirectHandle<Object> exception = args.at(0);
712
713 DCHECK(!isolate->has_exception());
714 isolate->set_exception(*exception);
715 MessageLocation* no_location = nullptr;
717 isolate->CreateMessageOrAbort(exception, no_location);
718 MessageHandler::ReportMessage(isolate, no_location, message);
719 isolate->clear_exception();
720 return ReadOnlyRoots(isolate).undefined_value();
721}
722
723RUNTIME_FUNCTION(Runtime_GetInitializerFunction) {
724 HandleScope scope(isolate);
725 DCHECK_EQ(1, args.length());
726
727 DirectHandle<JSReceiver> constructor = args.at<JSReceiver>(0);
728 DirectHandle<Symbol> key = isolate->factory()->class_fields_symbol();
729 DirectHandle<Object> initializer =
730 JSReceiver::GetDataProperty(isolate, constructor, key);
731 return *initializer;
732}
733
734RUNTIME_FUNCTION(Runtime_DoubleToStringWithRadix) {
735 HandleScope scope(isolate);
736 DCHECK_EQ(2, args.length());
737 double number = args.number_value_at(0);
738 int32_t radix = 0;
739 CHECK(Object::ToInt32(args[1], &radix));
740
741 char chars[kDoubleToRadixMaxChars];
743 std::string_view str = DoubleToRadixStringView(number, radix, buffer);
745 isolate->factory()->NewStringFromAsciiChecked(str);
746 return *result;
747}
748
749RUNTIME_FUNCTION(Runtime_SharedValueBarrierSlow) {
750 HandleScope scope(isolate);
751 DCHECK_EQ(1, args.length());
752 Handle<HeapObject> value = args.at<HeapObject>(0);
753 DirectHandle<Object> shared_value;
755 isolate, shared_value, Object::ShareSlow(isolate, value, kThrowOnError));
756 return *shared_value;
757}
758
759RUNTIME_FUNCTION(Runtime_InvalidateDependentCodeForScriptContextSlot) {
760 HandleScope scope(isolate);
761 DCHECK_EQ(1, args.length());
762 auto const_tracking_let_cell =
765 isolate, *const_tracking_let_cell,
767 return ReadOnlyRoots(isolate).undefined_value();
768}
769
770} // namespace internal
771} // namespace v8
Builtins::Kind kind
Definition builtins.cc:40
static constexpr T decode(U value)
Definition bit-field.h:66
static V8_EXPORT_PRIVATE BasicBlockProfiler * Get()
V8_EXPORT_PRIVATE void Log(Isolate *isolate, std::ostream &os)
V8_EXPORT_PRIVATE void ResetCounts(Isolate *isolate)
static bool AllowDynamicFunction(Isolate *isolate, DirectHandle< JSFunction > target, DirectHandle< JSObject > target_global_proxy)
Definition builtins.cc:534
static void DeoptimizeDependencyGroups(Isolate *isolate, ObjectT object, DependencyGroups groups)
static Tagged< Object > ThrowLoadFromNullOrUndefined(Isolate *isolate, DirectHandle< Object > object, MaybeDirectHandle< Object > key)
Definition messages.cc:1006
static DirectHandle< JSObject > NewCalledNonCallableError(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:985
static DirectHandle< JSObject > NewIteratorError(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:929
static Tagged< Object > ThrowSpreadArgError(Isolate *isolate, MessageTemplate id, DirectHandle< Object > object)
Definition messages.cc:947
static DirectHandle< JSObject > NewConstructedNonConstructable(Isolate *isolate, DirectHandle< Object > source)
Definition messages.cc:996
static void TypeAndSizeForElementsKind(ElementsKind kind, ExternalArrayType *array_type, size_t *element_size)
Definition factory.cc:3610
static Handle< Object > GetDataProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static V8_EXPORT_PRIVATE void ReportMessage(Isolate *isolate, const MessageLocation *loc, DirectHandle< JSMessageObject > message)
Definition messages.cc:98
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > OrdinaryHasInstance(Isolate *isolate, DirectHandle< JSAny > callable, DirectHandle< JSAny > object)
Definition objects.cc:1045
static Handle< String > TypeOf(Isolate *isolate, DirectHandle< Object > object)
Definition objects.cc:1001
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< FixedArray > CreateListFromArrayLike(Isolate *isolate, DirectHandle< Object > object, ElementTypes element_types)
Definition objects.cc:1176
static V8_EXPORT_PRIVATE bool ToInt32(Tagged< Object > obj, int32_t *value)
Definition objects.cc:1438
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it, bool is_global_reference=false)
Definition objects.cc:1248
static HandleType< Object >::MaybeType ShareSlow(Isolate *isolate, HandleType< HeapObject > value, ShouldThrow throw_if_cannot_be_shared)
Definition objects.cc:2765
static constexpr Tagged< Smi > FromInt(int value)
Definition smi.h:38
V8_EXPORT_PRIVATE void PrintOn(FILE *out)
Definition string.cc:1910
static DirectHandle< JSArray > GetTemplateObject(Isolate *isolate, DirectHandle< NativeContext > native_context, DirectHandle< TemplateObjectDescription > description, DirectHandle< SharedFunctionInfo > shared_info, int slot_id)
#define ALIGN_TO_ALLOCATION_ALIGNMENT(value)
Definition globals.h:1796
#define TYPED_ARRAYS(V)
#define RAB_GSAB_TYPED_ARRAYS_WITH_TYPED_ARRAY_TYPE(V)
#define RUNTIME_FUNCTION(Name)
Definition arguments.h:162
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
Definition isolate.h:284
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
Definition isolate.h:294
#define RETURN_FAILURE_ON_EXCEPTION(isolate, call)
Definition isolate.h:368
#define RETURN_RESULT_OR_FAILURE(isolate, call)
Definition isolate.h:264
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
std::string filename
ZoneVector< RpoNumber > & result
constexpr Vector< T > ArrayVector(T(&arr)[N])
Definition vector.h:354
constexpr Vector< T > VectorOf(T *start, size_t size)
Definition vector.h:360
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
MessageTemplate MessageTemplateFromInt(int message_id)
bool TryCast(Tagged< From > value, Tagged< To > *out)
Definition casting.h:77
constexpr int kTaggedSize
Definition globals.h:542
const char * CodeKindToString(CodeKind kind)
Definition code-kind.cc:10
ShouldThrow GetShouldThrow(Isolate *isolate, Maybe< ShouldThrow > should_throw)
Definition objects.cc:140
constexpr int kDoubleToRadixMaxChars
Definition conversions.h:86
V8_EXPORT_PRIVATE FlagValues v8_flags
std::string_view DoubleToRadixStringView(double value, int radix, base::Vector< char > buffer)
Arguments< ArgumentsType::kRuntime > RuntimeArguments
Definition globals.h:1047
kInstanceDescriptorsOffset kTransitionsOrPrototypeInfoOffset IsNull(value)||IsJSProxy(value)||IsWasmObject(value)||(IsJSObject(value) &&(HeapLayout
Definition map-inl.h:70
!IsContextMap !IsContextMap native_context
Definition map-inl.h:877
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Definition casting.h:150
Local< T > Handle
Maybe< T > Nothing()
Definition v8-maybe.h:112
#define ELEMENTS_KIND_CASE(Type, type, TYPE, ctype)
#define FATAL(...)
Definition logging.h:47
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define CHECK(condition)
Definition logging.h:124
#define CHECK_GT(lhs, rhs)
#define DCHECK_NOT_NULL(val)
Definition logging.h:492
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_LT(v1, v2)
Definition logging.h:489
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
constexpr bool IsAligned(T value, U alignment)
Definition macros.h:403
#define TRACE_EVENT0(category_group, name)