Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1671)

Unified Diff: test/mjsunit/harmony/classes-derived-return-type.js

Issue 1107203002: [es6] Fix return checking in derived constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix issue where the temp var was not declared in the right scope Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/classes-derived-return-type.js
diff --git a/test/mjsunit/harmony/classes-derived-return-type.js b/test/mjsunit/harmony/classes-derived-return-type.js
new file mode 100644
index 0000000000000000000000000000000000000000..8283bcb2270f13f41f1f3bbabb00c07de69a2766
--- /dev/null
+++ b/test/mjsunit/harmony/classes-derived-return-type.js
@@ -0,0 +1,90 @@
+// Copyright 2015 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: --harmony-sloppy
+
+
+class Base {}
+
+class DerivedWithReturn extends Base {
+ constructor(x) {
+ super();
+ return x;
+ }
+}
+
+assertThrows(function() {
+ new DerivedWithReturn(null);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturn(42);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturn(true);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturn('hi');
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturn(Symbol());
+}, TypeError);
+
+
+assertInstanceof(new DerivedWithReturn(undefined), DerivedWithReturn);
+function f() {}
+assertInstanceof(new DerivedWithReturn(new f()), f);
+assertInstanceof(new DerivedWithReturn(/re/), RegExp);
+
+
+class DerivedWithReturnNoSuper extends Base {
+ constructor(x) {
+ return x;
+ }
+}
+
+
+assertThrows(function() {
+ new DerivedWithReturnNoSuper(null);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturnNoSuper(42);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturnNoSuper(true);
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturnNoSuper('hi');
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturnNoSuper(Symbol());
+}, TypeError);
+assertThrows(function() {
+ new DerivedWithReturnNoSuper(undefined);
+}, ReferenceError);
+
+
+function f2() {}
+assertInstanceof(new DerivedWithReturnNoSuper(new f2()), f2);
+assertInstanceof(new DerivedWithReturnNoSuper(/re/), RegExp);
+
+
+class DerivedReturn extends Base {
+ constructor() {
+ super();
+ return;
+ }
+}
+
+assertInstanceof(new DerivedReturn(), DerivedReturn);
+
+
+
+class DerivedReturnThis extends Base {
+ constructor() {
+ super();
+ return this;
+ }
+}
+
+assertInstanceof(new DerivedReturnThis(), DerivedReturnThis);
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698