From 46c557247eb4511372297e9664ace0ed87819f3d Mon Sep 17 00:00:00 2001 From: Leo Balter <leonardo.balter@gmail.com> Date: Mon, 17 Dec 2018 16:58:39 -0200 Subject: [PATCH] Fix more false positives throwing TypeError in functions --- ...-object-cannot-convert-to-primitive-err.js | 2 + .../trimEnd/this-value-symbol-typeerror.js | 2 + ...-object-cannot-convert-to-primitive-err.js | 2 + .../trimStart/this-value-symbol-typeerror.js | 2 + .../Locale/constructor-newtarget-undefined.js | 2 + .../Locale/invalid-tag-throws-boolean.js | 2 + .../intl402/Locale/invalid-tag-throws-null.js | 2 + .../Locale/invalid-tag-throws-number.js | 2 + .../Locale/invalid-tag-throws-symbol.js | 2 + .../Locale/invalid-tag-throws-undefined.js | 2 + test/intl402/Locale/invalid-tag-throws.js | 3 +- .../constructor/locales-invalid.js | 6 +- .../constructor/newtarget-undefined.js | 2 + .../constructor/options-invalid.js | 2 + .../constructor/options-numeric-invalid.js | 2 + .../constructor/options-throwing-getters.js | 89 +++++++++++++++---- .../constructor/options-undefined.js | 8 +- .../constructor/newtarget-undefined.js | 2 + 18 files changed, 113 insertions(+), 21 deletions(-) diff --git a/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js b/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js index 1a9d5418ac..5868746d28 100644 --- a/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js +++ b/test/built-ins/String/prototype/trimEnd/this-value-object-cannot-convert-to-primitive-err.js @@ -43,6 +43,8 @@ info: | features: [string-trimming, String.prototype.trimEnd, Symbol.toPrimitive] ---*/ +assert.sameValue(typeof String.prototype.trimEnd, "function"); + var thisVal = { [Symbol.toPrimitive]: undefined, toString: undefined, diff --git a/test/built-ins/String/prototype/trimEnd/this-value-symbol-typeerror.js b/test/built-ins/String/prototype/trimEnd/this-value-symbol-typeerror.js index d043708aac..b01bf3a9e0 100644 --- a/test/built-ins/String/prototype/trimEnd/this-value-symbol-typeerror.js +++ b/test/built-ins/String/prototype/trimEnd/this-value-symbol-typeerror.js @@ -14,6 +14,8 @@ info: | features: [string-trimming, String.prototype.trimEnd] ---*/ +assert.sameValue(typeof String.prototype.trimEnd, "function"); + var trimEnd = String.prototype.trimEnd; var symbol = Symbol(); diff --git a/test/built-ins/String/prototype/trimStart/this-value-object-cannot-convert-to-primitive-err.js b/test/built-ins/String/prototype/trimStart/this-value-object-cannot-convert-to-primitive-err.js index 36db2ae671..7005c12815 100644 --- a/test/built-ins/String/prototype/trimStart/this-value-object-cannot-convert-to-primitive-err.js +++ b/test/built-ins/String/prototype/trimStart/this-value-object-cannot-convert-to-primitive-err.js @@ -43,6 +43,8 @@ info: | features: [string-trimming, String.prototype.trimStart, Symbol.toPrimitive] ---*/ +assert.sameValue(typeof String.prototype.trimStart, "function"); + var thisVal = { [Symbol.toPrimitive]: undefined, toString: undefined, diff --git a/test/built-ins/String/prototype/trimStart/this-value-symbol-typeerror.js b/test/built-ins/String/prototype/trimStart/this-value-symbol-typeerror.js index f492807597..cf5568bec5 100644 --- a/test/built-ins/String/prototype/trimStart/this-value-symbol-typeerror.js +++ b/test/built-ins/String/prototype/trimStart/this-value-symbol-typeerror.js @@ -14,6 +14,8 @@ info: | features: [string-trimming, String.prototype.trimStart] ---*/ +assert.sameValue(typeof String.prototype.trimStart, "function"); + var trimStart = String.prototype.trimStart; var symbol = Symbol(); diff --git a/test/intl402/Locale/constructor-newtarget-undefined.js b/test/intl402/Locale/constructor-newtarget-undefined.js index e8e542976d..a0583b7039 100644 --- a/test/intl402/Locale/constructor-newtarget-undefined.js +++ b/test/intl402/Locale/constructor-newtarget-undefined.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { Intl.Locale(); }, 'Intl.Locale() throws TypeError'); diff --git a/test/intl402/Locale/invalid-tag-throws-boolean.js b/test/intl402/Locale/invalid-tag-throws-boolean.js index ce6937e2ea..55226570c0 100644 --- a/test/intl402/Locale/invalid-tag-throws-boolean.js +++ b/test/intl402/Locale/invalid-tag-throws-boolean.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { new Intl.Locale(true); }, "true is an invalid tag value"); diff --git a/test/intl402/Locale/invalid-tag-throws-null.js b/test/intl402/Locale/invalid-tag-throws-null.js index 6d08c26286..d611f1c477 100644 --- a/test/intl402/Locale/invalid-tag-throws-null.js +++ b/test/intl402/Locale/invalid-tag-throws-null.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { new Intl.Locale(null); }, "null is an invalid tag value"); diff --git a/test/intl402/Locale/invalid-tag-throws-number.js b/test/intl402/Locale/invalid-tag-throws-number.js index 805d36c525..eef4a85110 100644 --- a/test/intl402/Locale/invalid-tag-throws-number.js +++ b/test/intl402/Locale/invalid-tag-throws-number.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { new Intl.Locale(0); }, "0 is an invalid tag value"); diff --git a/test/intl402/Locale/invalid-tag-throws-symbol.js b/test/intl402/Locale/invalid-tag-throws-symbol.js index d99264671d..7274916db6 100644 --- a/test/intl402/Locale/invalid-tag-throws-symbol.js +++ b/test/intl402/Locale/invalid-tag-throws-symbol.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale, Symbol] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { new Intl.Locale(Symbol()); }, "Symbol() is an invalid tag value"); diff --git a/test/intl402/Locale/invalid-tag-throws-undefined.js b/test/intl402/Locale/invalid-tag-throws-undefined.js index 609c20b384..c3a35dd93f 100644 --- a/test/intl402/Locale/invalid-tag-throws-undefined.js +++ b/test/intl402/Locale/invalid-tag-throws-undefined.js @@ -12,6 +12,8 @@ info: | features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + assert.throws(TypeError, function() { new Intl.Locale(); }, "(empty) is an invalid tag value"); diff --git a/test/intl402/Locale/invalid-tag-throws.js b/test/intl402/Locale/invalid-tag-throws.js index ee6449510f..86e5a13070 100644 --- a/test/intl402/Locale/invalid-tag-throws.js +++ b/test/intl402/Locale/invalid-tag-throws.js @@ -24,10 +24,11 @@ includes: [testIntl.js] features: [Intl.Locale] ---*/ +assert.sameValue(typeof Intl.Locale, "function"); + // Intl.Locale step 11.a. assert.throws(TypeError, function() { new Intl.Locale("en", null) }) - // ApplyOptionsToTag step 2. for (const invalidTag of getInvalidLanguageTags()) { assert.throws(RangeError, function() { diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/locales-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/locales-invalid.js index 9c98223d41..8d3dcd8354 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/locales-invalid.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/locales-invalid.js @@ -11,6 +11,10 @@ includes: [testIntl.js] features: [Intl.RelativeTimeFormat] ---*/ +assert.sameValue(typeof Intl.RelativeTimeFormat, "function"); + for (const [locales, expectedError] of getInvalidLocaleArguments()) { - assert.throws(expectedError, function() { new Intl.RelativeTimeFormat(locales) }) + assert.throws(expectedError, function() { + new Intl.RelativeTimeFormat(locales) + }, `using ${String(locales)} expects ${expectedError}`); } diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js b/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js index e4775cc517..53a169fb68 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/newtarget-undefined.js @@ -12,6 +12,8 @@ info: | features: [Intl.RelativeTimeFormat] ---*/ +assert.sameValue(typeof Intl.RelativeTimeFormat, "function"); + assert.throws(TypeError, function() { Intl.RelativeTimeFormat(); }); diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-invalid.js index 90df4ffdb4..287f7e4b49 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/options-invalid.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-invalid.js @@ -11,4 +11,6 @@ info: | features: [Intl.RelativeTimeFormat] ---*/ +assert.sameValue(typeof Intl.RelativeTimeFormat, "function"); + assert.throws(TypeError, function() { new Intl.RelativeTimeFormat([], null) }) diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js index d0733a06e4..4b27d06902 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-numeric-invalid.js @@ -10,6 +10,8 @@ info: | features: [Intl.RelativeTimeFormat] ---*/ +assert.sameValue(typeof Intl.RelativeTimeFormat, "function"); + const invalidOptions = [ null, 1, diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-throwing-getters.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-throwing-getters.js index 705574c4d3..273995b2c1 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/options-throwing-getters.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-throwing-getters.js @@ -4,23 +4,82 @@ /*--- esid: sec-InitializeRelativeTimeFormat description: Checks the propagation of exceptions from the options for the RelativeTimeFormat constructor. +info: | + InitializeRelativeTimeFormat + + 5. Let matcher be ? GetOption(options, "localeMatcher", "string", «"lookup", "best fit"», "best fit"). + ... + 12. Let s be ? GetOption(options, "style", "string", «"long", "short", "narrow"», "long"). + ... + 14. Let numeric be ? GetOption(options, "numeric", "string", «"always", "auto"», "always"). + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + a. Assert: type is "boolean" or "string". + b. If type is "boolean", then + i. Let value be ToBoolean(value). + c. If type is "string", then + i. Let value be ? ToString(value). + d. If values is not undefined, then + i. If values does not contain an element equal to value, throw a RangeError exception. + e. Return value. + 3. Else, return fallback. features: [Intl.RelativeTimeFormat] +includes: [compareArray.js] ---*/ function CustomError() {} -const options = [ - "localeMatcher", - "style", - "numeric", -]; - -for (const option of options) { - assert.throws(CustomError, () => { - new Intl.RelativeTimeFormat("en", { - get [option]() { - throw new CustomError(); - } - }); - }, `Exception from ${option} getter should be propagated`); -} +const o1 = { + get localeMatcher() { + throw new CustomError(); + }, + get style() { + throw "should not get the style option before localeMatcher"; + }, + get numeric() { + throw "should not get the numeric option before localeMatcher"; + } +}; + +const o2captures = []; +const o2 = { + get localeMatcher() { + o2captures.push('localeMatcher'); + }, + get style() { + throw new CustomError(); + }, + get numeric() { + throw "should not get the numeric option before style"; + } +}; + +const o3captures = []; +const o3 = { + get localeMatcher() { + o3captures.push('localeMatcher'); + }, + get style() { + o3captures.push('style'); + }, + get numeric() { + throw new CustomError(); + } +}; + +assert.throws(CustomError, () => { + new Intl.RelativeTimeFormat("en", o1); +}, `Exception from localeMatcher getter should be propagated`); + +assert.throws(CustomError, () => { + new Intl.RelativeTimeFormat("en", o2); +}, `Exception from style getter should be propagated`); +assert.compareArray(o2captures, ['localeMatcher']); + +assert.throws(CustomError, () => { + new Intl.RelativeTimeFormat("en", o3); +}, `Exception from numeric getter should be propagated`); +assert.compareArray(o3captures, ['localeMatcher', 'style']); diff --git a/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js b/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js index f5ab4bf838..c2cd1c3df1 100644 --- a/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js +++ b/test/intl402/RelativeTimeFormat/constructor/constructor/options-undefined.js @@ -10,12 +10,12 @@ features: [Intl.RelativeTimeFormat] ---*/ Object.defineProperties(Object.prototype, { - "style": { + style: { get() { throw new Error("Should not call style getter"); } }, - "numeric": { + numeric: { get() { throw new Error("Should not call numeric getter"); } @@ -32,7 +32,7 @@ for (const args of optionsArguments) { const rtf = new Intl.RelativeTimeFormat(...args); const resolvedOptions = rtf.resolvedOptions(); assert.sameValue(resolvedOptions.style, "long", - `Calling with ${args.length} empty arguments should yield the correct value for "style"`); + `Calling with ${args.length} empty arguments should yield the fallback value for "style"`); assert.sameValue(resolvedOptions.numeric, "always", - `Calling with ${args.length} empty arguments should yield the correct value for "numeric"`); + `Calling with ${args.length} empty arguments should yield the fallback value for "numeric"`); } diff --git a/test/intl402/Segmenter/constructor/constructor/newtarget-undefined.js b/test/intl402/Segmenter/constructor/constructor/newtarget-undefined.js index 2482634884..387304e9e8 100644 --- a/test/intl402/Segmenter/constructor/constructor/newtarget-undefined.js +++ b/test/intl402/Segmenter/constructor/constructor/newtarget-undefined.js @@ -11,6 +11,8 @@ info: | features: [Intl.Segmenter] ---*/ +assert.sameValue(typeof Intl.Segmenter, "function"); + assert.throws(TypeError, function() { Intl.Segmenter(); }); -- GitLab