[MERGE #6097 @wyrichte] Fixes #5993 - path to fromCodePoint in JIT now throws range error on large input
Merge pull request #6097 from wyrichte:build/wyrichte/fromCodePoint
diff --git a/lib/Runtime/Base/CharStringCache.cpp b/lib/Runtime/Base/CharStringCache.cpp
index adcce77..f41cb54 100644
--- a/lib/Runtime/Base/CharStringCache.cpp
+++ b/lib/Runtime/Base/CharStringCache.cpp
@@ -78,10 +78,19 @@
{
Assert(c >= 0x10000);
CompileAssert(sizeof(char16) * 2 == sizeof(codepoint_t));
+
+ ScriptContext* scriptContext = JavascriptLibrary::FromCharStringCache(this)->GetScriptContext();
+
+ // #sec - string.fromcodepoint: "If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception"
+ if (c > 0x10FFFF)
+ {
+ JavascriptError::ThrowRangeError(scriptContext, JSERR_InvalidCodePoint, scriptContext->GetIntegerString(c));
+ }
+
char16 buffer[2];
Js::NumberUtilities::CodePointAsSurrogatePair(c, buffer, buffer + 1);
- JavascriptString* str = JavascriptString::NewCopyBuffer(buffer, 2, JavascriptLibrary::FromCharStringCache(this)->GetScriptContext());
+ JavascriptString* str = JavascriptString::NewCopyBuffer(buffer, 2, scriptContext);
// TODO: perhaps do some sort of cache for supplementary characters
return str;
}
diff --git a/test/Strings/fromCodePoint.js b/test/Strings/fromCodePoint.js
new file mode 100644
index 0000000..fe8943f
--- /dev/null
+++ b/test/Strings/fromCodePoint.js
@@ -0,0 +1,18 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+function f() {
+ var var_0 = new Array(1024);
+ for (var var_1 = 0; ; var_1 += 1024) {
+ var_0[var_1] = String.fromCodePoint(var_1);
+ }
+}
+
+try {
+ f();
+}
+catch(e) {
+ WScript.Echo("pass");
+}
diff --git a/test/Strings/rlexe.xml b/test/Strings/rlexe.xml
index fc5b3aa..9a44d07 100644
--- a/test/Strings/rlexe.xml
+++ b/test/Strings/rlexe.xml
@@ -14,6 +14,11 @@
</test>
<test>
<default>
+ <files>fromCodePoint.js</files>
+ </default>
+ </test>
+ <test>
+ <default>
<files>charCodeAt.js</files>
<baseline>charCodeAt.baseline</baseline>
</default>