forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagObjectModel.h
More file actions
1010 lines (807 loc) · 43.3 KB
/
DiagObjectModel.h
File metadata and controls
1010 lines (807 loc) · 43.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
namespace Js
{
class IDiagObjectAddress;
class IDiagObjectModelDisplay;
class RecyclableMethodsGroupWalker;
class RecyclableObjectWalker;
class RecyclableArrayWalker;
// Concrete type for manipulating JS Vars
struct ResolvedObject
{
ResolvedObject() : propId(Js::Constants::NoProperty), scriptContext(nullptr), address(nullptr),
objectDisplay(nullptr), obj(nullptr), originalObj(nullptr), isConst(false), name(nullptr)
{}
PropertyId propId;
ScriptContext *scriptContext;
IDiagObjectAddress *address;
IDiagObjectModelDisplay *objectDisplay;
Var obj;
Var originalObj;
LPCWSTR name;
TypeId typeId;
bool isConst;
WeakArenaReference<IDiagObjectModelDisplay>* GetObjectDisplay();
IDiagObjectModelDisplay * CreateDisplay();
bool IsInDeadZone() const;
};
// interfaces for manipulating DataTypes
// Allow setting the value across different parent data types
class IDiagObjectAddress
{
public:
virtual BOOL Set(Var updateObject) = 0;
virtual BOOL IsWritable() { return !IsInDeadZone(); }
virtual Var GetValue(BOOL fUpdated) { return nullptr; }
virtual BOOL IsInDeadZone() const { return FALSE; };
};
class IDiagObjectModelWalkerBase
{
public:
// Get the child at i'th position.
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) = 0;
// Returns number of children for the current diag object.
virtual ulong GetChildrenCount() = 0;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) = 0;
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propId, bool& isConst) { return nullptr;}
};
enum DiagObjectModelDisplayType
{
DiagObjectModelDisplayType_LocalsDisplay,
DiagObjectModelDisplayType_RecyclableObjectDisplay,
DiagObjectModelDisplayType_RecyclableCollectionObjectDisplay,
DiagObjectModelDisplayType_RecyclableKeyValueDisplay,
DiagObjectModelDisplayType_RecyclableSimdDisplay,
};
// Allow getting information across different data types
class IDiagObjectModelDisplay
{
public:
virtual LPCWSTR Name() = 0;
virtual LPCWSTR Type() = 0;
virtual LPCWSTR Value(int radix) = 0;
virtual BOOL HasChildren() = 0;
virtual BOOL Set(Var updateObject) = 0;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() = 0;
virtual BOOL SetDefaultTypeAttribute(DBGPROP_ATTRIB_FLAGS attributes) { return FALSE; };
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() = 0;
virtual BOOL IsLocalsAsRoot() { return FALSE; }
virtual Var GetVarValue(BOOL fUpdated) { return nullptr; }
virtual IDiagObjectAddress * GetDiagAddress() { return nullptr; }
virtual DiagObjectModelDisplayType GetType() = 0;
virtual bool IsFake() { return (this->GetTypeAttribute() & DBGPROP_ATTRIB_VALUE_IS_FAKE) == DBGPROP_ATTRIB_VALUE_IS_FAKE; }
virtual bool IsLiteralProperty() const = 0;
virtual bool IsSymbolProperty() { return false; }
};
//
// There are three distinct types of classes defined in order to inspect a variable on watch/locals window.
// If someone has to change or provide the support for custom types/objects (such as PixelArray etc) be displayed on the debugger, they need to aware
// of few things which are mentioned below.
// <...>Display (eg RecyclableArrayDisplay), mentions how current variable is given to debugger, and tells what walker (enumerator) to be chosen
// in order to walk to children of the current variable.
// <...>Walker (eg RecyclableArrayWalker), mentions logic of walk thru content of the current variable (the object generally acts like an enumerator). Let say for an array, it has logic to go thru each
// indices and populate values.
// <...>Address (eg RecyclableArrayAddress), associated with each child and will be used to updating that item. The object if this will be consumed by "<...>Walker"
// object when it walks thru each children of the current variable.
// In order to support the custom objects, above classes should be used (or derived) to get started.
//
enum DebuggerPropertyDisplayInfoFlags
{
DebuggerPropertyDisplayInfoFlags_None = 0x0,
DebuggerPropertyDisplayInfoFlags_Const = 0x1,
DebuggerPropertyDisplayInfoFlags_InDeadZone = 0x2,
DebuggerPropertyDisplayInfoFlags_Unscope = 0x4,
};
struct DebuggerPropertyDisplayInfo
{
PropertyId propId;
Var aVar;
DWORD flags; // DebuggerPropertyDisplayInfoFlags.
DebuggerPropertyDisplayInfo(PropertyId _propId, Var _aVar, DWORD _flags) : propId(_propId), aVar(_aVar), flags(_flags)
{}
bool IsUnscoped() const { return (flags & DebuggerPropertyDisplayInfoFlags_Unscope) != 0; }
bool IsConst() const { return (flags & DebuggerPropertyDisplayInfoFlags_Const) != 0; }
bool IsInDeadZone() const { return (flags & DebuggerPropertyDisplayInfoFlags_InDeadZone) != 0; }
};
enum UIGroupType
{
UIGroupType_None,
UIGroupType_InnerScope, // variables under the innerscope (such as Block/Catch)
UIGroupType_Scope,
UIGroupType_Globals
};
enum FramesLocalType
{
LocalType_None = 0x0,
LocalType_Reg = 0x1,
LocalType_InSlot = 0x2,
LocalType_InObject = 0x4,
};
enum FrameWalkerFlags
{
FW_None = 0x0,
FW_MakeGroups = 0x1, // Make groups such as [Scope], [Globals] etc.
FW_EnumWithScopeAlso = 0x2, // While walking include the with scope as well.
FW_AllowLexicalThis = 0x4, // Do not filter out Js::PropertyIds::_lexicalThisSlotSymbol
FW_AllowSuperReference = 0x8, // Allow walking of Js::PropertyIds::_superReferenceSymbol and Js::PropertyIds::_superCtorReferenceSymbol
FW_DontAddGlobalsDirectly = 0x10, // Do not add global object directly.
};
class VariableWalkerBase : public IDiagObjectModelWalkerBase
{
public:
DiagStackFrame* pFrame;
Var instance;
JsUtil::List<DebuggerPropertyDisplayInfo*, ArenaAllocator> *pMembersList;
UIGroupType groupType;
private:
bool allowLexicalThis;
bool allowSuperReference;
public :
VariableWalkerBase(DiagStackFrame* _pFrame, Var _instance, UIGroupType _groupType, bool allowLexicalThis, bool allowSuperReference = false)
: pFrame(_pFrame), instance(_instance), pMembersList(nullptr), groupType(_groupType), allowLexicalThis(allowLexicalThis), allowSuperReference(allowSuperReference)
{
}
// Defined virtual function, should be extended by type of variable scope.
virtual void PopulateMembers() { };
virtual IDiagObjectAddress * GetObjectAddress(int index) { return nullptr; }
virtual Var GetVarObjectAt(int index);
virtual bool IsConstAt(int index);
/// IDiagObjectModelWalkerBase
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override sealed;
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propId, bool& isConst) override;
static BOOL GetExceptionObject(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject);
static bool HasExceptionObject(DiagStackFrame* frame);
static BOOL GetReturnedValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject);
static int GetReturnedValueCount(DiagStackFrame* frame);
#ifdef ENABLE_MUTATION_BREAKPOINT
static BOOL GetBreakMutationBreakpointValue(int &index, DiagStackFrame* frame, ResolvedObject* pResolvedObject);
static uint GetBreakMutationBreakpointsCount(DiagStackFrame* frame);
#endif
bool IsInGroup() const { return (groupType != UIGroupType::UIGroupType_None && groupType != UIGroupType::UIGroupType_InnerScope); }
bool IsWalkerForCurrentFrame() const { return groupType == UIGroupType::UIGroupType_None; }
DebuggerScope * GetScopeWhenHaltAtFormals();
int GetAdjustedByteCodeOffset() const;
DebuggerPropertyDisplayInfo* AllocateNewPropertyDisplayInfo(PropertyId propertyId, Var value, bool isConst, bool isInDeadZone);
protected:
int GetMemberCount() { return pMembersList ? pMembersList->Count() : 0; }
bool IsPropertyValid(PropertyId propertyId, RegSlot location, bool *isPropertyInDebuggerScope, bool* isConst, bool* isInDeadZone) const;
};
class RegSlotVariablesWalker : public VariableWalkerBase
{
// This will be pointing to the inner debugger scope (block/catch)
DebuggerScope* debuggerScope;
public:
RegSlotVariablesWalker(DiagStackFrame* _pFrame, DebuggerScope *_debuggerScope, UIGroupType _groupType, bool allowSuperReference = false)
: VariableWalkerBase(_pFrame, nullptr, _groupType, /* allowLexicalThis */ false, allowSuperReference), debuggerScope(_debuggerScope)
{
}
virtual void PopulateMembers() override;
virtual IDiagObjectAddress * GetObjectAddress(int index) override;
virtual Var GetVarObjectAt(int index) override;
private:
bool IsRegisterValid(PropertyId propertyId, RegSlot registerSlot) const;
bool IsRegisterInScope(PropertyId propertyId, RegSlot registerSlot) const;
Var GetVarObjectAndRegAt(int index, RegSlot* reg = nullptr);
};
class SlotArrayVariablesWalker : public VariableWalkerBase
{
public:
SlotArrayVariablesWalker(DiagStackFrame* _pFrame, Var _instance, UIGroupType _groupType, bool allowLexicalThis, bool allowSuperReference = false) : VariableWalkerBase(_pFrame, _instance, _groupType, allowLexicalThis, allowSuperReference) {}
virtual void PopulateMembers() override;
virtual IDiagObjectAddress * GetObjectAddress(int index) override;
ScopeSlots GetSlotArray() {
Var *slotArray = (Var *) instance;
Assert(slotArray != nullptr);
return ScopeSlots(slotArray);
}
};
class ObjectVariablesWalker : public VariableWalkerBase
{
public:
ObjectVariablesWalker(DiagStackFrame* _pFrame, Var _instance, UIGroupType _groupType, bool allowLexicalThis, bool allowSuperReference = false) : VariableWalkerBase(_pFrame, _instance, _groupType, allowLexicalThis, allowSuperReference) {}
virtual void PopulateMembers() override;
virtual IDiagObjectAddress * GetObjectAddress(int index) override;
protected:
void AddObjectProperties(int count, Js::RecyclableObject* object);
};
class RootObjectVariablesWalker : public ObjectVariablesWalker
{
public:
RootObjectVariablesWalker(DiagStackFrame* _pFrame, Var _instance, UIGroupType _groupType) : ObjectVariablesWalker(_pFrame, _instance, _groupType, /* allowLexicalThis */ false) {}
virtual void PopulateMembers() override;
};
class DiagScopeVariablesWalker sealed : public VariableWalkerBase
{
public:
// Represent catch/with scope objects, (ie. the representation for the diagnostics purposes.)
JsUtil::List<IDiagObjectModelWalkerBase*, ArenaAllocator> *pDiagScopeObjects;
ulong diagScopeVarCount;
bool scopeIsInitialized;
bool enumWithScopeAlso;
public:
DiagScopeVariablesWalker(DiagStackFrame* _pFrame, Var _instance, bool _enumWithScopeAlso)
: VariableWalkerBase(_pFrame, _instance, UIGroupType_InnerScope, /* allowLexicalThis */ false), pDiagScopeObjects(nullptr), diagScopeVarCount(0), scopeIsInitialized(false), enumWithScopeAlso(_enumWithScopeAlso)
{}
DiagScopeVariablesWalker(DiagStackFrame* _pFrame, Var _instance, IDiagObjectModelWalkerBase* innerWalker);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propId, bool& isConst) override;
};
// Display of variable on the locals window
// Also responsible for walking on the current frame and build up chain of scopes.
class LocalsWalker sealed : public IDiagObjectModelWalkerBase
{
friend class RecyclableArgumentsArrayWalker;
DiagStackFrame* pFrame;
JsUtil::List<VariableWalkerBase *, ArenaAllocator> * pVarWalkers; // This includes, current frame, all scopes and globals for a current frame
uint totalLocalsCount;
DWORD frameWalkerFlags;
// true, if user has not defined the 'arguments' in the script, this is used for displaying a fake arguments object and display in the locals window.
bool hasUserNotDefinedArguments;
public:
LocalsWalker(DiagStackFrame* _frame, DWORD _frameWalkerFlags);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) {return FALSE; }
static DWORD GetCurrentFramesLocalsType(DiagStackFrame* frame);
static DebuggerScope * GetScopeWhenHaltAtFormals(DiagStackFrame* frame);
static int GetAdjustedByteCodeOffset(DiagStackFrame* frame);
IDiagObjectAddress * FindPropertyAddress(PropertyId propId, bool& isConst) override;
// enumerateGroups will be true for the when fetching from a variable from the expression evaluation.
IDiagObjectAddress * FindPropertyAddress(PropertyId propId, bool enumerateGroups, bool& isConst);
template <typename FnProcessResolvedObject>
DynamicObject* CreateAndPopulateActivationObject(ScriptContext* scriptContext, FnProcessResolvedObject processResolvedObjectFn)
{
Assert(scriptContext);
Js::DynamicObject* activeScopeObject = nullptr;
ulong count = this->GetChildrenCount();
if (count > 0)
{
activeScopeObject = scriptContext->GetLibrary()->CreateActivationObject();
for (ulong i = 0; i < count; i++)
{
Js::ResolvedObject resolveObject;
if (this->Get(i, &resolveObject) && resolveObject.propId != Js::Constants::NoProperty)
{
if (!activeScopeObject->HasOwnProperty(resolveObject.propId))
{
OUTPUT_TRACE(Js::ConsoleScopePhase, _u("Adding '%s' property to activeScopeObject\n"), resolveObject.scriptContext->GetPropertyName(resolveObject.propId)->GetBuffer());
if (resolveObject.IsInDeadZone())
{
PropertyOperationFlags flags = static_cast<PropertyOperationFlags>(PropertyOperation_SpecialValue | PropertyOperation_AllowUndecl);
PropertyAttributes attributes = resolveObject.isConst ? PropertyConstDefaults : PropertyLetDefaults;
resolveObject.obj = scriptContext->GetLibrary()->GetUndeclBlockVar();
activeScopeObject->SetPropertyWithAttributes(
resolveObject.propId,
resolveObject.obj,
attributes, nullptr, flags);
}
else
{
activeScopeObject->SetPropertyWithAttributes(
resolveObject.propId,
JavascriptOperators::BoxStackInstance(resolveObject.obj, scriptContext), //The value escapes, box if necessary.
resolveObject.isConst ? PropertyConstDefaults : PropertyDynamicTypeDefaults,
nullptr);
}
processResolvedObjectFn(resolveObject);
}
}
}
}
return activeScopeObject;
}
private:
BOOL CreateArgumentsObject(ResolvedObject* pResolvedObject);
bool ShouldMakeGroups() const { return frameWalkerFlags & FW_MakeGroups; }
bool ShouldInsertFakeArguments();
void ExpandArgumentsObject(IDiagObjectModelDisplay * argumentsDisplay);
};
class LocalsDisplay : public IDiagObjectModelDisplay
{
DiagStackFrame* pFrame;
public:
LocalsDisplay(DiagStackFrame* _frame);
virtual LPCWSTR Name() override;
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override;
virtual BOOL Set(Var updateObject) override;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
virtual BOOL IsLocalsAsRoot() { return TRUE; }
virtual DiagObjectModelDisplayType GetType() { return DiagObjectModelDisplayType_LocalsDisplay; }
virtual bool IsLiteralProperty() const { return false; }
};
//
// The locals var's addresses.
// A representation of an address when this Var is taken from the slot array.
class LocalObjectAddressForSlot : public IDiagObjectAddress
{
ScopeSlots slotArray;
int slotIndex;
Var value;
public:
LocalObjectAddressForSlot(ScopeSlots _pSlotArray, int _slotIndex, Js::Var _value);
virtual BOOL Set(Var updateObject) override;
virtual Var GetValue(BOOL fUpdated);
virtual BOOL IsInDeadZone() const;
};
// A representation of an address when this Var is taken from the direct regslot.
class LocalObjectAddressForRegSlot : public IDiagObjectAddress
{
DiagStackFrame* pFrame;
RegSlot regSlot;
Var value;
public:
LocalObjectAddressForRegSlot(DiagStackFrame* _pFrame, RegSlot _regSlot, Js::Var _value);
virtual BOOL Set(Var updateObject) override;
virtual Var GetValue(BOOL fUpdated);
BOOL IsInDeadZone() const;
};
class CatchScopeWalker sealed : public IDiagObjectModelWalkerBase
{
DiagStackFrame* pFrame;
DebuggerScope * debuggerScope;
public :
CatchScopeWalker(DiagStackFrame* _pFrame, DebuggerScope* _debuggerScope)
: pFrame(_pFrame), debuggerScope(_debuggerScope)
{
}
/// IDiagObjectModelWalkerBase
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override { return FALSE; }
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propId, bool& isConst) override;
private:
void FetchValueAndAddress(DebuggerScopeProperty &scopeProperty, _Out_opt_ Var *pValue, _Out_opt_ IDiagObjectAddress ** ppAddress);
};
// Concrete Classes for Objects
class RecyclableObjectWalker : public IDiagObjectModelWalkerBase
{
protected:
ScriptContext* scriptContext;
Var instance;
Var originalInstance; // Remember original instance for prototype walk, because evaluating getters in CallGetter() if __proto__ instance is passed does not work
JsUtil::List<DebuggerPropertyDisplayInfo *, ArenaAllocator> * pMembersList;
RecyclableArrayWalker * innerArrayObjectWalker; // Will be used for array indices on the object
JsUtil::List<IDiagObjectModelWalkerBase *, ArenaAllocator> * fakeGroupObjectWalkerList; // such as [prototype], [Methods] etc.
void InsertItem(Js::RecyclableObject *pOriginalObject, Js::RecyclableObject *pObject, PropertyId propertyId, bool isConst, bool isUnscoped, Js::RecyclableMethodsGroupWalker **ppMethodsGrouptWalker, bool shouldPinProperty = false);
void InsertItem(PropertyId propertyId, bool isConst, bool isUnscoped, Var itemObj, Js::RecyclableMethodsGroupWalker **ppMethodsGrouptWalker, bool shouldPinProperty = false);
void EnsureFakeGroupObjectWalkerList();
public:
RecyclableObjectWalker(ScriptContext* pContext, Var slot);
RecyclableObjectWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) { return FALSE; };
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propertyId, bool& isConst) override;
static Var GetObject(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, ScriptContext* scriptContext);
};
class RecyclableObjectAddress : public IDiagObjectAddress
{
Var parentObj;
Js::PropertyId propId;
Js::Var value;
BOOL isInDeadZone;
public:
RecyclableObjectAddress(Var parentObj, Js::PropertyId _propId, Js::Var _value, BOOL _isInDeadZone);
virtual BOOL Set(Var updateObject) override;
virtual BOOL IsWritable() override;
virtual Var GetValue(BOOL fUpdated);
BOOL IsInDeadZone() const;
};
class RecyclableObjectDisplay : public IDiagObjectModelDisplay
{
protected:
ScriptContext* scriptContext;
Var instance;
Var originalInstance;
LPCWSTR name;
IDiagObjectAddress* pObjAddress;
DBGPROP_ATTRIB_FLAGS defaultAttributes;
PropertyId propertyId;
public:
RecyclableObjectDisplay(ResolvedObject* resolvedObject, DBGPROP_ATTRIB_FLAGS defaultAttributes = DBGPROP_ATTRIB_NO_ATTRIB);
virtual LPCWSTR Name() override;
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override;
virtual BOOL Set(Var updateObject) override;
virtual BOOL SetDefaultTypeAttribute(DBGPROP_ATTRIB_FLAGS attributes) override { defaultAttributes = attributes; return TRUE; };
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
virtual Var GetVarValue(BOOL fUpdated) override;
virtual IDiagObjectAddress * GetDiagAddress() override { return pObjAddress; }
virtual DiagObjectModelDisplayType GetType() { return DiagObjectModelDisplayType_RecyclableObjectDisplay; }
virtual bool IsLiteralProperty() const;
virtual bool IsSymbolProperty() override;
static BOOL GetPropertyWithScriptEnter(RecyclableObject* originalInstance, RecyclableObject* instance, PropertyId propertyId, Var* value, ScriptContext* scriptContext);
StringBuilder<ArenaAllocator>* GetStringBuilder();
PropertyId GetPropertyId() const;
};
// Concrete classes for Arrays
class RecyclableArrayAddress : public IDiagObjectAddress
{
protected:
Var parentArray;
unsigned int index;
public:
RecyclableArrayAddress(Var parentArray, unsigned int index);
virtual BOOL Set(Var updateObject) override;
};
class RecyclableArrayDisplay : public RecyclableObjectDisplay
{
protected:
BOOL HasChildrenInternal(Js::JavascriptArray* arrayObj);
public:
RecyclableArrayDisplay(ResolvedObject* resolvedObject);
virtual BOOL HasChildren() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclableArrayWalker : public RecyclableObjectWalker
{
protected:
uint32 indexedItemCount;
JsUtil::List<uint32, ArenaAllocator> * pAbsoluteIndexList;
// Just populate the indexes only.
bool fOnlyOwnProperties;
uint32 RecyclableArrayWalker::GetItemCount(Js::JavascriptArray* arrayObj);
// ES5Array will extend this.
virtual uint32 GetNextDescriptor(uint32 currentDescriptor) { return Js::JavascriptArray::InvalidIndex; }
LPCWSTR RecyclableArrayWalker::GetIndexName(uint32 index, StringBuilder<ArenaAllocator>* stringBuilder);
Js::JavascriptArray* GetArrayObject();
public:
RecyclableArrayWalker(ScriptContext* pContext, Var slot, Var originalInstance);
void SetOnlyWalkOwnProperties(bool set) { fOnlyOwnProperties = set; }
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var *value);
virtual Var FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index);
virtual BOOL GetResolvedObject(Js::JavascriptArray* arrayObj, int index, ResolvedObject* pResolvedObject, uint32 * pabsIndex) sealed;
StringBuilder<ArenaAllocator>* GetBuilder();
};
// Concrete classes for Arguments object
//
class RecyclableArgumentsObjectDisplay : public RecyclableObjectDisplay
{
LocalsWalker *pLocalsWalker;
public:
RecyclableArgumentsObjectDisplay(ResolvedObject* resolvedObject, LocalsWalker *localsWalker);
virtual BOOL HasChildren() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclableArgumentsObjectWalker : public RecyclableObjectWalker
{
LocalsWalker *pLocalsWalker;
public:
RecyclableArgumentsObjectWalker(ScriptContext* pContext, Var instance, LocalsWalker * localsWalker);
virtual ulong GetChildrenCount() override;
};
class RecyclableArgumentsArrayAddress : public IDiagObjectAddress
{
Var parentArray;
unsigned int index;
public:
RecyclableArgumentsArrayAddress(Var parentArray, unsigned int index);
virtual BOOL Set(Var updateObject) override;
};
class RecyclableArgumentsArrayWalker : public RecyclableArrayWalker
{
JsUtil::List<IDiagObjectAddress *, ArenaAllocator> * pFormalsList;
public:
RecyclableArgumentsArrayWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
void FetchFormalsAddress (LocalsWalker * localsWalker);
};
// Concrete classes for Typed array objects
//
class RecyclableTypedArrayAddress : public RecyclableArrayAddress
{
public:
RecyclableTypedArrayAddress(Var parentArray, unsigned int index);
virtual BOOL Set(Var updateObject) override;
};
class RecyclableTypedArrayDisplay : public RecyclableObjectDisplay
{
public:
RecyclableTypedArrayDisplay(ResolvedObject* resolvedObject);
virtual BOOL HasChildren() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclableTypedArrayWalker : public RecyclableArrayWalker
{
public:
RecyclableTypedArrayWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
};
// Concrete classes for Pixel array objects
//
class RecyclablePixelArrayAddress : public RecyclableArrayAddress
{
public:
RecyclablePixelArrayAddress(Var parentArray, unsigned int index);
virtual BOOL Set(Var updateObject) override;
};
class RecyclablePixelArrayDisplay : public RecyclableObjectDisplay
{
public:
RecyclablePixelArrayDisplay(ResolvedObject* resolvedObject);
virtual BOOL HasChildren() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclablePixelArrayWalker : public RecyclableArrayWalker
{
public:
RecyclablePixelArrayWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
};
// Concrete classes for ES5 array objects
//
class RecyclableES5ArrayAddress : public RecyclableArrayAddress
{
public:
RecyclableES5ArrayAddress(Var parentArray, unsigned int index);
virtual BOOL Set(Var updateObject) override;
};
class RecyclableES5ArrayDisplay : public RecyclableArrayDisplay
{
public:
RecyclableES5ArrayDisplay(ResolvedObject* resolvedObject);
virtual BOOL HasChildren() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclableES5ArrayWalker sealed : public RecyclableArrayWalker
{
public:
RecyclableES5ArrayWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual uint32 GetNextDescriptor(uint32 currentDescriptor) override;
virtual BOOL FetchItemAtIndex(Js::JavascriptArray* arrayObj, uint32 index, Var *value) override;
virtual Var FetchItemAt(Js::JavascriptArray* arrayObj, uint32 index) override;
};
// Concrete classes for Proto group object
//
class RecyclableProtoObjectWalker : public RecyclableObjectWalker
{
public:
RecyclableProtoObjectWalker(ScriptContext* pContext, Var slot, Var originalInstance);
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override;
virtual IDiagObjectAddress *FindPropertyAddress(PropertyId propId, bool& isConst) override;
};
class RecyclableProtoObjectAddress : public RecyclableObjectAddress
{
public:
RecyclableProtoObjectAddress(Var _parentObj, Js::PropertyId _propId, Js::Var _value);
};
// Concrete classes for Map, Set, and WeakMap group objects
//
template <typename TData>
struct RecyclableCollectionObjectWalkerPropertyData
{
RecyclableCollectionObjectWalkerPropertyData():key(nullptr), value(nullptr) { }
RecyclableCollectionObjectWalkerPropertyData(Var key, Var value):key(key), value(value) { }
Var key;
Var value;
};
template<>
struct RecyclableCollectionObjectWalkerPropertyData<JavascriptSet>
{
RecyclableCollectionObjectWalkerPropertyData():value(nullptr) { }
RecyclableCollectionObjectWalkerPropertyData(Var value):value(value) { }
Var value;
};
template<>
struct RecyclableCollectionObjectWalkerPropertyData<JavascriptWeakSet>
{
RecyclableCollectionObjectWalkerPropertyData():value(nullptr) { }
RecyclableCollectionObjectWalkerPropertyData(Var value):value(value) { }
Var value;
};
template <typename TData>
class RecyclableCollectionObjectWalker : public IDiagObjectModelWalkerBase
{
ScriptContext* scriptContext;
Var instance;
JsUtil::List<RecyclableCollectionObjectWalkerPropertyData<TData>, ArenaAllocator>* propertyList;
const char16* Name();
IDiagObjectModelDisplay* CreateTDataDisplay(ResolvedObject* resolvedObject, int i);
void GetChildren();
public:
RecyclableCollectionObjectWalker(ScriptContext* scriptContext, Var instance):scriptContext(scriptContext), instance(instance), propertyList(nullptr) { }
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override;
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
};
typedef RecyclableCollectionObjectWalker<JavascriptMap> RecyclableMapObjectWalker;
typedef RecyclableCollectionObjectWalker<JavascriptSet> RecyclableSetObjectWalker;
typedef RecyclableCollectionObjectWalker<JavascriptWeakMap> RecyclableWeakMapObjectWalker;
typedef RecyclableCollectionObjectWalker<JavascriptWeakSet> RecyclableWeakSetObjectWalker;
template <typename TData>
class RecyclableCollectionObjectDisplay : public IDiagObjectModelDisplay
{
ScriptContext* scriptContext;
const char16* name;
RecyclableCollectionObjectWalker<TData>* walker;
public:
RecyclableCollectionObjectDisplay(ScriptContext* scriptContext, const char16* name, RecyclableCollectionObjectWalker<TData>* walker) : scriptContext(scriptContext), name(name), walker(walker) { }
virtual LPCWSTR Name() override { return name; }
virtual LPCWSTR Type() override { return _u(""); }
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override { return walker->GetChildrenCount() > 0; }
virtual BOOL Set(Var updateObject) override { return FALSE; }
virtual BOOL SetDefaultTypeAttribute(DBGPROP_ATTRIB_FLAGS attributes) override { return FALSE; }
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override { return DBGPROP_ATTRIB_VALUE_READONLY | DBGPROP_ATTRIB_VALUE_IS_FAKE | (HasChildren() ? DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE : 0); }
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
virtual Var GetVarValue(BOOL fUpdated) override { return nullptr; }
virtual IDiagObjectAddress * GetDiagAddress() override { return nullptr; }
virtual DiagObjectModelDisplayType GetType() { return DiagObjectModelDisplayType_RecyclableCollectionObjectDisplay; }
virtual bool IsLiteralProperty() const { return false; }
};
class RecyclableKeyValueDisplay : public IDiagObjectModelDisplay
{
ScriptContext* scriptContext;
Var key;
Var value;
const char16* name;
public:
RecyclableKeyValueDisplay(ScriptContext* scriptContext, Var key, Var value, const char16* name) : scriptContext(scriptContext), key(key), value(value), name(name) { }
virtual LPCWSTR Name() override { return name; }
virtual LPCWSTR Type() override { return _u(""); }
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override { return TRUE; }
virtual BOOL Set(Var updateObject) override { return FALSE; }
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override { return DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_READONLY; }
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
virtual DiagObjectModelDisplayType GetType() { return DiagObjectModelDisplayType_RecyclableKeyValueDisplay; }
virtual bool IsLiteralProperty() const { return false; }
};
class RecyclableKeyValueWalker : public IDiagObjectModelWalkerBase
{
ScriptContext* scriptContext;
Var key;
Var value;
public:
RecyclableKeyValueWalker(ScriptContext* scriptContext, Var key, Var value):scriptContext(scriptContext), key(key), value(value) { }
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override { return 2; }
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override { return FALSE; }
};
class RecyclableProxyObjectDisplay : public RecyclableObjectDisplay
{
public:
RecyclableProxyObjectDisplay(ResolvedObject* resolvedObject);
virtual BOOL HasChildren() override { return TRUE; }
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class RecyclableProxyObjectWalker : public RecyclableObjectWalker
{
public:
RecyclableProxyObjectWalker(ScriptContext* pContext, Var instance);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override { return 2; }
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override;
};
// Concrete classes for Methods group object
//
class RecyclableMethodsGroupWalker : public RecyclableObjectWalker
{
public:
RecyclableMethodsGroupWalker(ScriptContext* pContext, Var slot);
void AddItem(Js::PropertyId propertyId, Var obj);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
virtual BOOL GetGroupObject(ResolvedObject* pResolvedObject) override;
void Sort();
};
class RecyclableMethodsGroupDisplay : public RecyclableObjectDisplay
{
public:
RecyclableMethodsGroupWalker *methodGroupWalker;
RecyclableMethodsGroupDisplay(RecyclableMethodsGroupWalker *_methodGroupWalker, ResolvedObject* resolvedObject);
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
// Concrete classes for Scope group object
//
class ScopeVariablesGroupDisplay : public RecyclableObjectDisplay
{
public:
VariableWalkerBase *scopeGroupWalker;
ScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject);
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
// Concrete classes for Globals group object
//
class GlobalsScopeVariablesGroupDisplay sealed : public RecyclableObjectDisplay
{
public:
VariableWalkerBase *globalsGroupWalker;
GlobalsScopeVariablesGroupDisplay(VariableWalkerBase *walker, ResolvedObject* resolvedObject);
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override;
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
#ifdef ENABLE_MUTATION_BREAKPOINT
// For Pending Mutation breakpoint
class PendingMutationBreakpointDisplay : public RecyclableObjectDisplay
{
MutationType mutationType;
public:
PendingMutationBreakpointDisplay(ResolvedObject* resolvedObject, MutationType mutationType);
virtual LPCWSTR Value(int radix) override { return _u(""); }
virtual BOOL HasChildren() override { return TRUE; }
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
};
class PendingMutationBreakpointWalker : public RecyclableObjectWalker
{
MutationType mutationType;
public:
PendingMutationBreakpointWalker(ScriptContext* pContext, Var instance, MutationType mutationType);
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override;
};
#endif
// For SIMD walker
template <typename simdType, uint elementCount>
class RecyclableSimdObjectWalker : public RecyclableObjectWalker
{
public:
RecyclableSimdObjectWalker(ScriptContext* pContext, Var instance) : RecyclableObjectWalker(pContext, instance) { }
virtual BOOL Get(int i, ResolvedObject* pResolvedObject) override;
virtual ulong GetChildrenCount() override { return elementCount; }
};
// For SIMD concrete walker: specify SIMD type and total elementCount
// elementCount can be 4, 8 or 16 for SIMD type like int32x4, int16x8, int8x16
typedef RecyclableSimdObjectWalker<JavascriptSIMDFloat32x4, 4> RecyclableSimdFloat32x4ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDInt32x4, 4> RecyclableSimdInt32x4ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDInt8x16, 16> RecyclableSimdInt8x16ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDInt16x8, 8> RecyclableSimdInt16x8ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDBool32x4, 4> RecyclableSimdBool32x4ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDBool8x16, 16> RecyclableSimdBool8x16ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDBool16x8, 8> RecyclableSimdBool16x8ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDUint32x4, 4> RecyclableSimdUint32x4ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDUint8x16, 16> RecyclableSimdUint8x16ObjectWalker;
typedef RecyclableSimdObjectWalker<JavascriptSIMDUint16x8, 8> RecyclableSimdUint16x8ObjectWalker;
// For SIMD display
template <typename simdType, typename simdWalker>
class RecyclableSimdObjectDisplay : public RecyclableObjectDisplay
{
public:
RecyclableSimdObjectDisplay(ResolvedObject* resolvedObject) : RecyclableObjectDisplay(resolvedObject) {};
virtual LPCWSTR Type() override;
virtual LPCWSTR Value(int radix) override;
virtual BOOL HasChildren() override { return TRUE; }
virtual WeakArenaReference<IDiagObjectModelWalkerBase>* CreateWalker() override;
virtual DBGPROP_ATTRIB_FLAGS GetTypeAttribute() override { return DBGPROP_ATTRIB_VALUE_IS_EXPANDABLE | DBGPROP_ATTRIB_VALUE_IS_FAKE | DBGPROP_ATTRIB_VALUE_READONLY; }
virtual DiagObjectModelDisplayType GetType() { return DiagObjectModelDisplayType_RecyclableSimdDisplay; }
};
// For SIMD concrete display: specify SIMD type and concrete simd walker
typedef RecyclableSimdObjectDisplay<JavascriptSIMDFloat32x4, RecyclableSimdFloat32x4ObjectWalker> RecyclableSimdFloat32x4ObjectDisplay;