34 NewTypeError(MessageTemplate::kConstAssign));
40 NewTypeError(MessageTemplate::kUsingAssign));
45enum class RedeclarationType { kSyntaxError = 0, kTypeError = 1 };
47Tagged<Object> ThrowRedeclarationError(Isolate* isolate, Handle<String> name,
48 RedeclarationType redeclaration_type) {
49 HandleScope scope(isolate);
50 if (redeclaration_type == RedeclarationType::kSyntaxError) {
52 isolate, NewSyntaxError(MessageTemplate::kVarRedeclaration, name));
55 isolate, NewTypeError(MessageTemplate::kVarRedeclaration, name));
61 DirectHandle<JSGlobalObject> global,
62 Handle<String> name, Handle<Object> value,
64 RedeclarationType redeclaration_type) {
65 DirectHandle<ScriptContextTable> script_contexts(
66 global->native_context()->script_context_table(), isolate);
67 VariableLookupResult lookup;
68 if (script_contexts->Lookup(name, &lookup) &&
73 return ThrowRedeclarationError(isolate, name,
74 RedeclarationType::kSyntaxError);
85 LookupIterator it(isolate, global, name, global, lookup_config);
87 if (maybe.IsNothing())
return ReadOnlyRoots(isolate).exception();
94 if (is_var)
return ReadOnlyRoots(isolate).undefined_value();
109 return ThrowRedeclarationError(isolate, name, redeclaration_type);
112 attr = old_attributes;
124 if (!is_var) it.Restart();
130 return ReadOnlyRoots(isolate).undefined_value();
143 closure->has_feedback_vector()
144 ? closure->feedback_vector()->closure_feedback_cell_array()
145 : closure->closure_feedback_cell_array(),
149 DCHECK(context->IsModuleContext());
153 int length = declarations->length();
164 int feedback_index =
Smi::ToInt(declarations->get(++
i));
167 closure_feedback_cell_array->get(feedback_index), isolate);
173 Cast<Cell>(exports->get(index - 1))->set_value(value);
190 closure->has_feedback_vector()
191 ? closure->feedback_vector()->closure_feedback_cell_array()
192 : closure->closure_feedback_cell_array(),
196 int length = declarations->length();
201 bool is_var = IsString(*decl);
205 value = isolate->factory()->undefined_value();
208 name =
handle(sfi->Name(), isolate);
211 closure_feedback_cell_array->get(index), isolate);
228 DeclareGlobal(isolate, global, name, value, attr, is_var,
229 RedeclarationType::kSyntaxError);
241 isolate->factory()->NewJSDisposableStackBase();
244 return *disposable_stack;
249 DirectHandle<JSDisposableStackBase> stack,
250 DirectHandle<JSAny> value,
253 DirectHandle<Object>
method;
277 MAYBE_RETURN(AddToDisposableStack(isolate, stack, value,
299 ? isolate->factory()->undefined_value()
322 *continuation_token ==
325 disposable_stack->set_error(*continuation_error);
326 disposable_stack->set_error_message(*continuation_message);
340 isolate, disposable_stack,
355 if (!isolate->is_catchable_by_javascript(*exception)) {
356 return isolate->Throw(*exception);
361 return *disposable_stack;
377 const bool is_debug_evaluate_in_module =
378 isolate->context()->IsDebugEvaluateContext() &&
379 context->IsModuleContext();
381 DCHECK(context->IsFunctionContext() || IsNativeContext(*context) ||
382 context->IsScriptContext() || context->IsEvalContext() ||
383 (context->IsBlockContext() &&
384 context->scope_info()->is_declaration_scope()) ||
385 is_debug_evaluate_in_module);
387 bool is_var = IsUndefined(*value, isolate);
395 DirectHandle<Object> holder =
398 DCHECK(holder.is_null() || !IsSourceTextModule(*holder));
399 DCHECK(!isolate->has_exception());
401 DirectHandle<JSObject> object;
403 if (attributes !=
ABSENT && IsJSGlobalObject(*holder)) {
407 NONE, is_var, RedeclarationType::kTypeError);
409 if (context->has_extension() && IsJSGlobalObject(context->extension())) {
410 DirectHandle<JSGlobalObject> global(
412 return DeclareGlobal(isolate, global, name, value,
NONE, is_var,
413 RedeclarationType::kTypeError);
414 }
else if (context->IsScriptContext()) {
415 DCHECK(IsJSGlobalObject(context->global_object()));
416 DirectHandle<JSGlobalObject> global(
418 return DeclareGlobal(isolate, global, name, value,
NONE, is_var,
419 RedeclarationType::kTypeError);
422 if (attributes !=
ABSENT) {
426 if (is_var)
return ReadOnlyRoots(isolate).undefined_value();
429 DCHECK(holder.is_identical_to(context));
430 context->set(index, *value);
431 return ReadOnlyRoots(isolate).undefined_value();
436 }
else if (context->has_extension() && !is_debug_evaluate_in_module) {
437 object =
direct_handle(context->extension_object(), isolate);
438 DCHECK(IsJSContextExtensionObject(*
object));
439 }
else if (context->scope_info()->HasContextExtensionSlot() &&
440 !is_debug_evaluate_in_module) {
444 DCHECK((context->IsBlockContext() &&
445 context->scope_info()->is_declaration_scope()) ||
446 context->IsFunctionContext());
447 DCHECK(context->scope_info()->SloppyEvalCanExtendVars());
449 isolate->factory()->NewJSObject(isolate->context_extension_function());
450 context->set_extension(*
object);
453 if (!scope_info->SomeContextHasExtension()) {
454 scope_info->mark_some_context_has_extension();
462 NewEvalError(MessageTemplate::kVarNotAllowedInEvalScope, name));
466 object, name, value,
NONE));
468 return ReadOnlyRoots(isolate).undefined_value();
478 return DeclareEvalHelper(isolate, name, value);
485 return DeclareEvalHelper(isolate, name,
486 isolate->factory()->undefined_value());
493DirectHandleVector<Object> GetCallerArguments(
Isolate* isolate) {
495 JavaScriptStackFrameIterator it(isolate);
496 JavaScriptFrame* frame = it.frame();
497 std::vector<Tagged<SharedFunctionInfo>> functions;
498 frame->GetFunctions(&functions);
499 if (functions.size() > 1) {
500 int inlined_jsframe_index =
static_cast<int>(functions.size()) - 1;
501 TranslatedState translated_values(frame);
502 translated_values.Prepare(frame->fp());
504 int argument_count = 0;
505 TranslatedFrame* translated_frame =
506 translated_values.GetArgumentsInfoFromJSFrameIndex(
507 inlined_jsframe_index, &argument_count);
508 TranslatedFrame::iterator iter = translated_frame->begin();
517 DirectHandleVector<Object> param_data(isolate, argument_count);
518 bool should_deoptimize =
false;
519 for (
int i = 0;
i < argument_count;
i++) {
522 should_deoptimize = should_deoptimize || iter->IsMaterializedObject();
523 DirectHandle<Object> value = iter->GetValue();
528 if (should_deoptimize) {
529 translated_values.StoreMaterializedValuesAndDeopt(frame);
534 int args_count = frame->GetActualArgumentCount();
535 DirectHandleVector<Object> param_data(isolate, args_count);
536 for (
int i = 0;
i < args_count;
i++) {
537 DirectHandle<Object> val =
538 DirectHandle<Object>(frame->GetParameter(
i), isolate);
546DirectHandle<JSObject> NewSloppyArguments(Isolate* isolate,
547 DirectHandle<JSFunction> callee,
548 T parameters,
int argument_count) {
550 DCHECK(callee->shared()->has_simple_parameters());
551 DirectHandle<JSObject>
result =
552 isolate->factory()->NewArgumentsObject(callee, argument_count);
556 callee->shared()->internal_formal_parameter_count_without_receiver();
557 if (argument_count > 0) {
563 DirectHandle<Context>
context(isolate->context(), isolate);
564 DirectHandle<FixedArray> arguments = isolate->factory()->NewFixedArray(
567 DirectHandle<SloppyArgumentsElements> parameter_map =
568 isolate->factory()->NewSloppyArgumentsElements(
572 isolate->native_context()->fast_aliased_arguments_map());
573 result->set_elements(*parameter_map);
576 int index = argument_count - 1;
577 while (index >= mapped_count) {
580 arguments->set(index, parameters[index]);
584 DirectHandle<ScopeInfo> scope_info(callee->shared()->scope_info(),
589 for (
int i = 0;
i < mapped_count;
i++) {
590 arguments->set(
i, parameters[
i]);
591 parameter_map->set_mapped_entries(
592 i, *isolate->factory()->the_hole_value());
597 ReadOnlyRoots roots{isolate};
598 for (
int i = 0;
i < scope_info->ContextLocalCount();
i++) {
599 if (!scope_info->ContextLocalIsParameter(
i))
continue;
600 int parameter = scope_info->ContextLocalParameterNumber(
i);
601 if (parameter >= mapped_count)
continue;
602 arguments->set_the_hole(roots, parameter);
604 parameter_map->set_mapped_entries(parameter, slot);
609 DirectHandle<FixedArray> elements = isolate->factory()->NewFixedArray(
611 result->set_elements(*elements);
612 for (
int i = 0;
i < argument_count; ++
i) {
613 elements->set(
i, parameters[
i]);
620class HandleArguments {
625 explicit HandleArguments(base::Vector<
const DirectHandle<Object>> array)
630 base::Vector<const DirectHandle<Object>>
array_;
633class ParameterArguments {
652 auto arguments = GetCallerArguments(isolate);
653 HandleArguments argument_getter({arguments.data(), arguments.size()});
654 return *NewSloppyArguments(isolate, callee, argument_getter,
655 static_cast<int>(arguments.size()));
664 auto arguments = GetCallerArguments(isolate);
665 int argument_count =
static_cast<int>(arguments.size());
667 isolate->factory()->NewArgumentsObject(callee, argument_count);
668 if (argument_count) {
670 isolate->factory()->NewFixedArray(argument_count);
673 for (
int i = 0;
i < argument_count;
i++) {
674 array->set(
i, *arguments[
i], mode);
676 result->set_elements(*array);
686 callee->shared()->internal_formal_parameter_count_without_receiver();
689 auto arguments = GetCallerArguments(isolate);
690 int argument_count =
static_cast<int>(arguments.size());
691 int num_elements = std::max(0, argument_count - start_index);
695 if (num_elements == 0)
return *
result;
700 for (
int i = 0;
i < num_elements;
i++) {
701 elements->set(
i, *arguments[
i + start_index], mode);
740 return *isolate->factory()->NewFunctionContext(outer, scope_info);
750 return *isolate->factory()->NewWithContext(current, scope_info,
761 return *isolate->factory()->NewCatchContext(current, scope_info,
771 return *isolate->factory()->NewBlockContext(current, scope_info);
786 context, name,
FOLLOW_CHAINS, &index, &attributes, &flag, &mode);
791 if (isolate->has_exception())
return ReadOnlyRoots(isolate).exception();
797 if (IsContext(*holder) || IsSourceTextModule(*holder)) {
807 return isolate->heap()->ToBoolean(
result.FromJust());
813MaybeDirectHandle<Object> LoadLookupSlot(
822 &attributes, &flag, &mode);
823 if (isolate->has_exception())
return MaybeDirectHandle<Object>();
825 if (!holder.is_null() && IsSourceTextModule(*holder)) {
827 if (receiver_return) *receiver_return =
receiver;
832 DCHECK(IsContext(*holder));
833 DirectHandle<Context> holder_context =
Cast<Context>(holder);
836 Handle<Object>
receiver = isolate->factory()->undefined_value();
837 DirectHandle<Object> value =
842 NewReferenceError(MessageTemplate::kNotDefined, name));
844 DCHECK(!IsTheHole(*value, isolate));
845 if (receiver_return) *receiver_return =
receiver;
846 if (
v8_flags.script_context_mutable_heap_number &&
847 holder_context->IsScriptContext()) {
849 holder_context, index, value, isolate),
858 if (!holder.is_null()) {
861 DirectHandle<Object>
value;
865 if (receiver_return) {
867 (IsJSGlobalObject(*holder) || IsJSContextExtensionObject(*holder))
877 NewReferenceError(MessageTemplate::kNotDefined, name));
881 if (receiver_return) *receiver_return = isolate->factory()->undefined_value();
882 return isolate->factory()->undefined_value();
928 DCHECK((isolate)->has_exception());
933 value_ret.store(*value);
940MaybeDirectHandle<Object> StoreLookupSlot(
948 bool is_sloppy_function_name;
950 Context::Lookup(context, name, context_lookup_flags, &index, &attributes,
951 &flag, &mode, &is_sloppy_function_name);
952 if (holder.is_null()) {
954 if (isolate->has_exception())
return MaybeDirectHandle<Object>();
955 }
else if (IsSourceTextModule(*holder)) {
961 NewTypeError(MessageTemplate::kConstAssign, name));
969 IsTheHole(holder_context->get(index), isolate)) {
971 NewReferenceError(MessageTemplate::kNotDefined, name));
974 if ((
v8_flags.script_context_mutable_heap_number ||
976 holder_context->IsScriptContext()) {
982 }
else if (!is_sloppy_function_name ||
is_strict(language_mode)) {
984 NewTypeError(MessageTemplate::kConstAssign, name));
992 DirectHandle<JSReceiver> object;
993 if (attributes !=
ABSENT) {
999 NewReferenceError(MessageTemplate::kNotDefined, name));
1044 Handle<Context> declaration_context(isolate->context()->declaration_context(),
1047 isolate, StoreLookupSlot(isolate, declaration_context, name, value,
1062 bool found = script_contexts->Lookup(name, &lookup_result);
1065 script_contexts->get(lookup_result.
context_index), isolate);
1070 if (
v8_flags.script_context_mutable_heap_number ||
1073 script_context, lookup_result.
slot_index, value, isolate);
1075 script_context->set(lookup_result.
slot_index, *value);
static Handle< Object > Lookup(Handle< Context > context, Handle< String > name, ContextLookupFlags flags, int *index, PropertyAttributes *attributes, InitializationFlag *init_flag, VariableMode *variable_mode, bool *is_sloppy_function_name=nullptr)
static DirectHandle< Object > LoadScriptContextElement(DirectHandle< Context > script_context, int index, DirectHandle< Object > new_value, Isolate *isolate)
static void StoreScriptContextAndUpdateSlotProperty(DirectHandle< Context > script_context, int index, DirectHandle< Object > new_value, Isolate *isolate)
static const int kNotFound
@ kEmptyContextExtensionGroup
static void DeoptimizeDependencyGroups(Isolate *isolate, ObjectT object, DependencyGroups groups)
V8_INLINE bool is_null() const
JSFunctionBuilder & set_feedback_cell(DirectHandle< FeedbackCell > v)
JSFunctionBuilder & set_allocation_type(AllocationType v)
V8_WARN_UNUSED_RESULT Handle< JSFunction > Build()
void store(Tagged< Object > value) const
static void InitializeJSDisposableStackBase(Isolate *isolate, DirectHandle< JSDisposableStackBase > stack)
static void HandleErrorInDisposal(Isolate *isolate, DirectHandle< JSDisposableStackBase > disposable_stack, DirectHandle< Object > current_error, DirectHandle< Object > current_error_message)
static MaybeDirectHandle< Object > DisposeResources(Isolate *isolate, DirectHandle< JSDisposableStackBase > disposable_stack, DisposableStackResourcesType resources_type)
static void Add(Isolate *isolate, DirectHandle< JSDisposableStackBase > disposable_stack, DirectHandle< Object > value, DirectHandle< Object > method, DisposeMethodCallType type, DisposeMethodHint hint)
static MaybeDirectHandle< Object > CheckValueAndGetDisposeMethod(Isolate *isolate, DirectHandle< JSAny > value, DisposeMethodHint hint)
static V8_WARN_UNUSED_RESULT HandleType< Object >::MaybeType DefineOwnPropertyIgnoreAttributes(LookupIterator *it, HandleType< T > value, PropertyAttributes attributes, AccessorInfoHandling handling=DONT_FORCE_FIELD, EnforceDefineSemantics semantics=EnforceDefineSemantics::kSet)
static V8_WARN_UNUSED_RESULT MaybeDirectHandle< Object > V8_EXPORT_PRIVATE SetOwnPropertyIgnoreAttributes(DirectHandle< JSObject > object, DirectHandle< Name > name, DirectHandle< Object > value, PropertyAttributes attributes)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > DeleteProperty(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name, LanguageMode language_mode=LanguageMode::kSloppy)
static V8_WARN_UNUSED_RESULT Maybe< PropertyAttributes > GetPropertyAttributes(Isolate *isolate, DirectHandle< JSReceiver > object, DirectHandle< Name > name)
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT Maybe< bool > SetProperty(LookupIterator *it, DirectHandle< Object > value, StoreOrigin store_origin, Maybe< ShouldThrow > should_throw=Nothing< ShouldThrow >())
V8_EXPORT_PRIVATE static V8_WARN_UNUSED_RESULT MaybeHandle< Object > GetProperty(LookupIterator *it, bool is_global_reference=false)
static constexpr int ToInt(const Tagged< Object > object)
static constexpr Tagged< Smi > FromInt(int value)
static void StoreVariable(DirectHandle< SourceTextModule > module, int cell_index, DirectHandle< Object > value)
static Handle< Object > LoadVariable(Isolate *isolate, DirectHandle< SourceTextModule > module, int cell_index)
#define RUNTIME_FUNCTION_RETURN_PAIR(Name)
#define RUNTIME_FUNCTION(Name)
#define ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, dst, call)
#define ASSIGN_RETURN_ON_EXCEPTION(isolate, dst, call)
#define THROW_NEW_ERROR(isolate, call)
#define ASSIGN_RETURN_ON_EXCEPTION_VALUE(isolate, dst, call, value)
#define THROW_NEW_ERROR_RETURN_FAILURE(isolate, call)
#define RETURN_FAILURE_ON_EXCEPTION(isolate, call)
#define FOR_WITH_HANDLE_SCOPE(isolate, loop_var_type, init, loop_var, limit_check, increment, body)
#define MAYBE_RETURN(call, value)
#define RETURN_RESULT_OR_FAILURE(isolate, call)
base::Vector< const DirectHandle< Object > > args
SharedFunctionInfoRef shared
ZoneVector< RpoNumber > & result
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
DisposableStackResourcesType
bool IsLexicalVariableMode(VariableMode mode)
Tagged(T object) -> Tagged< T >
bool IsDerivedConstructor(FunctionKind kind)
static ObjectPair MakePair(Tagged< Object > x, Tagged< Object > y)
V8_INLINE constexpr bool IsSmi(TaggedImpl< kRefType, StorageType > obj)
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
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 allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats TracingFlags::gc_stats track native contexts that are expected to be garbage collected verify heap pointers before and after GC memory reducer runs GC with ReduceMemoryFootprint flag Maximum number of memory reducer GCs scheduled Old gen GC speed is computed directly from gc tracer counters Perform compaction on full GCs based on V8 s default heuristics Perform compaction on every full GC Perform code space compaction when finalizing a full GC with stack Stress GC compaction to flush out bugs with moving objects flush of baseline code when it has not been executed recently Use time base code flushing instead of age Use a progress bar to scan large objects in increments when incremental marking is active force incremental marking for small heaps and run it more often force marking at random points between and force scavenge at random points between and reclaim otherwise unreachable unmodified wrapper objects when possible less compaction in non memory reducing mode use high priority threads for concurrent Marking Test mode only flag It allows an unit test to select evacuation candidates use incremental marking for CppHeap cppheap_concurrent_marking c value for membalancer A special constant to balance between memory and space tradeoff The smaller the more memory it uses enable use of SSE4 instructions if available enable use of AVX VNNI instructions if available enable use of POPCNT instruction if available force all emitted branches to be in long mode(MIPS/PPC only)") DEFINE_BOOL(partial_constant_pool
bool IsNullOrUndefined(Tagged< Object > obj, Isolate *isolate)
constexpr int kSystemPointerSize
bool is_strict(LanguageMode language_mode)
V8_EXPORT_PRIVATE FlagValues v8_flags
@ DONT_INITIALIZE_ARRAY_ELEMENTS
!IsContextMap !IsContextMap native_context
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
Maybe< T > Just(const T &t)
base::Vector< const DirectHandle< Object > > array_
#define DCHECK_IMPLIES(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(v1, v2)