Skip to content

Commit

Permalink
Bug 1642962: Add toStringTag to Intl prototypes referring to the cons…
Browse files Browse the repository at this point in the history
…tructor name. r=jwalden

Implement the changes from <tc39/ecma402#430>.

Differential Revision: https://phabricator.services.mozilla.com/D78035
  • Loading branch information
anba committed Jun 4, 2020
1 parent 29b8477 commit 90bfdea
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion js/src/builtin/intl/Collator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static const JSFunctionSpec collator_methods[] = {

static const JSPropertySpec collator_properties[] = {
JS_SELF_HOSTED_GET("compare", "$Intl_Collator_compare_get", 0),
JS_STRING_SYM_PS(toStringTag, "Object", JSPROP_READONLY), JS_PS_END};
JS_STRING_SYM_PS(toStringTag, "Intl.Collator", JSPROP_READONLY), JS_PS_END};

static bool Collator(JSContext* cx, unsigned argc, Value* vp);

Expand Down
3 changes: 2 additions & 1 deletion js/src/builtin/intl/DateTimeFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ static const JSFunctionSpec dateTimeFormat_methods[] = {

static const JSPropertySpec dateTimeFormat_properties[] = {
JS_SELF_HOSTED_GET("format", "$Intl_DateTimeFormat_format_get", 0),
JS_STRING_SYM_PS(toStringTag, "Object", JSPROP_READONLY), JS_PS_END};
JS_STRING_SYM_PS(toStringTag, "Intl.DateTimeFormat", JSPROP_READONLY),
JS_PS_END};

static bool DateTimeFormat(JSContext* cx, unsigned argc, Value* vp);

Expand Down
3 changes: 2 additions & 1 deletion js/src/builtin/intl/NumberFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ static const JSFunctionSpec numberFormat_methods[] = {

static const JSPropertySpec numberFormat_properties[] = {
JS_SELF_HOSTED_GET("format", "$Intl_NumberFormat_format_get", 0),
JS_STRING_SYM_PS(toStringTag, "Object", JSPROP_READONLY), JS_PS_END};
JS_STRING_SYM_PS(toStringTag, "Intl.NumberFormat", JSPROP_READONLY),
JS_PS_END};

static bool NumberFormat(JSContext* cx, unsigned argc, Value* vp);

Expand Down
6 changes: 5 additions & 1 deletion js/src/builtin/intl/PluralRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ static const JSFunctionSpec pluralRules_methods[] = {
JS_SELF_HOSTED_FN("select", "Intl_PluralRules_select", 1, 0),
JS_FN(js_toSource_str, pluralRules_toSource, 0, 0), JS_FS_END};

static const JSPropertySpec pluralRules_properties[] = {
JS_STRING_SYM_PS(toStringTag, "Intl.PluralRules", JSPROP_READONLY),
JS_PS_END};

static bool PluralRules(JSContext* cx, unsigned argc, Value* vp);

const ClassSpec PluralRulesObject::classSpec_ = {
Expand All @@ -86,7 +90,7 @@ const ClassSpec PluralRulesObject::classSpec_ = {
pluralRules_static_methods,
nullptr,
pluralRules_methods,
nullptr,
pluralRules_properties,
nullptr,
ClassSpec::DontDefineConstructor};

Expand Down
11 changes: 11 additions & 0 deletions js/src/tests/jstests.list
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,17 @@ skip script test262/built-ins/Promise/all/invoke-resolve-get-error-close.js
skip script test262/built-ins/Promise/race/invoke-resolve-get-error-close.js
skip script test262/built-ins/Promise/allSettled/invoke-resolve-get-error-close.js

# Not yet updated for <https://github.com/tc39/ecma402/pull/430>.
skip script test262/intl402/Collator/instance-class.js
skip script test262/intl402/Collator/prototype/builtin.js
skip script test262/intl402/PluralRules/prototype/builtins.js
skip script test262/intl402/NumberFormat/instance-class.js
skip script test262/intl402/NumberFormat/prototype/builtin.js
skip script test262/intl402/NumberFormat/prototype/toStringTag/configurable.js
skip script test262/intl402/NumberFormat/prototype/toStringTag/prop-desc.js
skip script test262/intl402/DateTimeFormat/instance-class.js
skip script test262/intl402/DateTimeFormat/prototype/builtin.js


##############################################
# Enable Iterator Helpers tests in the shell #
Expand Down
6 changes: 3 additions & 3 deletions js/src/tests/non262/Intl/Collator/toStringTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
var desc = Object.getOwnPropertyDescriptor(Intl.Collator.prototype, Symbol.toStringTag);

assertEq(desc !== undefined, true);
assertEq(desc.value, "Object");
assertEq(desc.value, "Intl.Collator");
assertEq(desc.writable, false);
assertEq(desc.enumerable, false);
assertEq(desc.configurable, true);

assertEq(Object.prototype.toString.call(Intl.Collator.prototype), "[object Object]");
assertEq(Object.prototype.toString.call(new Intl.Collator), "[object Object]");
assertEq(Object.prototype.toString.call(Intl.Collator.prototype), "[object Intl.Collator]");
assertEq(Object.prototype.toString.call(new Intl.Collator), "[object Intl.Collator]");

Object.defineProperty(Intl.Collator.prototype, Symbol.toStringTag, {value: "Collator"});

Expand Down
6 changes: 3 additions & 3 deletions js/src/tests/non262/Intl/DateTimeFormat/toStringTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
var desc = Object.getOwnPropertyDescriptor(Intl.DateTimeFormat.prototype, Symbol.toStringTag);

assertEq(desc !== undefined, true);
assertEq(desc.value, "Object");
assertEq(desc.value, "Intl.DateTimeFormat");
assertEq(desc.writable, false);
assertEq(desc.enumerable, false);
assertEq(desc.configurable, true);

assertEq(Object.prototype.toString.call(Intl.DateTimeFormat.prototype), "[object Object]");
assertEq(Object.prototype.toString.call(new Intl.DateTimeFormat), "[object Object]");
assertEq(Object.prototype.toString.call(Intl.DateTimeFormat.prototype), "[object Intl.DateTimeFormat]");
assertEq(Object.prototype.toString.call(new Intl.DateTimeFormat), "[object Intl.DateTimeFormat]");

Object.defineProperty(Intl.DateTimeFormat.prototype, Symbol.toStringTag, {value: "DateTimeFormat"});

Expand Down
6 changes: 3 additions & 3 deletions js/src/tests/non262/Intl/NumberFormat/toStringTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
var desc = Object.getOwnPropertyDescriptor(Intl.NumberFormat.prototype, Symbol.toStringTag);

assertEq(desc !== undefined, true);
assertEq(desc.value, "Object");
assertEq(desc.value, "Intl.NumberFormat");
assertEq(desc.writable, false);
assertEq(desc.enumerable, false);
assertEq(desc.configurable, true);

assertEq(Object.prototype.toString.call(Intl.NumberFormat.prototype), "[object Object]");
assertEq(Object.prototype.toString.call(new Intl.NumberFormat), "[object Object]");
assertEq(Object.prototype.toString.call(Intl.NumberFormat.prototype), "[object Intl.NumberFormat]");
assertEq(Object.prototype.toString.call(new Intl.NumberFormat), "[object Intl.NumberFormat]");

Object.defineProperty(Intl.NumberFormat.prototype, Symbol.toStringTag, {value: "NumberFormat"});

Expand Down

0 comments on commit 90bfdea

Please sign in to comment.