From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/test262/intl402/DisplayNames/browser.js | 0 .../ctor-custom-get-prototype-poison-throws.js | 46 ++++++++++ .../intl402/DisplayNames/ctor-custom-prototype.js | 42 +++++++++ .../intl402/DisplayNames/ctor-default-prototype.js | 26 ++++++ .../intl402/DisplayNames/instance-extensible.js | 40 +++++++++ .../tests/test262/intl402/DisplayNames/length.js | 33 +++++++ .../intl402/DisplayNames/locales-invalid-throws.js | 34 +++++++ .../DisplayNames/locales-length-poison-throws.js | 42 +++++++++ .../DisplayNames/locales-length-tolength-throws.js | 75 ++++++++++++++++ .../intl402/DisplayNames/locales-symbol-length.js | 64 +++++++++++++ js/src/tests/test262/intl402/DisplayNames/name.js | 29 ++++++ .../DisplayNames/options-fallback-abrupt-throws.js | 40 +++++++++ .../options-fallback-invalid-throws.js | 59 ++++++++++++ .../options-fallback-toString-abrupt-throws.js | 59 ++++++++++++ .../intl402/DisplayNames/options-fallback-valid.js | 50 +++++++++++ .../DisplayNames/options-getoptionsobject.js | 26 ++++++ .../options-languagedisplay-abrupt-throws.js | 39 ++++++++ .../options-languagedisplay-invalid-throws.js | 59 ++++++++++++ ...tions-languagedisplay-toString-abrupt-throws.js | 57 ++++++++++++ .../DisplayNames/options-languagedisplay-valid.js | 49 ++++++++++ .../options-localeMatcher-abrupt-throws.js | 39 ++++++++ .../options-localeMatcher-invalid-throws.js | 69 ++++++++++++++ ...options-localeMatcher-toString-abrupt-throws.js | 69 ++++++++++++++ .../DisplayNames/options-localeMatcher-valid.js | 50 +++++++++++ .../intl402/DisplayNames/options-null-throws.js | 28 ++++++ .../options-random-properties-unchecked.js | 54 +++++++++++ .../DisplayNames/options-style-abrupt-throws.js | 46 ++++++++++ .../DisplayNames/options-style-invalid-throws.js | 77 ++++++++++++++++ .../options-style-toString-abrupt-throws.js | 72 +++++++++++++++ .../intl402/DisplayNames/options-style-valid.js | 51 +++++++++++ .../DisplayNames/options-type-abrupt-throws.js | 46 ++++++++++ .../DisplayNames/options-type-invalid-throws.js | 78 ++++++++++++++++ .../options-type-toString-abrupt-throws.js | 76 ++++++++++++++++ .../intl402/DisplayNames/options-type-valid.js | 45 ++++++++++ .../test262/intl402/DisplayNames/prop-desc.js | 26 ++++++ .../intl402/DisplayNames/proto-from-ctor-realm.js | 41 +++++++++ js/src/tests/test262/intl402/DisplayNames/proto.js | 15 ++++ .../DisplayNames/prototype/Symbol.toStringTag.js | 23 +++++ .../intl402/DisplayNames/prototype/browser.js | 0 .../intl402/DisplayNames/prototype/of/browser.js | 0 .../intl402/DisplayNames/prototype/of/shell.js | 0 .../prototype/of/type-calendar-invalid.js | 63 +++++++++++++ .../prototype/of/type-calendar-valid.js | 29 ++++++ .../prototype/of/type-datetimefield-invalid.js | 39 ++++++++ .../prototype/of/type-datetimefield-valid.js | 24 +++++ .../prototype/of/type-language-invalid.js | 90 +++++++++++++++++++ .../prototype/of/type-language-valid.js | 76 ++++++++++++++++ .../prototype/of/type-region-invalid.js | 85 ++++++++++++++++++ .../intl402/DisplayNames/prototype/prop-desc.js | 22 +++++ .../prototype/resolvedOptions/browser.js | 0 .../resolvedOptions/default-option-values.js | 82 +++++++++++++++++ .../prototype/resolvedOptions/length.js | 33 +++++++ .../DisplayNames/prototype/resolvedOptions/name.js | 29 ++++++ .../prototype/resolvedOptions/option-fallback.js | 87 ++++++++++++++++++ .../resolvedOptions/option-languagedisplay.js | 70 +++++++++++++++ .../prototype/resolvedOptions/option-style.js | 89 ++++++++++++++++++ .../prototype/resolvedOptions/option-type.js | 86 ++++++++++++++++++ .../prototype/resolvedOptions/prop-desc.js | 30 +++++++ .../prototype/resolvedOptions/return-object.js | 100 +++++++++++++++++++++ .../prototype/resolvedOptions/shell.js | 0 .../resolvedOptions/this-not-object-throws.js | 49 ++++++++++ .../this-object-lacks-internal-throws.js | 43 +++++++++ .../intl402/DisplayNames/prototype/shell.js | 0 js/src/tests/test262/intl402/DisplayNames/shell.js | 0 .../DisplayNames/undefined-newtarget-throws.js | 28 ++++++ 65 files changed, 2928 insertions(+) create mode 100644 js/src/tests/test262/intl402/DisplayNames/browser.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/ctor-custom-get-prototype-poison-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/ctor-custom-prototype.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/ctor-default-prototype.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/instance-extensible.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/length.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/locales-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/locales-length-poison-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/locales-length-tolength-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/locales-symbol-length.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/name.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-fallback-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-fallback-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-fallback-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-getoptionsobject.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-toString-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-toString-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-null-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-random-properties-unchecked.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-style-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-style-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-style-toString-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-style-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-type-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-type-invalid-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-type-toString-abrupt-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/options-type-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prop-desc.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/proto-from-ctor-realm.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/proto.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/Symbol.toStringTag.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/browser.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/browser.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/shell.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-invalid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-invalid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-invalid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-valid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/of/type-region-invalid.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/prop-desc.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/browser.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/length.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/name.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-languagedisplay.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-style.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-type.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/prop-desc.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/return-object.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/shell.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-not-object-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-object-lacks-internal-throws.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/prototype/shell.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/shell.js create mode 100644 js/src/tests/test262/intl402/DisplayNames/undefined-newtarget-throws.js (limited to 'js/src/tests/test262/intl402/DisplayNames') diff --git a/js/src/tests/test262/intl402/DisplayNames/browser.js b/js/src/tests/test262/intl402/DisplayNames/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/ctor-custom-get-prototype-poison-throws.js b/js/src/tests/test262/intl402/DisplayNames/ctor-custom-get-prototype-poison-throws.js new file mode 100644 index 0000000000..cb68a161ba --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/ctor-custom-get-prototype-poison-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt from Get Prototype from a custom NewTarget +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + ... + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [Intl.DisplayNames, Reflect, Proxy] +---*/ + +var custom = new Proxy(new Function(), { + get(target, key) { + if (key === 'prototype') { + throw new Test262Error(); + } + + return target[key]; + } +}); + +assert.throws(Test262Error, () => { + Reflect.construct(Intl.DisplayNames, [], custom); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/ctor-custom-prototype.js b/js/src/tests/test262/intl402/DisplayNames/ctor-custom-prototype.js new file mode 100644 index 0000000000..7ee1e0d702 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/ctor-custom-prototype.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Custom Prototype of the returned object based on the NewTarget +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + ... + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [Intl.DisplayNames, Reflect] +---*/ + +var custom = new Function(); +custom.prototype = {}; + +const obj = Reflect.construct(Intl.DisplayNames, [undefined, {type: 'language'}], custom); + +assert.sameValue(Object.getPrototypeOf(obj), custom.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/ctor-default-prototype.js b/js/src/tests/test262/intl402/DisplayNames/ctor-default-prototype.js new file mode 100644 index 0000000000..cce416f9ff --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/ctor-default-prototype.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Prototype of the returned object is DisplayNames.prototype +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 27. Return displayNames. +features: [Intl.DisplayNames] +---*/ + +var obj = new Intl.DisplayNames(undefined, {type: 'language'}); + +assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/instance-extensible.js b/js/src/tests/test262/intl402/DisplayNames/instance-extensible.js new file mode 100644 index 0000000000..93d002091f --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/instance-extensible.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Instance is extensible +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + ObjectCreate ( proto [ , internalSlotsList ] ) + + ... + 2. Let obj be a newly created object with an internal slot for each name in internalSlotsList. + 3. Set obj's essential internal methods to the default ordinary object definitions specified in 9.1. + 4. Set obj.[[Prototype]] to proto. + 5. Set obj.[[Extensible]] to true. + 6. Return obj. +features: [Intl.DisplayNames] +---*/ + +var obj = new Intl.DisplayNames(undefined, {type: 'language'}); + +assert(Object.isExtensible(obj)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/length.js b/js/src/tests/test262/intl402/DisplayNames/length.js new file mode 100644 index 0000000000..2e8c435bd9 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Intl.DisplayNames.length is 2. +info: | + ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +verifyProperty(Intl.DisplayNames, "length", { + value: 2, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/locales-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/locales-invalid-throws.js new file mode 100644 index 0000000000..70bc899905 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/locales-invalid-throws.js @@ -0,0 +1,34 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Throws TypeError if locales is not undefined, a string, or an array-like object. +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). + ... + + CanonicalizeLocaleList ( locales ) + + 1. If locales is undefined, then + a. Return a new empty List. + 2. Let seen be a new empty List. + 3. If Type(locales) is String, then + a. Let O be CreateArrayFromList(« locales »). + 4. Else, + a. Let O be ? ToObject(locales). + 5. Let len be ? ToLength(? Get(O, "length")). +features: [Intl.DisplayNames] +---*/ + +assert.throws(TypeError, () => { + new Intl.DisplayNames(null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/locales-length-poison-throws.js b/js/src/tests/test262/intl402/DisplayNames/locales-length-poison-throws.js new file mode 100644 index 0000000000..5469678ecc --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/locales-length-poison-throws.js @@ -0,0 +1,42 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from Get Locales length +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). + ... + + CanonicalizeLocaleList ( locales ) + + 1. If locales is undefined, then + a. Return a new empty List. + 2. Let seen be a new empty List. + 3. If Type(locales) is String, then + a. Let O be CreateArrayFromList(« locales »). + 4. Else, + a. Let O be ? ToObject(locales). + 5. Let len be ? ToLength(? Get(O, "length")). +features: [Intl.DisplayNames] +---*/ + +var locales = {}; + +Object.defineProperty(locales, 'length', { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames(locales); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/locales-length-tolength-throws.js b/js/src/tests/test262/intl402/DisplayNames/locales-length-tolength-throws.js new file mode 100644 index 0000000000..a9c8b3e1e0 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/locales-length-tolength-throws.js @@ -0,0 +1,75 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from Locales invalid length +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). + ... + + CanonicalizeLocaleList ( locales ) + + 1. If locales is undefined, then + a. Return a new empty List. + 2. Let seen be a new empty List. + 3. If Type(locales) is String, then + a. Let O be CreateArrayFromList(« locales »). + 4. Else, + a. Let O be ? ToObject(locales). + 5. Let len be ? ToLength(? Get(O, "length")). + + ToLength ( argument ) + + 1. Let len be ? ToInteger(argument). + ... +features: [Intl.DisplayNames, Symbol, BigInt] +---*/ + +var locales = { + length: { + valueOf() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames(locales); +}, 'poisoned valueOf for ToNumber'); + +locales.length = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, () => { + new Intl.DisplayNames(locales); +}, 'poisoned ToPrimitive for ToNumber'); + +locales.length = { + toString() { + throw new Test262Error(); + } +}; +assert.throws(Test262Error, () => { + new Intl.DisplayNames(locales); +}, 'poisoned toString for ToNumber'); + +locales.length = Symbol(); +assert.throws(TypeError, () => { + new Intl.DisplayNames(locales); +}, 'length is Symbol'); + +locales.length = BigInt(1); +assert.throws(TypeError, () => { + new Intl.DisplayNames(locales); +}, 'length is BigInt'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/locales-symbol-length.js b/js/src/tests/test262/intl402/DisplayNames/locales-symbol-length.js new file mode 100644 index 0000000000..53f07eca22 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/locales-symbol-length.js @@ -0,0 +1,64 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + CanonicalizeLocaleList tries to fetch length from Object. +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + 3. Let requestedLocales be ? CanonicalizeLocaleList(locales). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + + CanonicalizeLocaleList ( locales ) + + 1. If locales is undefined, then + a. Return a new empty List. + 2. Let seen be a new empty List. + 3. If Type(locales) is String, then + a. Let O be CreateArrayFromList(« locales »). + 4. Else, + a. Let O be ? ToObject(locales). + 5. Let len be ? ToLength(? Get(O, "length")). +features: [Intl.DisplayNames, Symbol] +locale: [en] +includes: [compareArray.js] +---*/ + +let calls = []; +let symbol = Symbol(); + +Symbol.prototype.length = 1; + +Object.defineProperty(Symbol.prototype, 'length', { + get() { + assert.notSameValue(this, symbol, 'this is an object from given symbol'); + assert.sameValue(this.valueOf(), symbol, 'internal value is the symbol'); + assert(this instanceof Symbol); + calls.push('length'); + return 1; + } +}); + +Object.defineProperty(Symbol.prototype, '0', { + get() { + assert.notSameValue(this, symbol, 'this is an object from given symbol'); + assert.sameValue(this.valueOf(), symbol, 'internal value is the symbol'); + assert(this instanceof Symbol); + calls.push('0'); + return 'en'; + } +}); + +new Intl.DisplayNames(symbol, {type: 'language'}); + +assert.compareArray(calls, ['length', '0']); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/name.js b/js/src/tests/test262/intl402/DisplayNames/name.js new file mode 100644 index 0000000000..6cfaf9855f --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Intl.DisplayNames.name is "DisplayNames". +info: | + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. + + Unless otherwise specified, the name property of a built-in Function object, + if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +verifyProperty(Intl.DisplayNames, "name", { + value: "DisplayNames", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-fallback-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-fallback-abrupt-throws.js new file mode 100644 index 0000000000..6a798c142f --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-fallback-abrupt-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption fallback +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = { type: 'language' }; +Object.defineProperty(options, 'fallback', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-fallback-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-fallback-invalid-throws.js new file mode 100644 index 0000000000..c1d6c5ae21 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-fallback-invalid-throws.js @@ -0,0 +1,59 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from an invalid fallback option +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language"). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + ... + 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. + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {fallback: 'err', type: 'language'}); +}, 'err'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {fallback: 'non', type: 'language'}); +}, 'non, not none'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {fallback: null, type: 'language'}); +}, 'null'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {fallback: '', type: 'language'}); +}, 'the empty string'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {fallback: ['code', 'none'], type: 'language'}); +}, 'an array with the valid options is not necessarily valid'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js new file mode 100644 index 0000000000..231117aee4 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-fallback-toString-abrupt-throws.js @@ -0,0 +1,59 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption fallback +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames, Symbol] +locale: [en] +---*/ + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', fallback: { toString() { throw new Test262Error(); }} + }); +}, 'from toString'); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', + fallback: {toString: undefined, valueOf() {throw new Test262Error(); }} + }); +}, 'from valueOf'); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', + fallback: { [Symbol.toPrimitive]() { throw new Test262Error(); } } + }); +}, 'from ToPrimitive'); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', { + type: 'language', + fallback: Symbol() + }); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-fallback-valid.js b/js/src/tests/test262/intl402/DisplayNames/options-fallback-valid.js new file mode 100644 index 0000000000..b97245a3d2 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-fallback-valid.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Valid options for fallback +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const fallbacks = [ + undefined, + 'code', + 'none' +]; + +fallbacks.forEach(fallback => { + const obj = new Intl.DisplayNames('en', { fallback, type: 'language'}); + + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${fallback}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${fallback}`); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-getoptionsobject.js b/js/src/tests/test262/intl402/DisplayNames/options-getoptionsobject.js new file mode 100644 index 0000000000..a8046db499 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-getoptionsobject.js @@ -0,0 +1,26 @@ +// 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) }) +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-abrupt-throws.js new file mode 100644 index 0000000000..4c4604fd9e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-abrupt-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: Return abrupt completion from GetOption fallback +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames-v2] +locale: [en] +---*/ + +var options = { type: 'language' }; +Object.defineProperty(options, 'languageDisplay', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-invalid-throws.js new file mode 100644 index 0000000000..95a6f3a032 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-invalid-throws.js @@ -0,0 +1,59 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from an invalid fallback option +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », "language"). + 13. If type is undefined, throw a TypeError exception. + ... + 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + ... + 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. + ... +features: [Intl.DisplayNames-v2] +locale: [en] +---*/ + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {languageDisplay: 'err', type: 'language'}); +}, 'err'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {languageDisplay: 'standar', type: 'language'}); +}, 'standar, not standard'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {languageDisplay: null, type: 'language'}); +}, 'null'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {languageDisplay: '', type: 'language'}); +}, 'the empty string'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {languageDisplay: ['dialect', 'standard'], type: 'language'}); +}, 'an array with the valid options is not necessarily valid'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-toString-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-toString-abrupt-throws.js new file mode 100644 index 0000000000..96a4e3ce7c --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-toString-abrupt-throws.js @@ -0,0 +1,57 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption fallback +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames-v2, Symbol] +locale: [en] +---*/ + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', languageDisplay: { toString() { throw new Test262Error(); }} + }); +}, 'from toString'); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', + languageDisplay: {toString: undefined, valueOf() {throw new Test262Error(); }} + }); +}, 'from valueOf'); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', { + type: 'language', + languageDisplay: { [Symbol.toPrimitive]() { throw new Test262Error(); } } + }); +}, 'from ToPrimitive'); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', { + type: 'language', + languageDisplay: Symbol() + }); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-valid.js b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-valid.js new file mode 100644 index 0000000000..3b6ce728d4 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-languagedisplay-valid.js @@ -0,0 +1,49 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: Valid options for languageDisplay +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", « "dialect", "standard" », "dialect"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames-v2] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const languageDisplays = [ + undefined, + 'dialect', + 'standard' +]; + +languageDisplays.forEach(languageDisplay => { + const obj = new Intl.DisplayNames('en', { languageDisplay, type: 'language'}); + + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${languageDisplay}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${languageDisplay}`); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-abrupt-throws.js new file mode 100644 index 0000000000..1cb0a8013c --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-abrupt-throws.js @@ -0,0 +1,39 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption localeMatcher +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = {}; +Object.defineProperty(options, 'localeMatcher', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-invalid-throws.js new file mode 100644 index 0000000000..a0f1cfd744 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-invalid-throws.js @@ -0,0 +1,69 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from an invalid localeMatcher option +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + ... + 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. + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = { + localeMatcher: 'bestfit' // not "best fit" +}; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'bestfit'); + +options.localeMatcher = 'look up'; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'look up'); + +options.localeMatcher = null; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'null'); + +options.localeMatcher = ''; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'the empty string'); + +// The world could burn +options.localeMatcher = ['lookup', 'best fit']; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'an array with the valid options is not necessarily valid'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-toString-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-toString-abrupt-throws.js new file mode 100644 index 0000000000..64ecd3c1e9 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-toString-abrupt-throws.js @@ -0,0 +1,69 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption localeMatcher +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames, Symbol] +locale: [en] +---*/ + +var options = { + localeMatcher: { + toString() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from toString'); + +options.localeMatcher = { + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from valueOf'); + +options.localeMatcher = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from ToPrimitive'); + +options.localeMatcher = Symbol(); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', options); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-valid.js b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-valid.js new file mode 100644 index 0000000000..c934443d8a --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-localeMatcher-valid.js @@ -0,0 +1,50 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Valid options for localeMatcher +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const localeMatchers = [ + undefined, + 'lookup', + 'best fit' +]; + +localeMatchers.forEach(localeMatcher => { + const obj = new Intl.DisplayNames('en', { localeMatcher, type: 'language' }); + + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${localeMatcher}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${localeMatcher}`); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-null-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-null-throws.js new file mode 100644 index 0000000000..dca7bf9caa --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-null-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Throws TypeError if options is null +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', null); +}, 'null'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-random-properties-unchecked.js b/js/src/tests/test262/intl402/DisplayNames/options-random-properties-unchecked.js new file mode 100644 index 0000000000..2bd057a4dd --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-random-properties-unchecked.js @@ -0,0 +1,54 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Random options are not checked or used, including case sensitive +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = { type: 'language' }; +Object.defineProperty(options, 'fallBack', { + get() { throw new Test262Error(); } +}); +Object.defineProperty(options, 'localematcher', { + get() { throw new Test262Error(); } +}); +Object.defineProperty(options, 'locale-matcher', { + get() { throw new Test262Error(); } +}); +Object.defineProperty(options, 'Type', { + get() { throw new Test262Error(); } +}); + +var obj = new Intl.DisplayNames('en', options); + +assert(obj instanceof Intl.DisplayNames); +assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-style-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-style-abrupt-throws.js new file mode 100644 index 0000000000..51d7d4a6d8 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-style-abrupt-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption style +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = {}; +Object.defineProperty(options, 'style', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-style-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-style-invalid-throws.js new file mode 100644 index 0000000000..76083d3793 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-style-invalid-throws.js @@ -0,0 +1,77 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from an invalid style option +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + ... + 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. + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = { + style: 'small' +}; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'small'); + +options.style = 'very long'; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'very long'); + +options.style = 'full'; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'full'); + +options.style = null; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'null'); + +options.style = ''; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'the empty string'); + +options.style = ['narrow', 'short', 'long']; + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', options); +}, 'an array with the valid options is not necessarily valid'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-style-toString-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-style-toString-abrupt-throws.js new file mode 100644 index 0000000000..ac03b3ce1e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-style-toString-abrupt-throws.js @@ -0,0 +1,72 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption style +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames, Symbol] +locale: [en] +---*/ + +var options = { + style: { + toString() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from toString'); + +options.style = { + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from valueOf'); + +options.style = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from ToPrimitive'); + +options.style = Symbol(); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', options); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-style-valid.js b/js/src/tests/test262/intl402/DisplayNames/options-style-valid.js new file mode 100644 index 0000000000..e2a8fd9890 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-style-valid.js @@ -0,0 +1,51 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Valid options for localeMatcher +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const styles = [ + undefined, + 'narrow', + 'short', + 'long' +]; + +const types = ['language', 'region', 'script', 'currency']; + +types.forEach( type => { + styles.forEach(style => { + var obj = new Intl.DisplayNames('en', { style, type }); + + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${style}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${style}`); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-type-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-type-abrupt-throws.js new file mode 100644 index 0000000000..d7362cd778 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-type-abrupt-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption type +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +var options = {}; +Object.defineProperty(options, 'type', { + get() { throw new Test262Error(); }, +}); + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-type-invalid-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-type-invalid-throws.js new file mode 100644 index 0000000000..bdbaecae82 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-type-invalid-throws.js @@ -0,0 +1,78 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from an invalid type option +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + 2. If value is not undefined, then + ... + 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. + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', undefined); +}, 'undefined options'); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', {}); +}, '{} options'); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', {type: undefined}); +}, 'undefined type'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: 'lang'}); +}, 'type = lang'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: 'dayPeriod'}); +}, 'dayPeriod not supported yet'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: 'weekday'}); +}, 'weekday not supported yet'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: null}); +}, 'type = null'); + + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: ''}); +}, 'type = ""'); + +assert.throws(RangeError, () => { + new Intl.DisplayNames('en', {type: ['language', 'region', 'script', 'currency']}); +}, 'an array with the valid options is not necessarily valid'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-type-toString-abrupt-throws.js b/js/src/tests/test262/intl402/DisplayNames/options-type-toString-abrupt-throws.js new file mode 100644 index 0000000000..36f43563cf --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-type-toString-abrupt-throws.js @@ -0,0 +1,76 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Return abrupt completion from GetOption type +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. If options is undefined, then + a. Let options be ObjectCreate(null). + 5. Else + a. Let options be ? ToObject(options). + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency", "weekday", "month", "quarter", "dayPeriod", "dateTimeField" », "language"). + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames, Symbol] +locale: [en] +---*/ + +var options = { + type: { + toString() { + throw new Test262Error(); + } + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from toString'); + +options.type = { + toString: undefined, + valueOf() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from valueOf'); + +options.type = { + [Symbol.toPrimitive]() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => { + new Intl.DisplayNames('en', options); +}, 'from ToPrimitive'); + +options.type = Symbol(); + +assert.throws(TypeError, () => { + new Intl.DisplayNames('en', options); +}, 'symbol value'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/options-type-valid.js b/js/src/tests/test262/intl402/DisplayNames/options-type-valid.js new file mode 100644 index 0000000000..54e884e880 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/options-type-valid.js @@ -0,0 +1,45 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Valid options for localeMatcher +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 4. Let options be ? ToObject(options). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + + GetOption ( options, property, type, values, fallback ) + + 1. Let value be ? Get(options, property). + ... +features: [Intl.DisplayNames] +locale: [en] +---*/ + +// results for option values verified in the tests for resolvedOptions + +const types = [ + 'language', + 'region', + 'script', + 'currency' +]; + +types.forEach(type => { + const obj = new Intl.DisplayNames('en', { type }); + + assert(obj instanceof Intl.DisplayNames, `instanceof check - ${type}`); + assert.sameValue(Object.getPrototypeOf(obj), Intl.DisplayNames.prototype, `proto check - ${type}`); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prop-desc.js b/js/src/tests/test262/intl402/DisplayNames/prop-desc.js new file mode 100644 index 0000000000..337f52b0ab --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prop-desc.js @@ -0,0 +1,26 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Property descriptor of Intl.DisplayNames +info: | + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +assert.sameValue(typeof Intl.DisplayNames, "function", "`typeof Intl.DisplayNames` is `'function'`"); + +verifyProperty(Intl, "DisplayNames", { + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/proto-from-ctor-realm.js b/js/src/tests/test262/intl402/DisplayNames/proto-from-ctor-realm.js new file mode 100644 index 0000000000..cac9302e8f --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/proto-from-ctor-realm.js @@ -0,0 +1,41 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + Intl.DisplayNames ( locales , options ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let displayNames be ? OrdinaryCreateFromConstructor(NewTarget, "%DisplayNamesPrototype%", + « [[InitializedDisplayNames]], [[Locale]], [[Style]], [[Type]], [[Fallback]], [[Fields]] »). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Set proto to realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +features: [Intl.DisplayNames, cross-realm, Reflect] +---*/ + +var other = $262.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(Intl.DisplayNames, [undefined, {type: 'language'}], C); + +assert.sameValue(Object.getPrototypeOf(o), other.Intl.DisplayNames.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/proto.js b/js/src/tests/test262/intl402/DisplayNames/proto.js new file mode 100644 index 0000000000..7ef279226b --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/proto.js @@ -0,0 +1,15 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + The internal prototype of Intl.DisplayNames +features: [Intl.DisplayNames] +---*/ + +var proto = Object.getPrototypeOf(Intl.DisplayNames); + +assert.sameValue(proto, Function.prototype); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/Symbol.toStringTag.js b/js/src/tests/test262/intl402/DisplayNames/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000..de8db1a805 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/Symbol.toStringTag.js @@ -0,0 +1,23 @@ +// Copyright 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.DisplayNames.prototype-@@tostringtag +description: > + Property descriptor of DisplayNames.prototype[@@toStringTag] +info: | + The initial value of the @@toStringTag property is the string value "Intl.DisplayNames". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames, Symbol.toStringTag] +---*/ + +verifyProperty(Intl.DisplayNames.prototype, Symbol.toStringTag, { + value: "Intl.DisplayNames", + writable: false, + enumerable: false, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/browser.js b/js/src/tests/test262/intl402/DisplayNames/prototype/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/browser.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/shell.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-invalid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-invalid.js new file mode 100644 index 0000000000..1d7fc9ff43 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-invalid.js @@ -0,0 +1,63 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Throws a RangeError for invalid `calendar` codes +features: [Intl.DisplayNames-v2] +---*/ + +var displayNames = new Intl.DisplayNames(undefined, {type: 'calendar'}); + +assert.throws(RangeError, function() { + displayNames.of('00'); +}, 'insufficient length'); + +assert.throws(RangeError, function() { + displayNames.of('000000000'); +}, 'excessive length'); + +assert.throws(RangeError, function() { + displayNames.of('-00000000'); +}, 'leading separator (dash)'); + +assert.throws(RangeError, function() { + displayNames.of('_00000000'); +}, 'leading separator (underscore)'); + +assert.throws(RangeError, function() { + displayNames.of('00000000-'); +}, 'trailing separator (dash)'); + +assert.throws(RangeError, function() { + displayNames.of('00000000_'); +}, 'trailing separator (underscore)'); + +assert.throws(RangeError, function() { + displayNames.of(' abcdef'); +}, 'leading space'); + +assert.throws(RangeError, function() { + displayNames.of('abcdef '); +}, 'trailing space'); + +assert.throws(RangeError, function() { + displayNames.of('abc def'); +}, 'interstitial space'); + +assert.throws(RangeError, function() { + displayNames.of('123_abc'); +}, '2 segments, minimum length, underscore'); + +assert.throws(RangeError, function() { + displayNames.of('12345678_abcdefgh'); +}, '2 segments, maximum length, underscore'); + +assert.throws(RangeError, function() { + displayNames.of('123_abc_ABC'); +}, '3 segments, minimum length, underscore'); + +assert.throws(RangeError, function() { + displayNames.of('12345678_abcdefgh_ABCDEFGH'); +}, '3 segments, maximum length, underscore'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-valid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-valid.js new file mode 100644 index 0000000000..9f6bb2a8d1 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-calendar-valid.js @@ -0,0 +1,29 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Returns string value for valid `calendar` codes +features: [Intl.DisplayNames-v2] +---*/ + +var displayNames = new Intl.DisplayNames(undefined, {type: 'calendar'}); + +assert.sameValue(typeof displayNames.of('01234567'), 'string', '[0-7]'); +assert.sameValue(typeof displayNames.of('899'), 'string', '[89]'); + +assert.sameValue(typeof displayNames.of('abcdefgh'), 'string', '[a-h]'); +assert.sameValue(typeof displayNames.of('ijklmnop'), 'string', '[i-p]'); +assert.sameValue(typeof displayNames.of('qrstuvwx'), 'string', '[q-x]'); +assert.sameValue(typeof displayNames.of('yzz'), 'string', '[yz]'); + +assert.sameValue(typeof displayNames.of('ABCDEFGH'), 'string', '[A-H]'); +assert.sameValue(typeof displayNames.of('IJKLMNOP'), 'string', '[I-P]'); +assert.sameValue(typeof displayNames.of('QRSTUVWX'), 'string', '[Q-X]'); +assert.sameValue(typeof displayNames.of('YZZ'), 'string', '[YZ]'); + +assert.sameValue(typeof displayNames.of('123-abc'), 'string', '2 segments, minimum length, dash'); +assert.sameValue(typeof displayNames.of('12345678-abcdefgh'), 'string', '2 segments, maximum length, dash'); +assert.sameValue(typeof displayNames.of('123-abc-ABC'), 'string', '3 segments, minimum length, dash'); +assert.sameValue(typeof displayNames.of('12345678-abcdefgh-ABCDEFGH'), 'string', '3 segments, maximum length, dash'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-invalid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-invalid.js new file mode 100644 index 0000000000..b1532a389c --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-invalid.js @@ -0,0 +1,39 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Throws a RangeError for invalid `dateTimeField` codes +features: [Intl.DisplayNames-v2] +---*/ + +var displayNames = new Intl.DisplayNames(undefined, {type: 'dateTimeField'}); + +assert.throws(RangeError, function() { + displayNames.of(''); +}, 'empty string'); + +assert.throws(RangeError, function() { + displayNames.of('timezoneName'); +}, 'timezoneName'); + +assert.throws(RangeError, function() { + displayNames.of('timezonename'); +}, 'timezonename'); + +assert.throws(RangeError, function() { + displayNames.of('millisecond'); +}, 'millisecond'); + +assert.throws(RangeError, function() { + displayNames.of('seconds'); +}, 'seconds'); + +assert.throws(RangeError, function() { + displayNames.of(' year'); +}, 'year (with leading space)'); + +assert.throws(RangeError, function() { + displayNames.of('year '); +}, 'year (with trailing space)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-valid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-valid.js new file mode 100644 index 0000000000..d649742ed5 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-datetimefield-valid.js @@ -0,0 +1,24 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Returns string value for valid `dateTimeField` codes +features: [Intl.DisplayNames-v2] +---*/ + +var displayNames = new Intl.DisplayNames(undefined, {type: 'dateTimeField'}); + +assert.sameValue(typeof displayNames.of('era'), 'string', 'era'); +assert.sameValue(typeof displayNames.of('year'), 'string', 'year'); +assert.sameValue(typeof displayNames.of('quarter'), 'string', 'quarter'); +assert.sameValue(typeof displayNames.of('month'), 'string', 'month'); +assert.sameValue(typeof displayNames.of('weekOfYear'), 'string', 'weekOfYear'); +assert.sameValue(typeof displayNames.of('weekday'), 'string', 'weekday'); +assert.sameValue(typeof displayNames.of('day'), 'string', 'day'); +assert.sameValue(typeof displayNames.of('dayPeriod'), 'string', 'dayPeriod'); +assert.sameValue(typeof displayNames.of('hour'), 'string', 'hour'); +assert.sameValue(typeof displayNames.of('minute'), 'string', 'minute'); +assert.sameValue(typeof displayNames.of('second'), 'string', 'second'); +assert.sameValue(typeof displayNames.of('timeZoneName'), 'string', 'timeZoneName'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-invalid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-invalid.js new file mode 100644 index 0000000000..e00ed3f1f5 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-invalid.js @@ -0,0 +1,90 @@ +// Copyright (C) 2023 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Throws a RangeError for invalid `language` codes +info: | + 12.3.3 Intl.DisplayNames.prototype.of ( code ) + + 1. If type is "language", then + a. If code cannot be matched by the unicode_language_id Unicode locale nonterminal, throw a RangeError exception. + b. If IsStructurallyValidLanguageTag(code) is false, throw a RangeError exception. + c. Return CanonicalizeUnicodeLocaleId(code). +features: [Intl.DisplayNames-v2] +---*/ + +var displayNames = new Intl.DisplayNames(undefined, {type: 'language'}); + +assert.throws(RangeError, function() { + displayNames.of(''); +}, 'invalid language subtag - empty string'); + +assert.throws(RangeError, function() { + displayNames.of('a'); +}, 'invalid language subtag - only one character'); + +assert.throws(RangeError, function() { + displayNames.of('abcdefghi'); +}, 'invalid language subtag - greater than 8 characters'); + +assert.throws(RangeError, function() { + displayNames.of('en-u-hebrew'); +}, 'singleton subtag'); + +assert.throws(RangeError, function() { + displayNames.of('aa-aaaa-bbbb'); +}, 'multiple script subtags'); + +assert.throws(RangeError, function() { + displayNames.of('aa-aaaaa-aaaaa'); +}, 'duplicate variant subtag'); + +assert.throws(RangeError, function() { + displayNames.of('aa-bb-cc'); +}, 'multiple region subtags'); + +assert.throws(RangeError, function() { + displayNames.of('1a'); +}, 'invalid language subtag - leading digit'); + +assert.throws(RangeError, function() { + displayNames.of('aa-1a'); +}, 'leading-digit subtag of length 2'); + +assert.throws(RangeError, function() { + displayNames.of('aa-1aa'); +}, 'leading-digit non-numeric subtag of length 3'); + +assert.throws(RangeError, function() { + displayNames.of('@#$%@#$'); +}, 'invalid characters'); + +assert.throws(RangeError, function() { + displayNames.of('en-US-'); +}, 'separator not followed by subtag'); + +assert.throws(RangeError, function() { + displayNames.of('-en'); +}, 'separator at start'); + +assert.throws(RangeError, function() { + displayNames.of('en--GB'); +}, 'missing subtag between separators'); + +assert.throws(RangeError, function() { + displayNames.of('root'); +}, 'BCP 47-incompatible CLDR syntax ("root" instead of "und")'); + +assert.throws(RangeError, function(){ + displayNames.of('abcd-GB'); +}, 'BCP 47-incompatible CLDR syntax (script subtag without a language subtag)'); + +assert.throws(RangeError, function(){ + displayNames.of('abcd'); +}, 'BCP 47-incompatible CLDR syntax (bare script subtag)'); + +assert.throws(RangeError, function(){ + displayNames.of('en_GB'); +}, 'BCP 47-incompatible CLDR syntax (_ as separator)'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-valid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-valid.js new file mode 100644 index 0000000000..2b7932bf90 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-language-valid.js @@ -0,0 +1,76 @@ +// Copyright (C) 2023 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Returns string value for valid `language` codes +features: [Intl.DisplayNames] +---*/ + + +/* +unicode_language_id = "root" // not allowed in ES + | (unicode_language_subtag + (sep unicode_script_subtag)? + | unicode_script_subtag) + (sep unicode_region_subtag)? + (sep unicode_variant_subtag)* + */ + +// unicode_language_subtag = alpha{2,3} | alpha{5,8} ; + +var languages = [ { subtag: 'ab', description: '2 letter language_subtag' }, + { subtag: 'cde', description: '3 letter language_subtag' }, + { subtag: 'zzzzzzzz', description: '8 letter language_subtag'} ]; + +// unicode_script_subtag = alpha{4} ; +var scripts = [ {subtag: 'abcd', description: '4 letter script_subtag' }, + {subtag: '', description: ''} ]; + +// unicode_region_subtag = (alpha{2} | digit{3}) ; +var regions = [ {subtag: 'ab', description: '2 letter region_subtag' }, + {subtag: '123', description: '3 digit region_subtag'}, + {subtag: '', description: ''} ]; + +// unicode_variant_subtag = (alphanum{5, 8} | digit alphanum{3} + +var variants = [ {subtag: 'abcde', description: '5 letter variant_subtag'}, + {subtag: 'fghijklm', description: '8 letter variant_subtag'}, + {subtag: '12345', description: '5 digit variant_subtag'}, + {subtag: '1nopq', description: '5 chararcter leading digit variant_subtag'}, + {subtag: '12345678', description: '8 digit variant_subtag'}, + {subtag: 'a2345678', description: '8 character trailing digit variant_subtag'}, + {subtag: '1abc', description: 'leading digit 4 character variant_subtag' }, + {subtag: '2345', description: '4 digit variant_subtag'}, + {subtag: '6d7e', description: 'leading digit 4 character mixed alphanum variant_subtag'}, + {subtag: '', description: ''} ]; + + +function notEmpty(subtag) { + return subtag !== ''; +} + +var displayNames = new Intl.DisplayNames(undefined, {type: 'language'}); + +for (var l in languages) { + for (var s in scripts) { + for (var r in regions) { + for (var v in variants) { + var languageTag = [languages[l].subtag, scripts[s].subtag, regions[r].subtag, variants[v].subtag].filter(notEmpty).join('-'); + var languageDescription = [languages[l].description, scripts[s].description, regions[r].description, variants[v].description].filter(notEmpty).join(', '); + + assert.sameValue(typeof displayNames.of(languageTag), 'string', languageDescription + ": " + languageTag); + if (variants[v].subtag !== ''){ + for (var vAdditional in variants){ + if (variants[vAdditional].subtag !== '' && vAdditional !== v){ + languageTag += '-' + variants[vAdditional].subtag; + languageDescription += ", " + variants[vAdditional].description; + assert.sameValue(typeof displayNames.of(languageTag), 'string', languageDescription + ": " + languageTag); + } + } + } + } + } + } +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-region-invalid.js b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-region-invalid.js new file mode 100644 index 0000000000..0fcce4ac7e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/of/type-region-invalid.js @@ -0,0 +1,85 @@ +// Copyright 2023 Igalia S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.of +description: Throws a RangeError for invalid `region` codes +info: | + 12.5.1 CanonicalCodeForDisplayNames ( code ) + + ... + 2. If type is "region", then + a. If code cannot be matched by the unicode_region_subtag Unicode locale nonterminal, throw a RangeError exception. + b. Return the ASCII-uppercase of code. +features: [Intl.DisplayNames] +---*/ + +// https://unicode.org/reports/tr35/#unicode_region_subtag +// unicode_region_subtag = (alpha{2} | digit{3}) ; + +var displayNames = new Intl.DisplayNames(undefined, {type: 'region'}); + +assert.throws(RangeError, function() { + displayNames.of('00'); +}, 'insufficient length, numeric'); + +assert.throws(RangeError, function() { + displayNames.of('a'); +}, 'insufficient length, alpha'); + +assert.throws(RangeError, function() { + displayNames.of('aaa'); +}, 'excessive length, alpha'); + +assert.throws(RangeError, function() { + displayNames.of('1111'); +}, 'excessive length, numeric'); + +assert.throws(RangeError, function() { + displayNames.of(''); +}, 'empty string'); + +assert.throws(RangeError, function() { + displayNames.of('a01'); +}, 'mixed alphanumeric (alpha first, length 3)'); + +assert.throws(RangeError, function() { + displayNames.of('a1'); +}, 'mixed alphanumeric (alpha first, length 2)'); + +assert.throws(RangeError, function() { + displayNames.of('1a'); +}, 'mixed alphanumeric (numeric first, length 2)'); + +assert.throws(RangeError, function() { + displayNames.of('1a1'); +}, 'mixed alphanumeric (numeric first, length 3)'); + +assert.throws(RangeError, function() { + displayNames.of('-111'); +}, 'leading separator (dash)'); + +assert.throws(RangeError, function() { + displayNames.of('_111'); +}, 'leading separator (underscore)'); + +assert.throws(RangeError, function() { + displayNames.of('111-'); +}, 'trailing separator (dash)'); + +assert.throws(RangeError, function() { + displayNames.of('111-'); +}, 'trailing separator (underscore)'); + +assert.throws(RangeError, function() { + displayNames.of(' aa'); +}, 'leading space'); + +assert.throws(RangeError, function() { + displayNames.of('aa '); +}, 'trailing space'); + +assert.throws(RangeError, function() { + displayNames.of('a c'); +}, 'interstitial space'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/prop-desc.js b/js/src/tests/test262/intl402/DisplayNames/prototype/prop-desc.js new file mode 100644 index 0000000000..1c35488ac3 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/prop-desc.js @@ -0,0 +1,22 @@ +// Copyright 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype +description: > + Property descriptor of Intl.DisplayNames.prototype +info: | + The value of Intl.DisplayNames.prototype is %DisplayNamesPrototype%. + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +verifyProperty(Intl.DisplayNames, "prototype", { + writable: false, + enumerable: false, + configurable: false, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/browser.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js new file mode 100644 index 0000000000..96475e2ded --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/default-option-values.js @@ -0,0 +1,82 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Default values for each option +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + + Intl.DisplayNames ( locales , options ) + + ... + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 9. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + %DisplayNames%.[[RelevantExtensionKeys]]). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + 17. Set displayNames.[[Locale]] to the value of r.[[Locale]]. + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames] +includes: [propertyHelper.js] +---*/ + +var dn = new Intl.DisplayNames('en-US', {type: 'language'}); + +var options = dn.resolvedOptions(); + +verifyProperty(options, 'style', { + value: 'long', + writable: true, + enumerable: true, + configurable: true +}); + +verifyProperty(options, 'type', { + value: 'language', + writable: true, + enumerable: true, + configurable: true +}); + +verifyProperty(options, 'fallback', { + value: 'code', + writable: true, + enumerable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/length.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/length.js new file mode 100644 index 0000000000..402df82db0 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/length.js @@ -0,0 +1,33 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Intl.DisplayNames.prototype.resolvedOptions.length is 0. +info: | + ECMAScript Standard Built-in Objects: + + Every built-in function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description. Optional parameters + (which are indicated with brackets: [ ]) or rest parameters (which + are shown using the form «...name») are not included in the default + argument count. + + Unless otherwise specified, the length property of a built-in function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +verifyProperty(Intl.DisplayNames.prototype.resolvedOptions, "length", { + value: 0, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/name.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/name.js new file mode 100644 index 0000000000..91f54d44cc --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/name.js @@ -0,0 +1,29 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Intl.DisplayNames.prototype.resolvedOptions.name is "resolvedOptions". +info: | + 17 ECMAScript Standard Built-in Objects: + + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value is a + String. + + Unless otherwise specified, the name property of a built-in Function object, + if it exists, has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +verifyProperty(Intl.DisplayNames.prototype.resolvedOptions, "name", { + value: "resolvedOptions", + writable: false, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js new file mode 100644 index 0000000000..2fe0d03843 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-fallback.js @@ -0,0 +1,87 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Values for the fallback option +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + [[LanguageDisplay]]: "languageDisplay" + + Intl.DisplayNames ( locales , options ) + + ... + 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + %DisplayNames%.[[RelevantExtensionKeys]]). + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + 17. Set displayNames.[[Locale]] to the value of r.[[Locale]]. + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames] +includes: [propertyHelper.js] +---*/ + +const fallbacks = ['code', 'none']; +const types = ['language', 'region', 'script', 'currency']; + +types.forEach(type => { + fallbacks.forEach(fallback => { + const dn = new Intl.DisplayNames('en-US', { fallback, type }); + const options = dn.resolvedOptions(); + + verifyProperty(options, 'fallback', { + value: fallback, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'type', { + value: type, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'style', { + value: 'long', + writable: true, + enumerable: true, + configurable: true + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-languagedisplay.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-languagedisplay.js new file mode 100644 index 0000000000..3b3317a9d6 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-languagedisplay.js @@ -0,0 +1,70 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: Values for the languageDisplay option +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + [[LanguageDisplay]]: "languageDisplay" + + Intl.DisplayNames ( locales , options ) + + ... + 24. Let languageDisplay be ? GetOption(options, "languageDisplay", "string", + « "dialect", "standard" », "dialect"). + 25. If type is "language", then + a. Set displayNames.[[LanguageDisplay]] to languageDisplay. + b. Let typeFields be typeFields.[[]]. + c. Assert: typeFields is a Record (see 1.4.3). + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames-v2] +includes: [propertyHelper.js] +---*/ + +var dn; + +dn = new Intl.DisplayNames('en-US', { type: 'language', languageDisplay: 'dialect' }); + +verifyProperty(dn.resolvedOptions(), 'languageDisplay', { + value: 'dialect', + writable: true, + enumerable: true, + configurable: true +}); + +dn = new Intl.DisplayNames('en-US', { type: 'language', languageDisplay: 'standard' }); + +verifyProperty(dn.resolvedOptions(), 'languageDisplay', { + value: 'standard', + writable: true, + enumerable: true, + configurable: true +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-style.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-style.js new file mode 100644 index 0000000000..12961ca43e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-style.js @@ -0,0 +1,89 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Values for the style option +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + [[LanguageDisplay]]: "languageDisplay" + + Intl.DisplayNames ( locales , options ) + + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + %DisplayNames%.[[RelevantExtensionKeys]]). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + 17. Set displayNames.[[Locale]] to the value of r.[[Locale]]. + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames] +includes: [propertyHelper.js] +---*/ + +const styles = ['narrow', 'short', 'long']; +const types = ['language', 'region', 'script', 'currency']; + +types.forEach(type => { + styles.forEach(style => { + const dn = new Intl.DisplayNames('en-US', { style, type }); + const options = dn.resolvedOptions(); + + verifyProperty(options, 'style', { + value: style, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'type', { + value: type, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'fallback', { + value: 'code', + writable: true, + enumerable: true, + configurable: true + }); + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-type.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-type.js new file mode 100644 index 0000000000..5bb0254f0e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/option-type.js @@ -0,0 +1,86 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Values for the type option +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + [[LanguageDisplay]]: "languageDisplay" + + Intl.DisplayNames ([ locales [ , options ]]) + + ... + 8. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 10. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + %DisplayNames%.[[RelevantExtensionKeys]]). + 11. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 13. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency"», + "language"). + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + 17. Set displayNames.[[Locale]] to the value of r.[[Locale]]. + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames] +includes: [propertyHelper.js] +---*/ + +var types = ['language', 'region', 'script', 'currency']; + +types.forEach(type => { + var dn = new Intl.DisplayNames('en-US', { type }); + var options = dn.resolvedOptions(); + + verifyProperty(options, 'type', { + value: type, + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'fallback', { + value: 'code', + writable: true, + enumerable: true, + configurable: true + }); + + verifyProperty(options, 'style', { + value: 'long', + writable: true, + enumerable: true, + configurable: true + }); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/prop-desc.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/prop-desc.js new file mode 100644 index 0000000000..1766f5a5ce --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/prop-desc.js @@ -0,0 +1,30 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Property descriptor of Intl.DisplayNames.prototype.resolvedOptions +info: | + 17 ECMAScript Standard Built-in Objects: + + Every other data property described in clauses 18 through 26 and in Annex B.2 + has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +features: [Intl.DisplayNames] +---*/ + +assert.sameValue( + typeof Intl.DisplayNames.prototype.resolvedOptions, + "function", + "`typeof Intl.DisplayNames.prototype.resolvedOptions` is `'function'`" +); + +verifyProperty(Intl.DisplayNames.prototype, "resolvedOptions", { + writable: true, + enumerable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/return-object.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/return-object.js new file mode 100644 index 0000000000..9f5d2f8e3d --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/return-object.js @@ -0,0 +1,100 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Returns a new ordinary object on each call, with data properties containing values from internals +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + 3. Let options be ! ObjectCreate(%ObjectPrototype%). + 4. For each row of Table 6, except the header row, in table order, do + a. Let p be the Property value of the current row. + b. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row. + c. If v is not undefined, then + i. Perform ! CreateDataPropertyOrThrow(options, p, v). + 6. Return options. + + Table 6: Resolved Options of DisplayNames Instances + + [[Locale]]: "locale" + [[Style]]: "style" + [[Type]]: "type" + [[Fallback]]: "fallback" + [[LanguageDisplay]]: "languageDisplay" + + Intl.DisplayNames ( locales , options ) + + ... + 7. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit"). + ... + 9. Let r be ResolveLocale(%DisplayNames%.[[AvailableLocales]], requestedLocales, opt, + %DisplayNames%.[[RelevantExtensionKeys]]). + 10. Let style be ? GetOption(options, "style", "string", « "narrow", "short", "long" », "long"). + ... + 12. Let type be ? GetOption(options, "type", "string", « "language", "region", "script", "currency" », undefined). + 13. If type is undefined, throw a TypeError exception. + ... + 15. Let fallback be ? GetOption(options, "fallback", "string", « "code", "none" », "code"). + ... + 17. Set displayNames.[[Locale]] to the value of r.[[Locale]]. + ... + + CreateDataProperty ( O, P, V ) + + ... + 3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, + [[Configurable]]: true }. + ... +locale: [en-US] +features: [Intl.DisplayNames-v2, Reflect] +includes: [propertyHelper.js, compareArray.js] +---*/ + +const dn = new Intl.DisplayNames('en-US', {type: 'language'}); + +const options = dn.resolvedOptions(); +const other = dn.resolvedOptions(); + +assert.notSameValue(options, other, 'each call returns a new object'); + +assert.sameValue(Object.getPrototypeOf(options), Object.prototype, 'ordinary object #1'); +assert.sameValue(Object.getPrototypeOf(other), Object.prototype, 'ordinary object #2'); + +assert.compareArray( + Reflect.ownKeys(options), + ['locale', 'style', 'type', 'fallback', 'languageDisplay'], + 'all the data properties set to this object, in order of creation' +); + +verifyProperty(options, 'locale', { + value: 'en-US', + writable: true, + enumerable: true, + configurable: true +}); + +const explicit = new Intl.DisplayNames( + 'en', { localeMatcher: 'lookup', type: 'language' }).resolvedOptions(); + +assert.sameValue( + explicit.hasOwnProperty('localeMatcher'), + false, + 'the localeMatcher option is not set, option was explicitly set' +); + +const extra = new Intl.DisplayNames( + 'en', { chaos: 'yes', random: 'sure', '0': 42, type: 'language' }).resolvedOptions(); + +assert.compareArray( + Reflect.ownKeys(extra), + ['locale', 'style', 'type', 'fallback', 'languageDisplay'], + 'extra properties are not reflected in the resolvedOptions' +); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/shell.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-not-object-throws.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-not-object-throws.js new file mode 100644 index 0000000000..42cac5976e --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-not-object-throws.js @@ -0,0 +1,49 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Throws a TypeError if this is not Object. +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + ... +features: [Intl.DisplayNames, Symbol] +---*/ + +var resolvedOptions = Intl.DisplayNames.prototype.resolvedOptions; + +assert.throws(TypeError, function() { + resolvedOptions(); +}, 'direct call'); + +assert.throws(TypeError, function() { + resolvedOptions.call('en'); +}, 'string'); + +assert.throws(TypeError, function() { + resolvedOptions.call(1); +}, 'number'); + +assert.throws(TypeError, function() { + resolvedOptions.call(null); +}, 'null'); + +assert.throws(TypeError, function() { + resolvedOptions.call(true); +}, 'true'); + +assert.throws(TypeError, function() { + resolvedOptions.call(false); +}, 'false'); + +var symbol = Symbol(); +assert.throws(TypeError, function() { + resolvedOptions.call(symbol); +}, 'symbol'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-object-lacks-internal-throws.js b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-object-lacks-internal-throws.js new file mode 100644 index 0000000000..9ad4c1517b --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/prototype/resolvedOptions/this-object-lacks-internal-throws.js @@ -0,0 +1,43 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames.prototype.resolvedOptions +description: > + Throws a TypeError if this does not have an [[InitializedDisplayNames]] internal slot. +info: | + Intl.DisplayNames.prototype.resolvedOptions () + + 1. Let pr be the this value. + 2. If Type(pr) is not Object or pr does not have an [[InitializedDisplayNames]] internal slot, + throw a TypeError exception. + ... +features: [Intl.DisplayNames] +---*/ + +var resolvedOptions = Intl.DisplayNames.prototype.resolvedOptions; + +assert.throws(TypeError, function() { + Intl.DisplayNames.prototype.resolvedOptions(); +}, 'Intl.DisplayNames.prototype does not have the internal slot'); + +assert.throws(TypeError, function() { + resolvedOptions.call({}); +}, 'ordinary object'); + +assert.throws(TypeError, function() { + resolvedOptions.call(Intl.DisplayNames); +}, 'Intl.DisplayNames does not have the internal slot'); + +assert.throws(TypeError, function() { + resolvedOptions.call(Intl); +}, 'Intl does not have the internal slot'); + +// Not DisplayNames!!! +var dtf = new Intl.DateTimeFormat(); + +assert.throws(TypeError, function() { + resolvedOptions.call(dtf); +}, 'resolvedOptions cannot be used with instances from different Intl ctors'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/intl402/DisplayNames/prototype/shell.js b/js/src/tests/test262/intl402/DisplayNames/prototype/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/shell.js b/js/src/tests/test262/intl402/DisplayNames/shell.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/intl402/DisplayNames/undefined-newtarget-throws.js b/js/src/tests/test262/intl402/DisplayNames/undefined-newtarget-throws.js new file mode 100644 index 0000000000..3b28c14486 --- /dev/null +++ b/js/src/tests/test262/intl402/DisplayNames/undefined-newtarget-throws.js @@ -0,0 +1,28 @@ +// Copyright (C) 2019 Leo Balter. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DisplayNames +description: > + Throws a TypeError if Intl.DisplayNames is called as a function. +info: | + Intl.DisplayNames ([ locales [ , options ]]) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +features: [Intl.DisplayNames] +---*/ + +assert.throws(TypeError, function() { + Intl.DisplayNames(); +}); + +assert.throws(TypeError, function() { + Intl.DisplayNames('en'); +}); + +assert.throws(TypeError, function() { + Intl.DisplayNames(['en']); +}); + +reportCompare(0, 0); -- cgit v1.2.3