mirror of https://github.com/tc39/test262.git
Add "proto-from-ctor-realm" tests for Intl proposals (#2346)
* Add Intl.Segmenter test * Add Intl.RelativeTimeFormat test * Add Intl.Locale test * Add Intl.ListFormat test
This commit is contained in:
parent
13882715c3
commit
34cbf0aed2
|
@ -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.ListFormat
|
||||
description: Default [[Prototype]] value derived from realm of the NewTarget.
|
||||
info: |
|
||||
Intl.ListFormat ( [ locales [ , options ] ] )
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. Let listFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%ListFormatPrototype%", « ... »).
|
||||
...
|
||||
24. Return listFormat.
|
||||
|
||||
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.ListFormat, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
var lf;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = 'str';
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = NaN;
|
||||
lf = Reflect.construct(Intl.ListFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(lf), other.Intl.ListFormat.prototype, 'newTarget.prototype is a Number');
|
|
@ -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.Locale
|
||||
description: Default [[Prototype]] value derived from realm of the NewTarget.
|
||||
info: |
|
||||
Intl.Locale ( tag [ , options] )
|
||||
|
||||
...
|
||||
6. Let locale be ? OrdinaryCreateFromConstructor(NewTarget, %LocalePrototype%, internalSlotsList).
|
||||
...
|
||||
38. Return locale.
|
||||
|
||||
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.Locale, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
var locale;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = 'str';
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 0;
|
||||
locale = Reflect.construct(Intl.Locale, ['de'], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(locale), other.Intl.Locale.prototype, 'newTarget.prototype is a Number');
|
|
@ -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.RelativeTimeFormat
|
||||
description: Default [[Prototype]] value derived from realm of the NewTarget.
|
||||
info: |
|
||||
Intl.RelativeTimeFormat ([ locales [ , options ]])
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. Let relativeTimeFormat be ? OrdinaryCreateFromConstructor(NewTarget, "%RelativeTimeFormatPrototype%", « ... »).
|
||||
3. Return ? InitializeRelativeTimeFormat(relativeTimeFormat, 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: [Intl.RelativeTimeFormat, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
var rtf;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = true;
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = '';
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = -1;
|
||||
rtf = Reflect.construct(Intl.RelativeTimeFormat, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(rtf), other.Intl.RelativeTimeFormat.prototype, 'newTarget.prototype is a Number');
|
|
@ -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.Segmenter
|
||||
description: Default [[Prototype]] value derived from realm of the NewTarget.
|
||||
info: |
|
||||
Intl.Segmenter ([ locales [ , options ]])
|
||||
|
||||
1. If NewTarget is undefined, throw a TypeError exception.
|
||||
2. Let segmenter be ? OrdinaryCreateFromConstructor(NewTarget, "%SegmenterPrototype%", « [[InitializedSegmenter]] »).
|
||||
...
|
||||
14. Return segmenter.
|
||||
|
||||
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.Segmenter, cross-realm, Reflect, Symbol]
|
||||
---*/
|
||||
|
||||
var other = $262.createRealm().global;
|
||||
var newTarget = new other.Function();
|
||||
var seg;
|
||||
|
||||
newTarget.prototype = undefined;
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is undefined');
|
||||
|
||||
newTarget.prototype = null;
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is null');
|
||||
|
||||
newTarget.prototype = false;
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Boolean');
|
||||
|
||||
newTarget.prototype = 'str';
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a String');
|
||||
|
||||
newTarget.prototype = Symbol();
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Symbol');
|
||||
|
||||
newTarget.prototype = 1;
|
||||
seg = Reflect.construct(Intl.Segmenter, [], newTarget);
|
||||
assert.sameValue(Object.getPrototypeOf(seg), other.Intl.Segmenter.prototype, 'newTarget.prototype is a Number');
|
Loading…
Reference in New Issue