Skip to content

Commit 91bc9c5

Browse files
author
Irina Yatsenko
committed
[MERGE #5392 @irinayat-MS] Add SAVE_EXCEPTION_CHECK to LEAVE_SCRIPT_IF_ACTIVE when not in script
Merge pull request #5392 from irinayat-MS:OS.17525386 (cherry picked from commit cbb0c7c)
2 parents b6541b3 + 1433bac commit 91bc9c5

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/Runtime/Base/ThreadContext.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,19 @@ class InterruptPoller
107107
}\
108108
}
109109

110-
#define LEAVE_SCRIPT_IF(scriptContext, condition, block) \
111-
if (condition) \
110+
#define LEAVE_SCRIPT_IF_ACTIVE(scriptContext, externalCall) \
111+
if (scriptContext->GetThreadContext()->IsScriptActive()) \
112112
{ \
113113
BEGIN_LEAVE_SCRIPT(scriptContext); \
114-
block \
114+
externalCall \
115115
END_LEAVE_SCRIPT(scriptContext); \
116116
} \
117117
else \
118118
{ \
119-
block \
119+
DECLARE_EXCEPTION_CHECK_DATA \
120+
SAVE_EXCEPTION_CHECK \
121+
externalCall \
122+
RESTORE_EXCEPTION_CHECK \
120123
}
121124

122125
#define ENTER_SCRIPT_IF(scriptContext, doCleanup, isCallRoot, hasCaller, condition, block) \

lib/Runtime/Language/SourceTextModuleRecord.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,10 @@ namespace Js
203203
}
204204

205205
// Notify host if current module is dynamically-loaded module, or is root module and the host hasn't been notified
206-
bool isScriptActive = scriptContext->GetThreadContext()->IsScriptActive();
207206
if (this->promise != nullptr || (isRootModule && !hadNotifyHostReady))
208207
{
209208
OUTPUT_TRACE_DEBUGONLY(Js::ModulePhase, _u("\t>NotifyHostAboutModuleReady %s (ParseSource error)\n"), this->GetSpecifierSz());
210-
LEAVE_SCRIPT_IF(scriptContext, isScriptActive,
209+
LEAVE_SCRIPT_IF_ACTIVE(scriptContext,
211210
{
212211
scriptContext->GetHostScriptContext()->NotifyHostAboutModuleReady(this, this->errorObject);
213212
});
@@ -295,10 +294,8 @@ namespace Js
295294
{
296295
if (!hadNotifyHostReady && !WasEvaluated())
297296
{
298-
bool isScriptActive = scriptContext->GetThreadContext()->IsScriptActive();
299-
300297
OUTPUT_TRACE_DEBUGONLY(Js::ModulePhase, _u("\t>NotifyHostAboutModuleReady %s (PostProcessDynamicModuleImport)\n"), this->GetSpecifierSz());
301-
LEAVE_SCRIPT_IF(scriptContext, isScriptActive,
298+
LEAVE_SCRIPT_IF_ACTIVE(scriptContext,
302299
{
303300
hr = scriptContext->GetHostScriptContext()->NotifyHostAboutModuleReady(this, this->errorObject);
304301
});
@@ -341,8 +338,7 @@ namespace Js
341338
// TODO: move this as a promise call? if parser is called from a different thread
342339
// We'll need to call the bytecode gen in the main thread as we are accessing GC.
343340
ScriptContext* scriptContext = GetScriptContext();
344-
bool isScriptActive = scriptContext->GetThreadContext()->IsScriptActive();
345-
Assert(!isScriptActive || this->promise != nullptr);
341+
Assert(!scriptContext->GetThreadContext()->IsScriptActive() || this->promise != nullptr);
346342

347343
if (ModuleDeclarationInstantiation())
348344
{
@@ -351,7 +347,7 @@ namespace Js
351347
if (!hadNotifyHostReady && !WasEvaluated())
352348
{
353349
OUTPUT_TRACE_DEBUGONLY(Js::ModulePhase, _u("\t>NotifyHostAboutModuleReady %s (PrepareForModuleDeclarationInitialization)\n"), this->GetSpecifierSz());
354-
LEAVE_SCRIPT_IF(scriptContext, isScriptActive,
350+
LEAVE_SCRIPT_IF_ACTIVE(scriptContext,
355351
{
356352
hr = scriptContext->GetHostScriptContext()->NotifyHostAboutModuleReady(this, this->errorObject);
357353
});
@@ -378,8 +374,6 @@ namespace Js
378374
OUTPUT_TRACE_DEBUGONLY(Js::ModulePhase, _u("\t>NotifyParentAsNeeded (childException)\n"), this->GetSpecifierSz());
379375
NotifyParentsAsNeeded();
380376

381-
bool isScriptActive = scriptContext->GetThreadContext()->IsScriptActive();
382-
383377
if (this->promise != nullptr)
384378
{
385379
SourceTextModuleRecord::ResolveOrRejectDynamicImportPromise(false, this->errorObject, this->scriptContext, this);
@@ -388,7 +382,7 @@ namespace Js
388382
if (this->promise != nullptr || (isRootModule && !hadNotifyHostReady))
389383
{
390384
OUTPUT_TRACE_DEBUGONLY(Js::ModulePhase, _u("\t>NotifyHostAboutModuleReady %s (OnChildModuleReady)\n"), this->GetSpecifierSz());
391-
LEAVE_SCRIPT_IF(scriptContext, isScriptActive,
385+
LEAVE_SCRIPT_IF_ACTIVE(scriptContext,
392386
{
393387
hr = scriptContext->GetHostScriptContext()->NotifyHostAboutModuleReady(this, this->errorObject);
394388
});

0 commit comments

Comments
 (0)