@@ -154,6 +154,21 @@ HRESULT JsrtDebugManager::DbgRegisterFunction(Js::ScriptContext* scriptContext,
154
154
{
155
155
utf8SourceInfo->SetDebugDocument (debugDocument);
156
156
}
157
+
158
+ // Raising events during the middle of a source reparse allows the host to reenter the
159
+ // script context and cause memory race conditions. Suppressing these events during a
160
+ // reparse prevents the issue. Since the host was already expected to call JsDiagGetScripts
161
+ // once the attach is completed to get the list of parsed scripts, there is no change in
162
+ // behavior.
163
+ if (this ->debugEventCallback != nullptr &&
164
+ !scriptContext->GetDebugContext ()->GetIsReparsingSource ())
165
+ {
166
+ JsrtDebugEventObject debugEventObject (scriptContext);
167
+ Js::DynamicObject* eventDataObject = debugEventObject.GetEventDataObject ();
168
+ JsrtDebugUtils::AddSourceMetadataToObject (eventDataObject, utf8SourceInfo);
169
+
170
+ this ->CallDebugEventCallback (JsDiagDebugEventSourceCompile, eventDataObject, scriptContext, false /* isBreak*/ );
171
+ }
157
172
}
158
173
159
174
return S_OK;
@@ -170,16 +185,8 @@ void JsrtDebugManager::ReportScriptCompile_TTD(Js::FunctionBody* body, Js::Utf8S
170
185
Js::ScriptContext* scriptContext = utf8SourceInfo->GetScriptContext ();
171
186
172
187
JsrtDebugEventObject debugEventObject (scriptContext);
173
-
174
188
Js::DynamicObject* eventDataObject = debugEventObject.GetEventDataObject ();
175
189
176
- JsrtDebugUtils::AddFileNameOrScriptTypeToObject (eventDataObject, utf8SourceInfo);
177
- JsrtDebugUtils::AddLineCountToObject (eventDataObject, utf8SourceInfo);
178
- JsrtDebugUtils::AddPropertyToObject (eventDataObject, JsrtDebugPropertyId::sourceLength, utf8SourceInfo->GetCchLength (), utf8SourceInfo->GetScriptContext ());
179
-
180
- JsDiagDebugEvent jsDiagDebugEvent = JsDiagDebugEventCompileError;
181
-
182
-
183
190
JsrtDebugDocumentManager* debugDocumentManager = this ->GetDebugDocumentManager ();
184
191
Assert (debugDocumentManager != nullptr );
185
192
@@ -188,15 +195,13 @@ void JsrtDebugManager::ReportScriptCompile_TTD(Js::FunctionBody* body, Js::Utf8S
188
195
if (debugDocument != nullptr )
189
196
{
190
197
utf8SourceInfo->SetDebugDocument (debugDocument);
191
-
192
- // Only add scriptId if everything is ok as scriptId is used for other operations
193
- JsrtDebugUtils::AddScriptIdToObject (eventDataObject, utf8SourceInfo);
194
198
}
195
- jsDiagDebugEvent = JsDiagDebugEventSourceCompile;
199
+
200
+ JsrtDebugUtils::AddSourceMetadataToObject (eventDataObject, utf8SourceInfo);
196
201
197
202
if (notify)
198
203
{
199
- this ->CallDebugEventCallback (jsDiagDebugEvent , eventDataObject, scriptContext, false /* isBreak*/ );
204
+ this ->CallDebugEventCallback (JsDiagDebugEventSourceCompile , eventDataObject, scriptContext, false /* isBreak*/ );
200
205
}
201
206
}
202
207
#endif
@@ -208,13 +213,8 @@ void JsrtDebugManager::ReportScriptCompile(Js::JavascriptFunction* scriptFunctio
208
213
Js::ScriptContext* scriptContext = utf8SourceInfo->GetScriptContext ();
209
214
210
215
JsrtDebugEventObject debugEventObject (scriptContext);
211
-
212
216
Js::DynamicObject* eventDataObject = debugEventObject.GetEventDataObject ();
213
217
214
- JsrtDebugUtils::AddFileNameOrScriptTypeToObject (eventDataObject, utf8SourceInfo);
215
- JsrtDebugUtils::AddLineCountToObject (eventDataObject, utf8SourceInfo);
216
- JsrtDebugUtils::AddPropertyToObject (eventDataObject, JsrtDebugPropertyId::sourceLength, utf8SourceInfo->GetCchLength (), utf8SourceInfo->GetScriptContext ());
217
-
218
218
JsDiagDebugEvent jsDiagDebugEvent = JsDiagDebugEventCompileError;
219
219
220
220
if (scriptFunction == nullptr )
@@ -235,13 +235,13 @@ void JsrtDebugManager::ReportScriptCompile(Js::JavascriptFunction* scriptFunctio
235
235
if (debugDocument != nullptr )
236
236
{
237
237
utf8SourceInfo->SetDebugDocument (debugDocument);
238
-
239
- // Only add scriptId if everything is ok as scriptId is used for other operations
240
- JsrtDebugUtils::AddScriptIdToObject (eventDataObject, utf8SourceInfo);
241
238
}
239
+
242
240
jsDiagDebugEvent = JsDiagDebugEventSourceCompile;
243
241
}
244
242
243
+ JsrtDebugUtils::AddSourceMetadataToObject (eventDataObject, utf8SourceInfo);
244
+
245
245
this ->CallDebugEventCallback (jsDiagDebugEvent, eventDataObject, scriptContext, false /* isBreak*/ );
246
246
}
247
247
}
@@ -460,11 +460,7 @@ void JsrtDebugManager::CallDebugEventCallbackForBreak(JsDiagDebugEvent debugEven
460
460
Js::DynamicObject* JsrtDebugManager::GetScript (Js::Utf8SourceInfo* utf8SourceInfo)
461
461
{
462
462
Js::DynamicObject* scriptObject = utf8SourceInfo->GetScriptContext ()->GetLibrary ()->CreateObject ();
463
-
464
- JsrtDebugUtils::AddScriptIdToObject (scriptObject, utf8SourceInfo);
465
- JsrtDebugUtils::AddFileNameOrScriptTypeToObject (scriptObject, utf8SourceInfo);
466
- JsrtDebugUtils::AddLineCountToObject (scriptObject, utf8SourceInfo);
467
- JsrtDebugUtils::AddPropertyToObject (scriptObject, JsrtDebugPropertyId::sourceLength, utf8SourceInfo->GetCchLength (), utf8SourceInfo->GetScriptContext ());
463
+ JsrtDebugUtils::AddSourceMetadataToObject (scriptObject, utf8SourceInfo);
468
464
469
465
return scriptObject;
470
466
}
@@ -542,11 +538,8 @@ Js::DynamicObject* JsrtDebugManager::GetSource(Js::ScriptContext* scriptContext,
542
538
{
543
539
sourceObject = (Js::DynamicObject*)Js::CrossSite::MarshalVar (utf8SourceInfo->GetScriptContext (), scriptContext->GetLibrary ()->CreateObject ());
544
540
545
- JsrtDebugUtils::AddScriptIdToObject (sourceObject, utf8SourceInfo);
546
- JsrtDebugUtils::AddFileNameOrScriptTypeToObject (sourceObject, utf8SourceInfo);
547
- JsrtDebugUtils::AddLineCountToObject (sourceObject, utf8SourceInfo);
548
- JsrtDebugUtils::AddPropertyToObject (sourceObject, JsrtDebugPropertyId::sourceLength, utf8SourceInfo->GetCchLength (), utf8SourceInfo->GetScriptContext ());
549
- JsrtDebugUtils::AddSouceToObject (sourceObject, utf8SourceInfo);
541
+ JsrtDebugUtils::AddSourceMetadataToObject (sourceObject, utf8SourceInfo);
542
+ JsrtDebugUtils::AddSourceToObject (sourceObject, utf8SourceInfo);
550
543
}
551
544
552
545
return sourceObject;
0 commit comments