Skip to content

Commit c97139d

Browse files
committed
When appending a string to a constructor do not modify the constructor's original toString value.
1 parent 503294e commit c97139d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/Runtime/Math/JavascriptMath.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,14 @@ using namespace Js;
425425

426426
Var JavascriptMath::AddLeftDead(Var aLeft, Var aRight, ScriptContext* scriptContext, JavascriptNumber *result)
427427
{
428+
// Conservatively assume src1 is not dead until proven otherwise.
429+
bool leftIsDead = false;
430+
428431
JIT_HELPER_REENTRANT_HEADER(Op_AddLeftDead);
429432
if (JavascriptOperators::GetTypeId(aLeft) == TypeIds_String)
430433
{
434+
leftIsDead = true;
435+
431436
JavascriptString* leftString = UnsafeVarTo<JavascriptString>(aLeft);
432437
JavascriptString* rightString;
433438
TypeId rightType = JavascriptOperators::GetTypeId(aRight);
@@ -471,7 +476,7 @@ using namespace Js;
471476
{
472477
return JavascriptNumber::ToVarMaybeInPlace(JavascriptNumber::GetValue(aLeft) + JavascriptNumber::GetValue(aRight), scriptContext, result);
473478
}
474-
return Add_FullHelper_Wrapper(aLeft, aRight, scriptContext, result, true);
479+
return Add_FullHelper_Wrapper(aLeft, aRight, scriptContext, result, leftIsDead);
475480
JIT_HELPER_END(Op_AddLeftDead);
476481
}
477482

test/Strings/constructorConcat.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
function f(arg) {
6+
var i = 0;
7+
while (i < 5) {
8+
i++;
9+
arg += "this_should_not_stay";
10+
}
11+
}
12+
f("Hello");
13+
f(Int8Array);
14+
15+
if (!Int8Array.toString().includes("this_should_not_stay")) {
16+
WScript.Echo("Passed");
17+
}
18+
else {
19+
WScript.Echo("FAILED");
20+
}

test/Strings/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,10 @@
268268
<compile-flags>-args summary -endargs</compile-flags>
269269
</default>
270270
</test>
271+
<test>
272+
<default>
273+
<files>constructorConcat.js</files>
274+
<compile-flags>-lic:1 -mic:1 -bgjit-</compile-flags>
275+
</default>
276+
</test>
271277
</regress-exe>

0 commit comments

Comments
 (0)