DiagObjectModel.cpp 166 KB

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