Change Intl.(ListFormat|DisplayNames|Segmenter) (#2952)

* Change Intl.(ListFormat|DisplayNames|Segmenter)

Sync from ToObject to GetOptionsObject which throw TypeError
while the option is not object

* Add null and false to test
This commit is contained in:
Frank Yung-Fong Tang 2021-03-08 19:31:26 -08:00 committed by GitHub
parent aca79695ba
commit 31126581e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 54 additions and 106 deletions

View File

@ -0,0 +1,24 @@
// Copyright 2021 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.DisplayNames
description: Checks handling of non-object option arguments to the DisplayNames constructor.
info: |
Intl.DisplayNames ( locales, options )
features: [Intl.DisplayNames,BigInt]
---*/
const optionsArguments = [
null,
true,
false,
"test",
7,
Symbol(),
123456789n,
];
for (const options of optionsArguments) {
assert.throws(TypeError, function() { new Intl.DisplayNames([], options) })
}

View File

@ -6,21 +6,19 @@ esid: sec-Intl.ListFormat
description: Checks handling of non-object option arguments to the ListFormat constructor.
info: |
InitializeListFormat (listFormat, locales, options)
features: [Intl.ListFormat]
features: [Intl.ListFormat,BigInt]
---*/
const optionsArguments = [
null,
true,
false,
"test",
7,
Symbol(),
123456789n,
];
for (const options of optionsArguments) {
const lf = new Intl.ListFormat([], options);
const resolvedOptions = lf.resolvedOptions();
assert.sameValue(resolvedOptions.type, "conjunction",
`options argument ${String(options)} should yield the correct value for "type"`);
assert.sameValue(resolvedOptions.style, "long",
`options argument ${String(options)} should yield the correct value for "style"`);
assert.throws(TypeError, function() { new Intl.ListFormat([], options) })
}

View File

@ -1,35 +0,0 @@
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.ListFormat
description: Checks handling of non-object option arguments to the ListFormat constructor.
info: |
InitializeListFormat (listFormat, locales, options)
features: [Intl.ListFormat]
---*/
Object.defineProperties(Object.prototype, {
"type": {
value: "unit",
},
"style": {
value: "short",
},
})
const optionsArguments = [
true,
"test",
7,
Symbol(),
];
for (const options of optionsArguments) {
const lf = new Intl.ListFormat([], options);
const resolvedOptions = lf.resolvedOptions();
assert.sameValue(resolvedOptions.type, "unit",
`options argument ${String(options)} should yield the correct value for "type"`);
assert.sameValue(resolvedOptions.style, "short",
`options argument ${String(options)} should yield the correct value for "style"`);
}

View File

@ -0,0 +1,25 @@
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.Segmenter
description: Checks handling of non-object option arguments to the Segmenter constructor.
info: |
Intl.Segmenter ([ locales [ , options ]])
features: [Intl.Segmenter,BigInt]
---*/
const optionsArguments = [
null,
true,
false,
"test",
7,
Symbol(),
123456789n,
];
for (const options of optionsArguments) {
assert.throws(TypeError, function() { new Intl.Segment([], options) })
}

View File

@ -1,34 +0,0 @@
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.Segmenter
description: Checks handling of non-object option arguments to the Segmenter constructor.
info: |
Intl.Segmenter ([ locales [ , options ]])
5. Else
a. Let options be ? ToObject(options).
features: [Intl.Segmenter]
---*/
Object.defineProperties(Object.prototype, {
"granularity": {
value: "word",
},
})
const optionsArguments = [
true,
"test",
7,
Symbol(),
{},
];
for (const options of optionsArguments) {
const segmenter = new Intl.Segmenter([], options);
const resolvedOptions = segmenter.resolvedOptions();
assert.sameValue(resolvedOptions.granularity, "word",
`options argument ${String(options)} should yield the correct value for "granularity"`);
}

View File

@ -1,30 +0,0 @@
// Copyright 2018 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-Intl.Segmenter
description: Checks handling of non-object option arguments to the Segmenter constructor.
info: |
Intl.Segmenter ([ locales [ , options ]])
5. Else
a. Let options be ? ToObject(options).
features: [Intl.Segmenter]
---*/
const optionsArguments = [
true,
"test",
7,
Symbol(),
{},
];
for (const options of optionsArguments) {
const segmenter = new Intl.Segmenter([], options);
const resolvedOptions = segmenter.resolvedOptions();
assert.sameValue(resolvedOptions.granularity, "grapheme",
`options argument ${String(options)} should yield the correct value for "granularity"`);
assert.sameValue(resolvedOptions.lineBreakStyle, undefined,
`options argument ${String(options)} should yield the correct value for "lineBreakStyle"`);
}