1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// |reftest| skip-if(!this.hasOwnProperty("Intl"))
// Test subclassing %Intl.PluralRules% works correctly.
class MyPluralRules extends Intl.PluralRules {}
var obj = new MyPluralRules();
assertEq(obj instanceof MyPluralRules, true);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype);
obj = Reflect.construct(MyPluralRules, []);
assertEq(obj instanceof MyPluralRules, true);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype);
obj = Reflect.construct(MyPluralRules, [], MyPluralRules);
assertEq(obj instanceof MyPluralRules, true);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), MyPluralRules.prototype);
obj = Reflect.construct(MyPluralRules, [], Intl.PluralRules);
assertEq(obj instanceof MyPluralRules, false);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype);
// Set a different constructor as NewTarget.
obj = Reflect.construct(MyPluralRules, [], Array);
assertEq(obj instanceof MyPluralRules, false);
assertEq(obj instanceof Intl.PluralRules, false);
assertEq(obj instanceof Array, true);
assertEq(Object.getPrototypeOf(obj), Array.prototype);
obj = Reflect.construct(Intl.PluralRules, [], Array);
assertEq(obj instanceof Intl.PluralRules, false);
assertEq(obj instanceof Array, true);
assertEq(Object.getPrototypeOf(obj), Array.prototype);
// The prototype defaults to %PluralRulesPrototype% if null.
function NewTargetNullPrototype() {}
NewTargetNullPrototype.prototype = null;
obj = Reflect.construct(Intl.PluralRules, [], NewTargetNullPrototype);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype);
obj = Reflect.construct(MyPluralRules, [], NewTargetNullPrototype);
assertEq(obj instanceof MyPluralRules, false);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype);
// "prototype" property is retrieved exactly once.
var trapLog = [], getLog = [];
var ProxiedConstructor = new Proxy(Intl.PluralRules, new Proxy({
get(target, propertyKey, receiver) {
getLog.push(propertyKey);
return Reflect.get(target, propertyKey, receiver);
}
}, {
get(target, propertyKey, receiver) {
trapLog.push(propertyKey);
return Reflect.get(target, propertyKey, receiver);
}
}));
obj = Reflect.construct(Intl.PluralRules, [], ProxiedConstructor);
assertEqArray(trapLog, ["get"]);
assertEqArray(getLog, ["prototype"]);
assertEq(obj instanceof Intl.PluralRules, true);
assertEq(Object.getPrototypeOf(obj), Intl.PluralRules.prototype);
if (typeof reportCompare === "function")
reportCompare(0, 0);
|