@@ -641,10 +641,15 @@ std::string JSFunction::Inspect(InspectOptions* options, Error& err) {
641
641
snprintf (tmp, sizeof (tmp), " \n context=0x%016" PRIx64, context.raw ());
642
642
res += tmp;
643
643
644
- std::string context_str = context.Inspect (err);
645
- if (err.Fail ()) return std::string ();
644
+ {
645
+ InspectOptions ctx_options;
646
+ ctx_options.detailed = true ;
647
+ ctx_options.indent_depth = options->indent_depth + 1 ;
648
+ std::string context_str = context.Inspect (&ctx_options, err);
649
+ if (err.Fail ()) return std::string ();
646
650
647
- if (!context_str.empty ()) res += " :" + context_str;
651
+ if (!context_str.empty ()) res += " :" + context_str;
652
+ }
648
653
649
654
if (options->print_source ) {
650
655
SharedFunctionInfo info = Info (err);
@@ -1215,6 +1220,12 @@ std::string HeapObject::Inspect(InspectOptions* options, Error& err) {
1215
1220
return pre + str.Inspect (options, err);
1216
1221
}
1217
1222
1223
+ if (type >= v8 ()->types ()->kFirstContextType &&
1224
+ type <= v8 ()->types ()->kLastContextType ) {
1225
+ Context ctx (this );
1226
+ return pre + ctx.Inspect (options, err);
1227
+ }
1228
+
1218
1229
if (type == v8 ()->types ()->kFixedArrayType ) {
1219
1230
FixedArray arr (this );
1220
1231
return pre + arr.Inspect (options, err);
@@ -1765,13 +1776,19 @@ HeapObject Context::GetScopeInfo(Error& err) {
1765
1776
return info.GetScopeInfo (err);
1766
1777
}
1767
1778
1768
- std::string Context::Inspect (Error& err) {
1779
+ std::string Context::Inspect (InspectOptions* options, Error& err) {
1769
1780
// Not enough postmortem information, return bare minimum
1770
1781
if (v8 ()->shared_info ()->kScopeInfoOffset == -1 &&
1771
1782
v8 ()->shared_info ()->kNameOrScopeInfoOffset == -1 )
1772
1783
return std::string ();
1773
1784
1774
- std::string res = " <Context: {\n " ;
1785
+ std::string res = " <Context" ;
1786
+
1787
+ if (!options->detailed ) {
1788
+ return res + " >" ;
1789
+ }
1790
+
1791
+ res += " : {\n " ;
1775
1792
1776
1793
Value previous = Previous (err);
1777
1794
if (err.Fail ()) return std::string ();
@@ -1788,12 +1805,10 @@ std::string Context::Inspect(Error& err) {
1788
1805
Smi local_count_smi = scope.ContextLocalCount (err);
1789
1806
if (err.Fail ()) return std::string ();
1790
1807
1791
- InspectOptions options;
1792
-
1793
1808
HeapObject heap_previous = HeapObject (previous);
1794
1809
if (heap_previous.Check ()) {
1795
1810
char tmp[128 ];
1796
- snprintf (tmp, sizeof (tmp), " (previous)=0x%016" PRIx64, previous.raw ());
1811
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (previous)=0x%016" PRIx64). c_str () , previous.raw ());
1797
1812
res += std::string (tmp) + " :<Context>," ;
1798
1813
}
1799
1814
@@ -1803,16 +1818,16 @@ std::string Context::Inspect(Error& err) {
1803
1818
JSFunction closure = Closure (err);
1804
1819
if (err.Fail ()) return std::string ();
1805
1820
char tmp[128 ];
1806
- snprintf (tmp, sizeof (tmp), " (closure)=0x%016" PRIx64 " {" ,
1821
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (closure)=0x%016" PRIx64 " {" ). c_str () ,
1807
1822
closure.raw ());
1808
1823
res += tmp;
1809
1824
1810
- InspectOptions options ;
1811
- res += closure.Inspect (&options , err) + " }" ;
1825
+ InspectOptions closure_options ;
1826
+ res += closure.Inspect (&closure_options , err) + " }" ;
1812
1827
if (err.Fail ()) return std::string ();
1813
1828
} else {
1814
1829
char tmp[128 ];
1815
- snprintf (tmp, sizeof (tmp), " (scope_info)=0x%016" PRIx64,
1830
+ snprintf (tmp, sizeof (tmp), (options-> get_indent_spaces () + " (scope_info)=0x%016" PRIx64). c_str () ,
1816
1831
scope.raw ());
1817
1832
1818
1833
res += std::string (tmp) + " :<ScopeInfo" ;
@@ -1836,17 +1851,18 @@ std::string Context::Inspect(Error& err) {
1836
1851
1837
1852
if (!res.empty ()) res += " ,\n " ;
1838
1853
1839
- res += " " + name.ToString (err) + " =" ;
1854
+ res += options-> get_indent_spaces () + name.ToString (err) + " =" ;
1840
1855
if (err.Fail ()) return std::string ();
1841
1856
1842
1857
Value value = ContextSlot (i, err);
1843
1858
if (err.Fail ()) return std::string ();
1844
1859
1845
- res += value.Inspect (&options, err);
1860
+ InspectOptions val_options;
1861
+ res += value.Inspect (&val_options, err);
1846
1862
if (err.Fail ()) return std::string ();
1847
1863
}
1848
1864
1849
- return res + " }>" ;
1865
+ return res + " }>" ;
1850
1866
}
1851
1867
1852
1868
context_t * Context::InspectX (Error& err) {
0 commit comments