@@ -876,6 +876,10 @@ std::string HeapObject::GetTypeName(Error& err) {
876876 if (type == v8 ()->types ()->kMapType ) {
877877 return " (Map)" ;
878878 }
879+ if (type >= v8 ()->types ()->kFirstContextType &&
880+ type <= v8 ()->types ()->kLastContextType ) {
881+ return " Context" ;
882+ }
879883
880884 if (JSObject::IsObjectType (v8 (), type)) {
881885 v8::HeapObject map_obj = GetMap (err);
@@ -1058,17 +1062,43 @@ std::string FixedArray::InspectContents(int length, Error& err) {
10581062 return res;
10591063}
10601064
1061- HeapObject Context::GetScopeInfo (Error& err) {
1062- if (v8 ()->context ()->kScopeInfoIndex != -1 ) {
1063- return FixedArray::Get<HeapObject>(v8 ()->context ()->kScopeInfoIndex , err);
1064- }
1065- JSFunction closure = Closure (err);
1066- if (err.Fail ()) return HeapObject ();
1065+ // Context locals iterator implementations
1066+ Context::Locals::Locals (Context* context, Error& err) {
1067+ context_ = context;
1068+ HeapObject scope_obj = context_->GetScopeInfo (err);
1069+ if (err.Fail ()) return ;
1070+
1071+ scope_info_ = ScopeInfo (scope_obj);
1072+ Smi param_count_smi = scope_info_.ParameterCount (err);
1073+ if (err.Fail ()) return ;
1074+ Smi stack_count_smi = scope_info_.StackLocalCount (err);
1075+ if (err.Fail ()) return ;
1076+ Smi local_count_smi = scope_info_.ContextLocalCount (err);
1077+ if (err.Fail ()) return ;
1078+
1079+ param_count_ = param_count_smi.GetValue ();
1080+ stack_count_ = stack_count_smi.GetValue ();
1081+ local_count_ = local_count_smi.GetValue ();
1082+ }
10671083
1068- SharedFunctionInfo info = closure.Info (err);
1069- if (err.Fail ()) return HeapObject ();
1084+ Context::Locals::Iterator Context::Locals::begin () { return Iterator (0 , this ); }
10701085
1071- return info.GetScopeInfo (err);
1086+ Context::Locals::Iterator Context::Locals::end () {
1087+ return Iterator (local_count_, this );
1088+ }
1089+
1090+ const Context::Locals::Iterator Context::Locals::Iterator::operator ++(int ) {
1091+ current_++;
1092+ return Iterator (current_, this ->outer_ );
1093+ }
1094+
1095+ bool Context::Locals::Iterator::operator !=(Context::Locals::Iterator that) {
1096+ return current_ != that.current_ || outer_->context_ != that.outer_ ->context_ ;
1097+ }
1098+
1099+ v8::Value Context::Locals::Iterator::operator *() {
1100+ Error err;
1101+ return outer_->context_ ->ContextSlot (current_, err);
10721102}
10731103
10741104std::string Context::Inspect (InspectOptions* options, Error& err) {
@@ -1093,13 +1123,6 @@ std::string Context::Inspect(InspectOptions* options, Error& err) {
10931123
10941124 ScopeInfo scope (scope_obj);
10951125
1096- Smi param_count_smi = scope.ParameterCount (err);
1097- if (err.Fail ()) return std::string ();
1098- Smi stack_count_smi = scope.StackLocalCount (err);
1099- if (err.Fail ()) return std::string ();
1100- Smi local_count_smi = scope.ContextLocalCount (err);
1101- if (err.Fail ()) return std::string ();
1102-
11031126 HeapObject heap_previous = HeapObject (previous);
11041127 if (heap_previous.Check ()) {
11051128 char tmp[128 ];
@@ -1145,19 +1168,19 @@ std::string Context::Inspect(InspectOptions* options, Error& err) {
11451168 res += " >" ;
11461169 }
11471170
1148- int param_count = param_count_smi. GetValue ( );
1149- int stack_count = stack_count_smi. GetValue ();
1150- int local_count = local_count_smi. GetValue ();
1151- for ( int i = 0 ; i < local_count; i ++) {
1152- String name = scope. ContextLocalName (i, param_count, stack_count, err);
1171+ Context::Locals locals ( this , err );
1172+ if (err. Fail ()) return std::string ();
1173+ for (v8::Context::Locals::Iterator it = locals. begin (); it != locals. end ();
1174+ it ++) {
1175+ String name = it. LocalName ( err);
11531176 if (err.Fail ()) return std::string ();
11541177
11551178 if (!res.empty ()) res += " ,\n " ;
11561179
11571180 res += options->get_indent_spaces () + name.ToString (err) + " =" ;
11581181 if (err.Fail ()) return std::string ();
11591182
1160- Value value = ContextSlot (i, err);
1183+ Value value = it. GetValue ( err);
11611184 if (err.Fail ()) return std::string ();
11621185
11631186 InspectOptions val_options;
0 commit comments