14#if V8_ENABLE_WEBASSEMBLY
25DirectHandle<Object> NormalizeReceiver(Isolate* isolate,
38 static InvokeParams SetUpForNew(
39 Isolate* isolate, DirectHandle<Object> constructor,
40 DirectHandle<Object> new_target,
41 base::Vector<
const DirectHandle<Object>> args);
43 static InvokeParams SetUpForCall(
44 Isolate* isolate, DirectHandle<Object> callable,
45 DirectHandle<Object> receiver,
46 base::Vector<
const DirectHandle<Object>> args);
48 static InvokeParams SetUpForTryCall(
49 Isolate* isolate, DirectHandle<Object> callable,
50 DirectHandle<Object> receiver,
51 base::Vector<
const DirectHandle<Object>> args,
53 MaybeDirectHandle<Object>* exception_out);
55 static InvokeParams SetUpForRunMicrotasks(Isolate* isolate,
56 MicrotaskQueue* microtask_queue);
58 bool IsScript()
const {
59 if (!IsJSFunction(*target))
return false;
61 return function->shared()->is_script();
64 DirectHandle<FixedArray> GetAndResetHostDefinedOptions() {
72 DirectHandle<Object> target;
74 base::Vector<const DirectHandle<Object>> args;
87InvokeParams InvokeParams::SetUpForNew(
88 Isolate* isolate, DirectHandle<Object> constructor,
90 base::Vector<
const DirectHandle<Object>>
args) {
92 params.target = constructor;
93 params.receiver = isolate->factory()->undefined_value();
94 DCHECK(!params.IsScript());
97 params.microtask_queue =
nullptr;
98 params.message_handling = Execution::MessageHandling::kReport;
99 params.exception_out =
nullptr;
100 params.is_construct =
true;
101 params.execution_target = Execution::Target::kCallable;
106InvokeParams InvokeParams::SetUpForCall(
107 Isolate* isolate, DirectHandle<Object> callable,
109 base::Vector<
const DirectHandle<Object>>
args) {
111 params.target = callable;
112 params.receiver = NormalizeReceiver(isolate,
receiver);
117 params.new_target = isolate->factory()->undefined_value();
118 params.microtask_queue =
nullptr;
119 params.message_handling = Execution::MessageHandling::kReport;
120 params.exception_out =
nullptr;
121 params.is_construct =
false;
122 params.execution_target = Execution::Target::kCallable;
127InvokeParams InvokeParams::SetUpForTryCall(
128 Isolate* isolate, DirectHandle<Object> callable,
130 base::Vector<
const DirectHandle<Object>>
args,
134 params.target = callable;
135 params.receiver = NormalizeReceiver(isolate,
receiver);
140 params.new_target = isolate->factory()->undefined_value();
141 params.microtask_queue =
nullptr;
144 params.is_construct =
false;
145 params.execution_target = Execution::Target::kCallable;
150InvokeParams InvokeParams::SetUpForRunMicrotasks(
152 auto undefined = isolate->factory()->undefined_value();
154 params.target = undefined;
155 params.receiver = undefined;
157 params.new_target = undefined;
159 params.message_handling = Execution::MessageHandling::kReport;
160 params.exception_out =
nullptr;
161 params.is_construct =
false;
162 params.execution_target = Execution::Target::kRunMicrotasks;
181MaybeDirectHandle<Context> NewScriptContext(
182 Isolate* isolate, DirectHandle<JSFunction> function,
183 DirectHandle<FixedArray> host_defined_options) {
187 if (isolate->should_check_side_effects()) {
188 isolate->Throw(*isolate->factory()->NewEvalError(
189 MessageTemplate::kNoSideEffectDebugEvaluate));
190 return MaybeDirectHandle<Context>();
192 SaveAndSwitchContext save(isolate, function->context());
195 DirectHandle<ScopeInfo> scope_info(sfi->scope_info(), isolate);
198 DirectHandle<JSGlobalObject> global_object(
native_context->global_object(),
205 Handle<String>
name(name_it->name(), isolate);
206 VariableMode mode = scope_info->ContextLocalMode(name_it->index());
207 VariableLookupResult lookup;
208 if (script_context->Lookup(name, &lookup)) {
210 DirectHandle<Context>
context(script_context->get(lookup.context_index),
216 scope_info->IsReplModeScope() &&
217 context->scope_info()->IsReplModeScope())) {
221 MessageLocation location(script, 0, 1);
222 isolate->ThrowAt(isolate->factory()->NewSyntaxError(
223 MessageTemplate::kVarRedeclaration, name),
225 return MaybeDirectHandle<Context>();
231 LookupIterator lookup_it(isolate, global_object, name, global_object,
233 Maybe<PropertyAttributes> maybe =
237 CHECK(!maybe.IsNothing());
244 MessageLocation location(script, 0, 1);
245 isolate->ThrowAt(isolate->factory()->NewSyntaxError(
246 MessageTemplate::kVarRedeclaration, name),
248 return MaybeDirectHandle<Context>();
255 DirectHandle<Context>
result =
258 result->Initialize(isolate);
261 const bool ignore_duplicates = scope_info->IsReplModeScope();
262 DirectHandle<ScriptContextTable> new_script_context_table =
266 *new_script_context_table);
271 const InvokeParams& params) {
272 RCS_SCOPE(isolate, RuntimeCallCounterId::kInvoke);
273 DCHECK(!IsJSGlobalObject(*params.receiver));
275 DCHECK(!isolate->has_exception());
280#if V8_ENABLE_WEBASSEMBLY
292 StackLimitCheck check(isolate);
293 if (check.HasOverflowed()) {
294 isolate->StackOverflow();
295 isolate->ReportPendingMessages(params.message_handling ==
297 return MaybeHandle<Object>();
303 if (IsJSFunction(*params.target)) {
305 if ((!params.is_construct || IsConstructor(*function)) &&
306 function->shared()->IsApiFunction() &&
307 !function->shared()->BreakAtEntry(isolate)) {
308 SaveAndSwitchContext save(isolate, function->context());
309 DCHECK(IsJSGlobalObject(function->context()->global_object()));
311 DirectHandle<Object>
receiver = params.is_construct
312 ? isolate->factory()->the_hole_value()
314 DirectHandle<FunctionTemplateInfo> fun_data(
315 function->shared()->api_func_data(), isolate);
317 isolate, params.is_construct, fun_data,
receiver, params.args,
319 bool has_exception = value.is_null();
320 DCHECK_EQ(has_exception, isolate->has_exception());
322 isolate->ReportPendingMessages(params.message_handling ==
324 return MaybeHandle<Object>();
326 isolate->clear_pending_message();
331 if (function->shared()->is_script()) {
332 DCHECK(params.IsScript());
333 DCHECK(IsJSGlobalProxy(*params.receiver));
335 DCHECK(IsFixedArray(*params.args[0]));
337 DCHECK(!params.IsScript());
341 if (function->shared()->needs_script_context()) {
343 DirectHandle<FixedArray> host_defined_options =
344 const_cast<InvokeParams&
>(params).GetAndResetHostDefinedOptions();
345 if (!NewScriptContext(isolate, function, host_defined_options)
346 .ToHandle(&context)) {
347 isolate->ReportPendingMessages(params.message_handling ==
349 return MaybeHandle<Object>();
355 function->set_context(*context);
360 VMState<JS>
state(isolate);
361 if (!AllowJavascriptExecution::IsAllowed(isolate)) {
364 if (!ThrowOnJavascriptExecution::IsAllowed(isolate)) {
365 isolate->ThrowIllegalOperation();
366 isolate->ReportPendingMessages(params.message_handling ==
368 return MaybeHandle<Object>();
370 if (!DumpOnJavascriptExecution::IsAllowed(isolate)) {
372 return isolate->factory()->undefined_value();
374 isolate->IncrementJavascriptExecutionCounter();
377 DirectHandle<NativeContext> context = isolate->native_context();
378 if (!IsUndefined(context->script_execution_callback(), isolate)) {
382 isolate, context->script_execution_callback());
386 DCHECK(!isolate->has_exception());
388 isolate->ThrowIllegalOperation();
389 return MaybeHandle<Object>();
395 DirectHandle<Code> code =
396 JSEntry(isolate, params.execution_target, params.is_construct);
399 SaveContext save(isolate);
401 if (
v8_flags.clear_exceptions_on_js_entry) isolate->clear_exception();
407 using JSEntryFunction = GeneratedCode<
Address(
411 JSEntryFunction stub_entry =
412 JSEntryFunction::FromAddress(isolate, code->instruction_start());
414 Address orig_func = (*params.new_target).ptr();
415 Address func = (*params.target).ptr();
416 Address recv = (*params.receiver).ptr();
418 int argc =
static_cast<int>(params.args.size());
419#ifdef V8_ENABLE_DIRECT_HANDLE
425 HandleScope scope_for_conversion(isolate);
426 std::vector<IndirectHandle<Object>>
args(argc);
427 for (
int i = 0;
i < argc; ++
i)
432 reinterpret_cast<Address* const*
>(params.args.data()));
436 SealHandleScope shs(isolate);
438 RCS_SCOPE(isolate, RuntimeCallCounterId::kJS_Execution);
440 stub_entry.Call(isolate->isolate_data()->isolate_root(), orig_func,
448 using JSEntryFunction = GeneratedCode<
Address(
451 JSEntryFunction stub_entry =
452 JSEntryFunction::FromAddress(isolate, code->instruction_start());
455 SealHandleScope shs(isolate);
457 RCS_SCOPE(isolate, RuntimeCallCounterId::kJS_Execution);
459 isolate->isolate_data()->isolate_root(), params.microtask_queue));
465 Object::ObjectVerify(value, isolate);
470 bool has_exception = IsException(value, isolate);
471 DCHECK_EQ(has_exception, isolate->has_exception());
473 isolate->ReportPendingMessages(params.message_handling ==
475 return MaybeHandle<Object>();
477 isolate->clear_pending_message();
480 return Handle<Object>(value, isolate);
483MaybeDirectHandle<Object> InvokeWithTryCatch(Isolate* isolate,
484 const InvokeParams& params) {
486 !isolate->is_execution_terminating());
487 MaybeDirectHandle<Object> maybe_result;
488 if (params.exception_out !=
nullptr) {
489 *params.exception_out = {};
497 catcher.SetVerbose(
false);
498 catcher.SetCaptureMessage(
false);
500 maybe_result = Invoke(isolate, params);
502 if (
V8_LIKELY(!maybe_result.is_null())) {
503 DCHECK(!isolate->has_exception());
507 DCHECK(isolate->has_exception());
508 if (isolate->is_execution_terminating()) {
512 if (params.exception_out !=
nullptr) {
513 DCHECK(catcher.HasCaught());
530 return Invoke(isolate,
531 InvokeParams::SetUpForCall(isolate, callable,
receiver,
args));
538 DCHECK(script_function->shared()->is_script());
540 return Invoke(isolate,
541 InvokeParams::SetUpForCall(isolate, script_function,
receiver,
542 {&host_defined_options, 1}));
549 DCHECK(builtin->code(isolate)->is_builtin());
551 return Invoke(isolate,
552 InvokeParams::SetUpForCall(isolate, builtin,
receiver,
args));
559 return New(isolate, constructor, constructor,
args);
569 InvokeParams::SetUpForNew(isolate, constructor,
new_target,
args)));
577 DCHECK(script_function->shared()->is_script());
580 return InvokeWithTryCatch(
581 isolate, InvokeParams::SetUpForTryCall(
582 isolate, script_function,
receiver, {&argument, 1},
583 MessageHandling::kKeepPending,
nullptr));
596 return InvokeWithTryCatch(
597 isolate, InvokeParams::SetUpForTryCall(isolate, callable,
receiver,
args,
604 return InvokeWithTryCatch(
605 isolate, InvokeParams::SetUpForRunMicrotasks(isolate,
microtask_queue));
618#if V8_ENABLE_WEBASSEMBLY
624 WasmEntryStub stub_entry =
625 WasmEntryStub::FromAddress(isolate, wrapper_code->instruction_start());
632 Address saved_c_entry_fp = *isolate->c_entry_fp_address();
633 Address saved_js_entry_sp = *isolate->js_entry_sp_address();
637 StackHandlerMarker stack_handler;
638 stack_handler.next = isolate->thread_local_top()->handler_;
639#ifdef V8_USE_ADDRESS_SANITIZER
642 stack_handler.padding = 0;
644 isolate->thread_local_top()->handler_ =
645 reinterpret_cast<Address>(&stack_handler);
649 RCS_SCOPE(isolate, RuntimeCallCounterId::kJS_Execution);
655 stub_entry.Call(wasm_call_target.
value(), (*object_ref).ptr(),
656 packed_args, saved_c_entry_fp);
665 isolate->thread_local_top()->handler_ = stack_handler.next;
667 *isolate->js_entry_sp_address() = saved_js_entry_sp;
669 *isolate->c_entry_fp_address() = saved_c_entry_fp;
#define BUILTIN_CODE(isolate, name)
void(*)(Isolate *isolate, Local< Context > context) AbortScriptExecutionCallback
static Isolate * TryGetCurrent()
static v8::internal::DirectHandle< To > OpenDirectHandle(v8::Local< From > handle)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > InvokeApiFunction(Isolate *isolate, bool is_construct, DirectHandle< FunctionTemplateInfo > function, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args, DirectHandle< HeapObject > new_target)
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > TryCallScript(Isolate *isolate, DirectHandle< JSFunction > script_function, DirectHandle< Object > receiver, DirectHandle< FixedArray > host_defined_options)
static V8_EXPORT_PRIVATE MaybeDirectHandle< Object > TryCall(Isolate *isolate, DirectHandle< Object > callable, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args, MessageHandling message_handling, MaybeDirectHandle< Object > *exception_out)
static MaybeDirectHandle< Object > TryRunMicrotasks(Isolate *isolate, MicrotaskQueue *microtask_queue)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > CallScript(Isolate *isolate, DirectHandle< JSFunction > callable, DirectHandle< Object > receiver, DirectHandle< Object > host_defined_options)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > Call(Isolate *isolate, DirectHandle< Object > callable, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
static V8_WARN_UNUSED_RESULT MaybeHandle< Object > CallBuiltin(Isolate *isolate, DirectHandle< JSFunction > builtin, DirectHandle< Object > receiver, base::Vector< const DirectHandle< Object > > args)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< JSReceiver > New(Isolate *isolate, DirectHandle< Object > constructor, base::Vector< const DirectHandle< Object > > args)
static constexpr int kMaxLength
static void InvalidatePropertyCell(DirectHandle< JSGlobalObject > object, DirectHandle< Name > name)
static V8_WARN_UNUSED_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
static LocalNamesRange< DirectHandle< ScopeInfo > > IterateLocalNames(DirectHandle< ScopeInfo > scope_info)
V8_WARN_UNUSED_RESULT static V8_EXPORT_PRIVATE Handle< ScriptContextTable > Add(Isolate *isolate, Handle< ScriptContextTable > table, DirectHandle< Context > script_context, bool ignore_duplicates)
static const int kPaddingOffset
static const int kNextOffset
static V8_EXPORT_PRIVATE v8::Platform * GetCurrentPlatform()
MicrotaskQueue * microtask_queue
base::Vector< const DirectHandle< Object > > args
DirectHandle< Object > new_target
MaybeDirectHandle< Object > * exception_out
Execution::Target execution_target
Execution::MessageHandling message_handling
DirectHandle< JSReceiver > options
ZoneVector< RpoNumber > & result
LiftoffAssembler::CacheState state
V8_BASE_EXPORT int const char va_list args
TH_DISABLE_ASAN bool IsThreadInWasm()
WasmCodeManager * GetWasmCodeManager()
bool IsLexicalVariableMode(VariableMode mode)
Tagged(T object) -> Tagged< T >
V8_INLINE IndirectHandle< T > indirect_handle(DirectHandle< T > handle)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in name
uintptr_t GetCurrentStackPosition()
@ kApiAbortScriptExecutionCallbackTag
V8_EXPORT_PRIVATE FlagValues v8_flags
constexpr int JSParameterCount(int param_count_without_receiver)
static constexpr Address kNullAddress
kInterpreterTrampolineOffset script
!IsContextMap !IsContextMap native_context
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
T ToCData(i::Isolate *isolate, v8::internal::Tagged< v8::internal::Object > obj)
#define GRACEFUL_FATAL(...)
#define DCHECK_LE(v1, v2)
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)
#define V8_LIKELY(condition)
#define V8_WARN_UNUSED_RESULT