| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- #include "RuntimeDebugPch.h"
- // Parser includes
- #include "CharClassifier.h"
- // TODO: clean up the need of these regex related header here just for GroupInfo needed in JavascriptRegExpConstructor
- #include "RegexCommon.h"
- // Runtime includes
- #include "Library/ObjectPrototypeObject.h"
- #include "Library/JavascriptNumberObject.h"
- #include "Library/BoundFunction.h"
- #include "Library/JavascriptRegExpConstructor.h"
- #include "Library/SameValueComparer.h"
- #include "Library/MapOrSetDataList.h"
- #include "Library/JavascriptPromise.h"
- #include "Library/JavascriptProxy.h"
- #include "Library/JavascriptMap.h"
- #include "Library/JavascriptSet.h"
- #include "Library/JavascriptWeakMap.h"
- #include "Library/JavascriptWeakSet.h"
- #include "Library/ArgumentsObject.h"
- #include "Types/DynamicObjectEnumerator.h"
- #include "Types/DynamicObjectSnapshotEnumerator.h"
- #include "Types/DynamicObjectSnapshotEnumeratorWPCache.h"
- #include "Library/ForInObjectEnumerator.h"
- #include "Library/ES5Array.h"
- #include "Library/SimdLib.h"
- namespace Js
- {
- #define RETURN_VALUE_MAX_NAME 255
- #define PENDING_MUTATION_VALUE_MAX_NAME 255
- ArenaAllocator *GetArenaFromContext(ScriptContext *scriptContext)
- {
- Assert(scriptContext);
- return scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena()->Arena();
- }
- template <class T>
- WeakArenaReference<IDiagObjectModelWalkerBase>* CreateAWalker(ScriptContext * scriptContext, Var instance, Var originalInstance)
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), T, scriptContext, instance, originalInstance);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
- }
- return nullptr;
- }
- //-----------------------
- // ResolvedObject
- WeakArenaReference<IDiagObjectModelDisplay>* ResolvedObject::GetObjectDisplay()
- {
- AssertMsg(typeId != TypeIds_HostDispatch, "Bad usage of ResolvedObject::GetObjectDisplay");
- IDiagObjectModelDisplay* pOMDisplay = (this->objectDisplay != nullptr) ? this->objectDisplay : CreateDisplay();
- Assert(pOMDisplay);
- return HeapNew(WeakArenaReference<IDiagObjectModelDisplay>, scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena(), pOMDisplay);
- }
- IDiagObjectModelDisplay * ResolvedObject::CreateDisplay()
- {
- IDiagObjectModelDisplay* pOMDisplay = nullptr;
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (Js::TypedArrayBase::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableTypedArrayDisplay, this);
- }
- else if (Js::ES5Array::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableES5ArrayDisplay, this);
- }
- else if (Js::JavascriptArray::Is(obj))
- {
- // DisableJIT-TODO: Review- is this correct?
- #if ENABLE_COPYONACCESS_ARRAY
- // Make sure any NativeIntArrays are converted
- Js::JavascriptLibrary::CheckAndConvertCopyOnAccessNativeIntArray<Var>(obj);
- #endif
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableArrayDisplay, this);
- }
- #ifdef ENABLE_SIMDJS
- else if (Js::JavascriptSIMDInt32x4::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdInt32x4ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDFloat32x4::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdFloat32x4ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDInt8x16::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdInt8x16ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDInt16x8::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdInt16x8ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDBool32x4::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdBool32x4ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDBool8x16::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdBool8x16ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDBool16x8::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdBool16x8ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDUint32x4::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdUint32x4ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDUint8x16::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdUint8x16ObjectDisplay, this);
- }
- else if (Js::JavascriptSIMDUint16x8::Is(obj))
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableSimdUint16x8ObjectDisplay, this);
- }
- #endif
- else
- {
- pOMDisplay = Anew(pRefArena->Arena(), RecyclableObjectDisplay, this);
- }
- if (this->isConst || this->propId == Js::PropertyIds::_superReferenceSymbol || this->propId == Js::PropertyIds::_superCtorReferenceSymbol)
- {
- pOMDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY);
- }
- return pOMDisplay;
- }
- bool ResolvedObject::IsInDeadZone() const
- {
- Assert(scriptContext);
- return this->obj == scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
- }
- //-----------------------
- // LocalsDisplay
- LocalsDisplay::LocalsDisplay(DiagStackFrame* _frame)
- : pFrame(_frame)
- {
- }
- LPCWSTR LocalsDisplay::Name()
- {
- return _u("Locals");
- }
- LPCWSTR LocalsDisplay::Type()
- {
- return _u("");
- }
- LPCWSTR LocalsDisplay::Value(int radix)
- {
- return _u("Locals");
- }
- BOOL LocalsDisplay::HasChildren()
- {
- Js::JavascriptFunction* func = pFrame->GetJavascriptFunction();
- FunctionBody* function = func->GetFunctionBody();
- return function && function->GetLocalsCount() != 0;
- }
- DBGPROP_ATTRIB_FLAGS LocalsDisplay::GetTypeAttribute()
- {
- return DBGPROP_ATTRIB_NO_ATTRIB;
- }
- BOOL LocalsDisplay::Set(Var updateObject)
- {
- // This is the hidden root object for Locals it doesn't get updated.
- return FALSE;
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* LocalsDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = pFrame->GetScriptContext()->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase * pOMWalker = nullptr;
- IGNORE_STACKWALK_EXCEPTION(scriptContext);
- pOMWalker = Anew(pRefArena->Arena(), LocalsWalker, pFrame, FrameWalkerFlags::FW_MakeGroups);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
- }
- return nullptr;
- }
- // Variables on the scope or in current function.
- /*static*/
- BOOL VariableWalkerBase::GetExceptionObject(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- Assert(pResolvedObject->scriptContext);
- Assert(frame);
- Assert(index >= 0);
- if (HasExceptionObject(frame))
- {
- if (index == 0)
- {
- pResolvedObject->name = _u("{exception}");
- pResolvedObject->typeId = TypeIds_Error;
- pResolvedObject->address = nullptr;
- pResolvedObject->obj = pResolvedObject->scriptContext->GetDebugContext()->GetProbeContainer()->GetExceptionObject();
- if (pResolvedObject->obj == nullptr)
- {
- Assert(false);
- pResolvedObject->obj = pResolvedObject->scriptContext->GetLibrary()->GetUndefined();
- }
- return TRUE;
- }
- // Adjust the index
- index -= 1;
- }
- return FALSE;
- }
- /*static*/
- bool VariableWalkerBase::HasExceptionObject(DiagStackFrame* frame)
- {
- Assert(frame);
- Assert(frame->GetScriptContext());
- return frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetExceptionObject() != nullptr;
- }
- /*static*/
- void VariableWalkerBase::GetReturnedValueResolvedObject(ReturnedValue * returnValue, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
- {
- DBGPROP_ATTRIB_FLAGS defaultAttributes = DBGPROP_ATTRIB_VALUE_IS_RETURN_VALUE | DBGPROP_ATTRIB_VALUE_IS_FAKE;
- WCHAR * finalName = AnewArray(GetArenaFromContext(pResolvedObject->scriptContext), WCHAR, RETURN_VALUE_MAX_NAME);
- if (returnValue->isValueOfReturnStatement)
- {
- swprintf_s(finalName, RETURN_VALUE_MAX_NAME, _u("[Return value]"));
- pResolvedObject->obj = frame->GetRegValue(Js::FunctionBody::ReturnValueRegSlot);
- pResolvedObject->address = Anew(frame->GetArena(), LocalObjectAddressForRegSlot, frame, Js::FunctionBody::ReturnValueRegSlot, pResolvedObject->obj);
- }
- else
- {
- if (returnValue->calledFunction->IsScriptFunction())
- {
- swprintf_s(finalName, RETURN_VALUE_MAX_NAME, _u("[%s returned]"), returnValue->calledFunction->GetFunctionBody()->GetDisplayName());
- }
- else
- {
- Js::JavascriptString *builtInName = returnValue->calledFunction->GetDisplayName();
- swprintf_s(finalName, RETURN_VALUE_MAX_NAME, _u("[%s returned]"), builtInName->GetSz());
- }
- pResolvedObject->obj = returnValue->returnedValue;
- defaultAttributes |= DBGPROP_ATTRIB_VALUE_READONLY;
- pResolvedObject->address = nullptr;
- }
- Assert(pResolvedObject->obj != nullptr);
- pResolvedObject->name = finalName;
- pResolvedObject->typeId = TypeIds_Object;
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(defaultAttributes);
- }
- /*static*/
- BOOL VariableWalkerBase::GetReturnedValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- Assert(pResolvedObject->scriptContext);
- Assert(frame);
- Assert(index >= 0);
- ReturnedValueList *returnedValueList = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetReturnedValueList();
- if (returnedValueList != nullptr && returnedValueList->Count() > 0 && frame->IsTopFrame())
- {
- if (index < returnedValueList->Count())
- {
- ReturnedValue * returnValue = returnedValueList->Item(index);
- VariableWalkerBase::GetReturnedValueResolvedObject(returnValue, frame, pResolvedObject);
- return TRUE;
- }
- // Adjust the index
- index -= returnedValueList->Count();
- }
- return FALSE;
- }
- /*static*/
- int VariableWalkerBase::GetReturnedValueCount(DiagStackFrame* frame)
- {
- Assert(frame);
- Assert(frame->GetScriptContext());
- ReturnedValueList *returnedValueList = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetReturnedValueList();
- return returnedValueList != nullptr && frame->IsTopFrame() ? returnedValueList->Count() : 0;
- }
- #ifdef ENABLE_MUTATION_BREAKPOINT
- BOOL VariableWalkerBase::GetBreakMutationBreakpointValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- Assert(pResolvedObject->scriptContext);
- Assert(frame);
- Assert(index >= 0);
- Js::MutationBreakpoint *mutationBreakpoint = frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint();
- if (mutationBreakpoint != nullptr)
- {
- if (index == 0)
- {
- pResolvedObject->name = _u("[Pending Mutation]");
- pResolvedObject->typeId = TypeIds_Object;
- pResolvedObject->address = nullptr;
- pResolvedObject->obj = mutationBreakpoint->GetMutationObjectVar();
- ReferencedArenaAdapter* pRefArena = pResolvedObject->scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- pResolvedObject->objectDisplay = Anew(pRefArena->Arena(), PendingMutationBreakpointDisplay, pResolvedObject, mutationBreakpoint->GetBreakMutationType());
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_PENDING_MUTATION | DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- return TRUE;
- }
- index -= 1; // Adjust the index
- }
- return FALSE;
- }
- uint VariableWalkerBase::GetBreakMutationBreakpointsCount(DiagStackFrame* frame)
- {
- Assert(frame);
- Assert(frame->GetScriptContext());
- return frame->GetScriptContext()->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint() != nullptr ? 1 : 0;
- }
- #endif
- BOOL VariableWalkerBase::Get(int i, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of VariableWalkerBase::Get");
- Assert(pFrame);
- pResolvedObject->scriptContext = pFrame->GetScriptContext();
- if (i < 0)
- {
- return FALSE;
- }
- if (GetMemberCount() > i)
- {
- pResolvedObject->propId = pMembersList->Item(i)->propId;
- Assert(pResolvedObject->propId != Js::Constants::NoProperty);
- Assert(!Js::IsInternalPropertyId(pResolvedObject->propId));
- if (pResolvedObject->propId == Js::PropertyIds::_superReferenceSymbol || pResolvedObject->propId == Js::PropertyIds::_superCtorReferenceSymbol)
- {
- pResolvedObject->name = _u("super");
- }
- else
- {
- const Js::PropertyRecord* propertyRecord = pResolvedObject->scriptContext->GetPropertyName(pResolvedObject->propId);
- pResolvedObject->name = propertyRecord->GetBuffer();
- }
- pResolvedObject->obj = GetVarObjectAt(i);
- Assert(pResolvedObject->obj);
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = GetObjectAddress(i);
- pResolvedObject->isConst = IsConstAt(i);
- pResolvedObject->objectDisplay = nullptr;
- return TRUE;
- }
- return FALSE;
- }
- Var VariableWalkerBase::GetVarObjectAt(int index)
- {
- Assert(index < pMembersList->Count());
- return pMembersList->Item(index)->aVar;
- }
- bool VariableWalkerBase::IsConstAt(int index)
- {
- Assert(index < pMembersList->Count());
- DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
- // Dead zone variables are also displayed as read only.
- return displayInfo->IsConst() || displayInfo->IsInDeadZone();
- }
- uint32 VariableWalkerBase::GetChildrenCount()
- {
- PopulateMembers();
- return GetMemberCount();
- }
- BOOL VariableWalkerBase::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- if (!IsInGroup()) return FALSE;
- Assert(pResolvedObject);
- // This is fake [Methods] object.
- pResolvedObject->name = groupType == UIGroupType_Scope ? _u("[Scope]") : _u("[Globals]");
- pResolvedObject->obj = Js::RecyclableObject::FromVar(instance);
- pResolvedObject->typeId = TypeIds_Function;
- pResolvedObject->address = nullptr; // Scope object should not be editable
- ArenaAllocator *arena = GetArenaFromContext(pResolvedObject->scriptContext);
- Assert(arena);
- if (groupType == UIGroupType_Scope)
- {
- pResolvedObject->objectDisplay = Anew(arena, ScopeVariablesGroupDisplay, this, pResolvedObject);
- }
- else
- {
- pResolvedObject->objectDisplay = Anew(arena, GlobalsScopeVariablesGroupDisplay, this, pResolvedObject);
- }
- return TRUE;
- }
- IDiagObjectAddress *VariableWalkerBase::FindPropertyAddress(PropertyId propId, bool& isConst)
- {
- PopulateMembers();
- if (pMembersList)
- {
- for (int i = 0; i < pMembersList->Count(); i++)
- {
- DebuggerPropertyDisplayInfo *pair = pMembersList->Item(i);
- Assert(pair);
- if (pair->propId == propId)
- {
- isConst = pair->IsConst();
- return GetObjectAddress(i);
- }
- }
- }
- return nullptr;
- }
- // Determines if the given property is valid for display in the locals window.
- // Cases in which the property is valid are:
- // 1. It is not represented by an internal property.
- // 2. It is a var property.
- // 3. It is a let/const property in scope and is not in a dead zone (assuming isInDeadZone is nullptr).
- // (Determines if the given property is currently in block scope and not in a dead zone.)
- bool VariableWalkerBase::IsPropertyValid(PropertyId propertyId, RegSlot location, bool *isPropertyInDebuggerScope, bool* isConst, bool* isInDeadZone) const
- {
- Assert(isPropertyInDebuggerScope);
- Assert(isConst);
- *isPropertyInDebuggerScope = false;
- // Default to writable (for the case of vars and internal properties).
- *isConst = false;
- if (!allowLexicalThis && propertyId == Js::PropertyIds::_lexicalThisSlotSymbol)
- {
- return false;
- }
- if (!allowSuperReference && (propertyId == Js::PropertyIds::_superReferenceSymbol || propertyId == Js::PropertyIds::_superCtorReferenceSymbol))
- {
- return false;
- }
- if (Js::IsInternalPropertyId(propertyId))
- {
- return false;
- }
- Assert(pFrame);
- Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
- if (pFBody && pFBody->GetScopeObjectChain())
- {
- int offset = GetAdjustedByteCodeOffset();
- if (pFBody->GetScopeObjectChain()->TryGetDebuggerScopePropertyInfo(
- propertyId,
- location,
- offset,
- isPropertyInDebuggerScope,
- isConst,
- isInDeadZone))
- {
- return true;
- }
- }
- // If the register was not found in any scopes, then it's a var and should be in scope.
- return !*isPropertyInDebuggerScope;
- }
- int VariableWalkerBase::GetAdjustedByteCodeOffset() const
- {
- return LocalsWalker::GetAdjustedByteCodeOffset(pFrame);
- }
- DebuggerScope * VariableWalkerBase::GetScopeWhenHaltAtFormals()
- {
- if (IsWalkerForCurrentFrame())
- {
- return LocalsWalker::GetScopeWhenHaltAtFormals(pFrame);
- }
- return nullptr;
- }
- // Allocates and returns a property display info.
- DebuggerPropertyDisplayInfo* VariableWalkerBase::AllocateNewPropertyDisplayInfo(PropertyId propertyId, Var value, bool isConst, bool isInDeadZone)
- {
- Assert(pFrame);
- Assert(value);
- Assert(isInDeadZone || !pFrame->GetScriptContext()->IsUndeclBlockVar(value));
- DWORD flags = DebuggerPropertyDisplayInfoFlags_None;
- flags |= isConst ? DebuggerPropertyDisplayInfoFlags_Const : 0;
- flags |= isInDeadZone ? DebuggerPropertyDisplayInfoFlags_InDeadZone : 0;
- ArenaAllocator *arena = pFrame->GetArena();
- if (isInDeadZone)
- {
- value = pFrame->GetScriptContext()->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
- }
- return Anew(arena, DebuggerPropertyDisplayInfo, propertyId, value, flags);
- }
- /// Slot array
- void SlotArrayVariablesWalker::PopulateMembers()
- {
- if (pMembersList == nullptr && instance != nullptr)
- {
- ArenaAllocator *arena = pFrame->GetArena();
- ScopeSlots slotArray = GetSlotArray();
- if (slotArray.IsFunctionScopeSlotArray())
- {
- DebuggerScope *formalScope = GetScopeWhenHaltAtFormals();
- Js::FunctionBody *pFBody = slotArray.GetFunctionBody();
- uint slotArrayCount = slotArray.GetCount();
- if (formalScope != nullptr && !pFBody->IsParamAndBodyScopeMerged())
- {
- Assert(pFBody->paramScopeSlotArraySize > 0);
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, slotArrayCount);
- for (uint32 i = 0; i < slotArrayCount; i++)
- {
- Js::DebuggerScopeProperty scopeProperty = formalScope->scopeProperties->Item(i);
- Var value = slotArray.Get(i);
- bool isInDeadZone = pFrame->GetScriptContext()->IsUndeclBlockVar(value);
- DebuggerPropertyDisplayInfo *pair = AllocateNewPropertyDisplayInfo(
- scopeProperty.propId,
- value,
- false/*isConst*/,
- isInDeadZone);
- Assert(pair != nullptr);
- pMembersList->Add(pair);
- }
- }
- else if (pFBody->GetPropertyIdsForScopeSlotArray() != nullptr)
- {
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, slotArrayCount);
- for (uint32 i = 0; i < slotArrayCount; i++)
- {
- Js::PropertyId propertyId = pFBody->GetPropertyIdsForScopeSlotArray()[i];
- bool isConst = false;
- bool isPropertyInDebuggerScope = false;
- bool isInDeadZone = false;
- if (propertyId != Js::Constants::NoProperty && IsPropertyValid(propertyId, i, &isPropertyInDebuggerScope, &isConst, &isInDeadZone))
- {
- if (formalScope == nullptr || formalScope->HasProperty(propertyId))
- {
- Var value = slotArray.Get(i);
- if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
- {
- isInDeadZone = true;
- }
- DebuggerPropertyDisplayInfo *pair = AllocateNewPropertyDisplayInfo(
- propertyId,
- value,
- isConst,
- isInDeadZone);
- Assert(pair != nullptr);
- pMembersList->Add(pair);
- }
- }
- }
- }
- }
- else
- {
- DebuggerScope* debuggerScope = slotArray.GetDebuggerScope();
- AssertMsg(debuggerScope, "Slot array debugger scope is missing but should be created.");
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
- if (debuggerScope->HasProperties())
- {
- debuggerScope->scopeProperties->Map([&] (int i, Js::DebuggerScopeProperty& scopeProperty)
- {
- Var value = slotArray.Get(scopeProperty.location);
- bool isConst = scopeProperty.IsConst();
- bool isInDeadZone = false;
- if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
- {
- isInDeadZone = true;
- }
- DebuggerPropertyDisplayInfo *pair = AllocateNewPropertyDisplayInfo(
- scopeProperty.propId,
- value,
- isConst,
- isInDeadZone);
- Assert(pair != nullptr);
- pMembersList->Add(pair);
- });
- }
- }
- }
- }
- IDiagObjectAddress * SlotArrayVariablesWalker::GetObjectAddress(int index)
- {
- Assert(index < pMembersList->Count());
- ScopeSlots slotArray = GetSlotArray();
- return Anew(pFrame->GetArena(), LocalObjectAddressForSlot, slotArray, index, pMembersList->Item(index)->aVar);
- }
- // Regslot
- void RegSlotVariablesWalker::PopulateMembers()
- {
- if (pMembersList == nullptr)
- {
- Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
- ArenaAllocator *arena = pFrame->GetArena();
- PropertyIdOnRegSlotsContainer *propIdContainer = pFBody->GetPropertyIdOnRegSlotsContainer();
- DebuggerScope *formalScope = GetScopeWhenHaltAtFormals();
- // this container can be nullptr if there is no locals in current function.
- if (propIdContainer != nullptr)
- {
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
- for (uint i = 0; i < propIdContainer->length; i++)
- {
- Js::PropertyId propertyId;
- RegSlot reg;
- propIdContainer->FetchItemAt(i, pFBody, &propertyId, ®);
- bool shouldInsert = false;
- bool isConst = false;
- bool isInDeadZone = false;
- if (this->debuggerScope)
- {
- DebuggerScopeProperty debuggerScopeProperty;
- if (this->debuggerScope->TryGetValidProperty(propertyId, reg, GetAdjustedByteCodeOffset(), &debuggerScopeProperty, &isInDeadZone))
- {
- isConst = debuggerScopeProperty.IsConst();
- shouldInsert = true;
- }
- }
- else
- {
- bool isPropertyInDebuggerScope = false;
- shouldInsert = IsPropertyValid(propertyId, reg, &isPropertyInDebuggerScope, &isConst, &isInDeadZone) && !isPropertyInDebuggerScope;
- }
- if (shouldInsert && formalScope != nullptr)
- {
- shouldInsert = formalScope->HasProperty(propertyId);
- }
- if (shouldInsert)
- {
- Var value = pFrame->GetRegValue(reg);
- // If the user didn't supply an arguments object, a fake one will
- // be created when evaluating LocalsWalker::ShouldInsertFakeArguments().
- if (!(propertyId == PropertyIds::arguments && value == nullptr))
- {
- if (pFrame->GetScriptContext()->IsUndeclBlockVar(value))
- {
- isInDeadZone = true;
- }
- DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(
- propertyId,
- (Var)reg,
- isConst,
- isInDeadZone);
- Assert(info != nullptr);
- pMembersList->Add(info);
- }
- }
- }
- }
- }
- }
- Var RegSlotVariablesWalker::GetVarObjectAndRegAt(int index, RegSlot* reg /*= nullptr*/)
- {
- Assert(index < pMembersList->Count());
- Var returnedVar = nullptr;
- RegSlot returnedReg = Js::Constants::NoRegister;
- DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
- if (displayInfo->IsInDeadZone())
- {
- // The uninitialized string is already set in the var for the dead zone display.
- Assert(JavascriptString::Is(displayInfo->aVar));
- returnedVar = displayInfo->aVar;
- }
- else
- {
- returnedReg = ::Math::PointerCastToIntegral<RegSlot>(displayInfo->aVar);
- returnedVar = pFrame->GetRegValue(returnedReg);
- }
- if (reg != nullptr)
- {
- *reg = returnedReg;
- }
- AssertMsg(returnedVar, "Var should be replaced with the dead zone string object.");
- return returnedVar;
- }
- Var RegSlotVariablesWalker::GetVarObjectAt(int index)
- {
- return GetVarObjectAndRegAt(index);
- }
- IDiagObjectAddress * RegSlotVariablesWalker::GetObjectAddress(int index)
- {
- RegSlot reg = Js::Constants::NoRegister;
- Var obj = GetVarObjectAndRegAt(index, ®);
- return Anew(pFrame->GetArena(), LocalObjectAddressForRegSlot, pFrame, reg, obj);
- }
- // For an activation object.
- void ObjectVariablesWalker::PopulateMembers()
- {
- if (pMembersList == nullptr && instance != nullptr)
- {
- ScriptContext * scriptContext = pFrame->GetScriptContext();
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- Assert(Js::RecyclableObject::Is(instance));
- Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
- Assert(JavascriptOperators::IsObject(object));
- int count = object->GetPropertyCount();
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, count);
- AddObjectProperties(count, object);
- }
- }
- void ObjectVariablesWalker::AddObjectProperties(int count, Js::RecyclableObject* object)
- {
- ScriptContext * scriptContext = pFrame->GetScriptContext();
- DebuggerScope *formalScope = GetScopeWhenHaltAtFormals();
- // For the scopes and locals only enumerable properties will be shown.
- for (int i = 0; i < count; i++)
- {
- Js::PropertyId propertyId = object->GetPropertyId((PropertyIndex)i);
- bool isConst = false;
- bool isPropertyInDebuggerScope = false;
- bool isInDeadZone = false;
- if (propertyId != Js::Constants::NoProperty
- && IsPropertyValid(propertyId, Js::Constants::NoRegister, &isPropertyInDebuggerScope, &isConst, &isInDeadZone)
- && object->IsEnumerable(propertyId))
- {
- Var itemObj = RecyclableObjectWalker::GetObject(object, object, propertyId, scriptContext);
- if (itemObj == nullptr)
- {
- itemObj = scriptContext->GetLibrary()->GetUndefined();
- }
- if (formalScope == nullptr || formalScope->HasProperty(propertyId))
- {
- if (formalScope != nullptr && pFrame->GetScriptContext()->IsUndeclBlockVar(itemObj))
- {
- itemObj = scriptContext->GetLibrary()->GetUndefined();
- }
- AssertMsg(!RootObjectBase::Is(object) || !isConst, "root object shouldn't produce const properties through IsPropertyValid");
- DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(
- propertyId,
- itemObj,
- isConst,
- isInDeadZone);
- Assert(info);
- pMembersList->Add(info);
- }
- }
- }
- }
- IDiagObjectAddress * ObjectVariablesWalker::GetObjectAddress(int index)
- {
- Assert(index < pMembersList->Count());
- DebuggerPropertyDisplayInfo* info = pMembersList->Item(index);
- return Anew(pFrame->GetArena(), RecyclableObjectAddress, instance, info->propId, info->aVar, info->IsInDeadZone() ? TRUE : FALSE);
- }
- // For root access on the Global object (adds let/const variables before properties)
- void RootObjectVariablesWalker::PopulateMembers()
- {
- if (pMembersList == nullptr && instance != nullptr)
- {
- ScriptContext * scriptContext = pFrame->GetScriptContext();
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- Assert(Js::RootObjectBase::Is(instance));
- Js::RootObjectBase* object = Js::RootObjectBase::FromVar(instance);
- int count = object->GetPropertyCount();
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena, count);
- // Add let/const globals first so that they take precedence over the global properties. Then
- // VariableWalkerBase::FindPropertyAddress will correctly find let/const globals that shadow
- // global properties of the same name.
- object->MapLetConstGlobals([&](const PropertyRecord* propertyRecord, Var value, bool isConst) {
- if (!scriptContext->IsUndeclBlockVar(value))
- {
- // Let/const are always enumerable and valid
- DebuggerPropertyDisplayInfo *info = AllocateNewPropertyDisplayInfo(propertyRecord->GetPropertyId(), value, isConst, false /*isInDeadZone*/);
- pMembersList->Add(info);
- }
- });
- AddObjectProperties(count, object);
- }
- }
- // DiagScopeVariablesWalker
- DiagScopeVariablesWalker::DiagScopeVariablesWalker(DiagStackFrame* _pFrame, Var _instance, IDiagObjectModelWalkerBase* innerWalker)
- : VariableWalkerBase(_pFrame, _instance, UIGroupType_InnerScope, /* allowLexicalThis */ false)
- {
- ScriptContext * scriptContext = _pFrame->GetScriptContext();
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- pDiagScopeObjects = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
- pDiagScopeObjects->Add(innerWalker);
- diagScopeVarCount = innerWalker->GetChildrenCount();
- scopeIsInitialized = true;
- }
- uint32 DiagScopeVariablesWalker::GetChildrenCount()
- {
- if (scopeIsInitialized)
- {
- return diagScopeVarCount;
- }
- Assert(pFrame);
- Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
- if (pFBody->GetScopeObjectChain())
- {
- int bytecodeOffset = GetAdjustedByteCodeOffset();
- ScriptContext * scriptContext = pFrame->GetScriptContext();
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- pDiagScopeObjects = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
- // Look for catch/with/block scopes which encompass current offset (skip block scopes as
- // they are only used for lookup within the RegSlotVariablesWalker).
- // Go the reverse way so that we find the innermost scope first;
- Js::ScopeObjectChain * pScopeObjectChain = pFBody->GetScopeObjectChain();
- for (int i = pScopeObjectChain->pScopeChain->Count() - 1 ; i >= 0; i--)
- {
- Js::DebuggerScope *debuggerScope = pScopeObjectChain->pScopeChain->Item(i);
- bool isScopeInRange = debuggerScope->IsOffsetInScope(bytecodeOffset);
- if (isScopeInRange
- && !debuggerScope->IsParamScope()
- && (debuggerScope->IsOwnScope() || (debuggerScope->scopeType == DiagBlockScopeDirect && debuggerScope->HasProperties())))
- {
- switch (debuggerScope->scopeType)
- {
- case DiagWithScope:
- {
- if (enumWithScopeAlso)
- {
- RecyclableObjectWalker* recylableObjectWalker = Anew(arena, RecyclableObjectWalker, scriptContext,
- (Var)pFrame->GetRegValue(debuggerScope->GetLocation(), true));
- pDiagScopeObjects->Add(recylableObjectWalker);
- diagScopeVarCount += recylableObjectWalker->GetChildrenCount();
- }
- }
- break;
- case DiagCatchScopeDirect:
- case DiagCatchScopeInObject:
- {
- CatchScopeWalker* catchScopeWalker = Anew(arena, CatchScopeWalker, pFrame, debuggerScope);
- pDiagScopeObjects->Add(catchScopeWalker);
- diagScopeVarCount += catchScopeWalker->GetChildrenCount();
- }
- break;
- case DiagCatchScopeInSlot:
- case DiagBlockScopeInSlot:
- {
- SlotArrayVariablesWalker* blockScopeWalker = Anew(arena, SlotArrayVariablesWalker, pFrame,
- (Var)pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation()), UIGroupType_InnerScope, /* allowLexicalThis */ false);
- pDiagScopeObjects->Add(blockScopeWalker);
- diagScopeVarCount += blockScopeWalker->GetChildrenCount();
- }
- break;
- case DiagBlockScopeDirect:
- {
- RegSlotVariablesWalker *pObjWalker = Anew(arena, RegSlotVariablesWalker, pFrame, debuggerScope, UIGroupType_InnerScope);
- pDiagScopeObjects->Add(pObjWalker);
- diagScopeVarCount += pObjWalker->GetChildrenCount();
- }
- break;
- case DiagBlockScopeInObject:
- {
- ObjectVariablesWalker* objectVariablesWalker = Anew(arena, ObjectVariablesWalker, pFrame, pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation()), UIGroupType_InnerScope, /* allowLexicalThis */ false);
- pDiagScopeObjects->Add(objectVariablesWalker);
- diagScopeVarCount += objectVariablesWalker->GetChildrenCount();
- }
- break;
- default:
- Assert(false);
- }
- }
- }
- }
- scopeIsInitialized = true;
- return diagScopeVarCount;
- }
- BOOL DiagScopeVariablesWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- if (i >= 0 && i < (int)diagScopeVarCount)
- {
- for (int j = 0; j < pDiagScopeObjects->Count(); j++)
- {
- IDiagObjectModelWalkerBase *pObjWalker = pDiagScopeObjects->Item(j);
- if (i < (int)pObjWalker->GetChildrenCount())
- {
- return pObjWalker->Get(i, pResolvedObject);
- }
- i -= (int)pObjWalker->GetChildrenCount();
- Assert(i >=0);
- }
- }
- return FALSE;
- }
- IDiagObjectAddress * DiagScopeVariablesWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
- {
- IDiagObjectAddress * address = nullptr;
- // Ensure that children are fetched.
- GetChildrenCount();
- if (pDiagScopeObjects)
- {
- for (int j = 0; j < pDiagScopeObjects->Count(); j++)
- {
- IDiagObjectModelWalkerBase *pObjWalker = pDiagScopeObjects->Item(j);
- Assert(pObjWalker);
- address = pObjWalker->FindPropertyAddress(propId, isConst);
- if (address != nullptr)
- {
- break;
- }
- }
- }
- return address;
- }
- // Locals walker
- LocalsWalker::LocalsWalker(DiagStackFrame* _frame, DWORD _frameWalkerFlags)
- : pFrame(_frame), frameWalkerFlags(_frameWalkerFlags), pVarWalkers(nullptr), totalLocalsCount(0), hasUserNotDefinedArguments(false)
- {
- Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
- if (pFBody && !pFBody->GetUtf8SourceInfo()->GetIsLibraryCode())
- {
- // Allocate the container of all walkers.
- ArenaAllocator *arena = pFrame->GetArena();
- pVarWalkers = JsUtil::List<VariableWalkerBase *, ArenaAllocator>::New(arena);
- VariableWalkerBase *pVarWalker = nullptr;
- // Top most function will have one of these regslot, slotarray or activation object.
- FrameDisplay * pDisplay = pFrame->GetFrameDisplay();
- uint scopeCount = (uint)(pDisplay ? pDisplay->GetLength() : 0);
- uint nextStartIndex = 0;
- // Add the catch/with/block expression scope objects.
- if (pFBody->GetScopeObjectChain())
- {
- pVarWalkers->Add(Anew(arena, DiagScopeVariablesWalker, pFrame, nullptr, !!(frameWalkerFlags & FrameWalkerFlags::FW_EnumWithScopeAlso)));
- }
- // In the eval function, we will not show global items directly, instead they should go as a group node.
- bool shouldAddGlobalItemsDirectly = pFBody->GetIsGlobalFunc() && !pFBody->IsEval();
- bool dontAddGlobalsDirectly = (frameWalkerFlags & FrameWalkerFlags::FW_DontAddGlobalsDirectly) == FrameWalkerFlags::FW_DontAddGlobalsDirectly;
- if (shouldAddGlobalItemsDirectly && !dontAddGlobalsDirectly)
- {
- // Global properties will be enumerated using RootObjectVariablesWalker
- pVarWalkers->Add(Anew(arena, RootObjectVariablesWalker, pFrame, pFrame->GetRootObject(), UIGroupType_None));
- }
- DebuggerScope *formalScope = GetScopeWhenHaltAtFormals(pFrame);
- // 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.
- if (!pFBody->IsParamAndBodyScopeMerged() && formalScope != nullptr)
- {
- Assert(scopeCount > 0);
- if (formalScope->scopeType == Js::DiagParamScopeInObject)
- {
- pVarWalker = Anew(arena, ObjectVariablesWalker, pFrame, (Js::Var *)pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- }
- else
- {
- Assert(pFBody->paramScopeSlotArraySize > 0);
- pVarWalker = Anew(arena, SlotArrayVariablesWalker, pFrame, (Js::Var *)pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- }
- }
- else
- {
- DWORD localsType = GetCurrentFramesLocalsType(pFrame);
- if (localsType & FramesLocalType::LocalType_Reg)
- {
- pVarWalkers->Add(Anew(arena, RegSlotVariablesWalker, pFrame, nullptr /*not debugger scope*/, UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- }
- if (localsType & FramesLocalType::LocalType_InObject)
- {
- Assert(scopeCount > 0);
- pVarWalker = Anew(arena, ObjectVariablesWalker, pFrame, pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- }
- else if (localsType & FramesLocalType::LocalType_InSlot)
- {
- Assert(scopeCount > 0);
- pVarWalker = Anew(arena, SlotArrayVariablesWalker, pFrame, (Js::Var *)pDisplay->GetItem(nextStartIndex++), UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- }
- else if (scopeCount > 0 && pFBody->GetFrameDisplayRegister() != 0 )
- {
- Assert((Var)pDisplay->GetItem(0) == pFrame->GetScriptContext()->GetLibrary()->GetNull() || !pFBody->IsParamAndBodyScopeMerged());
- // A dummy scope with nullptr register is created. Skip this.
- nextStartIndex++;
- }
- }
- if (pVarWalker)
- {
- pVarWalkers->Add(pVarWalker);
- }
- const Js::Var nullVar = pFrame->GetScriptContext()->GetLibrary()->GetNull();
- for (uint i = nextStartIndex; i < (uint)scopeCount; i++)
- {
- Var currentScopeObject = pDisplay->GetItem(i);
- if (currentScopeObject != nullptr && currentScopeObject != nullVar) // Skip nullptr (dummy scope)
- {
- ScopeType scopeType = FrameDisplay::GetScopeType(currentScopeObject);
- switch(scopeType)
- {
- case ScopeType_ActivationObject:
- pVarWalker = Anew(arena, ObjectVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- pVarWalkers->Add(pVarWalker);
- break;
- case ScopeType_SlotArray:
- pVarWalker = Anew(arena, SlotArrayVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference));
- pVarWalkers->Add(pVarWalker);
- break;
- case ScopeType_WithScope:
- if( (frameWalkerFlags & FrameWalkerFlags::FW_EnumWithScopeAlso) == FrameWalkerFlags::FW_EnumWithScopeAlso)
- {
- RecyclableObjectWalker* withScopeWalker = Anew(arena, RecyclableObjectWalker, pFrame->GetScriptContext(), currentScopeObject);
- pVarWalker = Anew(arena, DiagScopeVariablesWalker, pFrame, currentScopeObject, withScopeWalker);
- pVarWalkers->Add(pVarWalker);
- }
- break;
- default:
- Assert(false);
- }
- }
- }
- // No need to add global properties if this is a global function, as it is already done above.
- if (!shouldAddGlobalItemsDirectly && !dontAddGlobalsDirectly)
- {
- pVarWalker = Anew(arena, RootObjectVariablesWalker, pFrame, pFrame->GetRootObject(), UIGroupType_Globals);
- pVarWalkers->Add(pVarWalker);
- }
- }
- }
- BOOL LocalsWalker::CreateArgumentsObject(ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- Assert(pResolvedObject->scriptContext);
- Assert(hasUserNotDefinedArguments);
- pResolvedObject->name = _u("arguments");
- pResolvedObject->propId = Js::PropertyIds::arguments;
- pResolvedObject->typeId = TypeIds_Arguments;
- Js::FunctionBody *pFBody = pFrame->GetJavascriptFunction()->GetFunctionBody();
- Assert(pFBody);
- pResolvedObject->obj = pFrame->GetArgumentsObject();
- if (pResolvedObject->obj == nullptr)
- {
- pResolvedObject->obj = pFrame->CreateHeapArguments();
- Assert(pResolvedObject->obj);
- pResolvedObject->objectDisplay = Anew(pFrame->GetArena(), RecyclableArgumentsObjectDisplay, pResolvedObject, this);
- ExpandArgumentsObject(pResolvedObject->objectDisplay);
- }
- pResolvedObject->address = Anew(GetArenaFromContext(pResolvedObject->scriptContext),
- RecyclableObjectAddress,
- pResolvedObject->scriptContext->GetGlobalObject(),
- Js::PropertyIds::arguments,
- pResolvedObject->obj,
- false /*isInDeadZone*/);
- return TRUE;
- }
- BOOL LocalsWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- if (i >= (int)totalLocalsCount)
- {
- return FALSE;
- }
- pResolvedObject->scriptContext = pFrame->GetScriptContext();
- if (VariableWalkerBase::GetExceptionObject(i, pFrame, pResolvedObject))
- {
- return TRUE;
- }
- #ifdef ENABLE_MUTATION_BREAKPOINT
- // Pending mutation display should be before any return value
- if (VariableWalkerBase::GetBreakMutationBreakpointValue(i, pFrame, pResolvedObject))
- {
- return TRUE;
- }
- #endif
- if (VariableWalkerBase::GetReturnedValue(i, pFrame, pResolvedObject))
- {
- return TRUE;
- }
- if (hasUserNotDefinedArguments)
- {
- if (i == 0)
- {
- return CreateArgumentsObject(pResolvedObject);
- }
- i--;
- }
- if (!pVarWalkers || pVarWalkers->Count() == 0)
- {
- return FALSE;
- }
- // In the case of not making groups, all variables will be arranged
- // as one int32 list in the locals window.
- if (!ShouldMakeGroups())
- {
- for (int j = 0; j < pVarWalkers->Count(); j++)
- {
- int count = pVarWalkers->Item(j)->GetChildrenCount();
- if (i < count)
- {
- return pVarWalkers->Item(j)->Get(i, pResolvedObject);
- }
- i-= count;
- }
- Assert(FALSE);
- return FALSE;
- }
- int startScopeIndex = 0;
- // Need to determine what range of local variables we're in for the requested index.
- // Non-grouped local variables are organized with reg slot coming first, then followed by
- // scope slot/activation object variables. Catch and with variables follow next
- // and group variables are stored last which come from upper scopes that
- // are accessed in this function (those passed down as part of a closure).
- // Note that all/any/none of these walkers may be present.
- // Example variable layout:
- // [0-2] - Reg slot vars.
- // [3-4] - Scope slot array vars.
- // [5-8] - Global vars (stored on the global object as properties).
- for (int j = 0; j < pVarWalkers->Count(); ++j)
- {
- VariableWalkerBase *variableWalker = pVarWalkers->Item(j);
- if (!variableWalker->IsInGroup())
- {
- int count = variableWalker->GetChildrenCount();
- if (i < count)
- {
- return variableWalker->Get(i, pResolvedObject);
- }
- i-= count;
- startScopeIndex++;
- }
- else
- {
- // We've finished with all walkers for the current locals level so
- // break out in order to handle the groups.
- break;
- }
- }
- // Handle groups.
- Assert((i + startScopeIndex) < pVarWalkers->Count());
- VariableWalkerBase *variableWalker = pVarWalkers->Item(i + startScopeIndex);
- return variableWalker->GetGroupObject(pResolvedObject);
- }
- bool LocalsWalker::ShouldInsertFakeArguments()
- {
- JavascriptFunction* func = pFrame->GetJavascriptFunction();
- if (func->IsScriptFunction()
- && !func->GetFunctionBody()->GetUtf8SourceInfo()->GetIsLibraryCode()
- && !func->GetFunctionBody()->GetIsGlobalFunc())
- {
- bool isConst = false;
- hasUserNotDefinedArguments = (nullptr == FindPropertyAddress(PropertyIds::arguments, false /*walkers on the current frame*/, isConst));
- }
- return hasUserNotDefinedArguments;
- }
- uint32 LocalsWalker::GetChildrenCount()
- {
- if (totalLocalsCount == 0)
- {
- if (pVarWalkers)
- {
- int groupWalkersStartIndex = 0;
- for (int i = 0; i < pVarWalkers->Count(); i++)
- {
- VariableWalkerBase* variableWalker = pVarWalkers->Item(i);
- // In the case of making groups, we want to include any variables that aren't
- // part of a group as part of the local variable count.
- if (!ShouldMakeGroups() || !variableWalker->IsInGroup())
- {
- ++groupWalkersStartIndex;
- totalLocalsCount += variableWalker->GetChildrenCount();
- }
- }
- // Add on the number of groups to display in locals
- // (group walkers come after function local walkers).
- totalLocalsCount += (pVarWalkers->Count() - groupWalkersStartIndex);
- }
- if (VariableWalkerBase::HasExceptionObject(pFrame))
- {
- totalLocalsCount++;
- }
- #ifdef ENABLE_MUTATION_BREAKPOINT
- totalLocalsCount += VariableWalkerBase::GetBreakMutationBreakpointsCount(pFrame);
- #endif
- totalLocalsCount += VariableWalkerBase::GetReturnedValueCount(pFrame);
- // Check if needed to add fake arguments.
- if (ShouldInsertFakeArguments())
- {
- // In this case we need to create arguments object explicitly.
- totalLocalsCount++;
- }
- }
- return totalLocalsCount;
- }
- uint32 LocalsWalker::GetLocalVariablesCount()
- {
- uint32 localsCount = 0;
- if (pVarWalkers)
- {
- for (int i = 0; i < pVarWalkers->Count(); i++)
- {
- VariableWalkerBase* variableWalker = pVarWalkers->Item(i);
- // In the case of making groups, we want to include any variables that aren't
- // part of a group as part of the local variable count.
- if (!ShouldMakeGroups() || !variableWalker->IsInGroup())
- {
- localsCount += variableWalker->GetChildrenCount();
- }
- }
- }
- return localsCount;
- }
- BOOL LocalsWalker::GetLocal(int i, ResolvedObject* pResolvedObject)
- {
- if (!pVarWalkers || pVarWalkers->Count() == 0)
- {
- return FALSE;
- }
- for (int j = 0; j < pVarWalkers->Count(); ++j)
- {
- VariableWalkerBase *variableWalker = pVarWalkers->Item(j);
- if (!ShouldMakeGroups() || !variableWalker->IsInGroup())
- {
- int count = variableWalker->GetChildrenCount();
- if (i < count)
- {
- return variableWalker->Get(i, pResolvedObject);
- }
- i -= count;
- }
- else
- {
- // We've finished with all walkers for the current locals level so
- // break out in order to handle the groups.
- break;
- }
- }
- return FALSE;
- }
- BOOL LocalsWalker::GetGroupObject(Js::UIGroupType uiGroupType, int i, ResolvedObject* pResolvedObject)
- {
- if (pVarWalkers)
- {
- int scopeCount = 0;
- for (int j = 0; j < pVarWalkers->Count(); j++)
- {
- VariableWalkerBase* variableWalker = pVarWalkers->Item(j);
- if (variableWalker->groupType == uiGroupType)
- {
- scopeCount++;
- if (i < scopeCount)
- {
- return variableWalker->GetGroupObject(pResolvedObject);
- }
- }
- }
- }
- return FALSE;
- }
- BOOL LocalsWalker::GetScopeObject(int i, ResolvedObject* pResolvedObject)
- {
- return this->GetGroupObject(Js::UIGroupType::UIGroupType_Scope, i, pResolvedObject);
- }
- BOOL LocalsWalker::GetGlobalsObject(ResolvedObject* pResolvedObject)
- {
- int i = 0;
- return this->GetGroupObject(Js::UIGroupType::UIGroupType_Globals, i, pResolvedObject);
- }
- /*static*/
- DebuggerScope * LocalsWalker::GetScopeWhenHaltAtFormals(DiagStackFrame* frame)
- {
- Js::ScopeObjectChain * scopeObjectChain = frame->GetJavascriptFunction()->GetFunctionBody()->GetScopeObjectChain();
- if (scopeObjectChain != nullptr && scopeObjectChain->pScopeChain != nullptr)
- {
- int currentOffset = GetAdjustedByteCodeOffset(frame);
- for (int i = 0; i < scopeObjectChain->pScopeChain->Count(); i++)
- {
- Js::DebuggerScope * scope = scopeObjectChain->pScopeChain->Item(i);
- if (scope->IsParamScope() && scope->GetEnd() > currentOffset)
- {
- return scope;
- }
- }
- }
- return nullptr;
- }
- // Gets an adjusted offset for the current bytecode location based on which stack frame we're in.
- // If we're in the top frame (leaf node), then the byte code offset should remain as is, to reflect
- // the current position of the instruction pointer. If we're not in the top frame, we need to subtract
- // 1 as the byte code location will be placed at the next statement to be executed at the top frame.
- // In the case of block scoping, this is an inaccurate location for viewing variables since the next
- // statement could be beyond the current block scope. For inspection, we want to remain in the
- // current block that the function was called from.
- // An example is this:
- // function foo() { ... } // Frame 0 (with breakpoint inside)
- // function bar() { // Frame 1
- // {
- // let a = 0;
- // foo(); // <-- Inspecting here, foo is already evaluated.
- // }
- // foo(); // <-- Byte code offset is now here, so we need to -1 to get back in the block scope.
- int LocalsWalker::GetAdjustedByteCodeOffset(DiagStackFrame* frame)
- {
- int offset = frame->GetByteCodeOffset();
- if (!frame->IsTopFrame() && frame->IsInterpreterFrame())
- {
- // Native frames are already adjusted so just need to adjust interpreted
- // frames that are not the top frame.
- --offset;
- }
- return offset;
- }
- /*static*/
- DWORD LocalsWalker::GetCurrentFramesLocalsType(DiagStackFrame* frame)
- {
- Assert(frame);
- FunctionBody *pFBody = frame->GetJavascriptFunction()->GetFunctionBody();
- Assert(pFBody);
- DWORD localType = FramesLocalType::LocalType_None;
- if (pFBody->GetFrameDisplayRegister() != 0)
- {
- if (pFBody->GetObjectRegister() != 0)
- {
- // current scope is activation object
- localType = FramesLocalType::LocalType_InObject;
- }
- else
- {
- if (pFBody->scopeSlotArraySize > 0)
- {
- localType = FramesLocalType::LocalType_InSlot;
- }
- }
- }
- if (pFBody->GetPropertyIdOnRegSlotsContainer() && pFBody->GetPropertyIdOnRegSlotsContainer()->length > 0)
- {
- localType |= FramesLocalType::LocalType_Reg;
- }
- return localType;
- }
- IDiagObjectAddress * LocalsWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
- {
- return FindPropertyAddress(propId, true, isConst);
- }
- IDiagObjectAddress * LocalsWalker::FindPropertyAddress(PropertyId propId, bool enumerateGroups, bool& isConst)
- {
- isConst = false;
- if (propId == PropertyIds::arguments && hasUserNotDefinedArguments)
- {
- ResolvedObject resolveObject;
- resolveObject.scriptContext = pFrame->GetScriptContext();
- if (CreateArgumentsObject(&resolveObject))
- {
- return resolveObject.address;
- }
- }
- if (pVarWalkers)
- {
- for (int i = 0; i < pVarWalkers->Count(); i++)
- {
- VariableWalkerBase *pVarWalker = pVarWalkers->Item(i);
- if (!enumerateGroups && !pVarWalker->IsWalkerForCurrentFrame())
- {
- continue;
- }
- IDiagObjectAddress *address = pVarWalkers->Item(i)->FindPropertyAddress(propId, isConst);
- if (address != nullptr)
- {
- return address;
- }
- }
- }
- return nullptr;
- }
- void LocalsWalker::ExpandArgumentsObject(IDiagObjectModelDisplay * argumentsDisplay)
- {
- Assert(argumentsDisplay != nullptr);
- WeakArenaReference<Js::IDiagObjectModelWalkerBase>* argumentsObjectWalkerRef = argumentsDisplay->CreateWalker();
- Assert(argumentsObjectWalkerRef != nullptr);
- IDiagObjectModelWalkerBase * walker = argumentsObjectWalkerRef->GetStrongReference();
- int count = (int)walker->GetChildrenCount();
- Js::ResolvedObject tempResolvedObj;
- for (int i = 0; i < count; i++)
- {
- walker->Get(i, &tempResolvedObj);
- }
- argumentsObjectWalkerRef->ReleaseStrongReference();
- HeapDelete(argumentsObjectWalkerRef);
- }
- //--------------------------
- // LocalObjectAddressForSlot
- LocalObjectAddressForSlot::LocalObjectAddressForSlot(ScopeSlots _pSlotArray, int _slotIndex, Js::Var _value)
- : slotArray(_pSlotArray),
- slotIndex(_slotIndex),
- value(_value)
- {
- }
- BOOL LocalObjectAddressForSlot::Set(Var updateObject)
- {
- if (IsInDeadZone())
- {
- AssertMsg(FALSE, "Should not be able to set the value of a slot in a dead zone.");
- return FALSE;
- }
- slotArray.Set(slotIndex, updateObject);
- return TRUE;
- }
- Var LocalObjectAddressForSlot::GetValue(BOOL fUpdated)
- {
- if (!fUpdated || IsInDeadZone())
- {
- #if DBG
- if (IsInDeadZone())
- {
- // If we're in a dead zone, the value will be the
- // [Uninitialized block variable] string.
- Assert(JavascriptString::Is(value));
- }
- #endif // DBG
- return value;
- }
- return slotArray.Get(slotIndex);
- }
- BOOL LocalObjectAddressForSlot::IsInDeadZone() const
- {
- Var value = slotArray.Get(slotIndex);
- if (!RecyclableObject::Is(value))
- {
- return FALSE;
- }
- RecyclableObject* obj = RecyclableObject::FromVar(value);
- ScriptContext* scriptContext = obj->GetScriptContext();
- return scriptContext->IsUndeclBlockVar(obj) ? TRUE : FALSE;
- }
- //--------------------------
- // LocalObjectAddressForSlot
- LocalObjectAddressForRegSlot::LocalObjectAddressForRegSlot(DiagStackFrame* _pFrame, RegSlot _regSlot, Js::Var _value)
- : pFrame(_pFrame),
- regSlot(_regSlot),
- value(_value)
- {
- }
- BOOL LocalObjectAddressForRegSlot::IsInDeadZone() const
- {
- return regSlot == Js::Constants::NoRegister;
- }
- BOOL LocalObjectAddressForRegSlot::Set(Var updateObject)
- {
- Assert(pFrame);
- if (IsInDeadZone())
- {
- AssertMsg(FALSE, "Should not be able to set the value of a register in a dead zone.");
- return FALSE;
- }
- pFrame->SetRegValue(regSlot, updateObject);
- return TRUE;
- }
- Var LocalObjectAddressForRegSlot::GetValue(BOOL fUpdated)
- {
- if (!fUpdated || IsInDeadZone())
- {
- #if DBG
- if (IsInDeadZone())
- {
- // If we're in a dead zone, the value will be the
- // [Uninitialized block variable] string.
- Assert(JavascriptString::Is(value));
- }
- #endif // DBG
- return value;
- }
- Assert(pFrame);
- return pFrame->GetRegValue(regSlot);
- }
- //
- // CatchScopeWalker
- BOOL CatchScopeWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- Assert(pFrame);
- pResolvedObject->scriptContext = pFrame->GetScriptContext();
- Assert(i < (int)GetChildrenCount());
- Js::DebuggerScopeProperty scopeProperty = debuggerScope->scopeProperties->Item(i);
- pResolvedObject->propId = scopeProperty.propId;
- const Js::PropertyRecord* propertyRecord = pResolvedObject->scriptContext->GetPropertyName(pResolvedObject->propId);
- // TODO: If this is a symbol-keyed property, we should indicate that in the name - "Symbol (description)"
- pResolvedObject->name = propertyRecord->GetBuffer();
- FetchValueAndAddress(scopeProperty, &pResolvedObject->obj, &pResolvedObject->address);
- Assert(pResolvedObject->obj);
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->objectDisplay = Anew(pFrame->GetArena(), RecyclableObjectDisplay, pResolvedObject);
- return TRUE;
- }
- uint32 CatchScopeWalker::GetChildrenCount()
- {
- return debuggerScope->scopeProperties->Count();
- }
- void CatchScopeWalker::FetchValueAndAddress(DebuggerScopeProperty &scopeProperty, _Out_opt_ Var *pValue, _Out_opt_ IDiagObjectAddress ** ppAddress)
- {
- Assert(pValue != nullptr || ppAddress != nullptr);
- ArenaAllocator* arena = pFrame->GetArena();
- Var outValue;
- IDiagObjectAddress * pAddress = nullptr;
- ScriptContext* scriptContext = pFrame->GetScriptContext();
- if (debuggerScope->scopeType == Js::DiagCatchScopeInObject)
- {
- Var obj = pFrame->GetInnerScopeFromRegSlot(debuggerScope->GetLocation());
- Assert(RecyclableObject::Is(obj));
- outValue = RecyclableObjectWalker::GetObject(RecyclableObject::FromVar(obj), RecyclableObject::FromVar(obj), scopeProperty.propId, scriptContext);
- bool isInDeadZone = scriptContext->IsUndeclBlockVar(outValue);
- if (isInDeadZone)
- {
- outValue = scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
- }
- pAddress = Anew(arena, RecyclableObjectAddress, obj, scopeProperty.propId, outValue, isInDeadZone);
- }
- else
- {
- outValue = pFrame->GetRegValue(scopeProperty.location);
- bool isInDeadZone = scriptContext->IsUndeclBlockVar(outValue);
- if (isInDeadZone)
- {
- outValue = scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString();
- }
- pAddress = Anew(arena, LocalObjectAddressForRegSlot, pFrame, scopeProperty.location, outValue);
- }
- if (pValue)
- {
- *pValue = outValue;
- }
- if (ppAddress)
- {
- *ppAddress = pAddress;
- }
- }
- IDiagObjectAddress *CatchScopeWalker::FindPropertyAddress(PropertyId _propId, bool& isConst)
- {
- isConst = false;
- IDiagObjectAddress * address = nullptr;
- auto properties = debuggerScope->scopeProperties;
- for (int i = 0; i < properties->Count(); i++)
- {
- if (properties->Item(i).propId == _propId)
- {
- FetchValueAndAddress(properties->Item(i), nullptr, &address);
- break;
- }
- }
- return address;
- }
- //--------------------------
- // RecyclableObjectAddress
- RecyclableObjectAddress::RecyclableObjectAddress(Var _parentObj, Js::PropertyId _propId, Js::Var _value, BOOL _isInDeadZone)
- : parentObj(_parentObj),
- propId(_propId),
- value(_value),
- isInDeadZone(_isInDeadZone)
- {
- parentObj = ((RecyclableObject*)parentObj)->GetThisObjectOrUnWrap();
- }
- BOOL RecyclableObjectAddress::IsInDeadZone() const
- {
- return isInDeadZone;
- }
- BOOL RecyclableObjectAddress::Set(Var updateObject)
- {
- if (Js::RecyclableObject::Is(parentObj))
- {
- Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
- ScriptContext* requestContext = obj->GetScriptContext(); //TODO: real requestContext
- return Js::JavascriptOperators::SetProperty(obj, obj, propId, updateObject, requestContext);
- }
- return FALSE;
- }
- BOOL RecyclableObjectAddress::IsWritable()
- {
- if (Js::RecyclableObject::Is(parentObj))
- {
- Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
- return obj->IsWritable(propId);
- }
- return TRUE;
- }
- Var RecyclableObjectAddress::GetValue(BOOL fUpdated)
- {
- if (!fUpdated)
- {
- return value;
- }
- if (Js::RecyclableObject::Is(parentObj))
- {
- Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(parentObj);
- ScriptContext* requestContext = obj->GetScriptContext();
- Var objValue = nullptr;
- if (Js::JavascriptOperators::GetProperty(obj, propId, &objValue, requestContext))
- {
- return objValue;
- }
- }
- return nullptr;
- }
- //--------------------------
- // RecyclableObjectDisplay
- RecyclableObjectDisplay::RecyclableObjectDisplay(ResolvedObject* resolvedObject, DBGPROP_ATTRIB_FLAGS defaultAttributes)
- : scriptContext(resolvedObject->scriptContext),
- instance(resolvedObject->obj),
- originalInstance(resolvedObject->originalObj != nullptr ? resolvedObject->originalObj : resolvedObject->obj), // If we don't have it set it means originalInstance should point to object itself
- name(resolvedObject->name),
- pObjAddress(resolvedObject->address),
- defaultAttributes(defaultAttributes),
- propertyId(resolvedObject->propId)
- {
- }
- bool RecyclableObjectDisplay::IsLiteralProperty() const
- {
- Assert(this->scriptContext);
- if (this->propertyId != Constants::NoProperty)
- {
- Js::PropertyRecord const * propertyRecord = this->scriptContext->GetThreadContext()->GetPropertyName(this->propertyId);
- const WCHAR* startOfPropertyName = propertyRecord->GetBuffer();
- const WCHAR* endOfIdentifier = this->scriptContext->GetCharClassifier()->SkipIdentifier((LPCOLESTR)propertyRecord->GetBuffer());
- return (charcount_t)(endOfIdentifier - startOfPropertyName) == propertyRecord->GetLength();
- }
- else
- {
- return true;
- }
- }
- bool RecyclableObjectDisplay::IsSymbolProperty()
- {
- Assert(this->scriptContext);
- if (this->propertyId != Constants::NoProperty)
- {
- Js::PropertyRecord const * propertyRecord = this->scriptContext->GetThreadContext()->GetPropertyName(this->propertyId);
- return propertyRecord->IsSymbol();
- }
- return false;
- }
- LPCWSTR RecyclableObjectDisplay::Name()
- {
- return name;
- }
- LPCWSTR RecyclableObjectDisplay::Type()
- {
- LPCWSTR typeStr;
- if(Js::TaggedInt::Is(instance) || Js::JavascriptNumber::Is(instance))
- {
- typeStr = _u("Number");
- }
- else
- {
- Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance);
- StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- builder->Reset();
- // For the RecyclableObject try to find out the constructor, which will be shown as type for the object.
- // This case is to handle the user defined function, built in objects have dedicated classes to handle.
- Var value = nullptr;
- TypeId typeId = obj->GetTypeId();
- if (typeId == TypeIds_Object && GetPropertyWithScriptEnter(obj, obj, PropertyIds::constructor, &value, scriptContext))
- {
- builder->AppendCppLiteral(_u("Object"));
- if (Js::JavascriptFunction::Is(value))
- {
- Js::JavascriptFunction *pfunction = Js::JavascriptFunction::FromVar(value);
- // For an odd chance that the constructor wasn't called to create the object.
- Js::ParseableFunctionInfo *pFuncBody = pfunction->GetFunctionProxy() != nullptr ? pfunction->GetFunctionProxy()->EnsureDeserialized() : nullptr;
- if (pFuncBody)
- {
- const char16* pDisplayName = pFuncBody->GetDisplayName();
- if (pDisplayName)
- {
- builder->AppendCppLiteral(_u(", ("));
- builder->AppendSz(pDisplayName);
- builder->Append(_u(')'));
- }
- }
- }
- typeStr = builder->Detach();
- }
- else if (obj->GetDiagTypeString(builder, scriptContext))
- {
- typeStr = builder->Detach();
- }
- else
- {
- typeStr = _u("Undefined");
- }
- }
- return typeStr;
- }
- Var RecyclableObjectDisplay::GetVarValue(BOOL fUpdated)
- {
- if (pObjAddress)
- {
- return pObjAddress->GetValue(fUpdated);
- }
- return instance;
- }
- LPCWSTR RecyclableObjectDisplay::Value(int radix)
- {
- LPCWSTR valueStr = _u("");
- if(Js::TaggedInt::Is(instance)
- || Js::JavascriptNumber::Is(instance)
- || Js::JavascriptNumberObject::Is(instance)
- || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number
- || Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number)
- {
- double value;
- if (Js::TaggedInt::Is(instance))
- {
- value = TaggedInt::ToDouble(instance);
- }
- else if (Js::JavascriptNumber::Is(instance))
- {
- value = Js::JavascriptNumber::GetValue(instance);
- }
- else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_Int64Number)
- {
- value = (double)JavascriptInt64Number::FromVar(instance)->GetValue();
- }
- else if (Js::JavascriptOperators::GetTypeId(instance) == TypeIds_UInt64Number)
- {
- value = (double)JavascriptUInt64Number::FromVar(instance)->GetValue();
- }
- else
- {
- Js::JavascriptNumberObject* numobj = Js::JavascriptNumberObject::FromVar(instance);
- value = numobj->GetValue();
- }
- // For fractional values, radix is ignored.
- int32 l = (int32)value;
- bool isZero = JavascriptNumber::IsZero(value - (double)l);
- if (radix == 10 || !isZero)
- {
- if (Js::JavascriptNumber::IsNegZero(value))
- {
- // In debugger, we wanted to show negative zero explicitly
- valueStr = _u("-0");
- }
- else
- {
- valueStr = Js::JavascriptNumber::ToStringRadix10(value, scriptContext)->GetSz();
- }
- }
- else if (radix >= 2 && radix <= 36)
- {
- if (radix == 16)
- {
- if (value < 0)
- {
- // On the tools side we show unsigned value.
- uint32 ul = static_cast<uint32>(static_cast<int32>(value)); // ARM: casting negative value to uint32 gives 0
- value = (double)ul;
- }
- valueStr = Js::JavascriptString::Concat(scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("0x")),
- Js::JavascriptNumber::ToStringRadixHelper(value, radix, scriptContext))->GetSz();
- }
- else
- {
- valueStr = Js::JavascriptNumber::ToStringRadixHelper(value, radix, scriptContext)->GetSz();
- }
- }
- }
- else
- {
- Js::RecyclableObject* obj = Js::RecyclableObject::FromVar(instance);
- StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- builder->Reset();
- if (obj->GetDiagValueString(builder, scriptContext))
- {
- valueStr = builder->Detach();
- }
- else
- {
- valueStr = _u("undefined");
- }
- }
- return valueStr;
- }
- BOOL RecyclableObjectDisplay::HasChildren()
- {
- if (Js::RecyclableObject::Is(instance))
- {
- Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
- if (JavascriptOperators::IsObject(object))
- {
- if (JavascriptOperators::GetTypeId(object) == TypeIds_HostDispatch)
- {
- return TRUE;
- }
- try
- {
- auto funcPtr = [&]()
- {
- IGNORE_STACKWALK_EXCEPTION(scriptContext);
- if (object->CanHaveInterceptors())
- {
- Js::ForInObjectEnumerator enumerator(object, object->GetScriptContext(), /* enumSymbols */ true);
- if (enumerator.MoveNext())
- {
- enumerator.Clear();
- return TRUE;
- }
- }
- else if (object->GetPropertyCount() > 0 || (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null))
- {
- return TRUE;
- }
- return FALSE;
- };
- BOOL autoFuncReturn = FALSE;
- if (!scriptContext->GetThreadContext()->IsScriptActive())
- {
- BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false)
- {
- autoFuncReturn = funcPtr();
- }
- END_JS_RUNTIME_CALL(scriptContext);
- }
- else
- {
- autoFuncReturn = funcPtr();
- }
- if (autoFuncReturn == TRUE)
- {
- return TRUE;
- }
- }
- catch (Js::JavascriptExceptionObject* exception)
- {
- // The For in enumerator can throw an exception and we will use the error object as a child in that case.
- Var error = exception->GetThrownObject(scriptContext);
- if (error != nullptr && Js::JavascriptError::Is(error))
- {
- return TRUE;
- }
- return FALSE;
- }
- }
- }
- return FALSE;
- }
- BOOL RecyclableObjectDisplay::Set(Var updateObject)
- {
- if (pObjAddress)
- {
- return pObjAddress->Set(updateObject);
- }
- return FALSE;
- }
- DBGPROP_ATTRIB_FLAGS RecyclableObjectDisplay::GetTypeAttribute()
- {
- DBGPROP_ATTRIB_FLAGS flag = defaultAttributes;
- if (Js::RecyclableObject::Is(instance))
- {
- if (instance == scriptContext->GetLibrary()->GetDebuggerDeadZoneBlockVariableString())
- {
- flag |= DBGPROP_ATTRIB_VALUE_IS_INVALID;
- }
- else if (JavascriptOperators::GetTypeId(instance) == TypeIds_Function)
- {
- flag |= DBGPROP_ATTRIB_VALUE_IS_METHOD;
- }
- else if (JavascriptOperators::GetTypeId(instance) == TypeIds_String
- || JavascriptOperators::GetTypeId(instance) == TypeIds_StringObject)
- {
- flag |= DBGPROP_ATTRIB_VALUE_IS_RAW_STRING;
- }
- }
- auto checkWriteableFunction = [&]()
- {
- if (pObjAddress && !pObjAddress->IsWritable())
- {
- flag |= DBGPROP_ATTRIB_VALUE_READONLY;
- }
- };
- if (!scriptContext->GetThreadContext()->IsScriptActive())
- {
- BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false);
- {
- IGNORE_STACKWALK_EXCEPTION(scriptContext);
- checkWriteableFunction();
- }
- END_JS_RUNTIME_CALL(scriptContext);
- }
- else
- {
- checkWriteableFunction();
- }
- // TODO : need to identify Events explicitly for fastDOM
- return flag;
- }
- /* static */
- BOOL RecyclableObjectDisplay::GetPropertyWithScriptEnter(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, Var* value, ScriptContext* scriptContext)
- {
- BOOL retValue = FALSE;
- if(!scriptContext->GetThreadContext()->IsScriptActive())
- {
- BEGIN_JS_RUNTIME_CALL_EX(scriptContext, false)
- {
- IGNORE_STACKWALK_EXCEPTION(scriptContext);
- retValue = Js::JavascriptOperators::GetProperty(originalInstance, instance, propertyId, value, scriptContext);
- }
- END_JS_RUNTIME_CALL(scriptContext);
- }
- else
- {
- retValue = Js::JavascriptOperators::GetProperty(originalInstance, instance, propertyId, value, scriptContext);
- }
- return retValue;
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableObjectDisplay::CreateWalker()
- {
- return CreateAWalker<RecyclableObjectWalker>(scriptContext, instance, originalInstance);
- }
- StringBuilder<ArenaAllocator>* RecyclableObjectDisplay::GetStringBuilder()
- {
- return scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- }
- PropertyId RecyclableObjectDisplay::GetPropertyId() const
- {
- return this->propertyId;
- }
- // ------------------------------------
- // RecyclableObjectWalker
- RecyclableObjectWalker::RecyclableObjectWalker(ScriptContext* _scriptContext, Var _slot)
- : scriptContext(_scriptContext),
- instance(_slot),
- originalInstance(_slot),
- pMembersList(nullptr),
- innerArrayObjectWalker(nullptr),
- fakeGroupObjectWalkerList(nullptr)
- {
- }
- RecyclableObjectWalker::RecyclableObjectWalker(ScriptContext* _scriptContext, Var _slot, Var _originalInstance)
- : scriptContext(_scriptContext),
- instance(_slot),
- originalInstance(_originalInstance),
- pMembersList(nullptr),
- innerArrayObjectWalker(nullptr),
- fakeGroupObjectWalkerList(nullptr)
- {
- }
- BOOL RecyclableObjectWalker::Get(int index, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of RecyclableObjectWalker::Get");
- int fakeObjCount = fakeGroupObjectWalkerList ? fakeGroupObjectWalkerList->Count() : 0;
- int arrayItemCount = innerArrayObjectWalker ? innerArrayObjectWalker->GetChildrenCount() : 0;
- if (index < 0 || !pMembersList || index >= (pMembersList->Count() + arrayItemCount + fakeObjCount))
- {
- return FALSE;
- }
- int nonArrayElementCount = Js::RecyclableObject::Is(instance) ? pMembersList->Count() : 0;
- // First the virtual groups
- if (index < fakeObjCount)
- {
- Assert(fakeGroupObjectWalkerList);
- return fakeGroupObjectWalkerList->Item(index)->GetGroupObject(pResolvedObject);
- }
- index -= fakeObjCount;
- if (index < nonArrayElementCount)
- {
- Assert(Js::RecyclableObject::Is(instance));
- pResolvedObject->propId = pMembersList->Item(index)->propId;
- if (pResolvedObject->propId == Js::Constants::NoProperty || Js::IsInternalPropertyId(pResolvedObject->propId))
- {
- Assert(FALSE);
- return FALSE;
- }
- Js::DebuggerPropertyDisplayInfo* displayInfo = pMembersList->Item(index);
- const Js::PropertyRecord* propertyRecord = scriptContext->GetPropertyName(pResolvedObject->propId);
- pResolvedObject->name = propertyRecord->GetBuffer();
- pResolvedObject->obj = displayInfo->aVar;
- Assert(pResolvedObject->obj);
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
- RecyclableObjectAddress,
- instance,
- pResolvedObject->propId,
- pResolvedObject->obj,
- displayInfo->IsInDeadZone() ? TRUE : FALSE);
- pResolvedObject->isConst = displayInfo->IsConst();
- return TRUE;
- }
- index -= nonArrayElementCount;
- if (index < arrayItemCount)
- {
- Assert(innerArrayObjectWalker);
- return innerArrayObjectWalker->Get(index, pResolvedObject);
- }
- Assert(false);
- return FALSE;
- }
- void RecyclableObjectWalker::EnsureFakeGroupObjectWalkerList()
- {
- if (fakeGroupObjectWalkerList == nullptr)
- {
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- fakeGroupObjectWalkerList = JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator>::New(arena);
- }
- }
- IDiagObjectAddress *RecyclableObjectWalker::FindPropertyAddress(PropertyId propertyId, bool& isConst)
- {
- GetChildrenCount(); // Ensure to populate members
- if (pMembersList != nullptr)
- {
- for (int i = 0; i < pMembersList->Count(); i++)
- {
- DebuggerPropertyDisplayInfo *pair = pMembersList->Item(i);
- Assert(pair);
- if (pair->propId == propertyId)
- {
- isConst = pair->IsConst();
- return Anew(GetArenaFromContext(scriptContext),
- RecyclableObjectAddress,
- instance,
- propertyId,
- pair->aVar,
- pair->IsInDeadZone() ? TRUE : FALSE);
- }
- }
- }
- // Following is for "with object" scope lookup. We may have members in [Methods] group or prototype chain that need to
- // be exposed to expression evaluation.
- if (fakeGroupObjectWalkerList != nullptr)
- {
- // WARNING: Following depends on [Methods] group being before [prototype] group. We need to check local [Methods] group
- // first for local properties before going to prototype chain.
- for (int i = 0; i < fakeGroupObjectWalkerList->Count(); i++)
- {
- IDiagObjectAddress* address = fakeGroupObjectWalkerList->Item(i)->FindPropertyAddress(propertyId, isConst);
- if (address != nullptr)
- {
- return address;
- }
- }
- }
- return nullptr;
- }
- uint32 RecyclableObjectWalker::GetChildrenCount()
- {
- if (pMembersList == nullptr)
- {
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(arena);
- RecyclableMethodsGroupWalker *pMethodsGroupWalker = nullptr;
- if (Js::RecyclableObject::Is(instance))
- {
- Js::RecyclableObject* object = Js::RecyclableObject::FromVar(instance);
- // If we are walking a prototype, we'll use its instance for property names enumeration, but originalInstance to get values
- Js::RecyclableObject* originalObject = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : object;
- const Js::TypeId typeId = JavascriptOperators::GetTypeId(instance);
- if (JavascriptOperators::IsObject(object))
- {
- if (object->CanHaveInterceptors() || JavascriptOperators::GetTypeId(object) == TypeIds_Proxy)
- {
- try
- {
- JavascriptEnumerator* enumerator;
- if (object->GetEnumerator(true/*enumNonEnumable*/, (Var*)&enumerator, scriptContext, false/*preferSnapshotSyntax*/, true/*enumSymbols*/))
- {
- Js::PropertyId propertyId;
- Var obj;
- while ((obj = enumerator->GetCurrentAndMoveNext(propertyId)) != nullptr)
- {
- if (!JavascriptString::Is(obj))
- {
- continue;
- }
- if (propertyId == Constants::NoProperty)
- {
- JavascriptString *pString = JavascriptString::FromVar(obj);
- if (VirtualTableInfo<Js::PropertyString>::HasVirtualTable(pString))
- {
- // If we have a property string, it is assumed that the propertyId is being
- // kept alive with the object
- PropertyString * propertyString = (PropertyString *)pString;
- propertyId = propertyString->GetPropertyRecord()->GetPropertyId();
- }
- else
- {
- const PropertyRecord* propertyRecord;
- scriptContext->GetOrAddPropertyRecord(pString->GetSz(), pString->GetLength(), &propertyRecord);
- propertyId = propertyRecord->GetPropertyId();
- }
- }
- // GetCurrentAndMoveNext shouldn't return an internal property id
- Assert(!Js::IsInternalPropertyId(propertyId));
- uint32 indexVal;
- Var varValue;
- if (scriptContext->IsNumericPropertyId(propertyId, &indexVal) && object->GetItem(object, indexVal, &varValue, scriptContext))
- {
- InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, varValue, &pMethodsGroupWalker, true /*shouldPinProperty*/);
- }
- else
- {
- InsertItem(originalObject, object, propertyId, false /*isConst*/, false /*isUnscoped*/, &pMethodsGroupWalker, true /*shouldPinProperty*/);
- }
- }
- }
- }
- catch (JavascriptExceptionObject* exception)
- {
- Var error = exception->GetThrownObject(scriptContext);
- if (error != nullptr && Js::JavascriptError::Is(error))
- {
- Js::PropertyId propertyId = scriptContext->GetOrAddPropertyIdTracked(_u("{error}"));
- InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, error, &pMethodsGroupWalker);
- }
- }
- if (typeId == TypeIds_Proxy)
- {
- // Provide [Proxy] group object
- EnsureFakeGroupObjectWalkerList();
- JavascriptProxy* proxy = JavascriptProxy::FromVar(object);
- RecyclableProxyObjectWalker* proxyWalker = Anew(arena, RecyclableProxyObjectWalker, scriptContext, proxy);
- fakeGroupObjectWalkerList->Add(proxyWalker);
- }
- // If current object has internal proto object then provide [prototype] group object.
- if (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null)
- {
- // Has [prototype] object.
- EnsureFakeGroupObjectWalkerList();
- RecyclableProtoObjectWalker *pProtoWalker = Anew(arena, RecyclableProtoObjectWalker, scriptContext, instance, (originalInstance == nullptr) ? instance : originalInstance);
- fakeGroupObjectWalkerList->Add(pProtoWalker);
- }
- }
- else
- {
- RecyclableObject* wrapperObject = nullptr;
- if (JavascriptOperators::GetTypeId(object) == TypeIds_WithScopeObject)
- {
- wrapperObject = object;
- object = object->GetThisObjectOrUnWrap();
- }
- int count = object->GetPropertyCount();
- for (int i = 0; i < count; i++)
- {
- Js::PropertyId propertyId = object->GetPropertyId((PropertyIndex)i);
- bool isUnscoped = false;
- if (wrapperObject && JavascriptOperators::IsPropertyUnscopable(object, propertyId))
- {
- isUnscoped = true;
- }
- if (propertyId != Js::Constants::NoProperty && !Js::IsInternalPropertyId(propertyId))
- {
- InsertItem(originalObject, object, propertyId, false /*isConst*/, isUnscoped, &pMethodsGroupWalker);
- }
- }
- if (CONFIG_FLAG(EnumerateSpecialPropertiesInDebugger))
- {
- count = object->GetSpecialPropertyCount();
- PropertyId const * specialPropertyIds = object->GetSpecialPropertyIds();
- for (int i = 0; i < count; i++)
- {
- Js::PropertyId propertyId = specialPropertyIds[i];
- bool isUnscoped = false;
- if (wrapperObject && JavascriptOperators::IsPropertyUnscopable(object, propertyId))
- {
- isUnscoped = true;
- }
- if (propertyId != Js::Constants::NoProperty)
- {
- bool isConst = true;
- if (propertyId == PropertyIds::length && Js::JavascriptArray::Is(object))
- {
- // For JavascriptArrays, we allow resetting the length special property.
- isConst = false;
- }
- auto containsPredicate = [&](Js::DebuggerPropertyDisplayInfo* info) { return info->propId == propertyId; };
- if (Js::BoundFunction::Is(object)
- && this->pMembersList->Any(containsPredicate))
- {
- // Bound functions can already contain their special properties,
- // so we need to check for that (caller and arguments). This occurs
- // when JavascriptFunction::EntryBind() is called. Arguments can similarly
- // already display caller in compat mode 8.
- continue;
- }
- AssertMsg(!this->pMembersList->Any(containsPredicate), "Special property already on the object, no need to insert.");
- InsertItem(originalObject, object, propertyId, isConst, isUnscoped, &pMethodsGroupWalker);
- }
- }
- if (Js::JavascriptFunction::Is(object))
- {
- // We need to special-case RegExp constructor here because it has some special properties (above) and some
- // special enumerable properties which should all show up in the debugger.
- JavascriptRegExpConstructor* regExp = scriptContext->GetLibrary()->GetRegExpConstructor();
- if (regExp == object)
- {
- bool isUnscoped = false;
- bool isConst = true;
- count = regExp->GetSpecialEnumerablePropertyCount();
- PropertyId const * specialEnumerablePropertyIds = regExp->GetSpecialEnumerablePropertyIds();
- for (int i = 0; i < count; i++)
- {
- Js::PropertyId propertyId = specialEnumerablePropertyIds[i];
- InsertItem(originalObject, object, propertyId, isConst, isUnscoped, &pMethodsGroupWalker);
- }
- }
- else if (Js::JavascriptFunction::FromVar(object)->IsScriptFunction() || Js::JavascriptFunction::FromVar(object)->IsBoundFunction())
- {
- // Adding special property length for the ScriptFunction, like it is done in JavascriptFunction::GetSpecialNonEnumerablePropertyName
- InsertItem(originalObject, object, PropertyIds::length, true/*not editable*/, false /*isUnscoped*/, &pMethodsGroupWalker);
- }
- }
- }
- // If current object has internal proto object then provide [prototype] group object.
- if (JavascriptOperators::GetTypeId(object->GetPrototype()) != TypeIds_Null)
- {
- // Has [prototype] object.
- EnsureFakeGroupObjectWalkerList();
- RecyclableProtoObjectWalker *pProtoWalker = Anew(arena, RecyclableProtoObjectWalker, scriptContext, instance, originalInstance);
- fakeGroupObjectWalkerList->Add(pProtoWalker);
- }
- }
- // If the object contains array indices.
- if (typeId == TypeIds_Arguments)
- {
- // Create ArgumentsArray walker for an arguments object
- Js::ArgumentsObject * argObj = static_cast<Js::ArgumentsObject*>(instance);
- Assert(argObj);
- if (argObj->GetNumberOfArguments() > 0 || argObj->HasNonEmptyObjectArray())
- {
- innerArrayObjectWalker = Anew(arena, RecyclableArgumentsArrayWalker, scriptContext, (Var)instance, originalInstance);
- }
- }
- else if (typeId == TypeIds_Map)
- {
- // Provide [Map] group object.
- EnsureFakeGroupObjectWalkerList();
- JavascriptMap* map = JavascriptMap::FromVar(object);
- RecyclableMapObjectWalker *pMapWalker = Anew(arena, RecyclableMapObjectWalker, scriptContext, map);
- fakeGroupObjectWalkerList->Add(pMapWalker);
- }
- else if (typeId == TypeIds_Set)
- {
- // Provide [Set] group object.
- EnsureFakeGroupObjectWalkerList();
- JavascriptSet* set = JavascriptSet::FromVar(object);
- RecyclableSetObjectWalker *pSetWalker = Anew(arena, RecyclableSetObjectWalker, scriptContext, set);
- fakeGroupObjectWalkerList->Add(pSetWalker);
- }
- else if (typeId == TypeIds_WeakMap)
- {
- // Provide [WeakMap] group object.
- EnsureFakeGroupObjectWalkerList();
- JavascriptWeakMap* weakMap = JavascriptWeakMap::FromVar(object);
- RecyclableWeakMapObjectWalker *pWeakMapWalker = Anew(arena, RecyclableWeakMapObjectWalker, scriptContext, weakMap);
- fakeGroupObjectWalkerList->Add(pWeakMapWalker);
- }
- else if (typeId == TypeIds_WeakSet)
- {
- // Provide [WeakSet] group object.
- EnsureFakeGroupObjectWalkerList();
- JavascriptWeakSet* weakSet = JavascriptWeakSet::FromVar(object);
- RecyclableWeakSetObjectWalker *pWeakSetWalker = Anew(arena, RecyclableWeakSetObjectWalker, scriptContext, weakSet);
- fakeGroupObjectWalkerList->Add(pWeakSetWalker);
- }
- else if (typeId == TypeIds_Promise)
- {
- // Provide [Promise] group object.
- EnsureFakeGroupObjectWalkerList();
- JavascriptPromise* promise = JavascriptPromise::FromVar(object);
- RecyclablePromiseObjectWalker *pPromiseWalker = Anew(arena, RecyclablePromiseObjectWalker, scriptContext, promise);
- fakeGroupObjectWalkerList->Add(pPromiseWalker);
- }
- else if (Js::DynamicType::Is(typeId))
- {
- DynamicObject *const dynamicObject = Js::DynamicObject::FromVar(instance);
- if (dynamicObject->HasNonEmptyObjectArray())
- {
- ArrayObject* objectArray = dynamicObject->GetObjectArray();
- if (Js::ES5Array::Is(objectArray))
- {
- innerArrayObjectWalker = Anew(arena, RecyclableES5ArrayWalker, scriptContext, objectArray, originalInstance);
- }
- else if (Js::JavascriptArray::Is(objectArray))
- {
- innerArrayObjectWalker = Anew(arena, RecyclableArrayWalker, scriptContext, objectArray, originalInstance);
- }
- else
- {
- innerArrayObjectWalker = Anew(arena, RecyclableTypedArrayWalker, scriptContext, objectArray, originalInstance);
- }
- innerArrayObjectWalker->SetOnlyWalkOwnProperties(true);
- }
- }
- }
- }
- // Sort the members of the methods group
- if (pMethodsGroupWalker)
- {
- pMethodsGroupWalker->Sort();
- }
- // Sort current pMembersList.
- HostDebugContext* hostDebugContext = scriptContext->GetDebugContext()->GetHostDebugContext();
- if (hostDebugContext != nullptr)
- {
- hostDebugContext->SortMembersList(pMembersList, scriptContext);
- }
- }
- uint32 childrenCount =
- pMembersList->Count()
- + (innerArrayObjectWalker ? innerArrayObjectWalker->GetChildrenCount() : 0)
- + (fakeGroupObjectWalkerList ? fakeGroupObjectWalkerList->Count() : 0);
- return childrenCount;
- }
- void RecyclableObjectWalker::InsertItem(
- Js::RecyclableObject *pOriginalObject,
- Js::RecyclableObject *pObject,
- PropertyId propertyId,
- bool isReadOnly,
- bool isUnscoped,
- Js::RecyclableMethodsGroupWalker **ppMethodsGroupWalker,
- bool shouldPinProperty /* = false*/)
- {
- Assert(pOriginalObject);
- Assert(pObject);
- Assert(propertyId);
- Assert(ppMethodsGroupWalker);
- if (propertyId != PropertyIds::__proto__)
- {
- InsertItem(propertyId, isReadOnly, isUnscoped, RecyclableObjectWalker::GetObject(pOriginalObject, pObject, propertyId, scriptContext), ppMethodsGroupWalker, shouldPinProperty);
- }
- else // Since __proto__ defined as a Getter we should always evaluate it against object itself instead of walking prototype chain
- {
- InsertItem(propertyId, isReadOnly, isUnscoped, RecyclableObjectWalker::GetObject(pObject, pObject, propertyId, scriptContext), ppMethodsGroupWalker, shouldPinProperty);
- }
- }
- void RecyclableObjectWalker::InsertItem(
- PropertyId propertyId,
- bool isConst,
- bool isUnscoped,
- Var itemObj,
- Js:: RecyclableMethodsGroupWalker **ppMethodsGroupWalker,
- bool shouldPinProperty /* = false*/)
- {
- Assert(propertyId);
- Assert(ppMethodsGroupWalker);
- if (itemObj == nullptr)
- {
- itemObj = scriptContext->GetLibrary()->GetUndefined();
- }
- if (shouldPinProperty)
- {
- const Js::PropertyRecord * propertyRecord = scriptContext->GetPropertyName(propertyId);
- if (propertyRecord)
- {
- // Pin this record so that it will not go away till we are done with this break.
- scriptContext->GetDebugContext()->GetProbeContainer()->PinPropertyRecord(propertyRecord);
- }
- }
- ArenaAllocator *arena = GetArenaFromContext(scriptContext);
- if (JavascriptOperators::GetTypeId(itemObj) == TypeIds_Function)
- {
- if (scriptContext->GetThreadContext()->GetDebugManager()->IsLocalsDisplayFlagsSet(Js::DebugManager::LocalsDisplayFlags::LocalsDisplayFlags_NoGroupMethods))
- {
- DebuggerPropertyDisplayInfo *info = Anew(arena, DebuggerPropertyDisplayInfo, propertyId, itemObj, DebuggerPropertyDisplayInfoFlags_Const);
- pMembersList->Add(info);
- }
- else
- {
- EnsureFakeGroupObjectWalkerList();
- if (*ppMethodsGroupWalker == nullptr)
- {
- *ppMethodsGroupWalker = Anew(arena, RecyclableMethodsGroupWalker, scriptContext, instance);
- fakeGroupObjectWalkerList->Add(*ppMethodsGroupWalker);
- }
- (*ppMethodsGroupWalker)->AddItem(propertyId, itemObj);
- }
- }
- else
- {
- DWORD flags = DebuggerPropertyDisplayInfoFlags_None;
- flags |= isConst ? DebuggerPropertyDisplayInfoFlags_Const : 0;
- flags |= isUnscoped ? DebuggerPropertyDisplayInfoFlags_Unscope : 0;
- DebuggerPropertyDisplayInfo *info = Anew(arena, DebuggerPropertyDisplayInfo, propertyId, itemObj, flags);
- pMembersList->Add(info);
- }
- }
- /*static*/
- Var RecyclableObjectWalker::GetObject(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, ScriptContext* scriptContext)
- {
- Assert(instance);
- Assert(!Js::IsInternalPropertyId(propertyId));
- Var obj = nullptr;
- try
- {
- if (!RecyclableObjectDisplay::GetPropertyWithScriptEnter(originalInstance, instance, propertyId, &obj, scriptContext))
- {
- return instance->GetScriptContext()->GetMissingPropertyResult();
- }
- }
- catch(Js::JavascriptExceptionObject * exceptionObject)
- {
- Var error = exceptionObject->GetThrownObject(instance->GetScriptContext());
- if (error != nullptr && Js::JavascriptError::Is(error))
- {
- obj = error;
- }
- }
- return obj;
- }
- //--------------------------
- // RecyclableArrayAddress
- RecyclableArrayAddress::RecyclableArrayAddress(Var _parentArray, unsigned int _index)
- : parentArray(_parentArray),
- index(_index)
- {
- }
- BOOL RecyclableArrayAddress::Set(Var updateObject)
- {
- if (Js::JavascriptArray::Is(parentArray))
- {
- Js::JavascriptArray* jsArray = Js::JavascriptArray::FromVar(parentArray);
- return jsArray->SetItem(index, updateObject, PropertyOperation_None);
- }
- return FALSE;
- }
- //--------------------------
- // RecyclableArrayDisplay
- RecyclableArrayDisplay::RecyclableArrayDisplay(ResolvedObject* resolvedObject)
- : RecyclableObjectDisplay(resolvedObject)
- {
- }
- BOOL RecyclableArrayDisplay::HasChildrenInternal(Js::JavascriptArray* arrayObj)
- {
- Assert(arrayObj);
- if (JavascriptOperators::GetTypeId(arrayObj->GetPrototype()) != TypeIds_Null)
- {
- return TRUE;
- }
- uint32 index = arrayObj->GetNextIndex(Js::JavascriptArray::InvalidIndex);
- return index != Js::JavascriptArray::InvalidIndex && index < arrayObj->GetLength();
- }
- BOOL RecyclableArrayDisplay::HasChildren()
- {
- if (Js::JavascriptArray::Is(instance))
- {
- Js::JavascriptArray* arrayObj = Js::JavascriptArray::FromVar(instance);
- if (HasChildrenInternal(arrayObj))
- {
- return TRUE;
- }
- }
- return RecyclableObjectDisplay::HasChildren();
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableArrayDisplay::CreateWalker()
- {
- return CreateAWalker<RecyclableArrayWalker>(scriptContext, instance, originalInstance);
- }
- //--------------------------
- // RecyclableArrayWalker
- uint32 RecyclableArrayWalker::GetItemCount(Js::JavascriptArray* arrayObj)
- {
- if (pAbsoluteIndexList == nullptr)
- {
- Assert(arrayObj);
- pAbsoluteIndexList = JsUtil::List<uint32, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
- Assert(pAbsoluteIndexList);
- uint32 dataIndex = Js::JavascriptArray::InvalidIndex;
- uint32 descriptorIndex = Js::JavascriptArray::InvalidIndex;
- uint32 absIndex = Js::JavascriptArray::InvalidIndex;
- do
- {
- if (absIndex == dataIndex)
- {
- dataIndex = arrayObj->GetNextIndex(dataIndex);
- }
- if (absIndex == descriptorIndex)
- {
- descriptorIndex = GetNextDescriptor(descriptorIndex);
- }
- absIndex = min(dataIndex, descriptorIndex);
- if (absIndex == Js::JavascriptArray::InvalidIndex || absIndex >= arrayObj->GetLength())
- {
- break;
- }
- pAbsoluteIndexList->Add(absIndex);
- } while (absIndex < arrayObj->GetLength());
- }
- return (uint32)pAbsoluteIndexList->Count();
- }
- BOOL RecyclableArrayWalker::FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var * value)
- {
- Assert(arrayObj);
- Assert(value);
- return arrayObj->DirectGetItemAt(index, value);
- }
- Var RecyclableArrayWalker::FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index)
- {
- Assert(arrayObj);
- return arrayObj->DirectGetItem(index);
- }
- LPCWSTR RecyclableArrayWalker::GetIndexName(uint32 index, StringBuilder<ArenaAllocator>* stringBuilder)
- {
- stringBuilder->Append(_u('['));
- if (stringBuilder->AppendUint64(index) != 0)
- {
- return _u("[.]");
- }
- stringBuilder->Append(_u(']'));
- return stringBuilder->Detach();
- }
- RecyclableArrayWalker::RecyclableArrayWalker(ScriptContext* scriptContext, Var instance, Var originalInstance)
- : indexedItemCount(0),
- pAbsoluteIndexList(nullptr),
- fOnlyOwnProperties(false),
- RecyclableObjectWalker(scriptContext,instance,originalInstance)
- {
- }
- BOOL RecyclableArrayWalker::GetResolvedObject(Js::JavascriptArray* arrayObj, int index, ResolvedObject* pResolvedObject, uint32 * pabsIndex)
- {
- Assert(arrayObj);
- Assert(pResolvedObject);
- Assert(pAbsoluteIndexList);
- Assert(pAbsoluteIndexList->Count() > index);
- // translate i'th Item to the correct array index and return
- uint32 absIndex = pAbsoluteIndexList->Item(index);
- pResolvedObject->obj = FetchItemAt(arrayObj, absIndex);
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr;
- StringBuilder<ArenaAllocator>* builder = GetBuilder();
- Assert(builder);
- builder->Reset();
- pResolvedObject->name = GetIndexName(absIndex, builder);
- if (pabsIndex)
- {
- *pabsIndex = absIndex;
- }
- return TRUE;
- }
- BOOL RecyclableArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of RecyclableArrayWalker::Get");
- if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance))
- {
- Js::JavascriptArray* arrayObj = GetArrayObject();
- int nonArrayElementCount = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
- if (i < nonArrayElementCount)
- {
- return RecyclableObjectWalker::Get(i, pResolvedObject);
- }
- else
- {
- i -= nonArrayElementCount;
- uint32 absIndex; // Absolute index
- GetResolvedObject(arrayObj, i, pResolvedObject, &absIndex);
- pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
- RecyclableArrayAddress,
- instance,
- absIndex);
- return TRUE;
- }
- }
- return FALSE;
- }
- Js::JavascriptArray* RecyclableArrayWalker::GetArrayObject()
- {
- Assert(Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance));
- return Js::ES5Array::Is(instance) ?
- static_cast<Js::JavascriptArray *>(RecyclableObject::FromVar(instance)) :
- Js::JavascriptArray::FromVar(instance);
- }
- uint32 RecyclableArrayWalker::GetChildrenCount()
- {
- if (Js::JavascriptArray::Is(instance) || Js::ES5Array::Is(instance))
- {
- uint32 count = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
- Js::JavascriptArray* arrayObj = GetArrayObject();
- return GetItemCount(arrayObj) + count;
- }
- return 0;
- }
- StringBuilder<ArenaAllocator>* RecyclableArrayWalker::GetBuilder()
- {
- return scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- }
- //--------------------------
- // RecyclableArgumentsArrayAddress
- RecyclableArgumentsArrayAddress::RecyclableArgumentsArrayAddress(Var _parentArray, unsigned int _index)
- : parentArray(_parentArray),
- index(_index)
- {
- }
- BOOL RecyclableArgumentsArrayAddress::Set(Var updateObject)
- {
- if (Js::ArgumentsObject::Is(parentArray))
- {
- Js::ArgumentsObject* argObj = static_cast<Js::ArgumentsObject*>(parentArray);
- return argObj->SetItem(index, updateObject, PropertyOperation_None);
- }
- return FALSE;
- }
- //--------------------------
- // RecyclableArgumentsObjectDisplay
- RecyclableArgumentsObjectDisplay::RecyclableArgumentsObjectDisplay(ResolvedObject* resolvedObject, LocalsWalker *localsWalker)
- : RecyclableObjectDisplay(resolvedObject), pLocalsWalker(localsWalker)
- {
- }
- BOOL RecyclableArgumentsObjectDisplay::HasChildren()
- {
- // It must have children otherwise object itself was not created in first place.
- return TRUE;
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableArgumentsObjectDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableArgumentsObjectWalker, scriptContext, instance, pLocalsWalker);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>,pRefArena, pOMWalker);
- }
- return nullptr;
- }
- //--------------------------
- // RecyclableArgumentsObjectWalker
- RecyclableArgumentsObjectWalker::RecyclableArgumentsObjectWalker(ScriptContext* pContext, Var _instance, LocalsWalker * localsWalker)
- : RecyclableObjectWalker(pContext, _instance), pLocalsWalker(localsWalker)
- {
- }
- uint32 RecyclableArgumentsObjectWalker::GetChildrenCount()
- {
- if (innerArrayObjectWalker == nullptr)
- {
- uint32 count = RecyclableObjectWalker::GetChildrenCount();
- if (innerArrayObjectWalker != nullptr)
- {
- RecyclableArgumentsArrayWalker *pWalker = static_cast<RecyclableArgumentsArrayWalker *> (innerArrayObjectWalker);
- pWalker->FetchFormalsAddress(pLocalsWalker);
- }
- return count;
- }
- return RecyclableObjectWalker::GetChildrenCount();
- }
- //--------------------------
- // RecyclableArgumentsArrayWalker
- RecyclableArgumentsArrayWalker::RecyclableArgumentsArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
- : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance), pFormalsList(nullptr)
- {
- }
- uint32 RecyclableArgumentsArrayWalker::GetChildrenCount()
- {
- if (pMembersList == nullptr)
- {
- Assert(Js::ArgumentsObject::Is(instance));
- Js::ArgumentsObject * argObj = static_cast<Js::ArgumentsObject*>(instance);
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
- Assert(pMembersList);
- uint32 totalCount = argObj->GetNumberOfArguments();
- Js::ArrayObject * objectArray = argObj->GetObjectArray();
- if (objectArray != nullptr && objectArray->GetLength() > totalCount)
- {
- totalCount = objectArray->GetLength();
- }
- for (uint32 index = 0; index < totalCount; index++)
- {
- Var itemObj;
- if (argObj->GetItem(argObj, index, &itemObj, scriptContext))
- {
- DebuggerPropertyDisplayInfo *info = Anew(GetArenaFromContext(scriptContext), DebuggerPropertyDisplayInfo, index, itemObj, DebuggerPropertyDisplayInfoFlags_None);
- Assert(info);
- pMembersList->Add(info);
- }
- }
- }
- return pMembersList ? pMembersList->Count() : 0;
- }
- void RecyclableArgumentsArrayWalker::FetchFormalsAddress(LocalsWalker * localsWalker)
- {
- Assert(localsWalker);
- Assert(localsWalker->pFrame);
- Js::FunctionBody *pFBody = localsWalker->pFrame->GetJavascriptFunction()->GetFunctionBody();
- Assert(pFBody);
- PropertyIdOnRegSlotsContainer * container = pFBody->GetPropertyIdOnRegSlotsContainer();
- if (container && container->propertyIdsForFormalArgs)
- {
- for (uint32 i = 0; i < container->propertyIdsForFormalArgs->count; i++)
- {
- if (container->propertyIdsForFormalArgs->elements[i] != Js::Constants::NoRegister)
- {
- bool isConst = false;
- IDiagObjectAddress * address = localsWalker->FindPropertyAddress(container->propertyIdsForFormalArgs->elements[i], false, isConst);
- if (address)
- {
- if (pFormalsList == nullptr)
- {
- pFormalsList = JsUtil::List<IDiagObjectAddress *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
- }
- pFormalsList->Add(address);
- }
- }
- }
- }
- }
- BOOL RecyclableArgumentsArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of RecyclableArgumentsArrayWalker::Get");
- Assert(i >= 0);
- Assert(Js::ArgumentsObject::Is(instance));
- if (pMembersList && i < pMembersList->Count())
- {
- Assert(pMembersList->Item(i) != nullptr);
- pResolvedObject->address = nullptr;
- if (pFormalsList && i < pFormalsList->Count())
- {
- pResolvedObject->address = pFormalsList->Item(i);
- pResolvedObject->obj = pResolvedObject->address->GetValue(FALSE);
- if (pResolvedObject->obj == nullptr)
- {
- // Temp workaround till the arguments (In jit code) work is ready.
- Assert(Js::Configuration::Global.EnableJitInDebugMode());
- pResolvedObject->obj = pMembersList->Item(i)->aVar;
- }
- else if (pResolvedObject->obj != pMembersList->Item(i)->aVar)
- {
- // We set the formals value in the object itself, so that expression evaluation can reflect them correctly
- Js::HeapArgumentsObject* argObj = static_cast<Js::HeapArgumentsObject*>(instance);
- JavascriptOperators::SetItem(instance, argObj, (uint32)pMembersList->Item(i)->propId, pResolvedObject->obj, scriptContext, PropertyOperation_None);
- }
- }
- else
- {
- pResolvedObject->obj = pMembersList->Item(i)->aVar;
- }
- Assert(pResolvedObject->obj);
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- StringBuilder<ArenaAllocator>* builder = GetBuilder();
- Assert(builder);
- builder->Reset();
- pResolvedObject->name = GetIndexName(pMembersList->Item(i)->propId, builder);
- if (pResolvedObject->typeId != TypeIds_HostDispatch && pResolvedObject->address == nullptr)
- {
- pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
- RecyclableArgumentsArrayAddress,
- instance,
- pMembersList->Item(i)->propId);
- }
- return TRUE;
- }
- return FALSE;
- }
- //--------------------------
- // RecyclableTypedArrayAddress
- RecyclableTypedArrayAddress::RecyclableTypedArrayAddress(Var _parentArray, unsigned int _index)
- : RecyclableArrayAddress(_parentArray, _index)
- {
- }
- BOOL RecyclableTypedArrayAddress::Set(Var updateObject)
- {
- if (Js::TypedArrayBase::Is(parentArray))
- {
- Js::TypedArrayBase* typedArrayObj = Js::TypedArrayBase::FromVar(parentArray);
- return typedArrayObj->SetItem(index, updateObject, PropertyOperation_None);
- }
- return FALSE;
- }
- //--------------------------
- // RecyclableTypedArrayDisplay
- RecyclableTypedArrayDisplay::RecyclableTypedArrayDisplay(ResolvedObject* resolvedObject)
- : RecyclableObjectDisplay(resolvedObject)
- {
- }
- BOOL RecyclableTypedArrayDisplay::HasChildren()
- {
- if (Js::TypedArrayBase::Is(instance))
- {
- Js::TypedArrayBase* typedArrayObj = Js::TypedArrayBase::FromVar(instance);
- if (typedArrayObj->GetLength() > 0)
- {
- return TRUE;
- }
- }
- return RecyclableObjectDisplay::HasChildren();
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableTypedArrayDisplay::CreateWalker()
- {
- return CreateAWalker<RecyclableTypedArrayWalker>(scriptContext, instance, originalInstance);
- }
- //--------------------------
- // RecyclableTypedArrayWalker
- RecyclableTypedArrayWalker::RecyclableTypedArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
- : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance)
- {
- }
- uint32 RecyclableTypedArrayWalker::GetChildrenCount()
- {
- if (!indexedItemCount)
- {
- Assert(Js::TypedArrayBase::Is(instance));
- Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance);
- indexedItemCount = typedArrayObj->GetLength() + (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
- }
- return indexedItemCount;
- }
- BOOL RecyclableTypedArrayWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of RecyclableTypedArrayWalker::Get");
- Assert(Js::TypedArrayBase::Is(instance));
- Js::TypedArrayBase * typedArrayObj = Js::TypedArrayBase::FromVar(instance);
- int nonArrayElementCount = (!fOnlyOwnProperties ? RecyclableObjectWalker::GetChildrenCount() : 0);
- if (i < nonArrayElementCount)
- {
- return RecyclableObjectWalker::Get(i, pResolvedObject);
- }
- else
- {
- i -= nonArrayElementCount;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->obj = typedArrayObj->DirectGetItem(i);
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- StringBuilder<ArenaAllocator>* builder = GetBuilder();
- Assert(builder);
- builder->Reset();
- pResolvedObject->name = GetIndexName(i, builder);
- Assert(pResolvedObject->typeId != TypeIds_HostDispatch);
- pResolvedObject->address = Anew(GetArenaFromContext(scriptContext),
- RecyclableTypedArrayAddress,
- instance,
- i);
- }
- return TRUE;
- }
- //--------------------------
- // RecyclableES5ArrayAddress
- RecyclableES5ArrayAddress::RecyclableES5ArrayAddress(Var _parentArray, unsigned int _index)
- : RecyclableArrayAddress(_parentArray, _index)
- {
- }
- BOOL RecyclableES5ArrayAddress::Set(Var updateObject)
- {
- if (Js::ES5Array::Is(parentArray))
- {
- Js::ES5Array* arrayObj = Js::ES5Array::FromVar(parentArray);
- return arrayObj->SetItem(index, updateObject, PropertyOperation_None);
- }
- return FALSE;
- }
- //--------------------------
- // RecyclableES5ArrayDisplay
- RecyclableES5ArrayDisplay::RecyclableES5ArrayDisplay(ResolvedObject* resolvedObject)
- : RecyclableArrayDisplay(resolvedObject)
- {
- }
- BOOL RecyclableES5ArrayDisplay::HasChildren()
- {
- if (Js::ES5Array::Is(instance))
- {
- Js::JavascriptArray* arrayObj = static_cast<Js::JavascriptArray *>(RecyclableObject::FromVar(instance));
- if (HasChildrenInternal(arrayObj))
- {
- return TRUE;
- }
- }
- return RecyclableObjectDisplay::HasChildren();
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableES5ArrayDisplay::CreateWalker()
- {
- return CreateAWalker<RecyclableES5ArrayWalker>(scriptContext, instance, originalInstance);
- }
- //--------------------------
- // RecyclableES5ArrayWalker
- RecyclableES5ArrayWalker::RecyclableES5ArrayWalker(ScriptContext* _scriptContext, Var _instance, Var _originalInstance)
- : RecyclableArrayWalker(_scriptContext, _instance, _originalInstance)
- {
- }
- uint32 RecyclableES5ArrayWalker::GetNextDescriptor(uint32 currentDescriptor)
- {
- Js::ES5Array *es5Array = static_cast<Js::ES5Array *>(RecyclableObject::FromVar(instance));
- IndexPropertyDescriptor* descriptor = nullptr;
- void * descriptorValidationToken = nullptr;
- return es5Array->GetNextDescriptor(currentDescriptor, &descriptor, &descriptorValidationToken);
- }
- BOOL RecyclableES5ArrayWalker::FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var *value)
- {
- Assert(arrayObj);
- Assert(value);
- return arrayObj->GetItem(arrayObj, index, value, scriptContext);
- }
- Var RecyclableES5ArrayWalker::FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index)
- {
- Assert(arrayObj);
- Var value = nullptr;
- if (FetchItemAtIndex(arrayObj, index, &value))
- {
- return value;
- }
- return nullptr;
- }
- //--------------------------
- // RecyclableProtoObjectWalker
- RecyclableProtoObjectWalker::RecyclableProtoObjectWalker(ScriptContext* pContext, Var instance, Var originalInstance)
- : RecyclableObjectWalker(pContext, instance)
- {
- this->originalInstance = originalInstance;
- }
- BOOL RecyclableProtoObjectWalker::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- DBGPROP_ATTRIB_FLAGS defaultAttributes = DBGPROP_ATTRIB_NO_ATTRIB;
- if (scriptContext->GetLibrary()->GetObjectPrototypeObject()->is__proto__Enabled())
- {
- pResolvedObject->name = _u("__proto__");
- pResolvedObject->propId = PropertyIds::__proto__;
- }
- else
- {
- pResolvedObject->name = _u("[prototype]");
- pResolvedObject->propId = Constants::NoProperty; // This property will not be editable.
- defaultAttributes = DBGPROP_ATTRIB_VALUE_IS_FAKE;
- }
- RecyclableObject *obj = Js::RecyclableObject::FromVar(instance);
- Assert(obj->GetPrototype() != nullptr);
- //withscopeObjects prototype is null
- Assert(obj->GetPrototype()->GetTypeId() != TypeIds_Null || (obj->GetPrototype()->GetTypeId() == TypeIds_Null && obj->GetTypeId() == TypeIds_WithScopeObject));
- pResolvedObject->obj = obj->GetPrototype();
- pResolvedObject->originalObj = (originalInstance != nullptr) ? Js::RecyclableObject::FromVar(originalInstance) : pResolvedObject->obj;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- ArenaAllocator * arena = GetArenaFromContext(scriptContext);
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(defaultAttributes);
- pResolvedObject->address = Anew(arena,
- RecyclableProtoObjectAddress,
- instance,
- PropertyIds::prototype,
- pResolvedObject->obj);
- return TRUE;
- }
- IDiagObjectAddress* RecyclableProtoObjectWalker::FindPropertyAddress(PropertyId propId, bool& isConst)
- {
- ResolvedObject resolvedProto;
- GetGroupObject(&resolvedProto);
- struct AutoCleanup
- {
- WeakArenaReference<Js::IDiagObjectModelWalkerBase> * walkerRef;
- IDiagObjectModelWalkerBase * walker;
- AutoCleanup() : walkerRef(nullptr), walker(nullptr) {};
- ~AutoCleanup()
- {
- if (walker)
- {
- walkerRef->ReleaseStrongReference();
- }
- if (walkerRef)
- {
- HeapDelete(walkerRef);
- }
- }
- } autoCleanup;
- Assert(resolvedProto.objectDisplay);
- autoCleanup.walkerRef = resolvedProto.objectDisplay->CreateWalker();
- autoCleanup.walker = autoCleanup.walkerRef->GetStrongReference();
- return autoCleanup.walker ? autoCleanup.walker->FindPropertyAddress(propId, isConst) : nullptr;
- }
- //--------------------------
- // RecyclableProtoObjectAddress
- RecyclableProtoObjectAddress::RecyclableProtoObjectAddress(Var _parentObj, Js::PropertyId _propId, Js::Var _value)
- : RecyclableObjectAddress(_parentObj, _propId, _value, false /*isInDeadZone*/)
- {
- }
- //--------------------------
- // RecyclableCollectionObjectWalker
- template <typename TData> const char16* RecyclableCollectionObjectWalker<TData>::Name() { static_assert(false, _u("Must use specialization")); }
- template <> const char16* RecyclableCollectionObjectWalker<JavascriptMap>::Name() { return _u("[Map]"); }
- template <> const char16* RecyclableCollectionObjectWalker<JavascriptSet>::Name() { return _u("[Set]"); }
- template <> const char16* RecyclableCollectionObjectWalker<JavascriptWeakMap>::Name() { return _u("[WeakMap]"); }
- template <> const char16* RecyclableCollectionObjectWalker<JavascriptWeakSet>::Name() { return _u("[WeakSet]"); }
- template <typename TData>
- BOOL RecyclableCollectionObjectWalker<TData>::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- pResolvedObject->name = Name();
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->obj = instance;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr;
- typedef RecyclableCollectionObjectDisplay<TData> RecyclableDataObjectDisplay;
- pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableDataObjectDisplay, scriptContext, pResolvedObject->name, this);
- return TRUE;
- }
- template <typename TData>
- BOOL RecyclableCollectionObjectWalker<TData>::Get(int i, ResolvedObject* pResolvedObject)
- {
- auto builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- builder->Reset();
- builder->AppendUint64(i);
- pResolvedObject->name = builder->Detach();
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->obj = instance;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr;
- pResolvedObject->objectDisplay = CreateTDataDisplay(pResolvedObject, i);
- return TRUE;
- }
- template <typename TData>
- IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<TData>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
- {
- Var key = propertyList->Item(i).key;
- Var value = propertyList->Item(i).value;
- return Anew(GetArenaFromContext(scriptContext), RecyclableKeyValueDisplay, resolvedObject->scriptContext, key, value, resolvedObject->name);
- }
- template <>
- IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<JavascriptSet>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
- {
- resolvedObject->obj = propertyList->Item(i).value;
- IDiagObjectModelDisplay* display = resolvedObject->CreateDisplay();
- display->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- return display;
- }
- template <>
- IDiagObjectModelDisplay* RecyclableCollectionObjectWalker<JavascriptWeakSet>::CreateTDataDisplay(ResolvedObject* resolvedObject, int i)
- {
- resolvedObject->obj = propertyList->Item(i).value;
- IDiagObjectModelDisplay* display = resolvedObject->CreateDisplay();
- display->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- return display;
- }
- template <typename TData>
- uint32 RecyclableCollectionObjectWalker<TData>::GetChildrenCount()
- {
- TData* data = TData::FromVar(instance);
- if (data->Size() > 0 && propertyList == nullptr)
- {
- propertyList = JsUtil::List<RecyclableCollectionObjectWalkerPropertyData<TData>, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
- GetChildren();
- }
- return data->Size();
- }
- template <>
- void RecyclableCollectionObjectWalker<JavascriptMap>::GetChildren()
- {
- JavascriptMap* data = JavascriptMap::FromVar(instance);
- auto iterator = data->GetIterator();
- while (iterator.Next())
- {
- Var key = iterator.Current().Key();
- Var value = iterator.Current().Value();
- propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptMap>(key, value));
- }
- }
- template <>
- void RecyclableCollectionObjectWalker<JavascriptSet>::GetChildren()
- {
- JavascriptSet* data = JavascriptSet::FromVar(instance);
- auto iterator = data->GetIterator();
- while (iterator.Next())
- {
- Var value = iterator.Current();
- propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptSet>(value));
- }
- }
- template <>
- void RecyclableCollectionObjectWalker<JavascriptWeakMap>::GetChildren()
- {
- JavascriptWeakMap* data = JavascriptWeakMap::FromVar(instance);
- data->Map([&](Var key, Var value)
- {
- propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptWeakMap>(key, value));
- });
- }
- template <>
- void RecyclableCollectionObjectWalker<JavascriptWeakSet>::GetChildren()
- {
- JavascriptWeakSet* data = JavascriptWeakSet::FromVar(instance);
- data->Map([&](Var value)
- {
- propertyList->Add(RecyclableCollectionObjectWalkerPropertyData<JavascriptWeakSet>(value));
- });
- }
- //--------------------------
- // RecyclableCollectionObjectDisplay
- template <typename TData>
- LPCWSTR RecyclableCollectionObjectDisplay<TData>::Value(int radix)
- {
- StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- builder->Reset();
- builder->AppendCppLiteral(_u("size = "));
- builder->AppendUint64(walker->GetChildrenCount());
- return builder->Detach();
- }
- template <typename TData>
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableCollectionObjectDisplay<TData>::CreateWalker()
- {
- if (walker)
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, walker);
- }
- }
- return nullptr;
- }
- //--------------------------
- // RecyclableKeyValueDisplay
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableKeyValueDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableKeyValueWalker, scriptContext, key, value);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
- }
- return nullptr;
- }
- LPCWSTR RecyclableKeyValueDisplay::Value(int radix)
- {
- ResolvedObject ro;
- ro.scriptContext = scriptContext;
- ro.obj = key;
- RecyclableObjectDisplay keyDisplay(&ro);
- ro.obj = value;
- RecyclableObjectDisplay valueDisplay(&ro);
- // Note, RecyclableObjectDisplay::Value(int) uses the shared string builder
- // so we cannot call it while building our string below. Call both before hand.
- const char16* keyValue = keyDisplay.Value(radix);
- const char16* valueValue = valueDisplay.Value(radix);
- StringBuilder<ArenaAllocator>* builder = scriptContext->GetThreadContext()->GetDebugManager()->pCurrentInterpreterLocation->stringBuilder;
- builder->Reset();
- builder->Append('[');
- builder->AppendSz(keyValue);
- builder->AppendCppLiteral(_u(", "));
- builder->AppendSz(valueValue);
- builder->Append(']');
- return builder->Detach();
- }
- //--------------------------
- // RecyclableKeyValueWalker
- BOOL RecyclableKeyValueWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- if (i == 0)
- {
- pResolvedObject->name = _u("key");
- pResolvedObject->obj = key;
- }
- else if (i == 1)
- {
- pResolvedObject->name = _u("value");
- pResolvedObject->obj = value;
- }
- else
- {
- Assert(false);
- return FALSE;
- }
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- pResolvedObject->address = nullptr;
- return TRUE;
- }
- //--------------------------
- // RecyclableProxyObjectDisplay
- RecyclableProxyObjectDisplay::RecyclableProxyObjectDisplay(ResolvedObject* resolvedObject)
- : RecyclableObjectDisplay(resolvedObject)
- {
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableProxyObjectDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclableProxyObjectWalker, scriptContext, instance);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
- }
- return nullptr;
- }
- //--------------------------
- // RecyclableProxyObjectWalker
- RecyclableProxyObjectWalker::RecyclableProxyObjectWalker(ScriptContext* pContext, Var _instance)
- : RecyclableObjectWalker(pContext, _instance)
- {
- }
- BOOL RecyclableProxyObjectWalker::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- pResolvedObject->name = _u("[Proxy]");
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->obj = instance;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr;
- pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableProxyObjectDisplay, pResolvedObject);
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- return TRUE;
- }
- BOOL RecyclableProxyObjectWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- JavascriptProxy* proxy = JavascriptProxy::FromVar(instance);
- if (proxy->GetTarget() == nullptr || proxy->GetHandler() == nullptr)
- {
- return FALSE;
- }
- if (i == 0)
- {
- pResolvedObject->name = _u("[target]");
- pResolvedObject->obj = proxy->GetTarget();
- }
- else if (i == 1)
- {
- pResolvedObject->name = _u("[handler]");
- pResolvedObject->obj = proxy->GetHandler();
- }
- else
- {
- Assert(false);
- return FALSE;
- }
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- pResolvedObject->address = Anew(GetArenaFromContext(pResolvedObject->scriptContext),
- RecyclableObjectAddress,
- pResolvedObject->scriptContext->GetGlobalObject(),
- Js::PropertyIds::Proxy,
- pResolvedObject->obj,
- false /*isInDeadZone*/);
- return TRUE;
- }
- //--------------------------
- // RecyclablePromiseObjectDisplay
- RecyclablePromiseObjectDisplay::RecyclablePromiseObjectDisplay(ResolvedObject* resolvedObject)
- : RecyclableObjectDisplay(resolvedObject)
- {
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclablePromiseObjectDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), RecyclablePromiseObjectWalker, scriptContext, instance);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
- }
- return nullptr;
- }
- //--------------------------
- // RecyclablePromiseObjectWalker
- RecyclablePromiseObjectWalker::RecyclablePromiseObjectWalker(ScriptContext* pContext, Var _instance)
- : RecyclableObjectWalker(pContext, _instance)
- {
- }
- BOOL RecyclablePromiseObjectWalker::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- pResolvedObject->name = _u("[Promise]");
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->obj = instance;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr;
- pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclablePromiseObjectDisplay, pResolvedObject);
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- return TRUE;
- }
- BOOL RecyclablePromiseObjectWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- JavascriptPromise* promise = JavascriptPromise::FromVar(instance);
- if (i == 0)
- {
- pResolvedObject->name = _u("[status]");
- switch (promise->GetStatus())
- {
- case JavascriptPromise::PromiseStatusCode_Undefined:
- pResolvedObject->obj = scriptContext->GetLibrary()->GetUndefinedDisplayString();
- break;
- case JavascriptPromise::PromiseStatusCode_Unresolved:
- pResolvedObject->obj = scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("pending"));
- case JavascriptPromise::PromiseStatusCode_HasResolution:
- pResolvedObject->obj = scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("resolved"));
- break;
- case JavascriptPromise::PromiseStatusCode_HasRejection:
- pResolvedObject->obj = scriptContext->GetLibrary()->CreateStringFromCppLiteral(_u("rejected"));
- break;
- default:
- AssertMsg(false, "New PromiseStatusCode not handled in debugger");
- pResolvedObject->obj = scriptContext->GetLibrary()->GetUndefinedDisplayString();
- break;
- }
- }
- else if (i == 1)
- {
- pResolvedObject->name = _u("[value]");
- Var result = promise->GetResult();
- pResolvedObject->obj = result != nullptr ? result : scriptContext->GetLibrary()->GetUndefinedDisplayString();
- }
- else
- {
- Assert(false);
- return FALSE;
- }
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- pResolvedObject->address = nullptr;
- return TRUE;
- }
- // ---------------------------
- // RecyclableMethodsGroupWalker
- RecyclableMethodsGroupWalker::RecyclableMethodsGroupWalker(ScriptContext* scriptContext, Var instance)
- : RecyclableObjectWalker(scriptContext,instance)
- {
- }
- void RecyclableMethodsGroupWalker::AddItem(Js::PropertyId propertyId, Var obj)
- {
- if (pMembersList == nullptr)
- {
- pMembersList = JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator>::New(GetArenaFromContext(scriptContext));
- }
- Assert(pMembersList);
- DebuggerPropertyDisplayInfo *info = Anew(GetArenaFromContext(scriptContext), DebuggerPropertyDisplayInfo, propertyId, obj, DebuggerPropertyDisplayInfoFlags_Const);
- Assert(info);
- pMembersList->Add(info);
- }
- uint32 RecyclableMethodsGroupWalker::GetChildrenCount()
- {
- return pMembersList ? pMembersList->Count() : 0;
- }
- BOOL RecyclableMethodsGroupWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- AssertMsg(pResolvedObject, "Bad usage of RecyclableMethodsGroupWalker::Get");
- return RecyclableObjectWalker::Get(i, pResolvedObject);
- }
- BOOL RecyclableMethodsGroupWalker::GetGroupObject(ResolvedObject* pResolvedObject)
- {
- Assert(pResolvedObject);
- // This is fake [Methods] object.
- pResolvedObject->name = _u("[Methods]");
- pResolvedObject->obj = Js::RecyclableObject::FromVar(instance);
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->address = nullptr; // Methods object will not be editable
- pResolvedObject->objectDisplay = Anew(GetArenaFromContext(scriptContext), RecyclableMethodsGroupDisplay, this, pResolvedObject);
- return TRUE;
- }
- void RecyclableMethodsGroupWalker::Sort()
- {
- HostDebugContext* hostDebugContext = this->scriptContext->GetDebugContext()->GetHostDebugContext();
- if (hostDebugContext != nullptr)
- {
- hostDebugContext->SortMembersList(pMembersList, scriptContext);
- }
- }
- RecyclableMethodsGroupDisplay::RecyclableMethodsGroupDisplay(RecyclableMethodsGroupWalker *_methodGroupWalker, ResolvedObject* resolvedObject)
- : methodGroupWalker(_methodGroupWalker),
- RecyclableObjectDisplay(resolvedObject)
- {
- }
- LPCWSTR RecyclableMethodsGroupDisplay::Type()
- {
- return _u("");
- }
- LPCWSTR RecyclableMethodsGroupDisplay::Value(int radix)
- {
- return _u("{...}");
- }
- BOOL RecyclableMethodsGroupDisplay::HasChildren()
- {
- return methodGroupWalker ? TRUE : FALSE;
- }
- DBGPROP_ATTRIB_FLAGS RecyclableMethodsGroupDisplay::GetTypeAttribute()
- {
- return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_IS_METHOD | DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE;
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableMethodsGroupDisplay::CreateWalker()
- {
- if (methodGroupWalker)
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, methodGroupWalker);
- }
- }
- return nullptr;
- }
- ScopeVariablesGroupDisplay::ScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject)
- : scopeGroupWalker(walker),
- RecyclableObjectDisplay(resolvedObject)
- {
- }
- LPCWSTR ScopeVariablesGroupDisplay::Type()
- {
- return _u("");
- }
- LPCWSTR ScopeVariablesGroupDisplay::Value(int radix)
- {
- if (ActivationObject::Is(instance))
- {
- // The scope is defined by the activation object.
- Js::RecyclableObject *object = Js::RecyclableObject::FromVar(instance);
- try
- {
- // Trying to find out the JavascriptFunction from the scope.
- Var value = nullptr;
- if (object->GetTypeId() == TypeIds_ActivationObject && GetPropertyWithScriptEnter(object, object, PropertyIds::arguments, &value, scriptContext))
- {
- if (Js::RecyclableObject::Is(value))
- {
- Js::RecyclableObject *argObject = Js::RecyclableObject::FromVar(value);
- Var calleeFunc = nullptr;
- if (GetPropertyWithScriptEnter(argObject, argObject, PropertyIds::callee, &calleeFunc, scriptContext) && Js::JavascriptFunction::Is(calleeFunc))
- {
- Js::JavascriptFunction *calleeFunction = Js::JavascriptFunction::FromVar(calleeFunc);
- Js::FunctionBody *pFuncBody = calleeFunction->GetFunctionBody();
- if (pFuncBody)
- {
- const char16* pDisplayName = pFuncBody->GetDisplayName();
- if (pDisplayName)
- {
- StringBuilder<ArenaAllocator>* builder = GetStringBuilder();
- builder->Reset();
- builder->AppendSz(pDisplayName);
- return builder->Detach();
- }
- }
- }
- }
- }
- }
- catch(Js::JavascriptExceptionObject *exceptionObject)
- {
- exceptionObject;
- // Not doing anything over here.
- }
- return _u("");
- }
- else
- {
- // The scope is defined by a slot array object so grab the function body out to get the function name.
- ScopeSlots slotArray = ScopeSlots(reinterpret_cast<Var*>(instance));
- if(slotArray.IsFunctionScopeSlotArray())
- {
- Js::FunctionBody *functionBody = slotArray.GetFunctionBody();
- return functionBody->GetDisplayName();
- }
- else
- {
- // handling for block/catch scope
- return _u("");
- }
- }
- }
- BOOL ScopeVariablesGroupDisplay::HasChildren()
- {
- return scopeGroupWalker ? TRUE : FALSE;
- }
- DBGPROP_ATTRIB_FLAGS ScopeVariablesGroupDisplay::GetTypeAttribute()
- {
- return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE;
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* ScopeVariablesGroupDisplay::CreateWalker()
- {
- if (scopeGroupWalker)
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, scopeGroupWalker);
- }
- }
- return nullptr;
- }
- GlobalsScopeVariablesGroupDisplay::GlobalsScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject)
- : globalsGroupWalker(walker),
- RecyclableObjectDisplay(resolvedObject)
- {
- }
- LPCWSTR GlobalsScopeVariablesGroupDisplay::Type()
- {
- return _u("");
- }
- LPCWSTR GlobalsScopeVariablesGroupDisplay::Value(int radix)
- {
- return _u("");
- }
- BOOL GlobalsScopeVariablesGroupDisplay::HasChildren()
- {
- return globalsGroupWalker ? globalsGroupWalker->GetChildrenCount() > 0 : FALSE;
- }
- DBGPROP_ATTRIB_FLAGS GlobalsScopeVariablesGroupDisplay::GetTypeAttribute()
- {
- return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | (HasChildren() ? DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE : 0);
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* GlobalsScopeVariablesGroupDisplay::CreateWalker()
- {
- if (globalsGroupWalker)
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, globalsGroupWalker);
- }
- }
- return nullptr;
- }
- #ifdef ENABLE_MUTATION_BREAKPOINT
- PendingMutationBreakpointDisplay::PendingMutationBreakpointDisplay(ResolvedObject* resolvedObject, MutationType _mutationType)
- : RecyclableObjectDisplay(resolvedObject), mutationType(_mutationType)
- {
- AssertMsg(_mutationType > MutationTypeNone && _mutationType < MutationTypeAll, "Invalid mutationType value passed to PendingMutationBreakpointDisplay");
- }
- WeakArenaReference<IDiagObjectModelWalkerBase>* PendingMutationBreakpointDisplay::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), PendingMutationBreakpointWalker, scriptContext, instance, this->mutationType);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
- }
- return nullptr;
- }
- uint32 PendingMutationBreakpointWalker::GetChildrenCount()
- {
- switch (this->mutationType)
- {
- case MutationTypeUpdate:
- return 3;
- case MutationTypeDelete:
- case MutationTypeAdd:
- return 2;
- default:
- AssertMsg(false, "Invalid mutationType");
- return 0;
- }
- }
- PendingMutationBreakpointWalker::PendingMutationBreakpointWalker(ScriptContext* pContext, Var _instance, MutationType mutationType)
- : RecyclableObjectWalker(pContext, _instance)
- {
- this->mutationType = mutationType;
- }
- BOOL PendingMutationBreakpointWalker::Get(int i, ResolvedObject* pResolvedObject)
- {
- Js::MutationBreakpoint *mutationBreakpoint = scriptContext->GetDebugContext()->GetProbeContainer()->GetDebugManager()->GetActiveMutationBreakpoint();
- Assert(mutationBreakpoint);
- if (mutationBreakpoint != nullptr)
- {
- if (i == 0)
- {
- // <Property Name> [Adding] : New Value
- // <Property Name> [Changing] : Old Value
- // <Property Name> [Deleting] : Old Value
- WCHAR * displayName = AnewArray(GetArenaFromContext(scriptContext), WCHAR, PENDING_MUTATION_VALUE_MAX_NAME);
- swprintf_s(displayName, PENDING_MUTATION_VALUE_MAX_NAME, _u("%s [%s]"), mutationBreakpoint->GetBreakPropertyName(), Js::MutationBreakpoint::GetBreakMutationTypeName(mutationType));
- pResolvedObject->name = displayName;
- if (mutationType == MutationTypeUpdate || mutationType == MutationTypeDelete)
- {
- // Old/Current value
- PropertyId breakPId = mutationBreakpoint->GetBreakPropertyId();
- pResolvedObject->propId = breakPId;
- pResolvedObject->obj = JavascriptOperators::OP_GetProperty(mutationBreakpoint->GetMutationObjectVar(), breakPId, scriptContext);
- }
- else
- {
- // New Value
- pResolvedObject->obj = mutationBreakpoint->GetBreakNewValueVar();
- pResolvedObject->propId = Constants::NoProperty;
- }
- }
- else if ((i == 1) && (mutationType == MutationTypeUpdate))
- {
- pResolvedObject->name = _u("[New Value]");
- pResolvedObject->obj = mutationBreakpoint->GetBreakNewValueVar();
- pResolvedObject->propId = Constants::NoProperty;
- }
- else if (((i == 1) && (mutationType != MutationTypeUpdate)) || (i == 2))
- {
- WCHAR * displayName = AnewArray(GetArenaFromContext(scriptContext), WCHAR, PENDING_MUTATION_VALUE_MAX_NAME);
- swprintf_s(displayName, PENDING_MUTATION_VALUE_MAX_NAME, _u("[Property container %s]"), mutationBreakpoint->GetParentPropertyName());
- pResolvedObject->name = displayName;
- pResolvedObject->obj = mutationBreakpoint->GetMutationObjectVar();
- pResolvedObject->propId = mutationBreakpoint->GetParentPropertyId();
- }
- else
- {
- Assert(false);
- return FALSE;
- }
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = JavascriptOperators::GetTypeId(pResolvedObject->obj);
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- pResolvedObject->address = nullptr; // TODO: (SaAgarwa) Currently Pending mutation values are not editable, will do as part of another WI
- return TRUE;
- }
- return FALSE;
- }
- #endif
- //--------------------------
- // RecyclableSimdObjectWalker
- template <typename simdType, uint elementCount>
- BOOL RecyclableSimdObjectWalker<simdType, elementCount>::Get(int i, ResolvedObject* pResolvedObject)
- {
- Assert(elementCount == 4 || elementCount == 8 || elementCount == 16); // SIMD types such as int32x4, int8x16, int16x8
- Assert(i >= 0 && i <= elementCount);
- simdType* simd = simdType::FromVar(instance);
- SIMDValue value = simd->GetValue();
- WCHAR* indexName = AnewArray(GetArenaFromContext(scriptContext), WCHAR, SIMD_INDEX_VALUE_MAX);
- Assert(indexName);
- swprintf_s(indexName, SIMD_INDEX_VALUE_MAX, _u("[%d]"), i);
- pResolvedObject->name = indexName;
- TypeId simdTypeId = JavascriptOperators::GetTypeId(instance);
- switch (simdTypeId)
- {
- case TypeIds_SIMDInt32x4:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.i32[i], scriptContext);
- break;
- case TypeIds_SIMDFloat32x4:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.f32[i], scriptContext);
- break;
- case TypeIds_SIMDInt8x16:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.i8[i], scriptContext);
- break;
- case TypeIds_SIMDInt16x8:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.i16[i], scriptContext);
- break;
- case TypeIds_SIMDBool32x4:
- pResolvedObject->obj = JavascriptBoolean::ToVar(value.i32[i], scriptContext);
- break;
- case TypeIds_SIMDBool8x16:
- pResolvedObject->obj = JavascriptBoolean::ToVar(value.i8[i], scriptContext);
- break;
- case TypeIds_SIMDBool16x8:
- pResolvedObject->obj = JavascriptBoolean::ToVar(value.i16[i], scriptContext);
- break;
- case TypeIds_SIMDUint32x4:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.u32[i], scriptContext);
- break;
- case TypeIds_SIMDUint8x16:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.u8[i], scriptContext);
- break;
- case TypeIds_SIMDUint16x8:
- pResolvedObject->obj = JavascriptNumber::ToVarWithCheck(value.u16[i], scriptContext);
- break;
- default:
- AssertMsg(false, "Unexpected SIMD typeId");
- return FALSE;
- }
- pResolvedObject->propId = Constants::NoProperty;
- pResolvedObject->scriptContext = scriptContext;
- pResolvedObject->typeId = simdTypeId;
- pResolvedObject->objectDisplay = pResolvedObject->CreateDisplay();
- pResolvedObject->objectDisplay->SetDefaultTypeAttribute(DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE);
- pResolvedObject->address = nullptr;
-
- return TRUE;
- }
- //--------------------------
- // RecyclableSimdObjectDisplay
- template <typename simdType, typename simdWalker>
- LPCWSTR RecyclableSimdObjectDisplay<simdType, simdWalker>::Type()
- {
- TypeId simdTypeId = JavascriptOperators::GetTypeId(instance);
- switch (simdTypeId)
- {
- case TypeIds_SIMDInt32x4:
- return _u("SIMD.Int32x4");
- case TypeIds_SIMDFloat32x4:
- return _u("SIMD.Float32x4");
- case TypeIds_SIMDInt8x16:
- return _u("SIMD.Int8x16");
- case TypeIds_SIMDInt16x8:
- return _u("SIMD.Int16x8");
- case TypeIds_SIMDBool32x4:
- return _u("SIMD.Bool32x4");
- case TypeIds_SIMDBool8x16:
- return _u("SIMD.Bool8x16");
- case TypeIds_SIMDBool16x8:
- return _u("SIMD.Bool16x8");
- case TypeIds_SIMDUint32x4:
- return _u("SIMD.Uint32x4");
- case TypeIds_SIMDUint8x16:
- return _u("SIMD.Uint8x16");
- case TypeIds_SIMDUint16x8:
- return _u("SIMD.Uint16x8");
- default:
- AssertMsg(false, "Unexpected SIMD typeId");
- return nullptr;
- }
- }
- template <typename simdType, typename simdWalker>
- LPCWSTR RecyclableSimdObjectDisplay<simdType, simdWalker>::Value(int radix)
- {
- StringBuilder<ArenaAllocator>* builder = GetStringBuilder();
- builder->Reset();
- simdType* simd = simdType::FromVar(instance);
- SIMDValue value = simd->GetValue();
- char16* stringBuffer = AnewArray(GetArenaFromContext(scriptContext), char16, SIMD_STRING_BUFFER_MAX);
-
- simdType::ToStringBuffer(value, stringBuffer, SIMD_STRING_BUFFER_MAX, scriptContext);
- builder->AppendSz(stringBuffer);
- return builder->Detach();
- }
- template <typename simdType, typename simdWalker>
- WeakArenaReference<IDiagObjectModelWalkerBase>* RecyclableSimdObjectDisplay<simdType, simdWalker>::CreateWalker()
- {
- ReferencedArenaAdapter* pRefArena = scriptContext->GetThreadContext()->GetDebugManager()->GetDiagnosticArena();
- if (pRefArena)
- {
- IDiagObjectModelWalkerBase* pOMWalker = Anew(pRefArena->Arena(), simdWalker, scriptContext, instance);
- return HeapNew(WeakArenaReference<IDiagObjectModelWalkerBase>, pRefArena, pOMWalker);
- }
- return nullptr;
- }
- }
|