Skip to content

Commit f18b6b3

Browse files
committed
remove stale entry from sourceinfo after asm.js parse failure
1 parent 32a33ae commit f18b6b3

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

lib/Runtime/Base/ScriptContext.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,7 @@ namespace Js
25502550
SRCINFO const * pSrcInfo, CompileScriptException * pse, Utf8SourceInfo** ppSourceInfo,
25512551
const char16 *rootDisplayName, LoadScriptFlag loadScriptFlag, Js::Var scriptSource)
25522552
{
2553-
uint sourceIndex;
2553+
uint sourceIndex = Constants::InvalidSourceIndex;
25542554
JavascriptFunction * pFunction = nullptr;
25552555

25562556
ParseNodeProg * parseTree = ParseScript(parser, script, cb, pSrcInfo,
@@ -2567,7 +2567,11 @@ namespace Js
25672567
Assert((loadScriptFlag & LoadScriptFlag_disableAsmJs) != LoadScriptFlag_disableAsmJs);
25682568

25692569
pse->Free();
2570-
2570+
if (sourceIndex != Constants::InvalidSourceIndex)
2571+
{
2572+
// If we registered source, we should remove it or we will register another source info
2573+
this->RemoveSource(sourceIndex);
2574+
}
25712575
loadScriptFlag = (LoadScriptFlag)(loadScriptFlag | LoadScriptFlag_disableAsmJs);
25722576
return LoadScript(script, cb, pSrcInfo, pse, ppSourceInfo,
25732577
rootDisplayName, loadScriptFlag, scriptSource);
@@ -2806,6 +2810,12 @@ namespace Js
28062810
return info;
28072811
}
28082812

2813+
void ScriptContext::RemoveSource(uint index)
2814+
{
2815+
Assert(this->sourceList->IsItemValid(index)); // This assert should be a subset of info != null- if info was null, in the last collect, we'd have invalidated the item
2816+
this->sourceList->RemoveAt(index);
2817+
}
2818+
28092819
bool ScriptContext::IsItemValidInSourceList(int index)
28102820
{
28112821
return (index < this->sourceList->Count()) && this->sourceList->IsItemValid(index);

lib/Runtime/Base/ScriptContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,7 @@ namespace Js
14641464
uint SaveSourceNoCopy(Utf8SourceInfo* sourceInfo, int cchLength, bool isCesu8);
14651465

14661466
Utf8SourceInfo* GetSource(uint sourceIndex);
1467+
void RemoveSource(uint sourceIndex);
14671468

14681469
uint SourceCount() const { return (uint)sourceList->Count(); }
14691470
void CleanSourceList() { CleanSourceListInternal(false); }

lib/Runtime/Library/GlobalObject.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ using namespace Js;
866866
HRESULT hrCodeGen = S_OK;
867867
CompileScriptException se;
868868
Js::ParseableFunctionInfo * funcBody = NULL;
869-
869+
uint sourceIndex = Constants::InvalidSourceIndex;
870870
BEGIN_LEAVE_SCRIPT_INTERNAL(scriptContext);
871871
BEGIN_TRANSLATE_EXCEPTION_TO_HRESULT
872872
{
@@ -914,7 +914,7 @@ using namespace Js;
914914
Js::AutoDynamicCodeReference dynamicFunctionReference(scriptContext);
915915

916916
Assert(cchSource < MAXLONG);
917-
uint sourceIndex = scriptContext->SaveSourceNoCopy(sourceInfo, cchSource, true);
917+
sourceIndex = scriptContext->SaveSourceNoCopy(sourceInfo, cchSource, true);
918918

919919
// Tell byte code gen not to attempt to interact with the caller's context if this is indirect eval.
920920
// TODO: Handle strict mode.
@@ -958,8 +958,13 @@ using namespace Js;
958958
}
959959
else if (hrCodeGen == JSERR_AsmJsCompileError)
960960
{
961-
// if asm.js compilation succeeded, retry with asm.js disabled
961+
// if asm.js compilation failed, retry with asm.js disabled
962962
grfscr |= fscrNoAsmJs;
963+
if (sourceIndex != Constants::InvalidSourceIndex)
964+
{
965+
// If we registered source, we should remove it or we will register another source info
966+
scriptContext->RemoveSource(sourceIndex);
967+
}
963968
return DefaultEvalHelper(scriptContext, source, sourceLength, moduleID, grfscr, pszTitle, registerDocument, isIndirect, strictMode);
964969
}
965970
JavascriptError::MapAndThrowError(scriptContext, hrCodeGen);

test/DebuggerCommon/failedasm.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function func_0() {
7+
'use asm';
8+
}
9+
WScript.Attach(func_0);
10+
11+
print("Pass")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

test/DebuggerCommon/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@
359359
<compile-flags>-debuglaunch -dbgbaseline:level_1.js.dbg.baseline</compile-flags>
360360
</default>
361361
</test>
362+
<test>
363+
<default>
364+
<files>failedasm.js</files>
365+
<compile-flags>-dbgbaseline:failedasm.js.dbg.baseline</compile-flags>
366+
</default>
367+
</test>
362368
<test>
363369
<default>
364370
<files>ES6_spread.js</files>

0 commit comments

Comments
 (0)