forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsrtDebugEventObject.cpp
More file actions
102 lines (89 loc) · 3.53 KB
/
JsrtDebugEventObject.cpp
File metadata and controls
102 lines (89 loc) · 3.53 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
//---------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
//----------------------------------------------------------------------------
#include "JsrtPch.h"
#include "JsrtDebugEventObject.h"
#include "..\Runtime\Debug\RuntimeDebugPch.h"
#include "screrror.h" // For CompileScriptException
JsrtDebugEventObject::JsrtDebugEventObject(Js::ScriptContext *scriptContext)
{
Assert(scriptContext != nullptr);
this->scriptContext = scriptContext;
this->eventDataObject = scriptContext->GetLibrary()->CreateObject();
Assert(this->eventDataObject != nullptr);
}
JsrtDebugEventObject::~JsrtDebugEventObject()
{
this->eventDataObject = nullptr;
this->scriptContext = nullptr;
}
Js::DynamicObject* JsrtDebugEventObject::GetEventDataObject()
{
return this->eventDataObject;
}
DebugDocumentManager::DebugDocumentManager(JsrtDebug* debugObject)
{
Assert(debugObject != nullptr);
this->debugObject = debugObject;
}
DebugDocumentManager::~DebugDocumentManager()
{
if (this->breakpointDebugDocumentDictionary != nullptr)
{
AssertMsg(this->breakpointDebugDocumentDictionary->Count() == 0, "Should have cleared all entries by now?");
HeapDelete(this->breakpointDebugDocumentDictionary);
this->breakpointDebugDocumentDictionary = nullptr;
}
this->debugObject = nullptr;
}
void DebugDocumentManager::AddDocument(UINT bpId, Js::DebugDocument * debugDocument)
{
BreakpointDebugDocumentDictionary* breakpointDebugDocumentDictionary = this->GetBreakpointDictionary();
Assert(!breakpointDebugDocumentDictionary->ContainsKey(bpId));
breakpointDebugDocumentDictionary->Add(bpId, debugDocument);
}
void DebugDocumentManager::ClearDebugDocument(Js::ScriptContext * scriptContext)
{
if (scriptContext != nullptr && this->breakpointDebugDocumentDictionary != nullptr)
{
scriptContext->MapScript([&](Js::Utf8SourceInfo* sourceInfo)
{
if (sourceInfo->HasDebugDocument())
{
Js::DebugDocument* debugDocument = sourceInfo->GetDebugDocument();
this->breakpointDebugDocumentDictionary->MapAndRemoveIf([&](JsUtil::SimpleDictionaryEntry<UINT, Js::DebugDocument *> keyValue)
{
if (keyValue.Value() != nullptr && keyValue.Value() == debugDocument)
{
return true;
}
return false;
});
}
});
}
}
void DebugDocumentManager::RemoveBreakpoint(UINT breakpointId)
{
if (this->breakpointDebugDocumentDictionary != nullptr)
{
BreakpointDebugDocumentDictionary* breakpointDebugDocumentDictionary = this->GetBreakpointDictionary();
Js::DebugDocument* debugDocument = nullptr;
if (breakpointDebugDocumentDictionary->TryGetValue(breakpointId, &debugDocument))
{
Js::StatementLocation statement;
if (debugDocument->FindBPStatementLocation(breakpointId, &statement))
{
debugDocument->SetBreakPoint(statement, BREAKPOINT_DELETED);
}
}
}
}
DebugDocumentManager::BreakpointDebugDocumentDictionary * DebugDocumentManager::GetBreakpointDictionary()
{
if (this->breakpointDebugDocumentDictionary == nullptr)
{
this->breakpointDebugDocumentDictionary = Anew(this->debugObject->GetDebugObjectArena(), BreakpointDebugDocumentDictionary, this->debugObject->GetDebugObjectArena(), 10);
}
return breakpointDebugDocumentDictionary;
}