From ef7fd2bc27e7c10b4a71d2edc632a2934742a13e Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 11 Sep 2019 23:22:21 +0300 Subject: [PATCH] Add "proto-from-ctor-realm" tests for Intl constructors (#2334) * Rename "Object/proto-from-ctor.js" test * Add missing "Symbol" features * Add Intl.Collator test * Add Intl.DateTimeFormat test * Add Intl.NumberFormat test * Add Intl.PluralRules test --- .../proto-from-ctor-realm.js | 2 +- ...-from-ctor.js => proto-from-ctor-realm.js} | 0 .../WeakRef/proto-from-ctor-realm.js | 2 +- .../intl402/Collator/proto-from-ctor-realm.js | 58 +++++++++++++++++++ .../DateTimeFormat/proto-from-ctor-realm.js | 58 +++++++++++++++++++ .../NumberFormat/proto-from-ctor-realm.js | 58 +++++++++++++++++++ .../PluralRules/proto-from-ctor-realm.js | 57 ++++++++++++++++++ 7 files changed, 233 insertions(+), 2 deletions(-) rename test/built-ins/Object/{proto-from-ctor.js => proto-from-ctor-realm.js} (100%) create mode 100644 test/intl402/Collator/proto-from-ctor-realm.js create mode 100644 test/intl402/DateTimeFormat/proto-from-ctor-realm.js create mode 100644 test/intl402/NumberFormat/proto-from-ctor-realm.js create mode 100644 test/intl402/PluralRules/proto-from-ctor-realm.js diff --git a/test/built-ins/FinalizationGroup/proto-from-ctor-realm.js b/test/built-ins/FinalizationGroup/proto-from-ctor-realm.js index 836351fa41..85e9cde441 100644 --- a/test/built-ins/FinalizationGroup/proto-from-ctor-realm.js +++ b/test/built-ins/FinalizationGroup/proto-from-ctor-realm.js @@ -25,7 +25,7 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 5. Return proto. -features: [FinalizationGroup, cross-realm, Reflect] +features: [FinalizationGroup, cross-realm, Reflect, Symbol] ---*/ var other = $262.createRealm().global; diff --git a/test/built-ins/Object/proto-from-ctor.js b/test/built-ins/Object/proto-from-ctor-realm.js similarity index 100% rename from test/built-ins/Object/proto-from-ctor.js rename to test/built-ins/Object/proto-from-ctor-realm.js diff --git a/test/built-ins/WeakRef/proto-from-ctor-realm.js b/test/built-ins/WeakRef/proto-from-ctor-realm.js index 4345e095d1..e1bcb7ea2a 100644 --- a/test/built-ins/WeakRef/proto-from-ctor-realm.js +++ b/test/built-ins/WeakRef/proto-from-ctor-realm.js @@ -26,7 +26,7 @@ info: | a. Let realm be ? GetFunctionRealm(constructor). b. Set proto to realm's intrinsic object named intrinsicDefaultProto. 5. Return proto. -features: [WeakRef, cross-realm, Reflect] +features: [WeakRef, cross-realm, Reflect, Symbol] ---*/ var other = $262.createRealm().global; diff --git a/test/intl402/Collator/proto-from-ctor-realm.js b/test/intl402/Collator/proto-from-ctor-realm.js new file mode 100644 index 0000000000..872fa6fc11 --- /dev/null +++ b/test/intl402/Collator/proto-from-ctor-realm.js @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.collator +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.Collator ( [ locales [ , options ] ] ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + ... + 5. Let collator be ? OrdinaryCreateFromConstructor(newTarget, "%CollatorPrototype%", internalSlotsList). + 6. Return ? InitializeCollator(collator, locales, options). + + 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: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var col; + +newTarget.prototype = undefined; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = true; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = ''; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +col = Reflect.construct(Intl.Collator, [], newTarget); +assert.sameValue(Object.getPrototypeOf(col), other.Intl.Collator.prototype, 'newTarget.prototype is a Number'); diff --git a/test/intl402/DateTimeFormat/proto-from-ctor-realm.js b/test/intl402/DateTimeFormat/proto-from-ctor-realm.js new file mode 100644 index 0000000000..3245a3a4fb --- /dev/null +++ b/test/intl402/DateTimeFormat/proto-from-ctor-realm.js @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.datetimeformat +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.DateTimeFormat ( [ locales [ , options ] ] ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + 2. Let dateTimeFormat be ? OrdinaryCreateFromConstructor(newTarget, "%DateTimeFormatPrototype%", « ... »). + ... + 6. Return dateTimeFormat. + + 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: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var dtf; + +newTarget.prototype = undefined; +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = false; +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = 'str'; +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 1; +dtf = Reflect.construct(Intl.DateTimeFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(dtf), other.Intl.DateTimeFormat.prototype, 'newTarget.prototype is a Number'); diff --git a/test/intl402/NumberFormat/proto-from-ctor-realm.js b/test/intl402/NumberFormat/proto-from-ctor-realm.js new file mode 100644 index 0000000000..4c9ed05501 --- /dev/null +++ b/test/intl402/NumberFormat/proto-from-ctor-realm.js @@ -0,0 +1,58 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.numberformat +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.NumberFormat ( [ locales [ , options ] ] ) + + 1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. + 2. Let numberFormat be ? OrdinaryCreateFromConstructor(newTarget, "%NumberFormatPrototype%", « ... »). + ... + 6. Return numberFormat. + + 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: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var nf; + +newTarget.prototype = undefined; +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = true; +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = 'str'; +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 0; +nf = Reflect.construct(Intl.NumberFormat, [], newTarget); +assert.sameValue(Object.getPrototypeOf(nf), other.Intl.NumberFormat.prototype, 'newTarget.prototype is a Number'); diff --git a/test/intl402/PluralRules/proto-from-ctor-realm.js b/test/intl402/PluralRules/proto-from-ctor-realm.js new file mode 100644 index 0000000000..7cc7a934d7 --- /dev/null +++ b/test/intl402/PluralRules/proto-from-ctor-realm.js @@ -0,0 +1,57 @@ +// Copyright (C) 2019 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.pluralrules +description: Default [[Prototype]] value derived from realm of the NewTarget. +info: | + Intl.PluralRules ( [ locales [ , options ] ] ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let pluralRules be ? OrdinaryCreateFromConstructor(newTarget, "%PluralRulesPrototype%", « ... »). + 3. Return ? InitializePluralRules(pluralRules, locales, options). + + 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: [cross-realm, Reflect, Symbol] +---*/ + +var other = $262.createRealm().global; +var newTarget = new other.Function(); +var pr; + +newTarget.prototype = undefined; +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is undefined'); + +newTarget.prototype = null; +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is null'); + +newTarget.prototype = false; +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Boolean'); + +newTarget.prototype = ''; +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a String'); + +newTarget.prototype = Symbol(); +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Symbol'); + +newTarget.prototype = 0; +pr = Reflect.construct(Intl.PluralRules, [], newTarget); +assert.sameValue(Object.getPrototypeOf(pr), other.Intl.PluralRules.prototype, 'newTarget.prototype is a Number');