v8/test/mjsunit/harmony/classes-experimental.js
dslomov 8e4ec9dd13 Revert of new classes: implement new.target passing to superclass constructor. (patchset #9 id:150001 of https://codereview.chromium.org/908883002/)
Reason for revert:
Breaks Linux64 release

Original issue's description:
> new classes: implement new.target passing to superclass constructor.
>
> R=arv@chromium.org,rossberg@chromium.org
> BUG=v8:3834
> LOG=N
>
> Committed: https://crrev.com/8aed43e82c6d2742fe5988603cb8841324cc942b
> Cr-Commit-Position: refs/heads/master@{#26560}

TBR=arv@chromium.org,rossberg@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:3834

Review URL: https://codereview.chromium.org/911363002

Cr-Commit-Position: refs/heads/master@{#26561}
2015-02-11 01:36:32 +00:00

68 lines
1.4 KiB
JavaScript

// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Flags: --experimental-classes --harmony-classes
'use strict';
class Base {
constructor(a, b) {
let o = new Object();
o.prp = a + b;
return o;
}
}
class Subclass extends Base {
constructor(a, b) {
var exn;
try {
this.prp1 = 3;
} catch (e) {
exn = e;
}
assertTrue(exn instanceof ReferenceError);
super(a, b);
assertSame(a + b, this.prp);
assertSame(undefined, this.prp1);
assertFalse(this.hasOwnProperty("prp1"));
return this;
}
}
let b = new Base(1, 2);
assertSame(3, b.prp);
let s = new Subclass(2, -1);
assertSame(1, s.prp);
assertSame(undefined, s.prp1);
assertFalse(s.hasOwnProperty("prp1"));
class Subclass2 extends Base {
constructor(x) {
super(1,2);
if (x < 0) return;
let called = false;
function tmp() { called = true; return 3; }
var exn = null;
try {
super(tmp(),4);
} catch(e) { exn = e; }
assertTrue(exn !== null);
assertFalse(called);
}
}
var s2 = new Subclass2(1);
assertSame(3, s2.prp);
var s3 = new Subclass2(-1);
assertSame(3, s3.prp);
assertThrows(function() { Subclass.call(new Object(), 1, 2); }, TypeError);
assertThrows(function() { Base.call(new Object(), 1, 2); }, TypeError);