mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 22:15:24 +02:00
Fix more false positives throwing TypeError in functions
This commit is contained in:
parent
e87b5d6dab
commit
46c557247e
@ -43,6 +43,8 @@ info: |
|
|||||||
features: [string-trimming, String.prototype.trimEnd, Symbol.toPrimitive]
|
features: [string-trimming, String.prototype.trimEnd, Symbol.toPrimitive]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof String.prototype.trimEnd, "function");
|
||||||
|
|
||||||
var thisVal = {
|
var thisVal = {
|
||||||
[Symbol.toPrimitive]: undefined,
|
[Symbol.toPrimitive]: undefined,
|
||||||
toString: undefined,
|
toString: undefined,
|
||||||
|
@ -14,6 +14,8 @@ info: |
|
|||||||
features: [string-trimming, String.prototype.trimEnd]
|
features: [string-trimming, String.prototype.trimEnd]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof String.prototype.trimEnd, "function");
|
||||||
|
|
||||||
var trimEnd = String.prototype.trimEnd;
|
var trimEnd = String.prototype.trimEnd;
|
||||||
var symbol = Symbol();
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ info: |
|
|||||||
features: [string-trimming, String.prototype.trimStart, Symbol.toPrimitive]
|
features: [string-trimming, String.prototype.trimStart, Symbol.toPrimitive]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof String.prototype.trimStart, "function");
|
||||||
|
|
||||||
var thisVal = {
|
var thisVal = {
|
||||||
[Symbol.toPrimitive]: undefined,
|
[Symbol.toPrimitive]: undefined,
|
||||||
toString: undefined,
|
toString: undefined,
|
||||||
|
@ -14,6 +14,8 @@ info: |
|
|||||||
features: [string-trimming, String.prototype.trimStart]
|
features: [string-trimming, String.prototype.trimStart]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof String.prototype.trimStart, "function");
|
||||||
|
|
||||||
var trimStart = String.prototype.trimStart;
|
var trimStart = String.prototype.trimStart;
|
||||||
var symbol = Symbol();
|
var symbol = Symbol();
|
||||||
|
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
Intl.Locale();
|
Intl.Locale();
|
||||||
}, 'Intl.Locale() throws TypeError');
|
}, 'Intl.Locale() throws TypeError');
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
new Intl.Locale(true);
|
new Intl.Locale(true);
|
||||||
}, "true is an invalid tag value");
|
}, "true is an invalid tag value");
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
new Intl.Locale(null);
|
new Intl.Locale(null);
|
||||||
}, "null is an invalid tag value");
|
}, "null is an invalid tag value");
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
new Intl.Locale(0);
|
new Intl.Locale(0);
|
||||||
}, "0 is an invalid tag value");
|
}, "0 is an invalid tag value");
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale, Symbol]
|
features: [Intl.Locale, Symbol]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
new Intl.Locale(Symbol());
|
new Intl.Locale(Symbol());
|
||||||
}, "Symbol() is an invalid tag value");
|
}, "Symbol() is an invalid tag value");
|
||||||
|
@ -12,6 +12,8 @@ info: |
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
new Intl.Locale();
|
new Intl.Locale();
|
||||||
}, "(empty) is an invalid tag value");
|
}, "(empty) is an invalid tag value");
|
||||||
|
@ -24,10 +24,11 @@ includes: [testIntl.js]
|
|||||||
features: [Intl.Locale]
|
features: [Intl.Locale]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Locale, "function");
|
||||||
|
|
||||||
// Intl.Locale step 11.a.
|
// Intl.Locale step 11.a.
|
||||||
assert.throws(TypeError, function() { new Intl.Locale("en", null) })
|
assert.throws(TypeError, function() { new Intl.Locale("en", null) })
|
||||||
|
|
||||||
|
|
||||||
// ApplyOptionsToTag step 2.
|
// ApplyOptionsToTag step 2.
|
||||||
for (const invalidTag of getInvalidLanguageTags()) {
|
for (const invalidTag of getInvalidLanguageTags()) {
|
||||||
assert.throws(RangeError, function() {
|
assert.throws(RangeError, function() {
|
||||||
|
@ -11,6 +11,10 @@ includes: [testIntl.js]
|
|||||||
features: [Intl.RelativeTimeFormat]
|
features: [Intl.RelativeTimeFormat]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
for (const [locales, expectedError] of getInvalidLocaleArguments()) {
|
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]
|
features: [Intl.RelativeTimeFormat]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
Intl.RelativeTimeFormat();
|
Intl.RelativeTimeFormat();
|
||||||
});
|
});
|
||||||
|
@ -11,4 +11,6 @@ info: |
|
|||||||
features: [Intl.RelativeTimeFormat]
|
features: [Intl.RelativeTimeFormat]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() { new Intl.RelativeTimeFormat([], null) })
|
assert.throws(TypeError, function() { new Intl.RelativeTimeFormat([], null) })
|
||||||
|
@ -10,6 +10,8 @@ info: |
|
|||||||
features: [Intl.RelativeTimeFormat]
|
features: [Intl.RelativeTimeFormat]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.RelativeTimeFormat, "function");
|
||||||
|
|
||||||
const invalidOptions = [
|
const invalidOptions = [
|
||||||
null,
|
null,
|
||||||
1,
|
1,
|
||||||
|
@ -4,23 +4,82 @@
|
|||||||
/*---
|
/*---
|
||||||
esid: sec-InitializeRelativeTimeFormat
|
esid: sec-InitializeRelativeTimeFormat
|
||||||
description: Checks the propagation of exceptions from the options for the RelativeTimeFormat constructor.
|
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]
|
features: [Intl.RelativeTimeFormat]
|
||||||
|
includes: [compareArray.js]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
function CustomError() {}
|
function CustomError() {}
|
||||||
|
|
||||||
const options = [
|
const o1 = {
|
||||||
"localeMatcher",
|
get localeMatcher() {
|
||||||
"style",
|
throw new CustomError();
|
||||||
"numeric",
|
},
|
||||||
];
|
get style() {
|
||||||
|
throw "should not get the style option before localeMatcher";
|
||||||
|
},
|
||||||
|
get numeric() {
|
||||||
|
throw "should not get the numeric option before localeMatcher";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
for (const option of options) {
|
const o2captures = [];
|
||||||
assert.throws(CustomError, () => {
|
const o2 = {
|
||||||
new Intl.RelativeTimeFormat("en", {
|
get localeMatcher() {
|
||||||
get [option]() {
|
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();
|
throw new CustomError();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}, `Exception from ${option} getter should be propagated`);
|
|
||||||
}
|
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, {
|
Object.defineProperties(Object.prototype, {
|
||||||
"style": {
|
style: {
|
||||||
get() {
|
get() {
|
||||||
throw new Error("Should not call style getter");
|
throw new Error("Should not call style getter");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"numeric": {
|
numeric: {
|
||||||
get() {
|
get() {
|
||||||
throw new Error("Should not call numeric getter");
|
throw new Error("Should not call numeric getter");
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ for (const args of optionsArguments) {
|
|||||||
const rtf = new Intl.RelativeTimeFormat(...args);
|
const rtf = new Intl.RelativeTimeFormat(...args);
|
||||||
const resolvedOptions = rtf.resolvedOptions();
|
const resolvedOptions = rtf.resolvedOptions();
|
||||||
assert.sameValue(resolvedOptions.style, "long",
|
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",
|
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]
|
features: [Intl.Segmenter]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
|
assert.sameValue(typeof Intl.Segmenter, "function");
|
||||||
|
|
||||||
assert.throws(TypeError, function() {
|
assert.throws(TypeError, function() {
|
||||||
Intl.Segmenter();
|
Intl.Segmenter();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user