Skip to content

Commit e7731fc

Browse files
committed
Fixes #5950 - path to fromCodePoint in JIT now throws range error on large input
1 parent 8723255 commit e7731fc

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

lib/Runtime/Base/CharStringCache.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,19 @@ using namespace Js;
7878
{
7979
Assert(c >= 0x10000);
8080
CompileAssert(sizeof(char16) * 2 == sizeof(codepoint_t));
81+
82+
ScriptContext* scriptContext = JavascriptLibrary::FromCharStringCache(this)->GetScriptContext();
83+
84+
// #sec - string.fromcodepoint: "If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception"
85+
if (c > 0x10FFFF)
86+
{
87+
JavascriptError::ThrowRangeError(scriptContext, JSERR_InvalidCodePoint, scriptContext->GetIntegerString(c));
88+
}
89+
8190
char16 buffer[2];
8291

8392
Js::NumberUtilities::CodePointAsSurrogatePair(c, buffer, buffer + 1);
84-
JavascriptString* str = JavascriptString::NewCopyBuffer(buffer, 2, JavascriptLibrary::FromCharStringCache(this)->GetScriptContext());
93+
JavascriptString* str = JavascriptString::NewCopyBuffer(buffer, 2, scriptContext);
8594
// TODO: perhaps do some sort of cache for supplementary characters
8695
return str;
8796
}

test/Strings/fromCodePoint.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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 f() {
7+
var var_0 = new Array(1024);
8+
for (var var_1 = 0; ; var_1 += 1024) {
9+
var_0[var_1] = String.fromCodePoint(var_1);
10+
}
11+
}
12+
13+
try {
14+
f();
15+
}
16+
catch(e) {
17+
WScript.Echo("pass");
18+
}

test/Strings/rlexe.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<baseline>fromCharCode.baseline</baseline>
1313
</default>
1414
</test>
15+
<test>
16+
<default>
17+
<files>fromCodePoint.js</files>
18+
</default>
19+
</test>
1520
<test>
1621
<default>
1722
<files>charCodeAt.js</files>

0 commit comments

Comments
 (0)