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
This commit is contained in:
Alexey Shvayka 2019-09-11 23:22:21 +03:00 committed by Leo Balter
parent 652cfc764a
commit ef7fd2bc27
7 changed files with 233 additions and 2 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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');

View File

@ -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');

View File

@ -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');

View File

@ -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');