DiagObjectModel.cpp 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeDebugPch.h"
  6. // Parser includes
  7. #include "CharClassifier.h"
  8. // TODO: clean up the need of these regex related header here just for GroupInfo needed in JavascriptRegExpConstructor
  9. #include "RegexCommon.h"
  10. // Runtime includes
  11. #include "Library\ObjectPrototypeObject.h"
  12. #include "Library\JavascriptNumberObject.h"
  13. #include "Library\BoundFunction.h"
  14. #include "Library\JavascriptRegExpConstructor.h"
  15. #include "Library\SameValueComparer.h"
  16. #include "Library\MapOrSetDataList.h"
  17. #include "Library\JavascriptProxy.h"
  18. #include "Library\JavascriptMap.h"
  19. #include "Library\JavascriptSet.h"
  20. #include "Library\JavascriptWeakMap.h"
  21. #include "Library\JavascriptWeakSet.h"
  22. #include "Library\ArgumentsObject.h"
  23. #include "Types\DynamicObjectEnumerator.h"
  24. #include "Types\DynamicObjectSnapshotEnumerator.h"
  25. #include "Types\DynamicObjectSnapshotEnumeratorWPCache.h"
  26. #include "Library\ForInObjectEnumerator.h"
  27. #include "Library\ES5Array.h"
  28. // Other includes
  29. #include <shlwapi.h>
  30. #include <strsafe.h>
  31. namespace Js
  32. {
  33. #define RETURN_VALUE_MAX_NAME 255
  34. #define PENDING_MUTATION_VALUE_MAX_NAME 255
  35. //
  36. // Some helper routines
  37. int __cdecl ElementsComparer(__in void* context, __in const void* item1, __in const void* item2)
  38. {
  39. ScriptContext *scriptContext = (ScriptContext *)context;
  40. Assert(scriptContext);
  41. const DWORD_PTR *p1 = reinterpret_cast<const DWORD_PTR*>(item1);
  42. const DWORD_PTR *p2 = reinterpret_cast<const DWORD_PTR*>(item2);
  43. DebuggerPropertyDisplayInfo * pPVItem1 = (DebuggerPropertyDisplayInfo *)(*p1);
  44. DebuggerPropertyDisplayInfo * pPVItem2 = (DebuggerPropertyDisplayInfo *)(*p2);
  45. const Js::PropertyRecord *propertyRecord1 = scriptContext->GetPropertyName(pPVItem1->propId);
  46. const Js::PropertyRecord *propertyRecord2 = scriptContext->GetPropertyName(pPVItem2->propId);
  47. const wchar_t *str1 = propertyRecord1->GetBuffer();
  48. const wchar_t *str2 = propertyRecord2->GetBuffer();
  49. // Do the natural comparison, for example test2 comes before test11.
  50. return StrCmpLogicalW(str1, str2);
  51. }
  52. ArenaAllocator *GetArenaFromContext(ScriptContext *scriptContext)
  53. {
  54. Assert(scriptContext);
  55. return scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena()->Arena();
  56. }
  57. template <class T>
  58. WeakArenaReference<IDiagObjectModelWalkerBase>* CreateAWalker(ScriptContext * scriptContext, Var instance, Var originalInstance)
  59. {
  60. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  61. if (pRefArena)
  62. {
  63. IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), T, scriptContext, instance, originalInstance);
  64. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
  65. }
  66. return nullptr;
  67. }
  68. //-----------------------
  69. // ResolvedObject
  70. WeakArenaReference<IDiagObjectModelDisplay>* ResolvedObject::GetObjectDisplay()
  71. {
  72. AssertMsg(typeId != TypeIds_HostDispatch, "Bad usage of ResolvedObject::GetObjectDisplay");
  73. IDiagObjectModelDisplay* pOMDisplay = (this->objectDisplay != nullptr) ? this->objectDisplay : CreateDisplay();
  74. Assert(pOMDisplay);
  75. return HeapNew(WeakArenaReference<IDiagObjectModelDisplay>, scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena(), pOMDisplay);
  76. }
  77. IDiagObjectModelDisplay * ResolvedObject::CreateDisplay()
  78. {
  79. IDiagObjectModelDisplay* pOMDisplay = nullptr;
  80. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  81. if (Js::TypedArrayBase::Is(obj))
  82. {
  83. pOMDisplay = Anew(pRefArena->Arena(), RecyclableTypedArrayDisplay, this);
  84. }
  85. else if (Js::ES5Array::Is(obj))
  86. {
  87. pOMDisplay = Anew(pRefArena->Arena(), RecyclableES5ArrayDisplay, this);
  88. }
  89. else if (Js::JavascriptArray::Is(obj))
  90. {
  91. // DisableJIT-TODO: Review- is this correct?
  92. #if ENABLE_COPYONACCESS_ARRAY
  93. // Make sure any NativeIntArrays are converted
  94. Js::JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(obj);
  95. #endif
  96. pOMDisplay = Anew(pRefArena->Arena(), RecyclableArrayDisplay, this);
  97. }
  98. else
  99. {
  100. pOMDisplay = Anew(pRefArena->Arena(), RecyclableObjectDisplay, this);
  101. }
  102. if (this->isConst || this->propId == Js::PropertyIds::_superReferenceSymbol || this->propId == Js::PropertyIds::_superCtorReferenceSymbol)
  103. {
  104. pOMDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY);
  105. }
  106. return pOMDisplay;
  107. }
  108. bool ResolvedObject::IsInDeadZone() const
  109. {
  110. Assert(scriptContext);
  111. return this->obj == scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
  112. }
  113. //-----------------------
  114. // LocalsDisplay
  115. LocalsDisplay::LocalsDisplay(DiagStackFrame* _frame)
  116. : pFrame(_frame)
  117. {
  118. }
  119. LPCWSTR LocalsDisplay::Name()
  120. {
  121. return L"Locals";
  122. }
  123. LPCWSTR LocalsDisplay::Type()
  124. {
  125. return L"";
  126. }
  127. LPCWSTR LocalsDisplay::Value(int radix)
  128. {
  129. return L"Locals";
  130. }
  131. BOOL LocalsDisplay::HasChildren()
  132. {
  133. Js::JavascriptFunction* func = pFrame->GetJavascriptFunction();
  134. FunctionBody* function = func->GetFunctionBody();
  135. return function && function->GetLocalsCount() != 0;
  136. }
  137. DBGPROP_ATTRIB_FLAGS LocalsDisplay::GetTypeAttribute()
  138. {
  139. return DBGPROP_ATTRIB_NO_ATTRIB;
  140. }
  141. BOOL LocalsDisplay::Set(Var updateObject)
  142. {
  143. // This is the hidden root object for Locals it doesn't get updated.
  144. return FALSE;
  145. }
  146. WeakArenaReference<IDiagObjectModelWalkerBase>* LocalsDisplay::CreateWalker()
  147. {
  148. ReferencedArenaAdapter* pRefArena = pFrame->GetScriptContext()->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  149. if (pRefArena)
  150. {
  151. IDiagObjectModelWalkerBase * pOMWalker = nullptr;
  152. BEGIN_JS_RUNTIME_CALL_EX(pFrame->GetScriptContext(), false);
  153. {
  154. IGNORE_STACKWALK_EXCEPTION(scriptContext);
  155. pOMWalker = Anew(pRefArena->Arena(), LocalsWalker, pFrame, FrameWalkerFlags::FW_MakeGroups);
  156. }
  157. END_JS_RUNTIME_CALL(scriptContext);
  158. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
  159. }
  160. return nullptr;
  161. }
  162. // Variables on the scope or in current function.
  163. /*static*/
  164. BOOL VariableWalkerBase::GetExceptionObject(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
  165. {
  166. Assert(pResolvedObject);
  167. Assert(pResolvedObject->scriptContext);
  168. Assert(frame);
  169. Assert(index >= 0);
  170. if (HasExceptionObject(frame))
  171. {
  172. if (index == 0)
  173. {
  174. pResolvedObject->name = L"{exception}";
  175. pResolvedObject->typeId = TypeIds_Error;
  176. pResolvedObject->address = nullptr;
  177. pResolvedObject->obj = pResolvedObject->scriptContext->GetDebugContext()->GetProbeContainer()->GetExceptionObject();
  178. if (pResolvedObject->obj == nullptr)
  179. {
  180. Assert(false);
  181. pResolvedObject->obj = pResolvedObject->scriptContext->GetLibrary()->GetUndefined();
  182. }
  183. return TRUE;
  184. }
  185. // Adjust the index
  186. index -= 1;
  187. }
  188. return FALSE;
  189. }
  190. /*static*/
  191. bool VariableWalkerBase::HasExceptionObject(DiagStackFrame* frame)
  192. {
  193. Assert(frame);
  194. Assert(frame->GetScriptContext());
  195. return frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetExceptionObject() != nullptr;
  196. }
  197. /*static*/
  198. BOOL VariableWalkerBase::GetReturnedValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
  199. {
  200. Assert(pResolvedObject);
  201. Assert(pResolvedObject->scriptContext);
  202. Assert(frame);
  203. Assert(index >= 0);
  204. ReturnedValueList *returnedValueList = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetReturnedValueList();
  205. if (returnedValueList != nullptr && returnedValueList->Count() > 0 && frame->IsTopFrame())
  206. {
  207. if (index < returnedValueList->Count())
  208. {
  209. DBGPROP_ATTRIB_FLAGS defaultAttributes = DBGPROP_ATTRIB_VALUE_IS_RETURN_VALUE | DBGPROP_ATTRIB_VALUE_IS_FAKE;
  210. WCHAR * finalName = AnewArray(GetArenaFromContext(pResolvedObject->scriptContext), WCHAR, RETURN_VALUE_MAX_NAME);
  211. ReturnedValue * returnValue = returnedValueList->Item(index);
  212. if (returnValue->isValueOfReturnStatement)
  213. {
  214. swprintf_s(finalName, RETURN_VALUE_MAX_NAME, L"[Return value]");
  215. pResolvedObject->obj = frame->GetRegValue(Js::FunctionBody::ReturnValueRegSlot);
  216. pResolvedObject->address = Anew(frame->GetArena(), LocalObjectAddressForRegSlot, frame, Js::FunctionBody::ReturnValueRegSlot, pResolvedObject->obj);
  217. }
  218. else
  219. {
  220. if (returnValue->calledFunction->IsScriptFunction())
  221. {
  222. swprintf_s(finalName, RETURN_VALUE_MAX_NAME, L"[%s returned]", returnValue->calledFunction->GetFunctionBody()->GetDisplayName());
  223. }
  224. else
  225. {
  226. Js::JavascriptString *builtInName = returnValue->calledFunction->GetDisplayName();
  227. swprintf_s(finalName, RETURN_VALUE_MAX_NAME, L"[%s returned]", builtInName->GetSz());
  228. }
  229. pResolvedObject->obj = returnValue->returnedValue;
  230. defaultAttributes |= DBGPROP_ATTRIB_VALUE_READONLY;
  231. pResolvedObject->address = nullptr;
  232. }
  233. Assert(pResolvedObject->obj != nullptr);
  234. pResolvedObject->name = finalName;
  235. pResolvedObject->typeId = TypeIds_Object;
  236. pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
  237. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(defaultAttributes);
  238. return TRUE;
  239. }
  240. // Adjust the index
  241. index -= returnedValueList->Count();
  242. }
  243. return FALSE;
  244. }
  245. /*static*/
  246. int VariableWalkerBase::GetReturnedValueCount(DiagStackFrame* frame)
  247. {
  248. Assert(frame);
  249. Assert(frame->GetScriptContext());
  250. ReturnedValueList *returnedValueList = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetReturnedValueList();
  251. return returnedValueList != nullptr && frame->IsTopFrame() ? returnedValueList->Count() : 0;
  252. }
  253. #ifdef ENABLE_MUTATION_BREAKPOINT
  254. BOOL VariableWalkerBase::GetBreakMutationBreakpointValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
  255. {
  256. Assert(pResolvedObject);
  257. Assert(pResolvedObject->scriptContext);
  258. Assert(frame);
  259. Assert(index >= 0);
  260. Js::MutationBreakpoint *mutationBreakpoint = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint();
  261. if (mutationBreakpoint != nullptr)
  262. {
  263. if (index == 0)
  264. {
  265. pResolvedObject->name = L"[Pending Mutation]";
  266. pResolvedObject->typeId = TypeIds_Object;
  267. pResolvedObject->address = nullptr;
  268. pResolvedObject->obj = mutationBreakpoint->GetMutationObjectVar();
  269. ReferencedArenaAdapter* pRefArena = pResolvedObject->scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  270. pResolvedObject->objectDisplay = Anew(pRefArena->Arena(), PendingMutationBreakpointDisplay, pResolvedObject, mutationBreakpoint->GetBreakMutationType());
  271. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_PENDING_MUTATION | DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  272. return TRUE;
  273. }
  274. index -= 1; // Adjust the index
  275. }
  276. return FALSE;
  277. }
  278. uint VariableWalkerBase::GetBreakMutationBreakpointsCount(DiagStackFrame* frame)
  279. {
  280. Assert(frame);
  281. Assert(frame->GetScriptContext());
  282. return frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint() != nullptr ? 1 : 0;
  283. }
  284. #endif
  285. BOOL VariableWalkerBase::Get(int i, ResolvedObject* pResolvedObject)
  286. {
  287. AssertMsg(pResolvedObject, "Bad usage of VariableWalkerBase::Get");
  288. Assert(pFrame);
  289. pResolvedObject->scriptContext = pFrame->GetScriptContext();
  290. if (i < 0)
  291. {
  292. return FALSE;
  293. }
  294. if (GetMemberCount() > i)
  295. {
  296. pResolvedObject->propId = pMembersList->Item(i)->propId;
  297. Assert(pResolvedObject->propId != Js::Constants::NoProperty);
  298. Assert(!Js::IsInternalPropertyId(pResolvedObject->propId));
  299. if (pResolvedObject->propId == Js::PropertyIds::_superReferenceSymbol || pResolvedObject->propId == Js::PropertyIds::_superCtorReferenceSymbol)
  300. {
  301. pResolvedObject->name = L"super";
  302. }
  303. else
  304. {
  305. const Js::PropertyRecord* propertyRecord = pResolvedObject->scriptContext->GetPropertyName(pResolvedObject->propId);
  306. pResolvedObject->name = propertyRecord->GetBuffer();
  307. }
  308. pResolvedObject->obj = GetVarObjectAt(i);
  309. Assert(pResolvedObject->obj);
  310. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  311. pResolvedObject->address = GetObjectAddress(i);
  312. pResolvedObject->isConst = IsConstAt(i);
  313. pResolvedObject->objectDisplay = nullptr;
  314. return TRUE;
  315. }
  316. return FALSE;
  317. }
  318. Var VariableWalkerBase::GetVarObjectAt(int index)
  319. {
  320. Assert(index < pMembersList->Count());
  321. return pMembersList->Item(index)->aVar;
  322. }
  323. bool VariableWalkerBase::IsConstAt(int index)
  324. {
  325. Assert(index < pMembersList->Count());
  326. DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
  327. // Dead zone variables are also displayed as read only.
  328. return displayInfo->IsConst() || displayInfo->IsInDeadZone();
  329. }
  330. ulong VariableWalkerBase::GetChildrenCount()
  331. {
  332. PopulateMembers();
  333. return GetMemberCount();
  334. }
  335. BOOL VariableWalkerBase::GetGroupObject(ResolvedObject* pResolvedObject)
  336. {
  337. if (!IsInGroup()) return FALSE;
  338. Assert(pResolvedObject);
  339. // This is fake [Methods] object.
  340. pResolvedObject->name = groupType == UIGroupType_Scope ? L"[Scope]" : L"[Globals]";
  341. pResolvedObject->obj = Js::RecyclableObject::FromVar(instance);
  342. pResolvedObject->typeId = TypeIds_Function;
  343. pResolvedObject->address = nullptr; // Scope object should not be editable
  344. ArenaAllocator *arena = GetArenaFromContext(pResolvedObject->scriptContext);
  345. Assert(arena);
  346. if (groupType == UIGroupType_Scope)
  347. {
  348. pResolvedObject->objectDisplay = Anew(arena, ScopeVariablesGroupDisplay, this, pResolvedObject);
  349. }
  350. else
  351. {
  352. pResolvedObject->objectDisplay = Anew(arena, GlobalsScopeVariablesGroupDisplay, this, pResolvedObject);
  353. }
  354. return TRUE;
  355. }
  356. IDiagObjectAddress *VariableWalkerBase::FindPropertyAddress(PropertyId propId, bool& isConst)
  357. {
  358. PopulateMembers();
  359. if (pMembersList)
  360. {
  361. for (int i = 0; i < pMembersList->Count(); i++)
  362. {
  363. DebuggerPropertyDisplayInfo *pair = pMembersList->Item(i);
  364. Assert(pair);
  365. if (pair->propId == propId)
  366. {
  367. isConst = pair->IsConst();
  368. return GetObjectAddress(i);
  369. }
  370. }
  371. }
  372. return nullptr;
  373. }
  374. // Determines if the given property is valid for display in the locals window.
  375. // Cases in which the property is valid are:
  376. // 1. It is not represented by an internal property.
  377. // 2. It is a var property.
  378. // 3. It is a let/const property in scope and is not in a dead zone (assuming isInDeadZone is nullptr).
  379. // (Determines if the given property is currently in block scope and not in a dead zone.)
  380. bool VariableWalkerBase::IsPropertyValid(PropertyId propertyId, RegSlot location, bool *isPropertyInDebuggerScope, bool* isConst, bool* isInDeadZone) const
  381. {
  382. Assert(isPropertyInDebuggerScope);
  383. Assert(isConst);
  384. *isPropertyInDebuggerScope = false;
  385. // Default to writable (for the case of vars and internal properties).
  386. *isConst = false;
  387. if (!allowLexicalThis && propertyId == Js::PropertyIds::_lexicalThisSlotSymbol)
  388. {
  389. return false;
  390. }
  391. if (!allowSuperReference && (propertyId == Js::PropertyIds::_superReferenceSymbol || propertyId == Js::PropertyIds::_superCtorReferenceSymbol))
  392. {
  393. return false;
  394. }
  395. if (Js::IsInternalPropertyId(propertyId))
  396. {
  397. return false;
  398. }
  399. Assert(pFrame);
  400. Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
  401. if (pFBody && pFBody->GetScopeObjectChain())
  402. {
  403. int offset = GetAdjustedByteCodeOffset();
  404. if (pFBody->GetScopeObjectChain()->TryGetDebuggerScopePropertyInfo(
  405. propertyId,
  406. location,
  407. offset,
  408. isPropertyInDebuggerScope,
  409. isConst,
  410. isInDeadZone))
  411. {
  412. return true;
  413. }
  414. }
  415. // If the register was not found in any scopes, then it's a var and should be in scope.
  416. return !*isPropertyInDebuggerScope;
  417. }
  418. // Gets an adjusted offset for the current bytecode location based on which stack frame we're in.
  419. // If we're in the top frame (leaf node), then the byte code offset should remain as is, to reflect
  420. // the current position of the instruction pointer. If we're not in the top frame, we need to subtract
  421. // 1 as the byte code location will be placed at the next statement to be executed at the top frame.
  422. // In the case of block scoping, this is an inaccurate location for viewing variables since the next
  423. // statement could be beyond the current block scope. For inspection, we want to remain in the
  424. // current block that the function was called from.
  425. // An example is this:
  426. // function foo() { ... } // Frame 0 (with breakpoint inside)
  427. // function bar() { // Frame 1
  428. // {
  429. // let a = 0;
  430. // foo(); // <-- Inspecting here, foo is already evaluated.
  431. // }
  432. // foo(); // <-- Byte code offset is now here, so we need to -1 to get back in the block scope.
  433. int VariableWalkerBase::GetAdjustedByteCodeOffset() const
  434. {
  435. Assert(pFrame);
  436. int offset = pFrame->GetByteCodeOffset();
  437. if (!pFrame->IsTopFrame() && pFrame->IsInterpreterFrame())
  438. {
  439. // Native frames are already adjusted so just need to adjust interpreted
  440. // frames that are not the top frame.
  441. --offset;
  442. }
  443. return offset;
  444. }
  445. // Allocates and returns a property display info.
  446. DebuggerPropertyDisplayInfo* VariableWalkerBase::AllocateNewPropertyDisplayInfo(PropertyId propertyId, Var value, bool isConst, bool isInDeadZone)
  447. {
  448. Assert(pFrame);
  449. Assert(value);
  450. Assert(isInDeadZone || !pFrame->GetScriptContext()->IsUndeclBlockVar(value));
  451. DWORD flags = DebuggerPropertyDisplayInfoFlags_None;
  452. flags |= isConst ? DebuggerPropertyDisplayInfoFlags_Const : 0;
  453. flags |= isInDeadZone ? DebuggerPropertyDisplayInfoFlags_InDeadZone : 0;
  454. ArenaAllocator *arena = pFrame->GetArena();
  455. if (isInDeadZone)
  456. {
  457. value = pFrame->GetScriptContext()->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
  458. }
  459. return Anew(arena, DebuggerPropertyDisplayInfo, propertyId, value, flags);
  460. }
  461. /// Slot array
  462. void SlotArrayVariablesWalker::PopulateMembers()
  463. {
  464. if (pMembersList == nullptr && instance != nullptr)
  465. {
  466. ArenaAllocator *arena = pFrame->GetArena();
  467. ScopeSlots slotArray = GetSlotArray();
  468. if (slotArray.IsFunctionScopeSlotArray())
  469. {
  470. Js::FunctionBody *pFBody = slotArray.GetFunctionBody();
  471. if (pFBody->GetPropertyIdsForScopeSlotArray() != nullptr)
  472. {
  473. uint slotArrayCount = slotArray.GetCount();
  474. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, slotArrayCount);
  475. for (ulong i = 0; i < slotArrayCount; i++)
  476. {
  477. Js::PropertyId propertyId = pFBody->GetPropertyIdsForScopeSlotArray()[i];
  478. bool isConst = false;
  479. bool isPropertyInDebuggerScope = false;
  480. bool isInDeadZone = false;
  481. if (propertyId != Js::Constants::NoProperty && IsPropertyValid(propertyId, i, &isPropertyInDebuggerScope, &isConst, &isInDeadZone))
  482. {
  483. Var value = slotArray.Get(i);
  484. if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
  485. {
  486. isInDeadZone = true;
  487. }
  488. DebuggerPropertyDisplayInfo *pair = AllocateNewPropertyDisplayInfo(
  489. propertyId,
  490. value,
  491. isConst,
  492. isInDeadZone);
  493. Assert(pair != nullptr);
  494. pMembersList->Add(pair);
  495. }
  496. }
  497. }
  498. }
  499. else
  500. {
  501. DebuggerScope* debuggerScope = slotArray.GetDebuggerScope();
  502. AssertMsg(debuggerScope, "Slot array debugger scope is missing but should be created.");
  503. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
  504. if (debuggerScope->HasProperties())
  505. {
  506. debuggerScope->scopeProperties->Map([&] (int i, Js::DebuggerScopeProperty& scopeProperty)
  507. {
  508. Var value = slotArray.Get(scopeProperty.location);
  509. bool isConst = scopeProperty.IsConst();
  510. bool isInDeadZone = false;
  511. if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
  512. {
  513. isInDeadZone = true;
  514. }
  515. DebuggerPropertyDisplayInfo *pair = AllocateNewPropertyDisplayInfo(
  516. scopeProperty.propId,
  517. value,
  518. isConst,
  519. isInDeadZone);
  520. Assert(pair != nullptr);
  521. pMembersList->Add(pair);
  522. });
  523. }
  524. }
  525. }
  526. }
  527. IDiagObjectAddress * SlotArrayVariablesWalker::GetObjectAddress(int index)
  528. {
  529. Assert(index < pMembersList->Count());
  530. ScopeSlots slotArray = GetSlotArray();
  531. return Anew(pFrame->GetArena(), LocalObjectAddressForSlot, slotArray, index, pMembersList->Item(index)->aVar);
  532. }
  533. // Regslot
  534. void RegSlotVariablesWalker::PopulateMembers()
  535. {
  536. if (pMembersList == nullptr)
  537. {
  538. Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
  539. ArenaAllocator *arena = pFrame->GetArena();
  540. PropertyIdOnRegSlotsContainer *propIdContainer = pFBody->GetPropertyIdOnRegSlotsContainer();
  541. // this container can be nullptr if there is no locals in current function.
  542. if (propIdContainer != nullptr)
  543. {
  544. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
  545. for (uint i = 0; i < propIdContainer->length; i++)
  546. {
  547. Js::PropertyId propertyId;
  548. RegSlot reg;
  549. propIdContainer->FetchItemAt(i, pFBody, &propertyId, &reg);
  550. bool shouldInsert = false;
  551. bool isConst = false;
  552. bool isInDeadZone = false;
  553. if (this->debuggerScope)
  554. {
  555. DebuggerScopeProperty debuggerScopeProperty;
  556. if (this->debuggerScope->TryGetValidProperty(propertyId, reg, GetAdjustedByteCodeOffset(), &debuggerScopeProperty, &isInDeadZone))
  557. {
  558. isConst = debuggerScopeProperty.IsConst();
  559. shouldInsert = true;
  560. }
  561. }
  562. else
  563. {
  564. bool isPropertyInDebuggerScope = false;
  565. shouldInsert = IsPropertyValid(propertyId, reg, &isPropertyInDebuggerScope, &isConst, &isInDeadZone) && !isPropertyInDebuggerScope;
  566. }
  567. if (shouldInsert)
  568. {
  569. Var value = pFrame->GetRegValue(reg);
  570. // If the user didn't supply an arguments object, a fake one will
  571. // be created when evaluating LocalsWalker::ShouldInsertFakeArguments().
  572. if (!(propertyId == PropertyIds::arguments && value == nullptr))
  573. {
  574. if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
  575. {
  576. isInDeadZone = true;
  577. }
  578. DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(
  579. propertyId,
  580. (Var)reg,
  581. isConst,
  582. isInDeadZone);
  583. Assert(info != nullptr);
  584. pMembersList->Add(info);
  585. }
  586. }
  587. }
  588. }
  589. }
  590. }
  591. Var RegSlotVariablesWalker::GetVarObjectAndRegAt(int index, RegSlot* reg /*= nullptr*/)
  592. {
  593. Assert(index < pMembersList->Count());
  594. Var returnedVar = nullptr;
  595. RegSlot returnedReg = Js::Constants::NoRegister;
  596. DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
  597. if (displayInfo->IsInDeadZone())
  598. {
  599. // The uninitialized string is already set in the var for the dead zone display.
  600. Assert(JavascriptString::Is(displayInfo->aVar));
  601. returnedVar = displayInfo->aVar;
  602. }
  603. else
  604. {
  605. returnedReg = ::Math::PointerCastToIntegral<RegSlot>(displayInfo->aVar);
  606. returnedVar = pFrame->GetRegValue(returnedReg);
  607. }
  608. if (reg != nullptr)
  609. {
  610. *reg = returnedReg;
  611. }
  612. AssertMsg(returnedVar, "Var should be replaced with the dead zone string object.");
  613. return returnedVar;
  614. }
  615. Var RegSlotVariablesWalker::GetVarObjectAt(int index)
  616. {
  617. return GetVarObjectAndRegAt(index);
  618. }
  619. IDiagObjectAddress * RegSlotVariablesWalker::GetObjectAddress(int index)
  620. {
  621. RegSlot reg = Js::Constants::NoRegister;
  622. Var obj = GetVarObjectAndRegAt(index, &reg);
  623. return Anew(pFrame->GetArena(), LocalObjectAddressForRegSlot, pFrame, reg, obj);
  624. }
  625. // For an activation object.
  626. void ObjectVariablesWalker::PopulateMembers()
  627. {
  628. if (pMembersList == nullptr && instance != nullptr)
  629. {
  630. ScriptContext * scriptContext = pFrame->GetScriptContext();
  631. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  632. Assert(Js::RecyclableObject::Is(instance));
  633. Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
  634. Assert(JavascriptOperators::IsObject(object));
  635. int count = object->GetPropertyCount();
  636. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, count);
  637. AddObjectProperties(count, object);
  638. }
  639. }
  640. void ObjectVariablesWalker::AddObjectProperties(int count, Js::RecyclableObject* object)
  641. {
  642. ScriptContext * scriptContext = pFrame->GetScriptContext();
  643. // For the scopes and locals only enumerable properties will be shown.
  644. for (int i = 0; i < count; i++)
  645. {
  646. Js::PropertyId propertyId = object->GetPropertyId((PropertyIndex)i);
  647. bool isConst = false;
  648. bool isPropertyInDebuggerScope = false;
  649. bool isInDeadZone = false;
  650. if (propertyId != Js::Constants::NoProperty
  651. && IsPropertyValid(propertyId, Js::Constants::NoRegister, &isPropertyInDebuggerScope, &isConst, &isInDeadZone)
  652. && object->IsEnumerable(propertyId))
  653. {
  654. Var itemObj = RecyclableObjectWalker::GetObject(object, object, propertyId, scriptContext);
  655. if (itemObj == nullptr)
  656. {
  657. itemObj = scriptContext->GetLibrary()->GetUndefined();
  658. }
  659. AssertMsg(!RootObjectBase::Is(object) || !isConst, "root object shouldn't produce const properties through IsPropertyValid");
  660. DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(
  661. propertyId,
  662. itemObj,
  663. isConst,
  664. isInDeadZone);
  665. Assert(info);
  666. pMembersList->Add(info);
  667. }
  668. }
  669. }
  670. IDiagObjectAddress * ObjectVariablesWalker::GetObjectAddress(int index)
  671. {
  672. Assert(index < pMembersList->Count());
  673. DebuggerPropertyDisplayInfo* info = pMembersList->Item(index);
  674. return Anew(pFrame->GetArena(), RecyclableObjectAddress, instance, info->propId, info->aVar, info->IsInDeadZone() ? TRUE : FALSE);
  675. }
  676. // For root access on the Global object (adds let/const variables before properties)
  677. void RootObjectVariablesWalker::PopulateMembers()
  678. {
  679. if (pMembersList == nullptr && instance != nullptr)
  680. {
  681. ScriptContext * scriptContext = pFrame->GetScriptContext();
  682. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  683. Assert(Js::RootObjectBase::Is(instance));
  684. Js::RootObjectBase* object = Js::RootObjectBase::FromVar(instance);
  685. int count = object->GetPropertyCount();
  686. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, count);
  687. // Add let/const globals first so that they take precedence over the global properties. Then
  688. // VariableWalkerBase::FindPropertyAddress will correctly find let/const globals that shadow
  689. // global properties of the same name.
  690. object->MapLetConstGlobals([&](const PropertyRecord* propertyRecord, Var value, bool isConst) {
  691. if (!scriptContext->IsUndeclBlockVar(value))
  692. {
  693. // Let/const are always enumerable and valid
  694. DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(propertyRecord->GetPropertyId(), value, isConst, false /*isInDeadZone*/);
  695. pMembersList->Add(info);
  696. }
  697. });
  698. AddObjectProperties(count, object);
  699. }
  700. }
  701. // DiagScopeVariablesWalker
  702. DiagScopeVariablesWalker::DiagScopeVariablesWalker(DiagStackFrame* _pFrame, Var _instance, IDiagObjectModelWalkerBase* innerWalker)
  703. : VariableWalkerBase(_pFrame, _instance, UIGroupType_InnerScope, /* allowLexicalThis */ false)
  704. {
  705. ScriptContext * scriptContext = _pFrame->GetScriptContext();
  706. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  707. pDiagScopeObjects = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
  708. pDiagScopeObjects->Add(innerWalker);
  709. diagScopeVarCount = innerWalker->GetChildrenCount();
  710. scopeIsInitialized = true;
  711. }
  712. ulong DiagScopeVariablesWalker::GetChildrenCount()
  713. {
  714. if (scopeIsInitialized)
  715. {
  716. return diagScopeVarCount;
  717. }
  718. Assert(pFrame);
  719. Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
  720. if (pFBody->GetScopeObjectChain())
  721. {
  722. int bytecodeOffset = GetAdjustedByteCodeOffset();
  723. ScriptContext * scriptContext = pFrame->GetScriptContext();
  724. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  725. pDiagScopeObjects = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
  726. // Look for catch/with/block scopes which encompass current offset (skip block scopes as
  727. // they are only used for lookup within the RegSlotVariablesWalker).
  728. // Go the reverse way so that we find the innermost scope first;
  729. Js::ScopeObjectChain * pScopeObjectChain = pFBody->GetScopeObjectChain();
  730. for (int i = pScopeObjectChain->pScopeChain->Count() - 1 ; i >= 0; i--)
  731. {
  732. Js::DebuggerScope *debuggerScope = pScopeObjectChain->pScopeChain->Item(i);
  733. bool isScopeInRange = debuggerScope->IsOffsetInScope(bytecodeOffset);
  734. if (isScopeInRange && (debuggerScope->IsOwnScope() || debuggerScope->scopeType == DiagBlockScopeDirect))
  735. {
  736. switch (debuggerScope->scopeType)
  737. {
  738. case DiagWithScope:
  739. {
  740. if (enumWithScopeAlso)
  741. {
  742. RecyclableObjectWalker* recylableObjectWalker = Anew(arena, RecyclableObjectWalker, scriptContext,
  743. (Var)pFrame->GetRegValue(debuggerScope->GetLocation(), true));
  744. pDiagScopeObjects->Add(recylableObjectWalker);
  745. diagScopeVarCount += recylableObjectWalker->GetChildrenCount();
  746. }
  747. }
  748. break;
  749. case DiagCatchScopeDirect:
  750. case DiagCatchScopeInObject:
  751. {
  752. CatchScopeWalker* catchScopeWalker = Anew(arena, CatchScopeWalker, pFrame, debuggerScope);
  753. pDiagScopeObjects->Add(catchScopeWalker);
  754. diagScopeVarCount += catchScopeWalker->GetChildrenCount();
  755. }
  756. break;
  757. case DiagCatchScopeInSlot:
  758. case DiagBlockScopeInSlot:
  759. {
  760. SlotArrayVariablesWalker* blockScopeWalker = Anew(arena, SlotArrayVariablesWalker, pFrame,
  761. (Var)pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation()), UIGroupType_InnerScope, /* allowLexicalThis */ false);
  762. pDiagScopeObjects->Add(blockScopeWalker);
  763. diagScopeVarCount += blockScopeWalker->GetChildrenCount();
  764. }
  765. break;
  766. case DiagBlockScopeDirect:
  767. {
  768. RegSlotVariablesWalker *pObjWalker = Anew(arena, RegSlotVariablesWalker, pFrame, debuggerScope, UIGroupType_InnerScope);
  769. pDiagScopeObjects->Add(pObjWalker);
  770. diagScopeVarCount += pObjWalker->GetChildrenCount();
  771. }
  772. break;
  773. case DiagBlockScopeInObject:
  774. {
  775. ObjectVariablesWalker* objectVariablesWalker = Anew(arena, ObjectVariablesWalker, pFrame, pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation()), UIGroupType_InnerScope, /* allowLexicalThis */ false);
  776. pDiagScopeObjects->Add(objectVariablesWalker);
  777. diagScopeVarCount += objectVariablesWalker->GetChildrenCount();
  778. }
  779. break;
  780. default:
  781. Assert(false);
  782. }
  783. }
  784. }
  785. }
  786. scopeIsInitialized = true;
  787. return diagScopeVarCount;
  788. }
  789. BOOL DiagScopeVariablesWalker::Get(int i, ResolvedObject* pResolvedObject)
  790. {
  791. if (i >= 0 && i < (int)diagScopeVarCount)
  792. {
  793. for (int j = 0; j < pDiagScopeObjects->Count(); j++)
  794. {
  795. IDiagObjectModelWalkerBase *pObjWalker = pDiagScopeObjects->Item(j);
  796. if (i < (int)pObjWalker->GetChildrenCount())
  797. {
  798. return pObjWalker->Get(i, pResolvedObject);
  799. }
  800. i -= (int)pObjWalker->GetChildrenCount();
  801. Assert(i >=0);
  802. }
  803. }
  804. return FALSE;
  805. }
  806. IDiagObjectAddress * DiagScopeVariablesWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
  807. {
  808. IDiagObjectAddress * address = nullptr;
  809. // Ensure that children are fetched.
  810. GetChildrenCount();
  811. if (pDiagScopeObjects)
  812. {
  813. for (int j = 0; j < pDiagScopeObjects->Count(); j++)
  814. {
  815. IDiagObjectModelWalkerBase *pObjWalker = pDiagScopeObjects->Item(j);
  816. Assert(pObjWalker);
  817. address = pObjWalker->FindPropertyAddress(propId, isConst);
  818. if (address != nullptr)
  819. {
  820. break;
  821. }
  822. }
  823. }
  824. return address;
  825. }
  826. // Locals walker
  827. LocalsWalker::LocalsWalker(DiagStackFrame* _frame, DWORD _frameWalkerFlags)
  828. : pFrame(_frame), frameWalkerFlags(_frameWalkerFlags), pVarWalkers(nullptr), totalLocalsCount(0), hasUserNotDefinedArguments(false)
  829. {
  830. Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
  831. if (pFBody && !pFBody->GetUtf8SourceInfo()->GetIsLibraryCode())
  832. {
  833. // Allocate the container of all walkers.
  834. ArenaAllocator *arena = pFrame->GetArena();
  835. pVarWalkers = JsUtil::List<VariableWalkerBase *, ArenaAllocator>::New(arena);
  836. VariableWalkerBase *pVarWalker = nullptr;
  837. // Top most function will have one of these regslot, slotarray or activation object.
  838. FrameDisplay * pDisplay = pFrame->GetFrameDisplay();
  839. uint scopeCount = (uint)(pDisplay ? pDisplay->GetLength() : 0);
  840. uint nextStartIndex = 0;
  841. // Add the catch/with/block expression scope objects.
  842. if (pFBody->GetScopeObjectChain())
  843. {
  844. pVarWalkers->Add(Anew(arena, DiagScopeVariablesWalker, pFrame, nullptr, !!(frameWalkerFlags & FrameWalkerFlags::FW_EnumWithScopeAlso)));
  845. }
  846. // In the eval function, we will not show global items directly, instead they should go as a group node.
  847. bool shouldAddGlobalItemsDirectly = pFBody->GetIsGlobalFunc() && !pFBody->IsEval();
  848. if (shouldAddGlobalItemsDirectly)
  849. {
  850. // Global properties will be enumerated using RootObjectVariablesWalker
  851. pVarWalkers->Add(Anew(arena, RootObjectVariablesWalker, pFrame, pFrame->GetRootObject(), UIGroupType_None));
  852. }
  853. DWORD localsType = GetCurrentFramesLocalsType(pFrame);
  854. if (localsType & FramesLocalType::LocalType_Reg)
  855. {
  856. pVarWalkers->Add(Anew(arena, RegSlotVariablesWalker, pFrame, nullptr /*not debugger scope*/, UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
  857. }
  858. if (localsType & FramesLocalType::LocalType_InObject)
  859. {
  860. Assert(scopeCount > 0);
  861. pVarWalker = Anew(arena, ObjectVariablesWalker, pFrame, pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
  862. }
  863. else if (localsType & FramesLocalType::LocalType_InSlot)
  864. {
  865. Assert(scopeCount > 0);
  866. pVarWalker = Anew(arena, SlotArrayVariablesWalker, pFrame, (Js::Var *)pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
  867. }
  868. else if (scopeCount > 0 && pFBody->GetFrameDisplayRegister() != 0)
  869. {
  870. Assert((Var)pDisplay->GetItem(0) == pFrame->GetScriptContext()->GetLibrary()->GetNull());
  871. // A dummy scope with nullptr register is created. Skip this.
  872. nextStartIndex++;
  873. }
  874. if (pVarWalker)
  875. {
  876. pVarWalkers->Add(pVarWalker);
  877. }
  878. const Js::Var nullVar = pFrame->GetScriptContext()->GetLibrary()->GetNull();
  879. for (uint i = nextStartIndex; i < (uint)scopeCount; i++)
  880. {
  881. Var currentScopeObject = pDisplay->GetItem(i);
  882. if (currentScopeObject != nullptr && currentScopeObject != nullVar) // Skip nullptr (dummy scope)
  883. {
  884. ScopeType scopeType = FrameDisplay::GetScopeType(currentScopeObject);
  885. switch(scopeType)
  886. {
  887. case ScopeType_ActivationObject:
  888. pVarWalker = Anew(arena, ObjectVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
  889. pVarWalkers->Add(pVarWalker);
  890. break;
  891. case ScopeType_SlotArray:
  892. pVarWalker = Anew(arena, SlotArrayVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
  893. pVarWalkers->Add(pVarWalker);
  894. break;
  895. case ScopeType_WithScope:
  896. if( (frameWalkerFlags & FrameWalkerFlags::FW_EnumWithScopeAlso) == FrameWalkerFlags::FW_EnumWithScopeAlso)
  897. {
  898. RecyclableObjectWalker* withScopeWalker = Anew(arena, RecyclableObjectWalker, pFrame->GetScriptContext(), currentScopeObject);
  899. pVarWalker = Anew(arena, DiagScopeVariablesWalker, pFrame, currentScopeObject, withScopeWalker);
  900. pVarWalkers->Add(pVarWalker);
  901. }
  902. break;
  903. default:
  904. Assert(false);
  905. }
  906. }
  907. }
  908. // No need to add global properties if this is a global function, as it is already done above.
  909. if (!shouldAddGlobalItemsDirectly)
  910. {
  911. pVarWalker = Anew(arena, RootObjectVariablesWalker, pFrame, pFrame->GetRootObject(), UIGroupType_Globals);
  912. pVarWalkers->Add(pVarWalker);
  913. }
  914. }
  915. }
  916. BOOL LocalsWalker::CreateArgumentsObject(ResolvedObject* pResolvedObject)
  917. {
  918. Assert(pResolvedObject);
  919. Assert(pResolvedObject->scriptContext);
  920. Assert(hasUserNotDefinedArguments);
  921. pResolvedObject->name = L"arguments";
  922. pResolvedObject->propId = Js::PropertyIds::arguments;
  923. pResolvedObject->typeId = TypeIds_Arguments;
  924. Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
  925. Assert(pFBody);
  926. pResolvedObject->obj = pFrame->GetArgumentsObject();
  927. if (pResolvedObject->obj == nullptr)
  928. {
  929. pResolvedObject->obj = pFrame->CreateHeapArguments();
  930. Assert(pResolvedObject->obj);
  931. pResolvedObject->objectDisplay = Anew(pFrame->GetArena(), RecyclableArgumentsObjectDisplay, pResolvedObject, this);
  932. ExpandArgumentsObject(pResolvedObject->objectDisplay);
  933. }
  934. pResolvedObject->address = Anew(GetArenaFromContext(pResolvedObject->scriptContext),
  935. RecyclableObjectAddress,
  936. pResolvedObject->scriptContext->GetGlobalObject(),
  937. Js::PropertyIds::arguments,
  938. pResolvedObject->obj,
  939. false /*isInDeadZone*/);
  940. return TRUE;
  941. }
  942. BOOL LocalsWalker::Get(int i, ResolvedObject* pResolvedObject)
  943. {
  944. if (i >= (int)totalLocalsCount)
  945. {
  946. return FALSE;
  947. }
  948. pResolvedObject->scriptContext = pFrame->GetScriptContext();
  949. if (VariableWalkerBase::GetExceptionObject(i, pFrame, pResolvedObject))
  950. {
  951. return TRUE;
  952. }
  953. #ifdef ENABLE_MUTATION_BREAKPOINT
  954. // Pending mutation display should be before any return value
  955. if (VariableWalkerBase::GetBreakMutationBreakpointValue(i, pFrame, pResolvedObject))
  956. {
  957. return TRUE;
  958. }
  959. #endif
  960. if (VariableWalkerBase::GetReturnedValue(i, pFrame, pResolvedObject))
  961. {
  962. return TRUE;
  963. }
  964. if (hasUserNotDefinedArguments)
  965. {
  966. if (i == 0)
  967. {
  968. return CreateArgumentsObject(pResolvedObject);
  969. }
  970. i--;
  971. }
  972. if (!pVarWalkers || pVarWalkers->Count() == 0)
  973. {
  974. return FALSE;
  975. }
  976. // In the case of not making groups, all variables will be arranged
  977. // as one long list in the locals window.
  978. if (!ShouldMakeGroups())
  979. {
  980. for (int j = 0; j < pVarWalkers->Count(); j++)
  981. {
  982. int count = pVarWalkers->Item(j)->GetChildrenCount();
  983. if (i < count)
  984. {
  985. return pVarWalkers->Item(j)->Get(i, pResolvedObject);
  986. }
  987. i-= count;
  988. }
  989. Assert(FALSE);
  990. return FALSE;
  991. }
  992. int startScopeIndex = 0;
  993. // Need to determine what range of local variables we're in for the requested index.
  994. // Non-grouped local variables are organized with reg slot coming first, then followed by
  995. // scope slot/activation object variables. Catch and with variables follow next
  996. // and group variables are stored last which come from upper scopes that
  997. // are accessed in this function (those passed down as part of a closure).
  998. // Note that all/any/none of these walkers may be present.
  999. // Example variable layout:
  1000. // [0-2] - Reg slot vars.
  1001. // [3-4] - Scope slot array vars.
  1002. // [5-8] - Global vars (stored on the global object as properties).
  1003. for (int j = 0; j < pVarWalkers->Count(); ++j)
  1004. {
  1005. VariableWalkerBase *variableWalker = pVarWalkers->Item(j);
  1006. if (!variableWalker->IsInGroup())
  1007. {
  1008. int count = variableWalker->GetChildrenCount();
  1009. if (i < count)
  1010. {
  1011. return variableWalker->Get(i, pResolvedObject);
  1012. }
  1013. i-= count;
  1014. startScopeIndex++;
  1015. }
  1016. else
  1017. {
  1018. // We've finished with all walkers for the current locals level so
  1019. // break out in order to handle the groups.
  1020. break;
  1021. }
  1022. }
  1023. // Handle groups.
  1024. Assert((i + startScopeIndex) < pVarWalkers->Count());
  1025. VariableWalkerBase *variableWalker = pVarWalkers->Item(i + startScopeIndex);
  1026. return variableWalker->GetGroupObject(pResolvedObject);
  1027. }
  1028. bool LocalsWalker::ShouldInsertFakeArguments()
  1029. {
  1030. JavascriptFunction* func = pFrame->GetJavascriptFunction();
  1031. if (func->IsScriptFunction()
  1032. && !func->GetFunctionBody()->GetUtf8SourceInfo()->GetIsLibraryCode()
  1033. && !func->GetFunctionBody()->GetIsGlobalFunc())
  1034. {
  1035. bool isConst = false;
  1036. hasUserNotDefinedArguments = (nullptr == FindPropertyAddress(PropertyIds::arguments, false /*walkers on the current frame*/, isConst));
  1037. }
  1038. return hasUserNotDefinedArguments;
  1039. }
  1040. ulong LocalsWalker::GetChildrenCount()
  1041. {
  1042. if (totalLocalsCount == 0)
  1043. {
  1044. if (pVarWalkers)
  1045. {
  1046. int groupWalkersStartIndex = 0;
  1047. for (int i = 0; i < pVarWalkers->Count(); i++)
  1048. {
  1049. VariableWalkerBase* variableWalker = pVarWalkers->Item(i);
  1050. // In the case of making groups, we want to include any variables that aren't
  1051. // part of a group as part of the local variable count.
  1052. if (!ShouldMakeGroups() || !variableWalker->IsInGroup())
  1053. {
  1054. ++groupWalkersStartIndex;
  1055. totalLocalsCount += variableWalker->GetChildrenCount();
  1056. }
  1057. }
  1058. // Add on the number of groups to display in locals
  1059. // (group walkers come after function local walkers).
  1060. totalLocalsCount += (pVarWalkers->Count() - groupWalkersStartIndex);
  1061. }
  1062. if (VariableWalkerBase::HasExceptionObject(pFrame))
  1063. {
  1064. totalLocalsCount++;
  1065. }
  1066. #ifdef ENABLE_MUTATION_BREAKPOINT
  1067. totalLocalsCount += VariableWalkerBase::GetBreakMutationBreakpointsCount(pFrame);
  1068. #endif
  1069. totalLocalsCount += VariableWalkerBase::GetReturnedValueCount(pFrame);
  1070. // Check if needed to add fake arguments.
  1071. if (ShouldInsertFakeArguments())
  1072. {
  1073. // In this case we need to create arguments object explicitly.
  1074. totalLocalsCount++;
  1075. }
  1076. }
  1077. return totalLocalsCount;
  1078. }
  1079. /*static*/
  1080. DWORD LocalsWalker::GetCurrentFramesLocalsType(DiagStackFrame* frame)
  1081. {
  1082. Assert(frame);
  1083. FunctionBody *pFBody = frame->GetJavascriptFunction()->GetFunctionBody();
  1084. Assert(pFBody);
  1085. DWORD localType = FramesLocalType::LocalType_None;
  1086. if (pFBody->GetFrameDisplayRegister() != 0)
  1087. {
  1088. if (pFBody->GetObjectRegister() != 0)
  1089. {
  1090. // current scope is activation object
  1091. localType = FramesLocalType::LocalType_InObject;
  1092. }
  1093. else
  1094. {
  1095. if (pFBody->scopeSlotArraySize > 0)
  1096. {
  1097. localType = FramesLocalType::LocalType_InSlot;
  1098. }
  1099. }
  1100. }
  1101. if (pFBody->GetPropertyIdOnRegSlotsContainer() && pFBody->GetPropertyIdOnRegSlotsContainer()->length > 0)
  1102. {
  1103. localType |= FramesLocalType::LocalType_Reg;
  1104. }
  1105. return localType;
  1106. }
  1107. IDiagObjectAddress * LocalsWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
  1108. {
  1109. return FindPropertyAddress(propId, true, isConst);
  1110. }
  1111. IDiagObjectAddress * LocalsWalker::FindPropertyAddress(PropertyId propId, bool enumerateGroups, bool& isConst)
  1112. {
  1113. isConst = false;
  1114. if (propId == PropertyIds::arguments && hasUserNotDefinedArguments)
  1115. {
  1116. ResolvedObject resolveObject;
  1117. resolveObject.scriptContext = pFrame->GetScriptContext();
  1118. if (CreateArgumentsObject(&resolveObject))
  1119. {
  1120. return resolveObject.address;
  1121. }
  1122. }
  1123. if (pVarWalkers)
  1124. {
  1125. for (int i = 0; i < pVarWalkers->Count(); i++)
  1126. {
  1127. VariableWalkerBase *pVarWalker = pVarWalkers->Item(i);
  1128. if (!enumerateGroups && !pVarWalker->IsWalkerForCurrentFrame())
  1129. {
  1130. continue;
  1131. }
  1132. IDiagObjectAddress *address = pVarWalkers->Item(i)->FindPropertyAddress(propId, isConst);
  1133. if (address != nullptr)
  1134. {
  1135. return address;
  1136. }
  1137. }
  1138. }
  1139. return nullptr;
  1140. }
  1141. void LocalsWalker::ExpandArgumentsObject(IDiagObjectModelDisplay * argumentsDisplay)
  1142. {
  1143. Assert(argumentsDisplay != nullptr);
  1144. WeakArenaReference<Js::IDiagObjectModelWalkerBase>* argumentsObjectWalkerRef = argumentsDisplay->CreateWalker();
  1145. Assert(argumentsObjectWalkerRef != nullptr);
  1146. IDiagObjectModelWalkerBase * walker = argumentsObjectWalkerRef->GetStrongReference();
  1147. int count = (int)walker->GetChildrenCount();
  1148. Js::ResolvedObject tempResolvedObj;
  1149. for (int i = 0; i < count; i++)
  1150. {
  1151. walker->Get(i, &tempResolvedObj);
  1152. }
  1153. argumentsObjectWalkerRef->ReleaseStrongReference();
  1154. HeapDelete(argumentsObjectWalkerRef);
  1155. }
  1156. //--------------------------
  1157. // LocalObjectAddressForSlot
  1158. LocalObjectAddressForSlot::LocalObjectAddressForSlot(ScopeSlots _pSlotArray, int _slotIndex, Js::Var _value)
  1159. : slotArray(_pSlotArray),
  1160. slotIndex(_slotIndex),
  1161. value(_value)
  1162. {
  1163. }
  1164. BOOL LocalObjectAddressForSlot::Set(Var updateObject)
  1165. {
  1166. if (IsInDeadZone())
  1167. {
  1168. AssertMsg(FALSE, "Should not be able to set the value of a slot in a dead zone.");
  1169. return FALSE;
  1170. }
  1171. slotArray.Set(slotIndex, updateObject);
  1172. return TRUE;
  1173. }
  1174. Var LocalObjectAddressForSlot::GetValue(BOOL fUpdated)
  1175. {
  1176. if (!fUpdated || IsInDeadZone())
  1177. {
  1178. #if DBG
  1179. if (IsInDeadZone())
  1180. {
  1181. // If we're in a dead zone, the value will be the
  1182. // [Uninitialized block variable] string.
  1183. Assert(JavascriptString::Is(value));
  1184. }
  1185. #endif // DBG
  1186. return value;
  1187. }
  1188. return slotArray.Get(slotIndex);
  1189. }
  1190. BOOL LocalObjectAddressForSlot::IsInDeadZone() const
  1191. {
  1192. Var value = slotArray.Get(slotIndex);
  1193. if (!RecyclableObject::Is(value))
  1194. {
  1195. return FALSE;
  1196. }
  1197. RecyclableObject* obj = RecyclableObject::FromVar(value);
  1198. ScriptContext* scriptContext = obj->GetScriptContext();
  1199. return scriptContext->IsUndeclBlockVar(obj) ? TRUE : FALSE;
  1200. }
  1201. //--------------------------
  1202. // LocalObjectAddressForSlot
  1203. LocalObjectAddressForRegSlot::LocalObjectAddressForRegSlot(DiagStackFrame* _pFrame, RegSlot _regSlot, Js::Var _value)
  1204. : pFrame(_pFrame),
  1205. regSlot(_regSlot),
  1206. value(_value)
  1207. {
  1208. }
  1209. BOOL LocalObjectAddressForRegSlot::IsInDeadZone() const
  1210. {
  1211. return regSlot == Js::Constants::NoRegister;
  1212. }
  1213. BOOL LocalObjectAddressForRegSlot::Set(Var updateObject)
  1214. {
  1215. Assert(pFrame);
  1216. if (IsInDeadZone())
  1217. {
  1218. AssertMsg(FALSE, "Should not be able to set the value of a register in a dead zone.");
  1219. return FALSE;
  1220. }
  1221. pFrame->SetRegValue(regSlot, updateObject);
  1222. return TRUE;
  1223. }
  1224. Var LocalObjectAddressForRegSlot::GetValue(BOOL fUpdated)
  1225. {
  1226. if (!fUpdated || IsInDeadZone())
  1227. {
  1228. #if DBG
  1229. if (IsInDeadZone())
  1230. {
  1231. // If we're in a dead zone, the value will be the
  1232. // [Uninitialized block variable] string.
  1233. Assert(JavascriptString::Is(value));
  1234. }
  1235. #endif // DBG
  1236. return value;
  1237. }
  1238. Assert(pFrame);
  1239. return pFrame->GetRegValue(regSlot);
  1240. }
  1241. //
  1242. // CatchScopeWalker
  1243. BOOL CatchScopeWalker::Get(int i, ResolvedObject* pResolvedObject)
  1244. {
  1245. Assert(pResolvedObject);
  1246. Assert(pFrame);
  1247. pResolvedObject->scriptContext = pFrame->GetScriptContext();
  1248. Assert(i < (int)GetChildrenCount());
  1249. Js::DebuggerScopeProperty scopeProperty = debuggerScope->scopeProperties->Item(i);
  1250. pResolvedObject->propId = scopeProperty.propId;
  1251. const Js::PropertyRecord* propertyRecord = pResolvedObject->scriptContext->GetPropertyName(pResolvedObject->propId);
  1252. // TODO: If this is a symbol-keyed property, we should indicate that in the name - "Symbol (description)"
  1253. pResolvedObject->name = propertyRecord->GetBuffer();
  1254. FetchValueAndAddress(scopeProperty, &pResolvedObject->obj, &pResolvedObject->address);
  1255. Assert(pResolvedObject->obj);
  1256. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  1257. pResolvedObject->objectDisplay = Anew(pFrame->GetArena(), RecyclableObjectDisplay, pResolvedObject);
  1258. return TRUE;
  1259. }
  1260. ulong CatchScopeWalker::GetChildrenCount()
  1261. {
  1262. return debuggerScope->scopeProperties->Count();
  1263. }
  1264. void CatchScopeWalker::FetchValueAndAddress(DebuggerScopeProperty &scopeProperty, _Out_opt_ Var *pValue, _Out_opt_ IDiagObjectAddress ** ppAddress)
  1265. {
  1266. Assert(pValue != nullptr || ppAddress != nullptr);
  1267. ArenaAllocator* arena = pFrame->GetArena();
  1268. Var outValue;
  1269. IDiagObjectAddress * pAddress = nullptr;
  1270. ScriptContext* scriptContext = pFrame->GetScriptContext();
  1271. if (debuggerScope->scopeType == Js::DiagCatchScopeInObject)
  1272. {
  1273. Var obj = pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation());
  1274. Assert(RecyclableObject::Is(obj));
  1275. outValue = RecyclableObjectWalker::GetObject(RecyclableObject::FromVar(obj), RecyclableObject::FromVar(obj), scopeProperty.propId, scriptContext);
  1276. bool isInDeadZone = scriptContext->IsUndeclBlockVar(outValue);
  1277. if (isInDeadZone)
  1278. {
  1279. outValue = scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
  1280. }
  1281. pAddress = Anew(arena, RecyclableObjectAddress, obj, scopeProperty.propId, outValue, isInDeadZone);
  1282. }
  1283. else
  1284. {
  1285. outValue = pFrame->GetRegValue(scopeProperty.location);
  1286. bool isInDeadZone = scriptContext->IsUndeclBlockVar(outValue);
  1287. if (isInDeadZone)
  1288. {
  1289. outValue = scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
  1290. }
  1291. pAddress = Anew(arena, LocalObjectAddressForRegSlot, pFrame, scopeProperty.location, outValue);
  1292. }
  1293. if (pValue)
  1294. {
  1295. *pValue = outValue;
  1296. }
  1297. if (ppAddress)
  1298. {
  1299. *ppAddress = pAddress;
  1300. }
  1301. }
  1302. IDiagObjectAddress *CatchScopeWalker::FindPropertyAddress(PropertyId _propId, bool& isConst)
  1303. {
  1304. isConst = false;
  1305. IDiagObjectAddress * address = nullptr;
  1306. auto properties = debuggerScope->scopeProperties;
  1307. for (int i = 0; i < properties->Count(); i++)
  1308. {
  1309. if (properties->Item(i).propId == _propId)
  1310. {
  1311. FetchValueAndAddress(properties->Item(i), nullptr, &address);
  1312. break;
  1313. }
  1314. }
  1315. return address;
  1316. }
  1317. //--------------------------
  1318. // RecyclableObjectAddress
  1319. RecyclableObjectAddress::RecyclableObjectAddress(Var _parentObj, Js::PropertyId _propId, Js::Var _value, BOOL _isInDeadZone)
  1320. : parentObj(_parentObj),
  1321. propId(_propId),
  1322. value(_value),
  1323. isInDeadZone(_isInDeadZone)
  1324. {
  1325. parentObj = ((RecyclableObject*)parentObj)->GetThisObjectOrUnWrap();
  1326. }
  1327. BOOL RecyclableObjectAddress::IsInDeadZone() const
  1328. {
  1329. return isInDeadZone;
  1330. }
  1331. BOOL RecyclableObjectAddress::Set(Var updateObject)
  1332. {
  1333. if (Js::RecyclableObject::Is(parentObj))
  1334. {
  1335. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
  1336. ScriptContext* requestContext = obj->GetScriptContext(); //TODO: real requestContext
  1337. return Js::JavascriptOperators::SetProperty(obj, obj, propId, updateObject, requestContext);
  1338. }
  1339. return FALSE;
  1340. }
  1341. BOOL RecyclableObjectAddress::IsWritable()
  1342. {
  1343. if (Js::RecyclableObject::Is(parentObj))
  1344. {
  1345. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
  1346. return obj->IsWritable(propId);
  1347. }
  1348. return TRUE;
  1349. }
  1350. Var RecyclableObjectAddress::GetValue(BOOL fUpdated)
  1351. {
  1352. if (!fUpdated)
  1353. {
  1354. return value;
  1355. }
  1356. if (Js::RecyclableObject::Is(parentObj))
  1357. {
  1358. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
  1359. ScriptContext* requestContext = obj->GetScriptContext();
  1360. Var objValue = nullptr;
  1361. if (Js::JavascriptOperators::GetProperty(obj, propId, &objValue, requestContext))
  1362. {
  1363. return objValue;
  1364. }
  1365. }
  1366. return nullptr;
  1367. }
  1368. //--------------------------
  1369. // RecyclableObjectDisplay
  1370. RecyclableObjectDisplay::RecyclableObjectDisplay(ResolvedObject* resolvedObject, DBGPROP_ATTRIB_FLAGS defaultAttributes)
  1371. : scriptContext(resolvedObject->scriptContext),
  1372. instance(resolvedObject->obj),
  1373. originalInstance(resolvedObject->originalObj != nullptr ? resolvedObject->originalObj : resolvedObject->obj), // If we don't have it set it means originalInstance should point to object itself
  1374. name(resolvedObject->name),
  1375. pObjAddress(resolvedObject->address),
  1376. defaultAttributes(defaultAttributes),
  1377. propertyId(resolvedObject->propId)
  1378. {
  1379. }
  1380. bool RecyclableObjectDisplay::IsLiteralProperty() const
  1381. {
  1382. Assert(this->scriptContext);
  1383. if (this->propertyId != Constants::NoProperty)
  1384. {
  1385. Js::PropertyRecord const * propertyRecord = this->scriptContext->GetThreadContext()->GetPropertyName(this->propertyId);
  1386. const WCHAR* startOfPropertyName = propertyRecord->GetBuffer();
  1387. const WCHAR* endOfIdentifier = this->scriptContext->GetCharClassifier()->SkipIdentifier((LPCOLESTR)propertyRecord->GetBuffer());
  1388. return (charcount_t)(endOfIdentifier - startOfPropertyName) == propertyRecord->GetLength();
  1389. }
  1390. else
  1391. {
  1392. return true;
  1393. }
  1394. }
  1395. bool RecyclableObjectDisplay::IsSymbolProperty()
  1396. {
  1397. Assert(this->scriptContext);
  1398. if (this->propertyId != Constants::NoProperty)
  1399. {
  1400. Js::PropertyRecord const * propertyRecord = this->scriptContext->GetThreadContext()->GetPropertyName(this->propertyId);
  1401. return propertyRecord->IsSymbol();
  1402. }
  1403. return false;
  1404. }
  1405. LPCWSTR RecyclableObjectDisplay::Name()
  1406. {
  1407. return name;
  1408. }
  1409. LPCWSTR RecyclableObjectDisplay::Type()
  1410. {
  1411. LPCWSTR typeStr;
  1412. if(Js::TaggedInt::Is(instance) || Js::JavascriptNumber::Is(instance))
  1413. {
  1414. typeStr = L"Number";
  1415. }
  1416. else
  1417. {
  1418. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance);
  1419. StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  1420. builder->Reset();
  1421. // For the RecyclableObject try to find out the constructor, which will be shown as type for the object.
  1422. // This case is to handle the user defined function, built in objects have dedicated classes to handle.
  1423. Var value = nullptr;
  1424. TypeId typeId = obj->GetTypeId();
  1425. if (typeId == TypeIds_Object && GetPropertyWithScriptEnter(obj, obj, PropertyIds::constructor, &value, scriptContext))
  1426. {
  1427. builder->AppendCppLiteral(L"Object");
  1428. if (Js::JavascriptFunction::Is(value))
  1429. {
  1430. Js::JavascriptFunction *pfunction = Js::JavascriptFunction::FromVar(value);
  1431. // For an odd chance that the constructor wasn't called to create the object.
  1432. Js::ParseableFunctionInfo *pFuncBody = pfunction->GetFunctionProxy() != nullptr ? pfunction->GetFunctionProxy()->EnsureDeserialized() : nullptr;
  1433. if (pFuncBody)
  1434. {
  1435. const wchar_t* pDisplayName = pFuncBody->GetDisplayName();
  1436. if (pDisplayName)
  1437. {
  1438. builder->AppendCppLiteral(L", (");
  1439. builder->AppendSz(pDisplayName);
  1440. builder->Append(L')');
  1441. }
  1442. }
  1443. }
  1444. typeStr = builder->Detach();
  1445. }
  1446. else if (obj->GetDiagTypeString(builder, scriptContext))
  1447. {
  1448. typeStr = builder->Detach();
  1449. }
  1450. else
  1451. {
  1452. typeStr = L"Undefined";
  1453. }
  1454. }
  1455. return typeStr;
  1456. }
  1457. Var RecyclableObjectDisplay::GetVarValue(BOOL fUpdated)
  1458. {
  1459. if (pObjAddress)
  1460. {
  1461. return pObjAddress->GetValue(fUpdated);
  1462. }
  1463. return instance;
  1464. }
  1465. LPCWSTR RecyclableObjectDisplay::Value(int radix)
  1466. {
  1467. LPCWSTR valueStr = L"";
  1468. if(Js::TaggedInt::Is(instance)
  1469. || Js::JavascriptNumber::Is(instance)
  1470. || Js::JavascriptNumberObject::Is(instance)
  1471. || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number
  1472. || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number)
  1473. {
  1474. double value;
  1475. if (Js::TaggedInt::Is(instance))
  1476. {
  1477. value = TaggedInt::ToDouble(instance);
  1478. }
  1479. else if (Js::JavascriptNumber::Is(instance))
  1480. {
  1481. value = Js::JavascriptNumber::GetValue(instance);
  1482. }
  1483. else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number)
  1484. {
  1485. value = (double)JavascriptInt64Number::FromVar(instance)->GetValue();
  1486. }
  1487. else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number)
  1488. {
  1489. value = (double)JavascriptUInt64Number::FromVar(instance)->GetValue();
  1490. }
  1491. else
  1492. {
  1493. Js::JavascriptNumberObject* numobj = Js::JavascriptNumberObject::FromVar(instance);
  1494. value = numobj->GetValue();
  1495. }
  1496. // For fractional values, radix is ignored.
  1497. long l = (long)value;
  1498. bool isZero = JavascriptNumber::IsZero(value - (double)l);
  1499. if (radix == 10 || !isZero)
  1500. {
  1501. if (Js::JavascriptNumber::IsNegZero(value))
  1502. {
  1503. // In debugger, we wanted to show negative zero explicitly
  1504. valueStr = L"-0";
  1505. }
  1506. else
  1507. {
  1508. valueStr = Js::JavascriptNumber::ToStringRadix10(value, scriptContext)->GetSz();
  1509. }
  1510. }
  1511. else if (radix >= 2 && radix <= 36)
  1512. {
  1513. if (radix == 16)
  1514. {
  1515. if (value < 0)
  1516. {
  1517. // On the tools side we show unsigned value.
  1518. ulong ul = (ulong)(long)value; // ARM: casting negative value to ulong gives 0
  1519. value = (double)ul;
  1520. }
  1521. valueStr = Js::JavascriptString::Concat(scriptContext->GetLibrary()->CreateStringFromCppLiteral(L"0x"),
  1522. Js::JavascriptNumber::ToStringRadixHelper(value, radix, scriptContext))->GetSz();
  1523. }
  1524. else
  1525. {
  1526. valueStr = Js::JavascriptNumber::ToStringRadixHelper(value, radix, scriptContext)->GetSz();
  1527. }
  1528. }
  1529. }
  1530. else
  1531. {
  1532. Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance);
  1533. StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  1534. builder->Reset();
  1535. if (obj->GetDiagValueString(builder, scriptContext))
  1536. {
  1537. valueStr = builder->Detach();
  1538. }
  1539. else
  1540. {
  1541. valueStr = L"undefined";
  1542. }
  1543. }
  1544. return valueStr;
  1545. }
  1546. BOOL RecyclableObjectDisplay::HasChildren()
  1547. {
  1548. if (Js::RecyclableObject::Is(instance))
  1549. {
  1550. Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
  1551. if (JavascriptOperators::IsObject(object))
  1552. {
  1553. if (JavascriptOperators::GetTypeId(object) == TypeIds_HostDispatch)
  1554. {
  1555. return TRUE;
  1556. }
  1557. try
  1558. {
  1559. BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false)
  1560. {
  1561. IGNORE_STACKWALK_EXCEPTION(scriptContext);
  1562. if (object->CanHaveInterceptors())
  1563. {
  1564. Js::ForInObjectEnumerator enumerator(object, object->GetScriptContext(), /* enumSymbols */ true);
  1565. if (enumerator.MoveNext())
  1566. {
  1567. enumerator.Clear();
  1568. return TRUE;
  1569. }
  1570. }
  1571. else if (object->GetPropertyCount() > 0 || (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null))
  1572. {
  1573. return TRUE;
  1574. }
  1575. }
  1576. END_JS_RUNTIME_CALL(scriptContext);
  1577. }
  1578. catch (Js::JavascriptExceptionObject* exception)
  1579. {
  1580. // The For in enumerator can throw an exception and we will use the error object as a child in that case.
  1581. Var error = exception->GetThrownObject(scriptContext);
  1582. if (error != nullptr && Js::JavascriptError::Is(error))
  1583. {
  1584. return TRUE;
  1585. }
  1586. return FALSE;
  1587. }
  1588. }
  1589. }
  1590. return FALSE;
  1591. }
  1592. BOOL RecyclableObjectDisplay::Set(Var updateObject)
  1593. {
  1594. if (pObjAddress)
  1595. {
  1596. return pObjAddress->Set(updateObject);
  1597. }
  1598. return FALSE;
  1599. }
  1600. DBGPROP_ATTRIB_FLAGS RecyclableObjectDisplay::GetTypeAttribute()
  1601. {
  1602. DBGPROP_ATTRIB_FLAGS flag = defaultAttributes;
  1603. if (Js::RecyclableObject::Is(instance))
  1604. {
  1605. if (instance == scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString())
  1606. {
  1607. flag |= DBGPROP_ATTRIB_VALUE_IS_INVALID;
  1608. }
  1609. else if (JavascriptOperators::GetTypeId(instance) == TypeIds_Function)
  1610. {
  1611. flag |= DBGPROP_ATTRIB_VALUE_IS_METHOD;
  1612. }
  1613. else if (JavascriptOperators::GetTypeId(instance) == TypeIds_String
  1614. || JavascriptOperators::GetTypeId(instance) == TypeIds_StringObject)
  1615. {
  1616. flag |= DBGPROP_ATTRIB_VALUE_IS_RAW_STRING;
  1617. }
  1618. }
  1619. auto checkWriteableFunction = [&]()
  1620. {
  1621. if (pObjAddress && !pObjAddress->IsWritable())
  1622. {
  1623. flag |= DBGPROP_ATTRIB_VALUE_READONLY;
  1624. }
  1625. };
  1626. if (!scriptContext->GetThreadContext()->IsScriptActive())
  1627. {
  1628. BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false);
  1629. {
  1630. IGNORE_STACKWALK_EXCEPTION(scriptContext);
  1631. checkWriteableFunction();
  1632. }
  1633. END_JS_RUNTIME_CALL(scriptContext);
  1634. }
  1635. else
  1636. {
  1637. checkWriteableFunction();
  1638. }
  1639. // TODO : need to identify Events explicitly for fastDOM
  1640. return flag;
  1641. }
  1642. /* static */
  1643. BOOL RecyclableObjectDisplay::GetPropertyWithScriptEnter(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, Var* value, ScriptContext* scriptContext)
  1644. {
  1645. BOOL retValue = FALSE;
  1646. if(!scriptContext->GetThreadContext()->IsScriptActive())
  1647. {
  1648. BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false)
  1649. {
  1650. IGNORE_STACKWALK_EXCEPTION(scriptContext);
  1651. retValue = Js::JavascriptOperators::GetProperty(originalInstance, instance, propertyId, value, scriptContext);
  1652. }
  1653. END_JS_RUNTIME_CALL(scriptContext);
  1654. }
  1655. else
  1656. {
  1657. retValue = Js::JavascriptOperators::GetProperty(originalInstance, instance, propertyId, value, scriptContext);
  1658. }
  1659. return retValue;
  1660. }
  1661. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableObjectDisplay::CreateWalker()
  1662. {
  1663. return CreateAWalker<RecyclableObjectWalker>(scriptContext, instance, originalInstance);
  1664. }
  1665. StringBuilder<ArenaAllocator>* RecyclableObjectDisplay::GetStringBuilder()
  1666. {
  1667. return scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  1668. }
  1669. PropertyId RecyclableObjectDisplay::GetPropertyId() const
  1670. {
  1671. return this->propertyId;
  1672. }
  1673. // ------------------------------------
  1674. // RecyclableObjectWalker
  1675. RecyclableObjectWalker::RecyclableObjectWalker(ScriptContext* _scriptContext, Var _slot)
  1676. : scriptContext(_scriptContext),
  1677. instance(_slot),
  1678. originalInstance(_slot),
  1679. pMembersList(nullptr),
  1680. innerArrayObjectWalker(nullptr),
  1681. fakeGroupObjectWalkerList(nullptr)
  1682. {
  1683. }
  1684. RecyclableObjectWalker::RecyclableObjectWalker(ScriptContext* _scriptContext, Var _slot, Var _originalInstance)
  1685. : scriptContext(_scriptContext),
  1686. instance(_slot),
  1687. originalInstance(_originalInstance),
  1688. pMembersList(nullptr),
  1689. innerArrayObjectWalker(nullptr),
  1690. fakeGroupObjectWalkerList(nullptr)
  1691. {
  1692. }
  1693. BOOL RecyclableObjectWalker::Get(int index, ResolvedObject* pResolvedObject)
  1694. {
  1695. AssertMsg(pResolvedObject, "Bad usage of RecyclableObjectWalker::Get");
  1696. int fakeObjCount = fakeGroupObjectWalkerList ? fakeGroupObjectWalkerList->Count() : 0;
  1697. int arrayItemCount = innerArrayObjectWalker ? innerArrayObjectWalker->GetChildrenCount() : 0;
  1698. if (index < 0 || !pMembersList || index >= (pMembersList->Count() + arrayItemCount + fakeObjCount))
  1699. {
  1700. return FALSE;
  1701. }
  1702. int nonArrayElementCount = Js::RecyclableObject::Is(instance) ? pMembersList->Count() : 0;
  1703. // First the virtual groups
  1704. if (index < fakeObjCount)
  1705. {
  1706. Assert(fakeGroupObjectWalkerList);
  1707. return fakeGroupObjectWalkerList->Item(index)->GetGroupObject(pResolvedObject);
  1708. }
  1709. index -= fakeObjCount;
  1710. if (index < nonArrayElementCount)
  1711. {
  1712. Assert(Js::RecyclableObject::Is(instance));
  1713. pResolvedObject->propId = pMembersList->Item(index)->propId;
  1714. if (pResolvedObject->propId == Js::Constants::NoProperty || Js::IsInternalPropertyId(pResolvedObject->propId))
  1715. {
  1716. Assert(FALSE);
  1717. return FALSE;
  1718. }
  1719. Js::DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
  1720. const Js::PropertyRecord* propertyRecord = scriptContext->GetPropertyName(pResolvedObject->propId);
  1721. pResolvedObject->name = propertyRecord->GetBuffer();
  1722. pResolvedObject->obj = displayInfo->aVar;
  1723. Assert(pResolvedObject->obj);
  1724. pResolvedObject->scriptContext = scriptContext;
  1725. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  1726. pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
  1727. RecyclableObjectAddress,
  1728. instance,
  1729. pResolvedObject->propId,
  1730. pResolvedObject->obj,
  1731. displayInfo->IsInDeadZone() ? TRUE : FALSE);
  1732. pResolvedObject->isConst = displayInfo->IsConst();
  1733. return TRUE;
  1734. }
  1735. index -= nonArrayElementCount;
  1736. if (index < arrayItemCount)
  1737. {
  1738. Assert(innerArrayObjectWalker);
  1739. return innerArrayObjectWalker->Get(index, pResolvedObject);
  1740. }
  1741. Assert(false);
  1742. return FALSE;
  1743. }
  1744. void RecyclableObjectWalker::EnsureFakeGroupObjectWalkerList()
  1745. {
  1746. if (fakeGroupObjectWalkerList == nullptr)
  1747. {
  1748. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  1749. fakeGroupObjectWalkerList = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
  1750. }
  1751. }
  1752. IDiagObjectAddress *RecyclableObjectWalker::FindPropertyAddress(PropertyId propertyId, bool& isConst)
  1753. {
  1754. GetChildrenCount(); // Ensure to populate members
  1755. if (pMembersList != nullptr)
  1756. {
  1757. for (int i = 0; i < pMembersList->Count(); i++)
  1758. {
  1759. DebuggerPropertyDisplayInfo *pair = pMembersList->Item(i);
  1760. Assert(pair);
  1761. if (pair->propId == propertyId)
  1762. {
  1763. isConst = pair->IsConst();
  1764. return Anew(GetArenaFromContext(scriptContext),
  1765. RecyclableObjectAddress,
  1766. instance,
  1767. propertyId,
  1768. pair->aVar,
  1769. pair->IsInDeadZone() ? TRUE : FALSE);
  1770. }
  1771. }
  1772. }
  1773. // Following is for "with object" scope lookup. We may have members in [Methods] group or prototype chain that need to
  1774. // be exposed to expression evaluation.
  1775. if (fakeGroupObjectWalkerList != nullptr)
  1776. {
  1777. // WARNING: Following depends on [Methods] group being before [prototype] group. We need to check local [Methods] group
  1778. // first for local properties before going to prototype chain.
  1779. for (int i = 0; i < fakeGroupObjectWalkerList->Count(); i++)
  1780. {
  1781. IDiagObjectAddress* address = fakeGroupObjectWalkerList->Item(i)->FindPropertyAddress(propertyId, isConst);
  1782. if (address != nullptr)
  1783. {
  1784. return address;
  1785. }
  1786. }
  1787. }
  1788. return nullptr;
  1789. }
  1790. ulong RecyclableObjectWalker::GetChildrenCount()
  1791. {
  1792. if (pMembersList == nullptr)
  1793. {
  1794. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  1795. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
  1796. RecyclableMethodsGroupWalker *pMethodsGroupWalker = nullptr;
  1797. if (Js::RecyclableObject::Is(instance))
  1798. {
  1799. Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
  1800. // If we are walking a prototype, we'll use its instance for property names enumeration, but originalInstance to get values
  1801. Js::RecyclableObject* originalObject = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : object;
  1802. const Js::TypeId typeId = JavascriptOperators::GetTypeId(instance);
  1803. if (JavascriptOperators::IsObject(object))
  1804. {
  1805. if (object->CanHaveInterceptors() || JavascriptOperators::GetTypeId(object) == TypeIds_Proxy)
  1806. {
  1807. try
  1808. {
  1809. JavascriptEnumerator* enumerator;
  1810. if (object->GetEnumerator(true/*enumNonEnumable*/, (Var*)&enumerator, scriptContext, false/*preferSnapshotSyntax*/, true/*enumSymbols*/))
  1811. {
  1812. Js::PropertyId propertyId;
  1813. Var obj;
  1814. while ((obj = enumerator->GetCurrentAndMoveNext(propertyId)) != nullptr)
  1815. {
  1816. if (!JavascriptString::Is(obj))
  1817. {
  1818. continue;
  1819. }
  1820. if (propertyId == Constants::NoProperty)
  1821. {
  1822. JavascriptString *pString = JavascriptString::FromVar(obj);
  1823. if (VirtualTableInfo<Js::PropertyString>::HasVirtualTable(pString))
  1824. {
  1825. // If we have a property string, it is assumed that the propertyId is being
  1826. // kept alive with the object
  1827. PropertyString * propertyString = (PropertyString *)pString;
  1828. propertyId = propertyString->GetPropertyRecord()->GetPropertyId();
  1829. }
  1830. else
  1831. {
  1832. const PropertyRecord* propertyRecord;
  1833. scriptContext->GetOrAddPropertyRecord(pString->GetSz(), pString->GetLength(), &propertyRecord);
  1834. propertyId = propertyRecord->GetPropertyId();
  1835. }
  1836. }
  1837. // GetCurrentAndMoveNext shouldn't return an internal property id
  1838. Assert(!Js::IsInternalPropertyId(propertyId));
  1839. uint32 indexVal;
  1840. Var varValue;
  1841. if (scriptContext->IsNumericPropertyId(propertyId, &indexVal) && object->GetItem(object, indexVal, &varValue, scriptContext))
  1842. {
  1843. InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, varValue, &pMethodsGroupWalker, true /*shouldPinProperty*/);
  1844. }
  1845. else
  1846. {
  1847. InsertItem(originalObject, object, propertyId, false /*isConst*/, false /*isUnscoped*/, &pMethodsGroupWalker, true /*shouldPinProperty*/);
  1848. }
  1849. }
  1850. }
  1851. }
  1852. catch (JavascriptExceptionObject* exception)
  1853. {
  1854. Var error = exception->GetThrownObject(scriptContext);
  1855. if (error != nullptr && Js::JavascriptError::Is(error))
  1856. {
  1857. Js::PropertyId propertyId = scriptContext->GetOrAddPropertyIdTracked(L"{error}");
  1858. InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, error, &pMethodsGroupWalker);
  1859. }
  1860. }
  1861. if (typeId == TypeIds_Proxy)
  1862. {
  1863. // Provide [Proxy] group object
  1864. EnsureFakeGroupObjectWalkerList();
  1865. JavascriptProxy* proxy = JavascriptProxy::FromVar(object);
  1866. RecyclableProxyObjectWalker* proxyWalker = Anew(arena, RecyclableProxyObjectWalker, scriptContext, proxy);
  1867. fakeGroupObjectWalkerList->Add(proxyWalker);
  1868. }
  1869. // If current object has internal proto object then provide [prototype] group object.
  1870. if (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null)
  1871. {
  1872. // Has [prototype] object.
  1873. EnsureFakeGroupObjectWalkerList();
  1874. RecyclableProtoObjectWalker *pProtoWalker = Anew(arena, RecyclableProtoObjectWalker, scriptContext, instance, (originalInstance == nullptr) ? instance : originalInstance);
  1875. fakeGroupObjectWalkerList->Add(pProtoWalker);
  1876. }
  1877. }
  1878. else
  1879. {
  1880. RecyclableObject* wrapperObject = nullptr;
  1881. if (JavascriptOperators::GetTypeId(object) == TypeIds_WithScopeObject)
  1882. {
  1883. wrapperObject = object;
  1884. object = object->GetThisObjectOrUnWrap();
  1885. }
  1886. int count = object->GetPropertyCount();
  1887. for (int i = 0; i < count; i++)
  1888. {
  1889. Js::PropertyId propertyId = object->GetPropertyId((PropertyIndex)i);
  1890. bool isUnscoped = false;
  1891. if (wrapperObject && JavascriptOperators::IsPropertyUnscopable(object, propertyId))
  1892. {
  1893. isUnscoped = true;
  1894. }
  1895. if (propertyId != Js::Constants::NoProperty && !Js::IsInternalPropertyId(propertyId))
  1896. {
  1897. InsertItem(originalObject, object, propertyId, false /*isConst*/, isUnscoped, &pMethodsGroupWalker);
  1898. }
  1899. }
  1900. if (CONFIG_FLAG(EnumerateSpecialPropertiesInDebugger))
  1901. {
  1902. count = object->GetSpecialPropertyCount();
  1903. PropertyId const * specialPropertyIds = object->GetSpecialPropertyIds();
  1904. for (int i = 0; i < count; i++)
  1905. {
  1906. Js::PropertyId propertyId = specialPropertyIds[i];
  1907. bool isUnscoped = false;
  1908. if (wrapperObject && JavascriptOperators::IsPropertyUnscopable(object, propertyId))
  1909. {
  1910. isUnscoped = true;
  1911. }
  1912. if (propertyId != Js::Constants::NoProperty)
  1913. {
  1914. bool isConst = true;
  1915. if (propertyId == PropertyIds::length && Js::JavascriptArray::Is(object))
  1916. {
  1917. // For JavascriptArrays, we allow resetting the length special property.
  1918. isConst = false;
  1919. }
  1920. auto containsPredicate = [&](Js::DebuggerPropertyDisplayInfo* info) { return info->propId == propertyId; };
  1921. if (Js::BoundFunction::Is(object)
  1922. && this->pMembersList->Any(containsPredicate))
  1923. {
  1924. // Bound functions can already contain their special properties,
  1925. // so we need to check for that (caller and arguments). This occurs
  1926. // when JavascriptFunction::EntryBind() is called. Arguments can similarly
  1927. // already display caller in compat mode 8.
  1928. continue;
  1929. }
  1930. AssertMsg(!this->pMembersList->Any(containsPredicate), "Special property already on the object, no need to insert.");
  1931. InsertItem(originalObject, object, propertyId, isConst, isUnscoped, &pMethodsGroupWalker);
  1932. }
  1933. }
  1934. if (Js::JavascriptFunction::Is(object))
  1935. {
  1936. // We need to special-case RegExp constructor here because it has some special properties (above) and some
  1937. // special enumerable properties which should all show up in the debugger.
  1938. JavascriptRegExpConstructor* regExp = scriptContext->GetLibrary()->GetRegExpConstructor();
  1939. if (regExp == object)
  1940. {
  1941. bool isUnscoped = false;
  1942. bool isConst = true;
  1943. count = regExp->GetSpecialEnumerablePropertyCount();
  1944. PropertyId const * specialPropertyIds = regExp->GetSpecialEnumerablePropertyIds();
  1945. for (int i = 0; i < count; i++)
  1946. {
  1947. Js::PropertyId propertyId = specialPropertyIds[i];
  1948. InsertItem(originalObject, object, propertyId, isConst, isUnscoped, &pMethodsGroupWalker);
  1949. }
  1950. }
  1951. else if (Js::JavascriptFunction::FromVar(object)->IsScriptFunction() || Js::JavascriptFunction::FromVar(object)->IsBoundFunction())
  1952. {
  1953. // Adding special property length for the ScriptFunction, like it is done in JavascriptFunction::GetSpecialNonEnumerablePropertyName
  1954. InsertItem(originalObject, object, PropertyIds::length, true/*not editable*/, false /*isUnscoped*/, &pMethodsGroupWalker);
  1955. }
  1956. }
  1957. }
  1958. // If current object has internal proto object then provide [prototype] group object.
  1959. if (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null)
  1960. {
  1961. // Has [prototype] object.
  1962. EnsureFakeGroupObjectWalkerList();
  1963. RecyclableProtoObjectWalker *pProtoWalker = Anew(arena, RecyclableProtoObjectWalker, scriptContext, instance, originalInstance);
  1964. fakeGroupObjectWalkerList->Add(pProtoWalker);
  1965. }
  1966. }
  1967. // If the object contains array indices.
  1968. if (typeId == TypeIds_Arguments)
  1969. {
  1970. // Create ArgumentsArray walker for an arguments object
  1971. Js::ArgumentsObject * argObj = static_cast<Js::ArgumentsObject*>(instance);
  1972. Assert(argObj);
  1973. if (argObj->GetNumberOfArguments() > 0 || argObj->HasNonEmptyObjectArray())
  1974. {
  1975. innerArrayObjectWalker = Anew(arena, RecyclableArgumentsArrayWalker, scriptContext, (Var)instance, originalInstance);
  1976. }
  1977. }
  1978. else if (typeId == TypeIds_Map)
  1979. {
  1980. // Provide [Map] group object.
  1981. EnsureFakeGroupObjectWalkerList();
  1982. JavascriptMap* map = JavascriptMap::FromVar(object);
  1983. RecyclableMapObjectWalker *pMapWalker = Anew(arena, RecyclableMapObjectWalker, scriptContext, map);
  1984. fakeGroupObjectWalkerList->Add(pMapWalker);
  1985. }
  1986. else if (typeId == TypeIds_Set)
  1987. {
  1988. // Provide [Set] group object.
  1989. EnsureFakeGroupObjectWalkerList();
  1990. JavascriptSet* set = JavascriptSet::FromVar(object);
  1991. RecyclableSetObjectWalker *pSetWalker = Anew(arena, RecyclableSetObjectWalker, scriptContext, set);
  1992. fakeGroupObjectWalkerList->Add(pSetWalker);
  1993. }
  1994. else if (typeId == TypeIds_WeakMap)
  1995. {
  1996. // Provide [WeakMap] group object.
  1997. EnsureFakeGroupObjectWalkerList();
  1998. JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(object);
  1999. RecyclableWeakMapObjectWalker *pWeakMapWalker = Anew(arena, RecyclableWeakMapObjectWalker, scriptContext, weakMap);
  2000. fakeGroupObjectWalkerList->Add(pWeakMapWalker);
  2001. }
  2002. else if (typeId == TypeIds_WeakSet)
  2003. {
  2004. // Provide [WeakSet] group object.
  2005. EnsureFakeGroupObjectWalkerList();
  2006. JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(object);
  2007. RecyclableWeakSetObjectWalker *pWeakSetWalker = Anew(arena, RecyclableWeakSetObjectWalker, scriptContext, weakSet);
  2008. fakeGroupObjectWalkerList->Add(pWeakSetWalker);
  2009. }
  2010. else if (Js::DynamicType::Is(typeId))
  2011. {
  2012. DynamicObject *const dynamicObject = Js::DynamicObject::FromVar(instance);
  2013. if (dynamicObject->HasNonEmptyObjectArray())
  2014. {
  2015. ArrayObject* objectArray = dynamicObject->GetObjectArray();
  2016. if (Js::ES5Array::Is(objectArray))
  2017. {
  2018. innerArrayObjectWalker = Anew(arena, RecyclableES5ArrayWalker, scriptContext, objectArray, originalInstance);
  2019. }
  2020. else if (Js::JavascriptArray::Is(objectArray))
  2021. {
  2022. innerArrayObjectWalker = Anew(arena, RecyclableArrayWalker, scriptContext, objectArray, originalInstance);
  2023. }
  2024. else
  2025. {
  2026. innerArrayObjectWalker = Anew(arena, RecyclableTypedArrayWalker, scriptContext, objectArray, originalInstance);
  2027. }
  2028. innerArrayObjectWalker->SetOnlyWalkOwnProperties(true);
  2029. }
  2030. }
  2031. }
  2032. }
  2033. // Sort the members of the methods group
  2034. if (pMethodsGroupWalker)
  2035. {
  2036. pMethodsGroupWalker->Sort();
  2037. }
  2038. // Sort current pMembersList.
  2039. pMembersList->Sort(ElementsComparer, scriptContext);
  2040. }
  2041. ulong childrenCount =
  2042. pMembersList->Count()
  2043. + (innerArrayObjectWalker ? innerArrayObjectWalker->GetChildrenCount() : 0)
  2044. + (fakeGroupObjectWalkerList ? fakeGroupObjectWalkerList->Count() : 0);
  2045. return childrenCount;
  2046. }
  2047. void RecyclableObjectWalker::InsertItem(
  2048. Js::RecyclableObject *pOriginalObject,
  2049. Js::RecyclableObject *pObject,
  2050. PropertyId propertyId,
  2051. bool isReadOnly,
  2052. bool isUnscoped,
  2053. Js::RecyclableMethodsGroupWalker **ppMethodsGroupWalker,
  2054. bool shouldPinProperty /* = false*/)
  2055. {
  2056. Assert(pOriginalObject);
  2057. Assert(pObject);
  2058. Assert(propertyId);
  2059. Assert(ppMethodsGroupWalker);
  2060. if (propertyId != PropertyIds::__proto__)
  2061. {
  2062. InsertItem(propertyId, isReadOnly, isUnscoped, RecyclableObjectWalker::GetObject(pOriginalObject, pObject, propertyId, scriptContext), ppMethodsGroupWalker, shouldPinProperty);
  2063. }
  2064. else // Since __proto__ defined as a Getter we should always evaluate it against object itself instead of walking prototype chain
  2065. {
  2066. InsertItem(propertyId, isReadOnly, isUnscoped, RecyclableObjectWalker::GetObject(pObject, pObject, propertyId, scriptContext), ppMethodsGroupWalker, shouldPinProperty);
  2067. }
  2068. }
  2069. void RecyclableObjectWalker::InsertItem(
  2070. PropertyId propertyId,
  2071. bool isConst,
  2072. bool isUnscoped,
  2073. Var itemObj,
  2074. Js:: RecyclableMethodsGroupWalker **ppMethodsGroupWalker,
  2075. bool shouldPinProperty /* = false*/)
  2076. {
  2077. Assert(propertyId);
  2078. Assert(ppMethodsGroupWalker);
  2079. if (itemObj == nullptr)
  2080. {
  2081. itemObj = scriptContext->GetLibrary()->GetUndefined();
  2082. }
  2083. if (shouldPinProperty)
  2084. {
  2085. const Js::PropertyRecord * propertyRecord = scriptContext->GetPropertyName(propertyId);
  2086. if (propertyRecord)
  2087. {
  2088. // Pin this record so that it will not go away till we are done with this break.
  2089. scriptContext->GetDebugContext()->GetProbeContainer()->PinPropertyRecord(propertyRecord);
  2090. }
  2091. }
  2092. ArenaAllocator *arena = GetArenaFromContext(scriptContext);
  2093. if (JavascriptOperators::GetTypeId(itemObj) == TypeIds_Function)
  2094. {
  2095. EnsureFakeGroupObjectWalkerList();
  2096. if (*ppMethodsGroupWalker == nullptr)
  2097. {
  2098. *ppMethodsGroupWalker = Anew(arena, RecyclableMethodsGroupWalker, scriptContext, instance);
  2099. fakeGroupObjectWalkerList->Add(*ppMethodsGroupWalker);
  2100. }
  2101. (*ppMethodsGroupWalker)->AddItem(propertyId, itemObj);
  2102. }
  2103. else
  2104. {
  2105. DWORD flags = DebuggerPropertyDisplayInfoFlags_None;
  2106. flags |= isConst ? DebuggerPropertyDisplayInfoFlags_Const : 0;
  2107. flags |= isUnscoped ? DebuggerPropertyDisplayInfoFlags_Unscope : 0;
  2108. DebuggerPropertyDisplayInfo *info = Anew(arena, DebuggerPropertyDisplayInfo, propertyId, itemObj, flags);
  2109. pMembersList->Add(info);
  2110. }
  2111. }
  2112. /*static*/
  2113. Var RecyclableObjectWalker::GetObject(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, ScriptContext* scriptContext)
  2114. {
  2115. Assert(instance);
  2116. Assert(!Js::IsInternalPropertyId(propertyId));
  2117. Var obj = nullptr;
  2118. try
  2119. {
  2120. if (!RecyclableObjectDisplay::GetPropertyWithScriptEnter(originalInstance, instance, propertyId, &obj, scriptContext))
  2121. {
  2122. return instance->GetScriptContext()->GetMissingPropertyResult(instance, propertyId);
  2123. }
  2124. }
  2125. catch(Js::JavascriptExceptionObject * exceptionObject)
  2126. {
  2127. Var error = exceptionObject->GetThrownObject(instance->GetScriptContext());
  2128. if (error != nullptr && Js::JavascriptError::Is(error))
  2129. {
  2130. obj = error;
  2131. }
  2132. }
  2133. return obj;
  2134. }
  2135. //--------------------------
  2136. // RecyclableArrayAddress
  2137. RecyclableArrayAddress::RecyclableArrayAddress(Var _parentArray, unsigned int _index)
  2138. : parentArray(_parentArray),
  2139. index(_index)
  2140. {
  2141. }
  2142. BOOL RecyclableArrayAddress::Set(Var updateObject)
  2143. {
  2144. if (Js::JavascriptArray::Is(parentArray))
  2145. {
  2146. Js::JavascriptArray* jsArray = Js::JavascriptArray::FromVar(parentArray);
  2147. return jsArray->SetItem(index, updateObject, PropertyOperation_None);
  2148. }
  2149. return FALSE;
  2150. }
  2151. //--------------------------
  2152. // RecyclableArrayDisplay
  2153. RecyclableArrayDisplay::RecyclableArrayDisplay(ResolvedObject* resolvedObject)
  2154. : RecyclableObjectDisplay(resolvedObject)
  2155. {
  2156. }
  2157. BOOL RecyclableArrayDisplay::HasChildrenInternal(Js::JavascriptArray* arrayObj)
  2158. {
  2159. Assert(arrayObj);
  2160. if (JavascriptOperators::GetTypeId(arrayObj->GetPrototype()) != TypeIds_Null)
  2161. {
  2162. return TRUE;
  2163. }
  2164. uint32 index = arrayObj->GetNextIndex(Js::JavascriptArray::InvalidIndex);
  2165. return index != Js::JavascriptArray::InvalidIndex && index < arrayObj->GetLength();
  2166. }
  2167. BOOL RecyclableArrayDisplay::HasChildren()
  2168. {
  2169. if (Js::JavascriptArray::Is(instance))
  2170. {
  2171. Js::JavascriptArray* arrayObj = Js::JavascriptArray::FromVar(instance);
  2172. if (HasChildrenInternal(arrayObj))
  2173. {
  2174. return TRUE;
  2175. }
  2176. }
  2177. return RecyclableObjectDisplay::HasChildren();
  2178. }
  2179. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableArrayDisplay::CreateWalker()
  2180. {
  2181. return CreateAWalker<RecyclableArrayWalker>(scriptContext, instance, originalInstance);
  2182. }
  2183. //--------------------------
  2184. // RecyclableArrayWalker
  2185. uint32 RecyclableArrayWalker::GetItemCount(Js::JavascriptArray* arrayObj)
  2186. {
  2187. if (pAbsoluteIndexList == nullptr)
  2188. {
  2189. Assert(arrayObj);
  2190. pAbsoluteIndexList = JsUtil::List<uint32, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
  2191. Assert(pAbsoluteIndexList);
  2192. uint32 dataIndex = Js::JavascriptArray::InvalidIndex;
  2193. uint32 descriptorIndex = Js::JavascriptArray::InvalidIndex;
  2194. uint32 absIndex = Js::JavascriptArray::InvalidIndex;
  2195. do
  2196. {
  2197. if (absIndex == dataIndex)
  2198. {
  2199. dataIndex = arrayObj->GetNextIndex(dataIndex);
  2200. }
  2201. if (absIndex == descriptorIndex)
  2202. {
  2203. descriptorIndex = GetNextDescriptor(descriptorIndex);
  2204. }
  2205. absIndex = min(dataIndex, descriptorIndex);
  2206. if (absIndex == Js::JavascriptArray::InvalidIndex || absIndex >= arrayObj->GetLength())
  2207. {
  2208. break;
  2209. }
  2210. pAbsoluteIndexList->Add(absIndex);
  2211. } while (absIndex < arrayObj->GetLength());
  2212. }
  2213. return (uint32)pAbsoluteIndexList->Count();
  2214. }
  2215. BOOL RecyclableArrayWalker::FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var * value)
  2216. {
  2217. Assert(arrayObj);
  2218. Assert(value);
  2219. return arrayObj->DirectGetItemAt(index, value);
  2220. }
  2221. Var RecyclableArrayWalker::FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index)
  2222. {
  2223. Assert(arrayObj);
  2224. return arrayObj->DirectGetItem(index);
  2225. }
  2226. LPCWSTR RecyclableArrayWalker::GetIndexName(uint32 index, StringBuilder<ArenaAllocator>* stringBuilder)
  2227. {
  2228. stringBuilder->Append(L'[');
  2229. if (stringBuilder->AppendUint64(index) != 0)
  2230. {
  2231. return L"[.]";
  2232. }
  2233. stringBuilder->Append(L']');
  2234. return stringBuilder->Detach();
  2235. }
  2236. RecyclableArrayWalker::RecyclableArrayWalker(ScriptContext* scriptContext, Var instance, Var originalInstance)
  2237. : indexedItemCount(0),
  2238. pAbsoluteIndexList(nullptr),
  2239. fOnlyOwnProperties(false),
  2240. RecyclableObjectWalker(scriptContext,instance,originalInstance)
  2241. {
  2242. }
  2243. BOOL RecyclableArrayWalker::GetResolvedObject(Js::JavascriptArray* arrayObj, int index, ResolvedObject* pResolvedObject, uint32 * pabsIndex)
  2244. {
  2245. Assert(arrayObj);
  2246. Assert(pResolvedObject);
  2247. Assert(pAbsoluteIndexList);
  2248. Assert(pAbsoluteIndexList->Count() > index);
  2249. // translate i'th Item to the correct array index and return
  2250. uint32 absIndex = pAbsoluteIndexList->Item(index);
  2251. pResolvedObject->obj = FetchItemAt(arrayObj, absIndex);
  2252. pResolvedObject->scriptContext = scriptContext;
  2253. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2254. pResolvedObject->address = nullptr;
  2255. StringBuilder<ArenaAllocator>* builder = GetBuilder();
  2256. Assert(builder);
  2257. builder->Reset();
  2258. pResolvedObject->name = GetIndexName(absIndex, builder);
  2259. if (pabsIndex)
  2260. {
  2261. *pabsIndex = absIndex;
  2262. }
  2263. return TRUE;
  2264. }
  2265. BOOL RecyclableArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
  2266. {
  2267. AssertMsg(pResolvedObject, "Bad usage of RecyclableArrayWalker::Get");
  2268. if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance))
  2269. {
  2270. Js::JavascriptArray* arrayObj = GetArrayObject();
  2271. int nonArrayElementCount = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
  2272. if (i < nonArrayElementCount)
  2273. {
  2274. return RecyclableObjectWalker::Get(i, pResolvedObject);
  2275. }
  2276. else
  2277. {
  2278. i -= nonArrayElementCount;
  2279. uint32 absIndex; // Absolute index
  2280. GetResolvedObject(arrayObj, i, pResolvedObject, &absIndex);
  2281. pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
  2282. RecyclableArrayAddress,
  2283. instance,
  2284. absIndex);
  2285. return TRUE;
  2286. }
  2287. }
  2288. return FALSE;
  2289. }
  2290. Js::JavascriptArray* RecyclableArrayWalker::GetArrayObject()
  2291. {
  2292. Assert(Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance));
  2293. return Js::ES5Array::Is(instance) ?
  2294. static_cast<Js::JavascriptArray *>(RecyclableObject::FromVar(instance)) :
  2295. Js::JavascriptArray::FromVar(instance);
  2296. }
  2297. ulong RecyclableArrayWalker::GetChildrenCount()
  2298. {
  2299. if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance))
  2300. {
  2301. ulong count = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
  2302. Js::JavascriptArray* arrayObj = GetArrayObject();
  2303. return GetItemCount(arrayObj) + count;
  2304. }
  2305. return 0;
  2306. }
  2307. StringBuilder<ArenaAllocator>* RecyclableArrayWalker::GetBuilder()
  2308. {
  2309. return scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  2310. }
  2311. //--------------------------
  2312. // RecyclableArgumentsArrayAddress
  2313. RecyclableArgumentsArrayAddress::RecyclableArgumentsArrayAddress(Var _parentArray, unsigned int _index)
  2314. : parentArray(_parentArray),
  2315. index(_index)
  2316. {
  2317. }
  2318. BOOL RecyclableArgumentsArrayAddress::Set(Var updateObject)
  2319. {
  2320. if (Js::ArgumentsObject::Is(parentArray))
  2321. {
  2322. Js::ArgumentsObject* argObj = static_cast<Js::ArgumentsObject*>(parentArray);
  2323. return argObj->SetItem(index, updateObject, PropertyOperation_None);
  2324. }
  2325. return FALSE;
  2326. }
  2327. //--------------------------
  2328. // RecyclableArgumentsObjectDisplay
  2329. RecyclableArgumentsObjectDisplay::RecyclableArgumentsObjectDisplay(ResolvedObject* resolvedObject, LocalsWalker *localsWalker)
  2330. : RecyclableObjectDisplay(resolvedObject), pLocalsWalker(localsWalker)
  2331. {
  2332. }
  2333. BOOL RecyclableArgumentsObjectDisplay::HasChildren()
  2334. {
  2335. // It must have children otherwise object itself was not created in first place.
  2336. return TRUE;
  2337. }
  2338. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableArgumentsObjectDisplay::CreateWalker()
  2339. {
  2340. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  2341. if (pRefArena)
  2342. {
  2343. IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableArgumentsObjectWalker, scriptContext, instance, pLocalsWalker);
  2344. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
  2345. }
  2346. return nullptr;
  2347. }
  2348. //--------------------------
  2349. // RecyclableArgumentsObjectWalker
  2350. RecyclableArgumentsObjectWalker::RecyclableArgumentsObjectWalker(ScriptContext* pContext, Var _instance, LocalsWalker * localsWalker)
  2351. : RecyclableObjectWalker(pContext, _instance), pLocalsWalker(localsWalker)
  2352. {
  2353. }
  2354. ulong RecyclableArgumentsObjectWalker::GetChildrenCount()
  2355. {
  2356. if (innerArrayObjectWalker == nullptr)
  2357. {
  2358. ulong count = RecyclableObjectWalker::GetChildrenCount();
  2359. if (innerArrayObjectWalker != nullptr)
  2360. {
  2361. RecyclableArgumentsArrayWalker *pWalker = static_cast<RecyclableArgumentsArrayWalker *> (innerArrayObjectWalker);
  2362. pWalker->FetchFormalsAddress(pLocalsWalker);
  2363. }
  2364. return count;
  2365. }
  2366. return RecyclableObjectWalker::GetChildrenCount();
  2367. }
  2368. //--------------------------
  2369. // RecyclableArgumentsArrayWalker
  2370. RecyclableArgumentsArrayWalker::RecyclableArgumentsArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
  2371. : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance), pFormalsList(nullptr)
  2372. {
  2373. }
  2374. ulong RecyclableArgumentsArrayWalker::GetChildrenCount()
  2375. {
  2376. if (pMembersList == nullptr)
  2377. {
  2378. Assert(Js::ArgumentsObject::Is(instance));
  2379. Js::ArgumentsObject * argObj = static_cast<Js::ArgumentsObject*>(instance);
  2380. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
  2381. Assert(pMembersList);
  2382. uint32 totalCount = argObj->GetNumberOfArguments();
  2383. Js::ArrayObject * objectArray = argObj->GetObjectArray();
  2384. if (objectArray != nullptr && objectArray->GetLength() > totalCount)
  2385. {
  2386. totalCount = objectArray->GetLength();
  2387. }
  2388. for (uint32 index = 0; index < totalCount; index++)
  2389. {
  2390. Var itemObj;
  2391. if (argObj->GetItem(argObj, index, &itemObj, scriptContext))
  2392. {
  2393. DebuggerPropertyDisplayInfo *info = Anew(GetArenaFromContext(scriptContext), DebuggerPropertyDisplayInfo, index, itemObj, DebuggerPropertyDisplayInfoFlags_None);
  2394. Assert(info);
  2395. pMembersList->Add(info);
  2396. }
  2397. }
  2398. }
  2399. return pMembersList ? pMembersList->Count() : 0;
  2400. }
  2401. void RecyclableArgumentsArrayWalker::FetchFormalsAddress(LocalsWalker * localsWalker)
  2402. {
  2403. Assert(localsWalker);
  2404. Assert(localsWalker->pFrame);
  2405. Js::FunctionBody *pFBody = localsWalker->pFrame->GetJavascriptFunction()->GetFunctionBody();
  2406. Assert(pFBody);
  2407. PropertyIdOnRegSlotsContainer * container = pFBody->GetPropertyIdOnRegSlotsContainer();
  2408. if (container && container->propertyIdsForFormalArgs)
  2409. {
  2410. for (uint32 i = 0; i < container->propertyIdsForFormalArgs->count; i++)
  2411. {
  2412. if (container->propertyIdsForFormalArgs->elements[i] != Js::Constants::NoRegister)
  2413. {
  2414. bool isConst = false;
  2415. IDiagObjectAddress * address = localsWalker->FindPropertyAddress(container->propertyIdsForFormalArgs->elements[i], false, isConst);
  2416. if (address)
  2417. {
  2418. if (pFormalsList == nullptr)
  2419. {
  2420. pFormalsList = JsUtil::List<IDiagObjectAddress *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
  2421. }
  2422. pFormalsList->Add(address);
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. BOOL RecyclableArgumentsArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
  2429. {
  2430. AssertMsg(pResolvedObject, "Bad usage of RecyclableArgumentsArrayWalker::Get");
  2431. Assert(i >= 0);
  2432. Assert(Js::ArgumentsObject::Is(instance));
  2433. if (pMembersList && i < pMembersList->Count())
  2434. {
  2435. Assert(pMembersList->Item(i) != nullptr);
  2436. pResolvedObject->address = nullptr;
  2437. if (pFormalsList && i < pFormalsList->Count())
  2438. {
  2439. pResolvedObject->address = pFormalsList->Item(i);
  2440. pResolvedObject->obj = pResolvedObject->address->GetValue(FALSE);
  2441. if (pResolvedObject->obj == nullptr)
  2442. {
  2443. // Temp workaround till the arguments (In jit code) work is ready.
  2444. Assert(Js::Configuration::Global.EnableJitInDebugMode());
  2445. pResolvedObject->obj = pMembersList->Item(i)->aVar;
  2446. }
  2447. else if (pResolvedObject->obj != pMembersList->Item(i)->aVar)
  2448. {
  2449. // We set the formals value in the object itself, so that expression evaluation can reflect them correctly
  2450. Js::HeapArgumentsObject* argObj = static_cast<Js::HeapArgumentsObject*>(instance);
  2451. JavascriptOperators::SetItem(instance, argObj, (uint32)pMembersList->Item(i)->propId, pResolvedObject->obj, scriptContext, PropertyOperation_None);
  2452. }
  2453. }
  2454. else
  2455. {
  2456. pResolvedObject->obj = pMembersList->Item(i)->aVar;
  2457. }
  2458. Assert(pResolvedObject->obj);
  2459. pResolvedObject->scriptContext = scriptContext;
  2460. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2461. StringBuilder<ArenaAllocator>* builder = GetBuilder();
  2462. Assert(builder);
  2463. builder->Reset();
  2464. pResolvedObject->name = GetIndexName(pMembersList->Item(i)->propId, builder);
  2465. if (pResolvedObject->typeId != TypeIds_HostDispatch && pResolvedObject->address == nullptr)
  2466. {
  2467. pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
  2468. RecyclableArgumentsArrayAddress,
  2469. instance,
  2470. pMembersList->Item(i)->propId);
  2471. }
  2472. return TRUE;
  2473. }
  2474. return FALSE;
  2475. }
  2476. //--------------------------
  2477. // RecyclableTypedArrayAddress
  2478. RecyclableTypedArrayAddress::RecyclableTypedArrayAddress(Var _parentArray, unsigned int _index)
  2479. : RecyclableArrayAddress(_parentArray, _index)
  2480. {
  2481. }
  2482. BOOL RecyclableTypedArrayAddress::Set(Var updateObject)
  2483. {
  2484. if (Js::TypedArrayBase::Is(parentArray))
  2485. {
  2486. Js::TypedArrayBase* typedArrayObj = Js::TypedArrayBase::FromVar(parentArray);
  2487. return typedArrayObj->SetItem(index, updateObject, PropertyOperation_None);
  2488. }
  2489. return FALSE;
  2490. }
  2491. //--------------------------
  2492. // RecyclableTypedArrayDisplay
  2493. RecyclableTypedArrayDisplay::RecyclableTypedArrayDisplay(ResolvedObject* resolvedObject)
  2494. : RecyclableObjectDisplay(resolvedObject)
  2495. {
  2496. }
  2497. BOOL RecyclableTypedArrayDisplay::HasChildren()
  2498. {
  2499. if (Js::TypedArrayBase::Is(instance))
  2500. {
  2501. Js::TypedArrayBase* typedArrayObj = Js::TypedArrayBase::FromVar(instance);
  2502. if (typedArrayObj->GetLength() > 0)
  2503. {
  2504. return TRUE;
  2505. }
  2506. }
  2507. return RecyclableObjectDisplay::HasChildren();
  2508. }
  2509. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableTypedArrayDisplay::CreateWalker()
  2510. {
  2511. return CreateAWalker<RecyclableTypedArrayWalker>(scriptContext, instance, originalInstance);
  2512. }
  2513. //--------------------------
  2514. // RecyclableTypedArrayWalker
  2515. RecyclableTypedArrayWalker::RecyclableTypedArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
  2516. : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance)
  2517. {
  2518. }
  2519. ulong RecyclableTypedArrayWalker::GetChildrenCount()
  2520. {
  2521. if (!indexedItemCount)
  2522. {
  2523. Assert(Js::TypedArrayBase::Is(instance));
  2524. Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance);
  2525. indexedItemCount = typedArrayObj->GetLength() + (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
  2526. }
  2527. return indexedItemCount;
  2528. }
  2529. BOOL RecyclableTypedArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
  2530. {
  2531. AssertMsg(pResolvedObject, "Bad usage of RecyclableTypedArrayWalker::Get");
  2532. Assert(Js::TypedArrayBase::Is(instance));
  2533. Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance);
  2534. int nonArrayElementCount = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
  2535. if (i < nonArrayElementCount)
  2536. {
  2537. return RecyclableObjectWalker::Get(i, pResolvedObject);
  2538. }
  2539. else
  2540. {
  2541. i -= nonArrayElementCount;
  2542. pResolvedObject->scriptContext = scriptContext;
  2543. pResolvedObject->obj = typedArrayObj->DirectGetItem(i);
  2544. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2545. StringBuilder<ArenaAllocator>* builder = GetBuilder();
  2546. Assert(builder);
  2547. builder->Reset();
  2548. pResolvedObject->name = GetIndexName(i, builder);
  2549. Assert(pResolvedObject->typeId != TypeIds_HostDispatch);
  2550. pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
  2551. RecyclableTypedArrayAddress,
  2552. instance,
  2553. i);
  2554. }
  2555. return TRUE;
  2556. }
  2557. //--------------------------
  2558. // RecyclableES5ArrayAddress
  2559. RecyclableES5ArrayAddress::RecyclableES5ArrayAddress(Var _parentArray, unsigned int _index)
  2560. : RecyclableArrayAddress(_parentArray, _index)
  2561. {
  2562. }
  2563. BOOL RecyclableES5ArrayAddress::Set(Var updateObject)
  2564. {
  2565. if (Js::ES5Array::Is(parentArray))
  2566. {
  2567. Js::ES5Array* arrayObj = Js::ES5Array::FromVar(parentArray);
  2568. return arrayObj->SetItem(index, updateObject, PropertyOperation_None);
  2569. }
  2570. return FALSE;
  2571. }
  2572. //--------------------------
  2573. // RecyclableES5ArrayDisplay
  2574. RecyclableES5ArrayDisplay::RecyclableES5ArrayDisplay(ResolvedObject* resolvedObject)
  2575. : RecyclableArrayDisplay(resolvedObject)
  2576. {
  2577. }
  2578. BOOL RecyclableES5ArrayDisplay::HasChildren()
  2579. {
  2580. if (Js::ES5Array::Is(instance))
  2581. {
  2582. Js::JavascriptArray* arrayObj = static_cast<Js::JavascriptArray *>(RecyclableObject::FromVar(instance));
  2583. if (HasChildrenInternal(arrayObj))
  2584. {
  2585. return TRUE;
  2586. }
  2587. }
  2588. return RecyclableObjectDisplay::HasChildren();
  2589. }
  2590. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableES5ArrayDisplay::CreateWalker()
  2591. {
  2592. return CreateAWalker<RecyclableES5ArrayWalker>(scriptContext, instance, originalInstance);
  2593. }
  2594. //--------------------------
  2595. // RecyclableES5ArrayWalker
  2596. RecyclableES5ArrayWalker::RecyclableES5ArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
  2597. : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance)
  2598. {
  2599. }
  2600. uint32 RecyclableES5ArrayWalker::GetNextDescriptor(uint32 currentDescriptor)
  2601. {
  2602. Js::ES5Array *es5Array = static_cast<Js::ES5Array *>(RecyclableObject::FromVar(instance));
  2603. IndexPropertyDescriptor* descriptor = nullptr;
  2604. void * descriptorValidationToken = nullptr;
  2605. return es5Array->GetNextDescriptor(currentDescriptor, &descriptor, &descriptorValidationToken);
  2606. }
  2607. BOOL RecyclableES5ArrayWalker::FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var *value)
  2608. {
  2609. Assert(arrayObj);
  2610. Assert(value);
  2611. return arrayObj->GetItem(arrayObj, index, value, scriptContext);
  2612. }
  2613. Var RecyclableES5ArrayWalker::FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index)
  2614. {
  2615. Assert(arrayObj);
  2616. Var value = nullptr;
  2617. if (FetchItemAtIndex(arrayObj, index, &value))
  2618. {
  2619. return value;
  2620. }
  2621. return nullptr;
  2622. }
  2623. //--------------------------
  2624. // RecyclableProtoObjectWalker
  2625. RecyclableProtoObjectWalker::RecyclableProtoObjectWalker(ScriptContext* pContext, Var instance, Var originalInstance)
  2626. : RecyclableObjectWalker(pContext, instance)
  2627. {
  2628. this->originalInstance = originalInstance;
  2629. }
  2630. BOOL RecyclableProtoObjectWalker::GetGroupObject(ResolvedObject* pResolvedObject)
  2631. {
  2632. Assert(pResolvedObject);
  2633. DBGPROP_ATTRIB_FLAGS defaultAttributes = DBGPROP_ATTRIB_NO_ATTRIB;
  2634. if (scriptContext->GetLibrary()->GetObjectPrototypeObject()->is__proto__Enabled())
  2635. {
  2636. pResolvedObject->name = L"__proto__";
  2637. pResolvedObject->propId = PropertyIds::__proto__;
  2638. }
  2639. else
  2640. {
  2641. pResolvedObject->name = L"[prototype]";
  2642. pResolvedObject->propId = Constants::NoProperty; // This property will not be editable.
  2643. defaultAttributes = DBGPROP_ATTRIB_VALUE_IS_FAKE;
  2644. }
  2645. RecyclableObject *obj = Js::RecyclableObject::FromVar(instance);
  2646. Assert(obj->GetPrototype() != nullptr);
  2647. //withscopeObjects prototype is null
  2648. Assert(obj->GetPrototype()->GetTypeId() != TypeIds_Null || (obj->GetPrototype()->GetTypeId() == TypeIds_Null && obj->GetTypeId() == TypeIds_WithScopeObject));
  2649. pResolvedObject->obj = obj->GetPrototype();
  2650. pResolvedObject->originalObj = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : pResolvedObject->obj;
  2651. pResolvedObject->scriptContext = scriptContext;
  2652. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2653. ArenaAllocator * arena = GetArenaFromContext(scriptContext);
  2654. pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
  2655. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(defaultAttributes);
  2656. pResolvedObject->address = Anew(arena,
  2657. RecyclableProtoObjectAddress,
  2658. instance,
  2659. PropertyIds::prototype,
  2660. pResolvedObject->obj);
  2661. return TRUE;
  2662. }
  2663. IDiagObjectAddress* RecyclableProtoObjectWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
  2664. {
  2665. ResolvedObject resolvedProto;
  2666. GetGroupObject(&resolvedProto);
  2667. struct AutoCleanup
  2668. {
  2669. WeakArenaReference<Js::IDiagObjectModelWalkerBase> * walkerRef;
  2670. IDiagObjectModelWalkerBase * walker;
  2671. AutoCleanup() : walkerRef(nullptr), walker(nullptr) {};
  2672. ~AutoCleanup()
  2673. {
  2674. if (walker)
  2675. {
  2676. walkerRef->ReleaseStrongReference();
  2677. }
  2678. if (walkerRef)
  2679. {
  2680. HeapDelete(walkerRef);
  2681. }
  2682. }
  2683. } autoCleanup;
  2684. Assert(resolvedProto.objectDisplay);
  2685. autoCleanup.walkerRef = resolvedProto.objectDisplay->CreateWalker();
  2686. autoCleanup.walker = autoCleanup.walkerRef->GetStrongReference();
  2687. return autoCleanup.walker ? autoCleanup.walker->FindPropertyAddress(propId, isConst) : nullptr;
  2688. }
  2689. //--------------------------
  2690. // RecyclableProtoObjectAddress
  2691. RecyclableProtoObjectAddress::RecyclableProtoObjectAddress(Var _parentObj, Js::PropertyId _propId, Js::Var _value)
  2692. : RecyclableObjectAddress(_parentObj, _propId, _value, false /*isInDeadZone*/)
  2693. {
  2694. }
  2695. //--------------------------
  2696. // RecyclableCollectionObjectWalker
  2697. template <typename TData> const wchar_t* RecyclableCollectionObjectWalker<TData>::Name() { static_assert(false, L"Must use specialization"); }
  2698. template <> const wchar_t* RecyclableCollectionObjectWalker<JavascriptMap>::Name() { return L"[Map]"; }
  2699. template <> const wchar_t* RecyclableCollectionObjectWalker<JavascriptSet>::Name() { return L"[Set]"; }
  2700. template <> const wchar_t* RecyclableCollectionObjectWalker<JavascriptWeakMap>::Name() { return L"[WeakMap]"; }
  2701. template <> const wchar_t* RecyclableCollectionObjectWalker<JavascriptWeakSet>::Name() { return L"[WeakSet]"; }
  2702. template <typename TData>
  2703. BOOL RecyclableCollectionObjectWalker<TData>::GetGroupObject(ResolvedObject* pResolvedObject)
  2704. {
  2705. pResolvedObject->name = Name();
  2706. pResolvedObject->propId = Constants::NoProperty;
  2707. pResolvedObject->obj = instance;
  2708. pResolvedObject->scriptContext = scriptContext;
  2709. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2710. pResolvedObject->address = nullptr;
  2711. typedef RecyclableCollectionObjectDisplay<TData> RecyclableDataObjectDisplay;
  2712. pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableDataObjectDisplay, scriptContext, pResolvedObject->name, this);
  2713. return TRUE;
  2714. }
  2715. template <typename TData>
  2716. BOOL RecyclableCollectionObjectWalker<TData>::Get(int i, ResolvedObject* pResolvedObject)
  2717. {
  2718. auto builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  2719. builder->Reset();
  2720. builder->AppendUint64(i);
  2721. pResolvedObject->name = builder->Detach();
  2722. pResolvedObject->propId = Constants::NoProperty;
  2723. pResolvedObject->obj = instance;
  2724. pResolvedObject->scriptContext = scriptContext;
  2725. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2726. pResolvedObject->address = nullptr;
  2727. pResolvedObject->objectDisplay = CreateTDataDisplay(pResolvedObject, i);
  2728. return TRUE;
  2729. }
  2730. template <typename TData>
  2731. IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<TData>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
  2732. {
  2733. Var key = propertyList->Item(i).key;
  2734. Var value = propertyList->Item(i).value;
  2735. return Anew(GetArenaFromContext(scriptContext), RecyclableKeyValueDisplay, resolvedObject->scriptContext, key, value, resolvedObject->name);
  2736. }
  2737. template <>
  2738. IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<JavascriptSet>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
  2739. {
  2740. resolvedObject->obj = propertyList->Item(i).value;
  2741. IDiagObjectModelDisplay* display = resolvedObject->CreateDisplay();
  2742. display->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  2743. return display;
  2744. }
  2745. template <>
  2746. IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<JavascriptWeakSet>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
  2747. {
  2748. resolvedObject->obj = propertyList->Item(i).value;
  2749. IDiagObjectModelDisplay* display = resolvedObject->CreateDisplay();
  2750. display->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  2751. return display;
  2752. }
  2753. template <typename TData>
  2754. ulong RecyclableCollectionObjectWalker<TData>::GetChildrenCount()
  2755. {
  2756. TData* data = TData::FromVar(instance);
  2757. if (data->Size() > 0 && propertyList == nullptr)
  2758. {
  2759. propertyList = JsUtil::List<RecyclableCollectionObjectWalkerPropertyData<TData>, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
  2760. GetChildren();
  2761. }
  2762. return data->Size();
  2763. }
  2764. template <>
  2765. void RecyclableCollectionObjectWalker<JavascriptMap>::GetChildren()
  2766. {
  2767. JavascriptMap* data = JavascriptMap::FromVar(instance);
  2768. auto iterator = data->GetIterator();
  2769. while (iterator.Next())
  2770. {
  2771. Var key = iterator.Current().Key();
  2772. Var value = iterator.Current().Value();
  2773. propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptMap>(key, value));
  2774. }
  2775. }
  2776. template <>
  2777. void RecyclableCollectionObjectWalker<JavascriptSet>::GetChildren()
  2778. {
  2779. JavascriptSet* data = JavascriptSet::FromVar(instance);
  2780. auto iterator = data->GetIterator();
  2781. while (iterator.Next())
  2782. {
  2783. Var value = iterator.Current();
  2784. propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptSet>(value));
  2785. }
  2786. }
  2787. template <>
  2788. void RecyclableCollectionObjectWalker<JavascriptWeakMap>::GetChildren()
  2789. {
  2790. JavascriptWeakMap* data = JavascriptWeakMap::FromVar(instance);
  2791. data->Map([&](Var key, Var value)
  2792. {
  2793. propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptWeakMap>(key, value));
  2794. });
  2795. }
  2796. template <>
  2797. void RecyclableCollectionObjectWalker<JavascriptWeakSet>::GetChildren()
  2798. {
  2799. JavascriptWeakSet* data = JavascriptWeakSet::FromVar(instance);
  2800. data->Map([&](Var value)
  2801. {
  2802. propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptWeakSet>(value));
  2803. });
  2804. }
  2805. //--------------------------
  2806. // RecyclableCollectionObjectDisplay
  2807. template <typename TData>
  2808. LPCWSTR RecyclableCollectionObjectDisplay<TData>::Value(int radix)
  2809. {
  2810. StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  2811. builder->Reset();
  2812. builder->AppendCppLiteral(L"size = ");
  2813. builder->AppendUint64(walker->GetChildrenCount());
  2814. return builder->Detach();
  2815. }
  2816. template <typename TData>
  2817. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableCollectionObjectDisplay<TData>::CreateWalker()
  2818. {
  2819. if (walker)
  2820. {
  2821. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  2822. if (pRefArena)
  2823. {
  2824. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, walker);
  2825. }
  2826. }
  2827. return nullptr;
  2828. }
  2829. //--------------------------
  2830. // RecyclableKeyValueDisplay
  2831. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableKeyValueDisplay::CreateWalker()
  2832. {
  2833. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  2834. if (pRefArena)
  2835. {
  2836. IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableKeyValueWalker, scriptContext, key, value);
  2837. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
  2838. }
  2839. return nullptr;
  2840. }
  2841. LPCWSTR RecyclableKeyValueDisplay::Value(int radix)
  2842. {
  2843. ResolvedObject ro;
  2844. ro.scriptContext = scriptContext;
  2845. ro.obj = key;
  2846. RecyclableObjectDisplay keyDisplay(&ro);
  2847. ro.obj = value;
  2848. RecyclableObjectDisplay valueDisplay(&ro);
  2849. // Note, RecyclableObjectDisplay::Value(int) uses the shared string builder
  2850. // so we cannot call it while building our string below. Call both before hand.
  2851. const wchar_t* keyValue = keyDisplay.Value(radix);
  2852. const wchar_t* valueValue = valueDisplay.Value(radix);
  2853. StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
  2854. builder->Reset();
  2855. builder->Append('[');
  2856. builder->AppendSz(keyValue);
  2857. builder->AppendCppLiteral(L", ");
  2858. builder->AppendSz(valueValue);
  2859. builder->Append(']');
  2860. return builder->Detach();
  2861. }
  2862. //--------------------------
  2863. // RecyclableKeyValueWalker
  2864. BOOL RecyclableKeyValueWalker::Get(int i, ResolvedObject* pResolvedObject)
  2865. {
  2866. if (i == 0)
  2867. {
  2868. pResolvedObject->name = L"key";
  2869. pResolvedObject->obj = key;
  2870. }
  2871. else if (i == 1)
  2872. {
  2873. pResolvedObject->name = L"value";
  2874. pResolvedObject->obj = value;
  2875. }
  2876. else
  2877. {
  2878. Assert(false);
  2879. return FALSE;
  2880. }
  2881. pResolvedObject->propId = Constants::NoProperty;
  2882. pResolvedObject->scriptContext = scriptContext;
  2883. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2884. pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
  2885. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  2886. pResolvedObject->address = nullptr;
  2887. return TRUE;
  2888. }
  2889. //--------------------------
  2890. // RecyclableProxyObjectDisplay
  2891. RecyclableProxyObjectDisplay::RecyclableProxyObjectDisplay(ResolvedObject* resolvedObject)
  2892. : RecyclableObjectDisplay(resolvedObject)
  2893. {
  2894. }
  2895. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableProxyObjectDisplay::CreateWalker()
  2896. {
  2897. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  2898. if (pRefArena)
  2899. {
  2900. IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableProxyObjectWalker, scriptContext, instance);
  2901. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
  2902. }
  2903. return nullptr;
  2904. }
  2905. //--------------------------
  2906. // RecyclableProxyObjectWalker
  2907. RecyclableProxyObjectWalker::RecyclableProxyObjectWalker(ScriptContext* pContext, Var _instance)
  2908. : RecyclableObjectWalker(pContext, _instance)
  2909. {
  2910. }
  2911. BOOL RecyclableProxyObjectWalker::GetGroupObject(ResolvedObject* pResolvedObject)
  2912. {
  2913. pResolvedObject->name = L"[Proxy]";
  2914. pResolvedObject->propId = Constants::NoProperty;
  2915. pResolvedObject->obj = instance;
  2916. pResolvedObject->scriptContext = scriptContext;
  2917. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2918. pResolvedObject->address = nullptr;
  2919. pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableProxyObjectDisplay, pResolvedObject);
  2920. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  2921. return TRUE;
  2922. }
  2923. BOOL RecyclableProxyObjectWalker::Get(int i, ResolvedObject* pResolvedObject)
  2924. {
  2925. JavascriptProxy* proxy = JavascriptProxy::FromVar(instance);
  2926. if (i == 0)
  2927. {
  2928. pResolvedObject->name = L"[target]";
  2929. pResolvedObject->obj = proxy->GetTarget();
  2930. }
  2931. else if (i == 1)
  2932. {
  2933. pResolvedObject->name = L"[handler]";
  2934. pResolvedObject->obj = proxy->GetHandler();
  2935. }
  2936. else
  2937. {
  2938. Assert(false);
  2939. return FALSE;
  2940. }
  2941. pResolvedObject->propId = Constants::NoProperty;
  2942. pResolvedObject->scriptContext = scriptContext;
  2943. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2944. pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
  2945. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  2946. pResolvedObject->address = Anew(GetArenaFromContext(pResolvedObject->scriptContext),
  2947. RecyclableObjectAddress,
  2948. pResolvedObject->scriptContext->GetGlobalObject(),
  2949. Js::PropertyIds::Proxy,
  2950. pResolvedObject->obj,
  2951. false /*isInDeadZone*/);
  2952. return TRUE;
  2953. }
  2954. // ---------------------------
  2955. // RecyclableMethodsGroupWalker
  2956. RecyclableMethodsGroupWalker::RecyclableMethodsGroupWalker(ScriptContext* scriptContext, Var instance)
  2957. : RecyclableObjectWalker(scriptContext,instance)
  2958. {
  2959. }
  2960. void RecyclableMethodsGroupWalker::AddItem(Js::PropertyId propertyId, Var obj)
  2961. {
  2962. if (pMembersList == nullptr)
  2963. {
  2964. pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
  2965. }
  2966. Assert(pMembersList);
  2967. DebuggerPropertyDisplayInfo *info = Anew(GetArenaFromContext(scriptContext), DebuggerPropertyDisplayInfo, propertyId, obj, DebuggerPropertyDisplayInfoFlags_Const);
  2968. Assert(info);
  2969. pMembersList->Add(info);
  2970. }
  2971. ulong RecyclableMethodsGroupWalker::GetChildrenCount()
  2972. {
  2973. return pMembersList ? pMembersList->Count() : 0;
  2974. }
  2975. BOOL RecyclableMethodsGroupWalker::Get(int i, ResolvedObject* pResolvedObject)
  2976. {
  2977. AssertMsg(pResolvedObject, "Bad usage of RecyclableMethodsGroupWalker::Get");
  2978. return RecyclableObjectWalker::Get(i, pResolvedObject);
  2979. }
  2980. BOOL RecyclableMethodsGroupWalker::GetGroupObject(ResolvedObject* pResolvedObject)
  2981. {
  2982. Assert(pResolvedObject);
  2983. // This is fake [Methods] object.
  2984. pResolvedObject->name = L"[Methods]";
  2985. pResolvedObject->obj = Js::RecyclableObject::FromVar(instance);
  2986. pResolvedObject->scriptContext = scriptContext;
  2987. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  2988. pResolvedObject->address = nullptr; // Methods object will not be editable
  2989. pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableMethodsGroupDisplay, this, pResolvedObject);
  2990. return TRUE;
  2991. }
  2992. void RecyclableMethodsGroupWalker::Sort()
  2993. {
  2994. pMembersList->Sort(ElementsComparer, scriptContext);
  2995. }
  2996. RecyclableMethodsGroupDisplay::RecyclableMethodsGroupDisplay(RecyclableMethodsGroupWalker *_methodGroupWalker, ResolvedObject* resolvedObject)
  2997. : methodGroupWalker(_methodGroupWalker),
  2998. RecyclableObjectDisplay(resolvedObject)
  2999. {
  3000. }
  3001. LPCWSTR RecyclableMethodsGroupDisplay::Type()
  3002. {
  3003. return L"";
  3004. }
  3005. LPCWSTR RecyclableMethodsGroupDisplay::Value(int radix)
  3006. {
  3007. return L"{...}";
  3008. }
  3009. BOOL RecyclableMethodsGroupDisplay::HasChildren()
  3010. {
  3011. return methodGroupWalker ? TRUE : FALSE;
  3012. }
  3013. DBGPROP_ATTRIB_FLAGS RecyclableMethodsGroupDisplay::GetTypeAttribute()
  3014. {
  3015. return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_IS_METHOD | DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE;
  3016. }
  3017. WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableMethodsGroupDisplay::CreateWalker()
  3018. {
  3019. if (methodGroupWalker)
  3020. {
  3021. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  3022. if (pRefArena)
  3023. {
  3024. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, methodGroupWalker);
  3025. }
  3026. }
  3027. return nullptr;
  3028. }
  3029. ScopeVariablesGroupDisplay::ScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject)
  3030. : scopeGroupWalker(walker),
  3031. RecyclableObjectDisplay(resolvedObject)
  3032. {
  3033. }
  3034. LPCWSTR ScopeVariablesGroupDisplay::Type()
  3035. {
  3036. return L"";
  3037. }
  3038. LPCWSTR ScopeVariablesGroupDisplay::Value(int radix)
  3039. {
  3040. if (ActivationObject::Is(instance))
  3041. {
  3042. // The scope is defined by the activation object.
  3043. Js::RecyclableObject *object = Js::RecyclableObject::FromVar(instance);
  3044. try
  3045. {
  3046. // Trying to find out the JavascriptFunction from the scope.
  3047. Var value = nullptr;
  3048. if (object->GetTypeId() == TypeIds_ActivationObject && GetPropertyWithScriptEnter(object, object, PropertyIds::arguments, &value, scriptContext))
  3049. {
  3050. if (Js::RecyclableObject::Is(value))
  3051. {
  3052. Js::RecyclableObject *argObject = Js::RecyclableObject::FromVar(value);
  3053. Var calleeFunc = nullptr;
  3054. if (GetPropertyWithScriptEnter(argObject, argObject, PropertyIds::callee, &calleeFunc, scriptContext) && Js::JavascriptFunction::Is(calleeFunc))
  3055. {
  3056. Js::JavascriptFunction *calleeFunction = Js::JavascriptFunction::FromVar(calleeFunc);
  3057. Js::FunctionBody *pFuncBody = calleeFunction->GetFunctionBody();
  3058. if (pFuncBody)
  3059. {
  3060. const wchar_t* pDisplayName = pFuncBody->GetDisplayName();
  3061. if (pDisplayName)
  3062. {
  3063. StringBuilder<ArenaAllocator>* builder = GetStringBuilder();
  3064. builder->Reset();
  3065. builder->AppendSz(pDisplayName);
  3066. return builder->Detach();
  3067. }
  3068. }
  3069. }
  3070. }
  3071. }
  3072. }
  3073. catch(Js::JavascriptExceptionObject *exceptionObject)
  3074. {
  3075. exceptionObject;
  3076. // Not doing anything over here.
  3077. }
  3078. return L"";
  3079. }
  3080. else
  3081. {
  3082. // The scope is defined by a slot array object so grab the function body out to get the function name.
  3083. ScopeSlots slotArray = ScopeSlots(reinterpret_cast<Var*>(instance));
  3084. if(slotArray.IsFunctionScopeSlotArray())
  3085. {
  3086. Js::FunctionBody *functionBody = slotArray.GetFunctionBody();
  3087. return functionBody->GetDisplayName();
  3088. }
  3089. else
  3090. {
  3091. // handling for block/catch scope
  3092. return L"";
  3093. }
  3094. }
  3095. }
  3096. BOOL ScopeVariablesGroupDisplay::HasChildren()
  3097. {
  3098. return scopeGroupWalker ? TRUE : FALSE;
  3099. }
  3100. DBGPROP_ATTRIB_FLAGS ScopeVariablesGroupDisplay::GetTypeAttribute()
  3101. {
  3102. return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE;
  3103. }
  3104. WeakArenaReference<IDiagObjectModelWalkerBase>* ScopeVariablesGroupDisplay::CreateWalker()
  3105. {
  3106. if (scopeGroupWalker)
  3107. {
  3108. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  3109. if (pRefArena)
  3110. {
  3111. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, scopeGroupWalker);
  3112. }
  3113. }
  3114. return nullptr;
  3115. }
  3116. GlobalsScopeVariablesGroupDisplay::GlobalsScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject)
  3117. : globalsGroupWalker(walker),
  3118. RecyclableObjectDisplay(resolvedObject)
  3119. {
  3120. }
  3121. LPCWSTR GlobalsScopeVariablesGroupDisplay::Type()
  3122. {
  3123. return L"";
  3124. }
  3125. LPCWSTR GlobalsScopeVariablesGroupDisplay::Value(int radix)
  3126. {
  3127. return L"";
  3128. }
  3129. BOOL GlobalsScopeVariablesGroupDisplay::HasChildren()
  3130. {
  3131. return globalsGroupWalker ? globalsGroupWalker->GetChildrenCount() > 0 : FALSE;
  3132. }
  3133. DBGPROP_ATTRIB_FLAGS GlobalsScopeVariablesGroupDisplay::GetTypeAttribute()
  3134. {
  3135. return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | (HasChildren() ? DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE : 0);
  3136. }
  3137. WeakArenaReference<IDiagObjectModelWalkerBase>* GlobalsScopeVariablesGroupDisplay::CreateWalker()
  3138. {
  3139. if (globalsGroupWalker)
  3140. {
  3141. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  3142. if (pRefArena)
  3143. {
  3144. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, globalsGroupWalker);
  3145. }
  3146. }
  3147. return nullptr;
  3148. }
  3149. #ifdef ENABLE_MUTATION_BREAKPOINT
  3150. PendingMutationBreakpointDisplay::PendingMutationBreakpointDisplay(ResolvedObject* resolvedObject, MutationType _mutationType)
  3151. : RecyclableObjectDisplay(resolvedObject), mutationType(_mutationType)
  3152. {
  3153. AssertMsg(_mutationType > MutationTypeNone && _mutationType < MutationTypeAll, "Invalid mutationType value passed to PendingMutationBreakpointDisplay");
  3154. }
  3155. WeakArenaReference<IDiagObjectModelWalkerBase>* PendingMutationBreakpointDisplay::CreateWalker()
  3156. {
  3157. ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
  3158. if (pRefArena)
  3159. {
  3160. IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), PendingMutationBreakpointWalker, scriptContext, instance, this->mutationType);
  3161. return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
  3162. }
  3163. return nullptr;
  3164. }
  3165. ulong PendingMutationBreakpointWalker::GetChildrenCount()
  3166. {
  3167. switch (this->mutationType)
  3168. {
  3169. case MutationTypeUpdate:
  3170. return 3;
  3171. case MutationTypeDelete:
  3172. case MutationTypeAdd:
  3173. return 2;
  3174. default:
  3175. AssertMsg(false, "Invalid mutationType");
  3176. return 0;
  3177. }
  3178. }
  3179. PendingMutationBreakpointWalker::PendingMutationBreakpointWalker(ScriptContext* pContext, Var _instance, MutationType mutationType)
  3180. : RecyclableObjectWalker(pContext, _instance)
  3181. {
  3182. this->mutationType = mutationType;
  3183. }
  3184. BOOL PendingMutationBreakpointWalker::Get(int i, ResolvedObject* pResolvedObject)
  3185. {
  3186. Js::MutationBreakpoint *mutationBreakpoint = scriptContext->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint();
  3187. Assert(mutationBreakpoint);
  3188. if (mutationBreakpoint != nullptr)
  3189. {
  3190. if (i == 0)
  3191. {
  3192. // <Property Name> [Adding] : New Value
  3193. // <Property Name> [Changing] : Old Value
  3194. // <Property Name> [Deleting] : Old Value
  3195. WCHAR * displayName = AnewArray(GetArenaFromContext(scriptContext), WCHAR, PENDING_MUTATION_VALUE_MAX_NAME);
  3196. swprintf_s(displayName, PENDING_MUTATION_VALUE_MAX_NAME, L"%s [%s]", mutationBreakpoint->GetBreakPropertyName(), Js::MutationBreakpoint::GetBreakMutationTypeName(mutationType));
  3197. pResolvedObject->name = displayName;
  3198. if (mutationType == MutationTypeUpdate || mutationType == MutationTypeDelete)
  3199. {
  3200. // Old/Current value
  3201. PropertyId breakPId = mutationBreakpoint->GetBreakPropertyId();
  3202. pResolvedObject->propId = breakPId;
  3203. pResolvedObject->obj = JavascriptOperators::OP_GetProperty(mutationBreakpoint->GetMutationObjectVar(), breakPId, scriptContext);
  3204. }
  3205. else
  3206. {
  3207. // New Value
  3208. pResolvedObject->obj = mutationBreakpoint->GetBreakNewValueVar();
  3209. pResolvedObject->propId = Constants::NoProperty;
  3210. }
  3211. }
  3212. else if ((i == 1) && (mutationType == MutationTypeUpdate))
  3213. {
  3214. pResolvedObject->name = L"[New Value]";
  3215. pResolvedObject->obj = mutationBreakpoint->GetBreakNewValueVar();
  3216. pResolvedObject->propId = Constants::NoProperty;
  3217. }
  3218. else if (((i == 1) && (mutationType != MutationTypeUpdate)) || (i == 2))
  3219. {
  3220. WCHAR * displayName = AnewArray(GetArenaFromContext(scriptContext), WCHAR, PENDING_MUTATION_VALUE_MAX_NAME);
  3221. swprintf_s(displayName, PENDING_MUTATION_VALUE_MAX_NAME, L"[Property container %s]", mutationBreakpoint->GetParentPropertyName());
  3222. pResolvedObject->name = displayName;
  3223. pResolvedObject->obj = mutationBreakpoint->GetMutationObjectVar();
  3224. pResolvedObject->propId = mutationBreakpoint->GetParentPropertyId();
  3225. }
  3226. else
  3227. {
  3228. Assert(false);
  3229. return FALSE;
  3230. }
  3231. pResolvedObject->scriptContext = scriptContext;
  3232. pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
  3233. pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
  3234. pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
  3235. pResolvedObject->address = nullptr; // TODO: (SaAgarwa) Currently Pending mutation values are not editable, will do as part of another WI
  3236. return TRUE;
  3237. }
  3238. return FALSE;
  3239. }
  3240. #endif
  3241. }