From 56323fe2dd948076a2181614236572516d02e8f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Thu, 21 Dec 2017 12:08:15 -0800 Subject: [PATCH] Also test Intl.PluralRules if available --- harness/testIntl.js | 10 +++++++++- test/intl402/Collator/10.1.1_1.js | 7 +++++++ test/intl402/DateTimeFormat/12.1.1_1.js | 7 +++++++ test/intl402/NumberFormat/11.1.1_1.js | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/harness/testIntl.js b/harness/testIntl.js index 158feb53ae..f36bdeae84 100644 --- a/harness/testIntl.js +++ b/harness/testIntl.js @@ -21,6 +21,14 @@ author: Norbert Lindenberg */ function testWithIntlConstructors(f) { var constructors = ["Collator", "NumberFormat", "DateTimeFormat"]; + + // Optionally supported Intl constructors. + ["PluralRules"].forEach(function(constructor) { + if (typeof Intl[constructor] === "function") { + constructors[constructors.length] = constructor; + } + }); + constructors.forEach(function (constructor) { var Constructor = Intl[constructor]; try { @@ -99,7 +107,7 @@ function taintArray() { /** * Gets locale support info for the given constructor object, which must be one - * of Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat. + * of Intl constructors. * @param {object} Constructor the constructor for which to get locale support info * @return {object} locale support info with the following properties: * supported: array of fully supported language tags diff --git a/test/intl402/Collator/10.1.1_1.js b/test/intl402/Collator/10.1.1_1.js index 9aad93df3b..4a51a1ae17 100644 --- a/test/intl402/Collator/10.1.1_1.js +++ b/test/intl402/Collator/10.1.1_1.js @@ -17,6 +17,13 @@ testWithIntlConstructors(function (Constructor) { assert.notSameValue(obj, newObj, "Collator object created with \"new\" was not ignored as this-value."); // variant 2: use constructor as a function + if (Constructor !== Intl.Collator && + Constructor !== Intl.NumberFormat && + Constructor !== Intl.DateTimeFormat) + { + // Newer Intl constructors are not callable as a function. + return; + } obj = Constructor(); newObj = Intl.Collator.call(obj); assert.notSameValue(obj, newObj, "Collator object created with constructor as function was not ignored as this-value."); diff --git a/test/intl402/DateTimeFormat/12.1.1_1.js b/test/intl402/DateTimeFormat/12.1.1_1.js index 0aa96266be..33b6bfb455 100644 --- a/test/intl402/DateTimeFormat/12.1.1_1.js +++ b/test/intl402/DateTimeFormat/12.1.1_1.js @@ -22,6 +22,13 @@ testWithIntlConstructors(function (Constructor) { assert.notSameValue(obj, newObj, "DateTimeFormat object created with \"new\" was not ignored as this-value."); // variant 2: use constructor as a function + if (Constructor !== Intl.Collator && + Constructor !== Intl.NumberFormat && + Constructor !== Intl.DateTimeFormat) + { + // Newer Intl constructors are not callable as a function. + return; + } obj = Constructor(); newObj = Intl.DateTimeFormat.call(obj); assert.notSameValue(obj, newObj, "DateTimeFormat object created with constructor as function was not ignored as this-value."); diff --git a/test/intl402/NumberFormat/11.1.1_1.js b/test/intl402/NumberFormat/11.1.1_1.js index 05c1649569..3850653946 100644 --- a/test/intl402/NumberFormat/11.1.1_1.js +++ b/test/intl402/NumberFormat/11.1.1_1.js @@ -22,6 +22,13 @@ testWithIntlConstructors(function (Constructor) { assert.notSameValue(obj, newObj, "NumberFormat object created with \"new\" was not ignored as this-value."); // variant 2: use constructor as a function + if (Constructor !== Intl.Collator && + Constructor !== Intl.NumberFormat && + Constructor !== Intl.DateTimeFormat) + { + // Newer Intl constructors are not callable as a function. + return; + } obj = Constructor(); newObj = Intl.NumberFormat.call(obj); assert.notSameValue(obj, newObj, "NumberFormat object created with constructor as function was not ignored as this-value.");