Skip to content

Commit 4764a5f

Browse files
committed
[MERGE #5742 @Dachande663] Fixed #5621 - toLocaleString now accesses object property
Merge pull request #5742 from Dachande663:pr/dachande663/fix-tolocalestring-object-property As per issue #5621, this PR enables toLocaleString to call JavascriptString underlying property.
2 parents 864867e + 2d4c552 commit 4764a5f

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

lib/Runtime/Language/JavascriptConversion.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,6 @@ using namespace Js;
701701
case TypeIds_Number:
702702
return JavascriptNumber::ToLocaleString(JavascriptNumber::GetValue(aValue), scriptContext);
703703

704-
case TypeIds_String:
705-
return UnsafeVarTo<JavascriptString>(aValue);
706-
707704
case TypeIds_VariantDate:
708705
// Legacy behavior was to create an empty object and call toLocaleString on it, which would result in this value
709706
return scriptContext->GetLibrary()->GetObjectDisplayString();

test/Array/toLocaleString.baseline

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ TypeError : The value of the property 'toLocaleString' is not a Function object
4343

4444
9. Array: toLocaleString should use length property
4545
10.00, 20.00, 30.00, , ,
46+
47+
48+
10. Array: toLocaleString should use toLocaleString accessor on element
49+
accessor-value
50+
51+
52+
11. Array: toLocaleString should throw TypeError on undefined
53+
TypeError : The value of the property 'toLocaleString' is not a Function object
54+
55+
56+
12. Array: toLocaleString should throw TypeError on invalid function
57+
TypeError : The value of the property 'toLocaleString' is not a Function object

test/Array/toLocaleString.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,32 @@ guarded_call(function () {
184184
echo(output);
185185
}
186186
});
187+
188+
scenario("Array: toLocaleString should use toLocaleString accessor on element");
189+
var originalToLocaleString = String.prototype.toLocaleString;
190+
String.prototype.toLocaleString = function () {
191+
return "accessor-value";
192+
};
193+
var o = ["test"];
194+
guarded_call(function () {
195+
echo(Array.prototype.toLocaleString.apply(o));
196+
});
197+
String.prototype.toLocaleString = originalToLocaleString;
198+
199+
scenario("Array: toLocaleString should throw TypeError on undefined");
200+
var originalToLocaleString = String.prototype.toLocaleString;
201+
String.prototype.toLocaleString = undefined;
202+
var o = ["test"];
203+
guarded_call(function () {
204+
echo(Array.prototype.toLocaleString.apply(o));
205+
});
206+
String.prototype.toLocaleString = originalToLocaleString;
207+
208+
scenario("Array: toLocaleString should throw TypeError on invalid function");
209+
var originalToLocaleString = String.prototype.toLocaleString;
210+
String.prototype.toLocaleString = 0;
211+
var o = ["test"];
212+
guarded_call(function () {
213+
echo(Array.prototype.toLocaleString.apply(o));
214+
});
215+
String.prototype.toLocaleString = originalToLocaleString;

0 commit comments

Comments
 (0)