Skip to content
Snippets Groups Projects
Commit 46c55724 authored by Leo Balter's avatar Leo Balter Committed by Rick Waldron
Browse files

Fix more false positives throwing TypeError in functions

parent e87b5d6d
No related branches found
No related tags found
No related merge requests found
Showing
with 113 additions and 21 deletions
......@@ -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,
......
......@@ -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();
......
......@@ -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,
......
......@@ -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();
......
......@@ -12,6 +12,8 @@ info: |
features: [Intl.Locale]
---*/
assert.sameValue(typeof Intl.Locale, "function");
assert.throws(TypeError, function() {
Intl.Locale();
}, 'Intl.Locale() throws TypeError');
......
......@@ -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");
......
......@@ -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");
......@@ -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");
......
......@@ -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");
......@@ -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");
......
......@@ -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() {
......
......@@ -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}`);
}
......@@ -12,6 +12,8 @@ info: |
features: [Intl.RelativeTimeFormat]
---*/
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
assert.throws(TypeError, function() {
Intl.RelativeTimeFormat();
});
......
......@@ -11,4 +11,6 @@ info: |
features: [Intl.RelativeTimeFormat]
---*/
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
assert.throws(TypeError, function() { new Intl.RelativeTimeFormat([], null) })
......@@ -10,6 +10,8 @@ info: |
features: [Intl.RelativeTimeFormat]
---*/
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
const invalidOptions = [
null,
1,
......
......@@ -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']);
......@@ -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"`);
}
......@@ -11,6 +11,8 @@ info: |
features: [Intl.Segmenter]
---*/
assert.sameValue(typeof Intl.Segmenter, "function");
assert.throws(TypeError, function() {
Intl.Segmenter();
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment