5 #include "src/debug/debug-scopes.h" 9 #include "src/ast/ast.h" 10 #include "src/ast/scopes.h" 11 #include "src/debug/debug.h" 12 #include "src/frames-inl.h" 13 #include "src/globals.h" 14 #include "src/isolate-inl.h" 15 #include "src/objects/js-generator-inl.h" 16 #include "src/objects/module.h" 17 #include "src/parsing/parse-info.h" 18 #include "src/parsing/parsing.h" 19 #include "src/parsing/rewriter.h" 24 ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
25 ScopeIterator::Option option)
27 frame_inspector_(frame_inspector),
28 function_(frame_inspector_->GetFunction()),
29 script_(frame_inspector_->GetScript()) {
30 if (!frame_inspector->GetContext()->IsContext()) {
34 context_ = Handle<Context>::cast(frame_inspector->GetContext());
37 DCHECK_NE(Script::TYPE_WASM, frame_inspector->GetScript()->type());
39 TryParseAndRetrieveScopes(option);
42 ScopeIterator::~ScopeIterator() {
delete info_; }
44 Handle<Object> ScopeIterator::GetFunctionDebugName()
const {
45 if (!function_.is_null())
return JSFunction::GetDebugName(function_);
47 if (!context_->IsNativeContext()) {
48 DisallowHeapAllocation no_gc;
49 ScopeInfo closure_info = context_->closure_context()->scope_info();
50 Handle<String> debug_name(closure_info->FunctionDebugName(), isolate_);
51 if (debug_name->length() > 0)
return debug_name;
53 return isolate_->factory()->undefined_value();
56 ScopeIterator::ScopeIterator(Isolate* isolate, Handle<JSFunction>
function)
57 : isolate_(isolate), context_(function->context(), isolate) {
58 if (!function->shared()->IsSubjectToDebugging()) {
59 context_ = Handle<Context>();
62 script_ = handle(Script::cast(function->shared()->script()), isolate);
63 UnwrapEvaluationContext();
66 ScopeIterator::ScopeIterator(Isolate* isolate,
67 Handle<JSGeneratorObject> generator)
69 generator_(generator),
70 function_(generator->function(), isolate),
71 context_(generator->context(), isolate),
72 script_(Script::cast(function_->shared()->script()), isolate) {
73 CHECK(function_->shared()->IsSubjectToDebugging());
74 TryParseAndRetrieveScopes(DEFAULT);
77 void ScopeIterator::Restart() {
78 DCHECK_NOT_NULL(frame_inspector_);
79 function_ = frame_inspector_->GetFunction();
80 context_ = Handle<Context>::cast(frame_inspector_->GetContext());
81 current_scope_ = start_scope_;
82 DCHECK_NOT_NULL(current_scope_);
83 UnwrapEvaluationContext();
86 void ScopeIterator::TryParseAndRetrieveScopes(ScopeIterator::Option option) {
88 Handle<SharedFunctionInfo> shared_info(function_->shared(), isolate_);
89 Handle<ScopeInfo> scope_info(shared_info->scope_info(), isolate_);
90 if (shared_info->script()->IsUndefined(isolate_)) {
91 current_scope_ = closure_scope_ =
nullptr;
92 context_ = handle(function_->context(), isolate_);
93 function_ = Handle<JSFunction>();
100 if (IsClassMembersInitializerFunction(shared_info->kind())) {
101 current_scope_ = closure_scope_ =
nullptr;
102 context_ = Handle<Context>();
103 function_ = Handle<JSFunction>();
107 DCHECK_NE(IGNORE_NESTED_SCOPES, option);
108 bool ignore_nested_scopes =
false;
109 if (shared_info->HasBreakInfo() && frame_inspector_ !=
nullptr) {
116 Handle<DebugInfo> debug_info(shared_info->GetDebugInfo(), isolate_);
119 BreakLocation location = BreakLocation::FromFrame(debug_info, GetFrame());
121 ignore_nested_scopes = location.IsReturn();
126 if (scope_info->scope_type() == FUNCTION_SCOPE) {
128 info_ =
new ParseInfo(isolate_, shared_info);
131 Handle<Script> script(Script::cast(shared_info->script()), isolate_);
132 info_ =
new ParseInfo(isolate_, script);
133 if (scope_info->scope_type() == EVAL_SCOPE) {
135 if (!context_->IsNativeContext()) {
136 info_->set_outer_scope_info(handle(context_->scope_info(), isolate_));
140 info_->set_language_mode(shared_info->language_mode());
141 }
else if (scope_info->scope_type() == MODULE_SCOPE) {
142 DCHECK(info_->is_module());
144 DCHECK_EQ(SCRIPT_SCOPE, scope_info->scope_type());
148 if (parsing::ParseAny(info_, shared_info, isolate_) &&
149 Rewriter::Rewrite(info_)) {
150 info_->ast_value_factory()->Internalize(isolate_);
151 closure_scope_ = info_->literal()->scope();
153 if (option == COLLECT_NON_LOCALS) {
154 DCHECK(non_locals_.is_null());
155 non_locals_ = info_->literal()->scope()->CollectNonLocals(
156 isolate_, info_, StringSet::New(isolate_));
159 CHECK(DeclarationScope::Analyze(info_));
160 if (ignore_nested_scopes) {
161 current_scope_ = closure_scope_;
162 start_scope_ = current_scope_;
163 if (closure_scope_->NeedsContext()) {
164 context_ = handle(context_->closure_context(), isolate_);
167 RetrieveScopeChain(closure_scope_);
169 UnwrapEvaluationContext();
178 CHECK(isolate_->has_pending_exception());
179 isolate_->clear_pending_exception();
180 context_ = Handle<Context>();
184 void ScopeIterator::UnwrapEvaluationContext() {
185 if (!context_->IsDebugEvaluateContext())
return;
186 Context current = *context_;
188 Object* wrapped = current->get(Context::WRAPPED_CONTEXT_INDEX);
189 if (wrapped->IsContext()) {
190 current = Context::cast(wrapped);
192 DCHECK(!current->previous().is_null());
193 current = current->previous();
195 }
while (current->IsDebugEvaluateContext());
196 context_ = handle(current, isolate_);
199 Handle<JSObject> ScopeIterator::MaterializeScopeDetails() {
201 Handle<FixedArray> details =
202 isolate_->factory()->NewFixedArray(kScopeDetailsSize);
204 details->set(kScopeDetailsTypeIndex, Smi::FromInt(
Type()));
205 Handle<JSObject> scope_object = ScopeObject(Mode::ALL);
206 details->set(kScopeDetailsObjectIndex, *scope_object);
207 if (
Type() == ScopeTypeGlobal ||
Type() == ScopeTypeScript) {
208 return isolate_->factory()->NewJSArrayWithElements(details);
209 }
else if (HasContext()) {
210 Handle<Object> closure_name = GetFunctionDebugName();
211 details->set(kScopeDetailsNameIndex, *closure_name);
212 details->set(kScopeDetailsStartPositionIndex,
213 Smi::FromInt(start_position()));
214 details->set(kScopeDetailsEndPositionIndex, Smi::FromInt(end_position()));
215 if (InInnerScope()) {
216 details->set(kScopeDetailsFunctionIndex, *function_);
219 return isolate_->factory()->NewJSArrayWithElements(details);
222 bool ScopeIterator::HasPositionInfo() {
223 return InInnerScope() || !context_->IsNativeContext();
226 int ScopeIterator::start_position() {
227 if (InInnerScope())
return current_scope_->start_position();
228 if (context_->IsNativeContext())
return 0;
229 return context_->closure_context()->scope_info()->StartPosition();
232 int ScopeIterator::end_position() {
233 if (InInnerScope())
return current_scope_->end_position();
234 if (context_->IsNativeContext())
return 0;
235 return context_->closure_context()->scope_info()->EndPosition();
238 bool ScopeIterator::DeclaresLocals(Mode mode)
const {
239 ScopeType type =
Type();
241 if (type == ScopeTypeWith)
return mode == Mode::ALL;
242 if (type == ScopeTypeGlobal)
return mode == Mode::ALL;
244 bool declares_local =
false;
245 auto visitor = [&](Handle<String> name, Handle<Object> value) {
246 declares_local =
true;
249 VisitScope(visitor, mode);
250 return declares_local;
253 bool ScopeIterator::HasContext()
const {
254 return !InInnerScope() || current_scope_->NeedsContext();
257 void ScopeIterator::Next() {
260 ScopeType scope_type =
Type();
262 if (scope_type == ScopeTypeGlobal) {
264 DCHECK(context_->IsNativeContext());
265 context_ = Handle<Context>();
270 bool inner = InInnerScope();
271 if (current_scope_ == closure_scope_) function_ = Handle<JSFunction>();
273 if (scope_type == ScopeTypeScript) {
274 DCHECK_IMPLIES(InInnerScope(), current_scope_->is_script_scope());
275 seen_script_scope_ =
true;
276 if (context_->IsScriptContext()) {
277 context_ = handle(context_->previous(), isolate_);
280 DCHECK(!context_->IsNativeContext());
281 context_ = handle(context_->previous(), isolate_);
283 DCHECK_NOT_NULL(current_scope_);
285 if (current_scope_->NeedsContext()) {
286 DCHECK(!context_->previous().is_null());
287 context_ = handle(context_->previous(), isolate_);
289 DCHECK_IMPLIES(InInnerScope(), current_scope_->outer_scope() !=
nullptr);
290 current_scope_ = current_scope_->outer_scope();
292 }
while (current_scope_->is_hidden());
295 UnwrapEvaluationContext();
300 ScopeIterator::ScopeType ScopeIterator::Type()
const {
302 if (InInnerScope()) {
303 switch (current_scope_->scope_type()) {
305 DCHECK_IMPLIES(current_scope_->NeedsContext(),
306 context_->IsFunctionContext());
307 return ScopeTypeLocal;
309 DCHECK_IMPLIES(current_scope_->NeedsContext(),
310 context_->IsModuleContext());
311 return ScopeTypeModule;
314 current_scope_->NeedsContext(),
315 context_->IsScriptContext() || context_->IsNativeContext());
316 return ScopeTypeScript;
319 current_scope_->NeedsContext(),
320 context_->IsWithContext() || context_->IsDebugEvaluateContext());
321 return ScopeTypeWith;
323 DCHECK(context_->IsCatchContext());
324 return ScopeTypeCatch;
326 DCHECK_IMPLIES(current_scope_->NeedsContext(),
327 context_->IsBlockContext());
328 return ScopeTypeBlock;
330 DCHECK_IMPLIES(current_scope_->NeedsContext(),
331 context_->IsEvalContext());
332 return ScopeTypeEval;
336 if (context_->IsNativeContext()) {
337 DCHECK(context_->global_object()->IsJSGlobalObject());
340 return seen_script_scope_ ? ScopeTypeGlobal : ScopeTypeScript;
342 if (context_->IsFunctionContext() || context_->IsEvalContext()) {
343 return ScopeTypeClosure;
345 if (context_->IsCatchContext()) {
346 return ScopeTypeCatch;
348 if (context_->IsBlockContext()) {
349 return ScopeTypeBlock;
351 if (context_->IsModuleContext()) {
352 return ScopeTypeModule;
354 if (context_->IsScriptContext()) {
355 return ScopeTypeScript;
357 DCHECK(context_->IsWithContext() || context_->IsDebugEvaluateContext());
358 return ScopeTypeWith;
361 Handle<JSObject> ScopeIterator::ScopeObject(Mode mode) {
364 ScopeType type =
Type();
365 if (type == ScopeTypeGlobal) {
366 DCHECK_EQ(Mode::ALL, mode);
367 return handle(context_->global_proxy(), isolate_);
369 if (type == ScopeTypeWith) {
370 DCHECK_EQ(Mode::ALL, mode);
371 return WithContextExtension();
374 Handle<JSObject> scope = isolate_->factory()->NewJSObjectWithNullProto();
375 auto visitor = [=](Handle<String> name, Handle<Object> value) {
376 JSObject::AddProperty(isolate_, scope, name, value, NONE);
380 VisitScope(visitor, mode);
384 void ScopeIterator::VisitScope(
const Visitor& visitor, Mode mode)
const {
387 case ScopeTypeClosure:
391 return VisitLocalScope(visitor, mode);
392 case ScopeTypeModule:
393 if (InInnerScope()) {
394 return VisitLocalScope(visitor, mode);
396 DCHECK_EQ(Mode::ALL, mode);
397 return VisitModuleScope(visitor);
398 case ScopeTypeScript:
399 DCHECK_EQ(Mode::ALL, mode);
400 return VisitScriptScope(visitor);
402 case ScopeTypeGlobal:
407 bool ScopeIterator::SetVariableValue(Handle<String> name,
408 Handle<Object> value) {
410 name = isolate_->factory()->InternalizeString(name);
412 case ScopeTypeGlobal:
419 case ScopeTypeModule:
420 if (InInnerScope())
return SetLocalVariableValue(name, value);
421 if (
Type() == ScopeTypeModule && SetModuleVariableValue(name, value)) {
424 return SetContextVariableValue(name, value);
427 case ScopeTypeClosure:
428 if (InInnerScope()) {
429 DCHECK_EQ(ScopeTypeLocal,
Type());
430 if (SetLocalVariableValue(name, value))
return true;
432 if (!current_scope_->NeedsContext())
return false;
434 DCHECK_EQ(ScopeTypeClosure,
Type());
435 if (SetContextVariableValue(name, value))
return true;
440 return SetContextExtensionValue(name, value);
442 case ScopeTypeScript:
443 return SetScriptVariableValue(name, value);
448 Handle<StringSet> ScopeIterator::GetNonLocals() {
return non_locals_; }
452 void ScopeIterator::DebugPrint() {
456 case ScopeIterator::ScopeTypeGlobal:
461 case ScopeIterator::ScopeTypeLocal: {
463 if (current_scope_->NeedsContext()) {
465 if (context_->has_extension()) {
466 Handle<HeapObject> extension(context_->extension(), isolate_);
467 DCHECK(extension->IsJSContextExtensionObject());
468 extension->Print(os);
474 case ScopeIterator::ScopeTypeWith:
476 context_->extension()->Print(os);
479 case ScopeIterator::ScopeTypeCatch:
481 context_->extension()->Print(os);
482 context_->get(Context::THROWN_OBJECT_INDEX)->Print(os);
485 case ScopeIterator::ScopeTypeClosure:
488 if (context_->has_extension()) {
489 Handle<HeapObject> extension(context_->extension(), isolate_);
490 DCHECK(extension->IsJSContextExtensionObject());
491 extension->Print(os);
495 case ScopeIterator::ScopeTypeScript:
497 context_->global_object()
499 ->script_context_table()
510 int ScopeIterator::GetSourcePosition() {
511 if (frame_inspector_) {
512 return frame_inspector_->GetSourcePosition();
514 DCHECK(!generator_.is_null());
515 return generator_->source_position();
519 void ScopeIterator::RetrieveScopeChain(DeclarationScope* scope) {
520 DCHECK_NOT_NULL(scope);
522 const int position = GetSourcePosition();
524 Scope* parent =
nullptr;
525 Scope* current = scope;
526 while (parent != current) {
528 for (Scope* inner_scope = current->inner_scope(); inner_scope !=
nullptr;
529 inner_scope = inner_scope->sibling()) {
530 int beg_pos = inner_scope->start_position();
531 int end_pos = inner_scope->end_position();
532 DCHECK((beg_pos >= 0 && end_pos >= 0) || inner_scope->is_hidden());
533 if (beg_pos <= position && position < end_pos) {
535 if (!inner_scope->is_function_scope()) {
536 current = inner_scope;
543 start_scope_ = current;
544 current_scope_ = current;
547 void ScopeIterator::VisitScriptScope(
const Visitor& visitor)
const {
548 Handle<JSGlobalObject> global(context_->global_object(), isolate_);
549 Handle<ScriptContextTable> script_contexts(
550 global->native_context()->script_context_table(), isolate_);
553 for (
int context_index = 1; context_index < script_contexts->used();
555 Handle<Context> context = ScriptContextTable::GetContext(
556 isolate_, script_contexts, context_index);
557 Handle<ScopeInfo> scope_info(context->scope_info(), isolate_);
558 if (VisitContextLocals(visitor, scope_info, context))
return;
562 void ScopeIterator::VisitModuleScope(
const Visitor& visitor)
const {
563 DCHECK(context_->IsModuleContext());
565 Handle<ScopeInfo> scope_info(context_->scope_info(), isolate_);
566 if (VisitContextLocals(visitor, scope_info, context_))
return;
568 int count_index = scope_info->ModuleVariableCountIndex();
569 int module_variable_count = Smi::cast(scope_info->get(count_index))->value();
571 Handle<Module> module(context_->module(), isolate_);
573 for (
int i = 0;
i < module_variable_count; ++
i) {
578 scope_info->ModuleVariable(
i, &raw_name, &index);
579 CHECK(!ScopeInfo::VariableIsSynthetic(raw_name));
580 name = handle(raw_name, isolate_);
582 Handle<Object> value = Module::LoadVariable(isolate_, module, index);
585 if (value->IsTheHole(isolate_))
continue;
586 if (visitor(name, value))
return;
590 bool ScopeIterator::VisitContextLocals(
const Visitor& visitor,
591 Handle<ScopeInfo> scope_info,
592 Handle<Context> context)
const {
594 for (
int i = 0;
i < scope_info->ContextLocalCount(); ++
i) {
595 Handle<String> name(scope_info->ContextLocalName(
i), isolate_);
596 if (ScopeInfo::VariableIsSynthetic(*name))
continue;
597 int context_index = Context::MIN_CONTEXT_SLOTS +
i;
598 Handle<Object> value(context->get(context_index), isolate_);
600 if (value->IsTheHole(isolate_))
continue;
601 if (visitor(name, value))
return true;
606 bool ScopeIterator::VisitLocals(
const Visitor& visitor, Mode mode)
const {
607 for (Variable* var : *current_scope_->locals()) {
608 if (!var->is_this() && ScopeInfo::VariableIsSynthetic(*var->name())) {
612 int index = var->index();
613 Handle<Object> value;
614 switch (var->location()) {
615 case VariableLocation::LOOKUP:
619 case VariableLocation::UNALLOCATED:
620 if (!var->is_this())
continue;
622 if (mode == Mode::ALL)
continue;
624 value = frame_inspector_->GetReceiver();
627 case VariableLocation::PARAMETER: {
628 if (frame_inspector_ ==
nullptr) {
630 DCHECK(!generator_.is_null());
631 if (var->is_this()) {
632 value = handle(generator_->receiver(), isolate_);
634 FixedArray parameters_and_registers =
635 generator_->parameters_and_registers();
636 DCHECK_LT(index, parameters_and_registers->length());
637 value = handle(parameters_and_registers->get(index), isolate_);
640 value = var->is_this() ? frame_inspector_->GetReceiver()
641 : frame_inspector_->GetParameter(index);
643 if (value->IsOptimizedOut(isolate_)) {
644 value = isolate_->factory()->undefined_value();
645 }
else if (var->is_this() && value->IsTheHole(isolate_)) {
646 value = isolate_->factory()->undefined_value();
652 case VariableLocation::LOCAL:
653 if (frame_inspector_ ==
nullptr) {
655 DCHECK(!generator_.is_null());
656 FixedArray parameters_and_registers =
657 generator_->parameters_and_registers();
658 int parameter_count =
659 function_->shared()->scope_info()->ParameterCount();
660 index += parameter_count;
661 DCHECK_LT(index, parameters_and_registers->length());
662 value = handle(parameters_and_registers->get(index), isolate_);
663 if (value->IsTheHole(isolate_)) {
664 value = isolate_->factory()->undefined_value();
667 value = frame_inspector_->GetExpression(index);
668 if (value->IsOptimizedOut(isolate_)) {
670 if (current_scope_->is_declaration_scope() &&
671 current_scope_->AsDeclarationScope()->arguments() == var) {
674 value = isolate_->factory()->undefined_value();
675 }
else if (value->IsTheHole(isolate_)) {
682 case VariableLocation::CONTEXT:
683 if (mode == Mode::STACK)
continue;
685 if (var->is_this())
continue;
686 DCHECK(var->IsContextSlot());
687 value = handle(context_->get(index), isolate_);
689 if (value->IsTheHole(isolate_))
continue;
692 case VariableLocation::MODULE: {
693 if (mode == Mode::STACK)
continue;
695 Handle<Module> module(context_->module(), isolate_);
696 value = Module::LoadVariable(isolate_, module, var->index());
698 if (value->IsTheHole(isolate_))
continue;
703 if (visitor(var->name(), value))
return true;
710 Handle<JSObject> ScopeIterator::WithContextExtension() {
711 DCHECK(context_->IsWithContext());
712 if (context_->extension_receiver()->IsJSProxy()) {
713 return isolate_->factory()->NewJSObjectWithNullProto();
715 return handle(JSObject::cast(context_->extension_receiver()), isolate_);
720 void ScopeIterator::VisitLocalScope(
const Visitor& visitor, Mode mode)
const {
721 if (InInnerScope()) {
722 if (VisitLocals(visitor, mode))
return;
723 if (mode == Mode::STACK &&
Type() == ScopeTypeLocal) {
727 if (!closure_scope_->has_this_declaration() &&
728 !non_locals_->Has(isolate_, isolate_->factory()->this_string())) {
729 if (visitor(isolate_->factory()->this_string(),
730 isolate_->factory()->undefined_value()))
738 if (frame_inspector_ !=
nullptr && !closure_scope_->is_arrow_scope() &&
739 (closure_scope_->arguments() ==
nullptr ||
740 frame_inspector_->GetExpression(closure_scope_->arguments()->index())
741 ->IsOptimizedOut(isolate_))) {
742 JavaScriptFrame* frame = GetFrame();
743 Handle<JSObject> arguments = Accessors::FunctionGetArguments(
744 frame, frame_inspector_->inlined_frame_index());
745 if (visitor(isolate_->factory()->arguments_string(), arguments))
return;
749 DCHECK_EQ(Mode::ALL, mode);
750 Handle<ScopeInfo> scope_info(context_->scope_info(), isolate_);
751 if (VisitContextLocals(visitor, scope_info, context_))
return;
754 if (mode == Mode::ALL && HasContext()) {
755 DCHECK(!context_->IsScriptContext());
756 DCHECK(!context_->IsNativeContext());
757 DCHECK(!context_->IsWithContext());
758 if (!context_->scope_info()->CallsSloppyEval())
return;
759 if (context_->extension_object() ==
nullptr)
return;
760 Handle<JSObject> extension(context_->extension_object(), isolate_);
761 Handle<FixedArray> keys =
762 KeyAccumulator::GetKeys(extension, KeyCollectionMode::kOwnOnly,
766 for (
int i = 0;
i < keys->length();
i++) {
768 DCHECK(keys->get(
i)->IsString());
769 Handle<String> key(String::cast(keys->get(
i)), isolate_);
770 Handle<Object> value = JSReceiver::GetDataProperty(extension, key);
771 if (visitor(key, value))
return;
776 bool ScopeIterator::SetLocalVariableValue(Handle<String> variable_name,
777 Handle<Object> new_value) {
780 for (Variable* var : *current_scope_->locals()) {
781 if (String::Equals(isolate_, var->name(), variable_name)) {
782 int index = var->index();
783 switch (var->location()) {
784 case VariableLocation::LOOKUP:
785 case VariableLocation::UNALLOCATED:
787 DCHECK(var->is_this() ||
788 *variable_name == ReadOnlyRoots(isolate_).arguments_string());
791 case VariableLocation::PARAMETER: {
792 if (var->is_this())
return false;
793 if (frame_inspector_ ==
nullptr) {
795 DCHECK(!generator_.is_null());
796 Handle<FixedArray> parameters_and_registers(
797 generator_->parameters_and_registers(), isolate_);
798 DCHECK_LT(index, parameters_and_registers->length());
799 parameters_and_registers->set(index, *new_value);
801 JavaScriptFrame* frame = GetFrame();
802 if (frame->is_optimized())
return false;
804 frame->SetParameterValue(index, *new_value);
809 case VariableLocation::LOCAL:
810 if (frame_inspector_ ==
nullptr) {
812 DCHECK(!generator_.is_null());
813 int parameter_count =
814 function_->shared()->scope_info()->ParameterCount();
815 index += parameter_count;
816 Handle<FixedArray> parameters_and_registers(
817 generator_->parameters_and_registers(), isolate_);
818 DCHECK_LT(index, parameters_and_registers->length());
819 parameters_and_registers->set(index, *new_value);
822 JavaScriptFrame* frame = GetFrame();
823 if (frame->is_optimized())
return false;
825 frame->SetExpression(index, *new_value);
829 case VariableLocation::CONTEXT:
830 DCHECK(var->IsContextSlot());
831 context_->set(index, *new_value);
834 case VariableLocation::MODULE:
835 if (!var->IsExport())
return false;
836 Handle<Module> module(context_->module(), isolate_);
837 Module::StoreVariable(module, var->index(), new_value);
847 bool ScopeIterator::SetContextExtensionValue(Handle<String> variable_name,
848 Handle<Object> new_value) {
849 if (!context_->has_extension())
return false;
851 DCHECK(context_->extension_object()->IsJSContextExtensionObject());
852 Handle<JSObject> ext(context_->extension_object(), isolate_);
853 LookupIterator it(isolate_, ext, variable_name, LookupIterator::OWN);
854 Maybe<bool> maybe = JSReceiver::HasOwnProperty(ext, variable_name);
855 DCHECK(maybe.IsJust());
856 if (!maybe.FromJust())
return false;
858 CHECK(Object::SetDataProperty(&it, new_value).ToChecked());
862 bool ScopeIterator::SetContextVariableValue(Handle<String> variable_name,
863 Handle<Object> new_value) {
864 Handle<ScopeInfo> scope_info(context_->scope_info(), isolate_);
867 InitializationFlag flag;
868 MaybeAssignedFlag maybe_assigned_flag;
869 int slot_index = ScopeInfo::ContextSlotIndex(scope_info, variable_name, &mode,
870 &flag, &maybe_assigned_flag);
871 if (slot_index < 0)
return false;
873 context_->set(slot_index, *new_value);
877 bool ScopeIterator::SetModuleVariableValue(Handle<String> variable_name,
878 Handle<Object> new_value) {
881 InitializationFlag init_flag;
882 MaybeAssignedFlag maybe_assigned_flag;
883 cell_index = context_->scope_info()->ModuleIndex(
884 variable_name, &mode, &init_flag, &maybe_assigned_flag);
887 if (ModuleDescriptor::GetCellIndexKind(cell_index) !=
888 ModuleDescriptor::kExport) {
892 Handle<Module> module(context_->module(), isolate_);
893 Module::StoreVariable(module, cell_index, new_value);
897 bool ScopeIterator::SetScriptVariableValue(Handle<String> variable_name,
898 Handle<Object> new_value) {
899 Handle<ScriptContextTable> script_contexts(
900 context_->global_object()->native_context()->script_context_table(),
902 ScriptContextTable::LookupResult lookup_result;
903 if (ScriptContextTable::Lookup(isolate_, script_contexts, variable_name,
905 Handle<Context> script_context = ScriptContextTable::GetContext(
906 isolate_, script_contexts, lookup_result.context_index);
907 script_context->set(lookup_result.slot_index, *new_value);