[es6] Fix Object built-in subclassing.
BUG=v8:3886 LOG=Y Review URL: https://codereview.chromium.org/1422853004 Cr-Commit-Position: refs/heads/master@{#31760}
This commit is contained in:
parent
208744bc10
commit
059478165c
@ -1311,14 +1311,13 @@ function ObjectSetProto(proto) {
|
||||
}
|
||||
|
||||
|
||||
// ECMA-262, Edition 6, section 19.1.1.1
|
||||
function ObjectConstructor(x) {
|
||||
if (%_IsConstructCall()) {
|
||||
if (x == null) return this;
|
||||
return TO_OBJECT(x);
|
||||
} else {
|
||||
if (x == null) return { };
|
||||
return TO_OBJECT(x);
|
||||
if (GlobalObject != new.target && !IS_UNDEFINED(new.target)) {
|
||||
return this;
|
||||
}
|
||||
if (IS_NULL(x) || IS_UNDEFINED(x)) return {};
|
||||
return TO_OBJECT(x);
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,6 +17,55 @@ function checkPrototypeChain(object, constructors) {
|
||||
}
|
||||
|
||||
|
||||
(function() {
|
||||
class A extends Object {
|
||||
constructor(...args) {
|
||||
assertTrue(%IsConstructCall());
|
||||
super(...args);
|
||||
this.a = 42;
|
||||
this.d = 4.2;
|
||||
}
|
||||
}
|
||||
|
||||
var s = new A("foo");
|
||||
assertTrue(s instanceof Object);
|
||||
assertTrue(s instanceof A);
|
||||
assertEquals("object", typeof s);
|
||||
checkPrototypeChain(s, [A, Object]);
|
||||
assertEquals(42, s.a);
|
||||
assertEquals(4.2, s.d);
|
||||
|
||||
var s1 = new A("bar");
|
||||
assertTrue(%HaveSameMap(s, s1));
|
||||
|
||||
|
||||
var n = new A(153);
|
||||
assertTrue(n instanceof Object);
|
||||
assertTrue(n instanceof A);
|
||||
assertEquals("object", typeof s);
|
||||
checkPrototypeChain(s, [A, Object]);
|
||||
assertEquals(42, n.a);
|
||||
assertEquals(4.2, n.d);
|
||||
|
||||
var n1 = new A(312);
|
||||
assertTrue(%HaveSameMap(n, n1));
|
||||
assertTrue(%HaveSameMap(n, s));
|
||||
|
||||
|
||||
var b = new A(true);
|
||||
assertTrue(b instanceof Object);
|
||||
assertTrue(b instanceof A);
|
||||
assertEquals("object", typeof s);
|
||||
checkPrototypeChain(s, [A, Object]);
|
||||
assertEquals(42, b.a);
|
||||
assertEquals(4.2, b.d);
|
||||
|
||||
var b1 = new A(true);
|
||||
assertTrue(%HaveSameMap(b, b1));
|
||||
assertTrue(%HaveSameMap(b, s));
|
||||
})();
|
||||
|
||||
|
||||
(function() {
|
||||
class A extends Function {
|
||||
constructor(...args) {
|
||||
|
@ -1978,8 +1978,8 @@ TestKeyedSetterCreatingOwnPropertiesNonConfigurable(42, 43, 44);
|
||||
class F extends Object { }
|
||||
var f = new F(42);
|
||||
|
||||
// TODO(dslomov,arv): Fix this. BUG=v8:3886.
|
||||
assertInstanceof(f, Number);
|
||||
assertInstanceof(f, F);
|
||||
assertInstanceof(f, Object);
|
||||
}());
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user