| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404 |
- //-------------------------------------------------------------------------------------------------------
- // 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/DynamicObjectPropertyEnumerator.h"
- #include "Types/JavascriptStaticEnumerator.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::_super || this->propId == Js::PropertyIds::_superConstructor)
- {
- 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 = ParseFunctionName(returnValue->calledFunction->GetDisplayName(), pResolvedObject->scriptContext);
- 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);
- }
- // The debugger uses the functionNameId field instead of the "name" property to get the name of the funtion. The functionNameId field is overloaded and may contain the display name if
- // toString() has been called on the function object. For built-in or external functions the display name can be something like "function Echo() { native code }". We will try to parse the
- // function name out of the display name so the user will see just the function name e.g. "Echo" instead of the full display name in debugger.
- JavascriptString * VariableWalkerBase::ParseFunctionName(JavascriptString* displayName, ScriptContext* scriptContext)
- {
- Assert(displayName);
- const char16 * displayNameBuffer = displayName->GetString();
- const charcount_t displayNameBufferLength = displayName->GetLength();
- const charcount_t funcStringLength = _countof(JS_DISPLAY_STRING_FUNCTION_HEADER) - 1; // discount the ending null character in string literal
- const charcount_t templateStringLength = funcStringLength + _countof(JS_DISPLAY_STRING_FUNCTION_BODY) - 1; // discount the ending null character in string literal
- // If the string doesn't meet our expected format; return the original string.
- if (displayNameBufferLength <= templateStringLength || (wmemcmp(displayNameBuffer, JS_DISPLAY_STRING_FUNCTION_HEADER, funcStringLength) != 0))
- {
- return displayName;
- }
- // Look for the left parenthesis, if we don't find one; return the original string.
- const char16* parenChar = wcschr(displayNameBuffer, '(');
- if (parenChar == nullptr)
- {
- return displayName;
- }
- charcount_t actualFunctionNameLength = displayNameBufferLength - templateStringLength;
- uint byteLengthForCopy = sizeof(char16) * actualFunctionNameLength;
- char16 * actualFunctionNameBuffer = AnewArray(GetArenaFromContext(scriptContext), char16, actualFunctionNameLength + 1); // The last character will be the null character.
- if (actualFunctionNameBuffer == nullptr)
- {
- return displayName;
- }
- js_memcpy_s(actualFunctionNameBuffer, byteLengthForCopy, displayNameBuffer + funcStringLength, byteLengthForCopy);
- actualFunctionNameBuffer[actualFunctionNameLength] = _u('\0');
- JavascriptString * actualFunctionName = JavascriptString::NewWithArenaSz(actualFunctionNameBuffer, scriptContext);
- if (actualFunctionName == nullptr)
- {
- return displayName;
- }
- return actualFunctionName;
- }
- /*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::_super || pResolvedObject->propId == Js::PropertyIds::_superConstructor)
- {
- 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::_this || propertyId == Js::PropertyIds::_newTarget))
- {
- return false;
- }
- if (!allowSuperReference && (propertyId == Js::PropertyIds::_super || propertyId == Js::PropertyIds::_superConstructor))
- {
- 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;
- }
- bool VariableWalkerBase::IsInParamScope(DebuggerScope* scope, DiagStackFrame* pFrame)
- {
- return scope != nullptr && scope->GetEnd() > LocalsWalker::GetAdjustedByteCodeOffset(pFrame);
- }
- // 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();
- bool isInParamScope = IsInParamScope(formalScope, pFrame);
- Js::FunctionBody *pFBody = slotArray.GetFunctionInfo()->GetFunctionBody();
- if (this->groupType & UIGroupType_Param)
- {
- Assert(formalScope != nullptr && pFBody->paramScopeSlotArraySize > 0);
- uint slotArrayCount = pFBody->paramScopeSlotArraySize;
- 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)
- {
- uint slotArrayCount = static_cast<uint>(slotArray.GetCount());
- 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 (!isInParamScope || 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)
- {
- RegSlot limit = propIdContainer->formalsUpperBound == Js::Constants::NoRegister ? Js::Constants::NoRegister : pFBody->MapRegSlot(propIdContainer->formalsUpperBound);
- 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)
- {
- if (IsInParamScope(formalScope, pFrame))
- {
- if (limit != Js::Constants::NoRegister)
- {
- shouldInsert = reg <= limit;
- }
- else
- {
- shouldInsert = formalScope->HasProperty(propertyId);
- }
- }
- else if (!pFBody->IsParamAndBodyScopeMerged() && formalScope->HasProperty(propertyId))
- {
- DebuggerScopeProperty prop;
- prop.flags = DebuggerScopePropertyFlags_None;
- prop.propId = 0;
- formalScope->TryGetProperty(propertyId, reg, &prop);
- if (prop.flags & DebuggerScopePropertyFlags_HasDuplicateInBody)
- {
- shouldInsert = false;
- }
- }
- }
- 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 = LocalsWalker::GetScopeWhenHaltAtFormals(pFrame);
- // 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 (IsInParamScope(formalScope, pFrame) && 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);
- // 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);
- DWORD localsType = GetCurrentFramesLocalsType(pFrame);
- // If we are in the formal scope of a split scoped function then we can skip checking the body scope
- if (!VariableWalkerBase::IsInParamScope(formalScope, pFrame) || pFBody->IsParamAndBodyScopeMerged())
- {
- VariableWalkerBase *pVarWalker = nullptr;
- // More than one localsType can occur in the scope
- 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));
- nextStartIndex++;
- }
- 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));
- nextStartIndex++;
- }
- else if (scopeCount > 0 && pFBody->GetFrameDisplayRegister() != 0 && pFBody->IsParamAndBodyScopeMerged())
- {
- Assert((Var)pDisplay->GetItem(0) == pFrame->GetScriptContext()->GetLibrary()->GetNull());
- nextStartIndex++;
- }
- if (pVarWalker)
- {
- pVarWalkers->Add(pVarWalker);
- }
- }
- // If we are halted at formal place, and param and body scopes are splitted we need to make use of formal debugger scope to to determine the locals type.
- if (formalScope != nullptr && !pFBody->IsParamAndBodyScopeMerged())
- {
- if (pFBody->GetPropertyIdOnRegSlotsContainer() && pFBody->GetPropertyIdOnRegSlotsContainer()->formalsUpperBound != Js::Constants::NoRegister)
- {
- localsType |= FramesLocalType::LocalType_Reg;
- }
- Assert(scopeCount > 0);
- if (formalScope->scopeType == Js::DiagParamScopeInObject)
- {
- // Need to add the param scope frame display as a separate walker as the ObjectVariablesWalker directly uses the socpe object to retrieve properties
- pVarWalkers->Add(Anew(arena, ObjectVariablesWalker, pFrame, pDisplay->GetItem(nextStartIndex), UIGroupType_Param, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- }
- else
- {
- pVarWalkers->Add(Anew(arena, SlotArrayVariablesWalker, pFrame, (Js::Var *)pDisplay->GetItem(nextStartIndex), UIGroupType_Param, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- }
- nextStartIndex++;
- }
- if (localsType & FramesLocalType::LocalType_Reg)
- {
- pVarWalkers->Add(Anew(arena, RegSlotVariablesWalker, pFrame, nullptr /*not debugger scope*/, UIGroupType_None, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- }
- 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:
- pVarWalkers->Add(Anew(arena, ObjectVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- break;
- case ScopeType_SlotArray:
- pVarWalkers->Add(Anew(arena, SlotArrayVariablesWalker, pFrame, currentScopeObject, UIGroupType_Scope, !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowLexicalThis), !!(frameWalkerFlags & FrameWalkerFlags::FW_AllowSuperReference)));
- break;
- case ScopeType_WithScope:
- if( (frameWalkerFlags & FrameWalkerFlags::FW_EnumWithScopeAlso) == FrameWalkerFlags::FW_EnumWithScopeAlso)
- {
- RecyclableObjectWalker* withScopeWalker = Anew(arena, RecyclableObjectWalker, pFrame->GetScriptContext(), currentScopeObject);
- pVarWalkers->Add(Anew(arena, DiagScopeVariablesWalker, pFrame, currentScopeObject, withScopeWalker));
- }
- 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)
- {
- pVarWalkers->Add(Anew(arena, RootObjectVariablesWalker, pFrame, pFrame->GetRootObject(), UIGroupType_Globals));
- }
- }
- }
- 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)
- {
- for (int i = 0; i < scopeObjectChain->pScopeChain->Count(); i++)
- {
- Js::DebuggerScope * scope = scopeObjectChain->pScopeChain->Item(i);
- if (scope->IsParamScope())
- {
- 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 ENABLE_TTD
- bool suppressGetterForTTDebug = requestContext->GetThreadContext()->IsRuntimeInTTDMode() && requestContext->GetThreadContext()->TTDLog->ShouldDoGetterInvocationSupression();
- TTD::TTModeStackAutoPopper suppressModeAutoPopper(requestContext->GetThreadContext()->TTDLog);
- if(suppressGetterForTTDebug)
- {
- suppressModeAutoPopper.PushModeAndSetToAutoPop(TTD::TTDMode::DebuggerSuppressGetter);
- }
- #endif
- 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);
- Js::PropertyId propertyId;
- if (enumerator.MoveAndGetNext(propertyId))
- {
- 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 (const JavascriptException& err)
- {
- // The For in enumerator can throw an exception and we will use the error object as a child in that case.
- Var error = err.GetAndClear()->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 ENABLE_TTD
- bool suppressGetterForTTDebug = scriptContext->GetThreadContext()->IsRuntimeInTTDMode() && scriptContext->GetThreadContext()->TTDLog->ShouldDoGetterInvocationSupression();
- TTD::TTModeStackAutoPopper suppressModeAutoPopper(scriptContext->GetThreadContext()->TTDLog);
- if(suppressGetterForTTDebug)
- {
- suppressModeAutoPopper.PushModeAndSetToAutoPop(TTD::TTDMode::DebuggerSuppressGetter);
- }
- #endif
- 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
- {
- ScriptContext * objectContext = object->GetScriptContext();
- JavascriptStaticEnumerator enumerator;
- if (object->GetEnumerator(&enumerator, EnumeratorFlags::EnumNonEnumerable | EnumeratorFlags::EnumSymbols, objectContext))
- {
- Js::PropertyId propertyId;
- JavascriptString * obj;
- while ((obj = enumerator.MoveAndGetNext(propertyId)) != nullptr)
- {
- if (propertyId == Constants::NoProperty)
- {
- if (VirtualTableInfo<Js::PropertyString>::HasVirtualTable(obj))
- {
- // If we have a property string, it is assumed that the propertyId is being
- // kept alive with the object
- PropertyString * propertyString = (PropertyString *)obj;
- propertyId = propertyString->GetPropertyRecord()->GetPropertyId();
- }
- else
- {
- const PropertyRecord* propertyRecord;
- objectContext->GetOrAddPropertyRecord(obj, &propertyRecord);
- propertyId = propertyRecord->GetPropertyId();
- }
- }
- // MoveAndGetNext shouldn't return an internal property id
- Assert(!Js::IsInternalPropertyId(propertyId));
- uint32 indexVal;
- Var varValue;
- if (objectContext->IsNumericPropertyId(propertyId, &indexVal) && object->GetItem(object, indexVal, &varValue, objectContext))
- {
- InsertItem(propertyId, false /*isConst*/, false /*isUnscoped*/, varValue, &pMethodsGroupWalker, true /*shouldPinProperty*/);
- }
- else
- {
- InsertItem(originalObject, object, propertyId, false /*isConst*/, false /*isUnscoped*/, &pMethodsGroupWalker, true /*shouldPinProperty*/);
- }
- }
- }
- }
- catch (const JavascriptException& err)
- {
- Var error = err.GetAndClear()->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(const JavascriptException& err)
- {
- Var error = err.GetAndClear()->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(const JavascriptException& err)
- {
- err.GetAndClear(); // discard exception object
- }
- 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.GetFunctionInfo()->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
- #ifdef ENABLE_SIMDJS
- //--------------------------
- // 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;
- }
- #endif // #ifdef ENABLE_SIMDJS
- }
|