[es6] Class extends may not be a generator function
authorarv <arv@chromium.org>
Wed, 22 Apr 2015 16:07:34 +0000 (09:07 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 22 Apr 2015 16:07:21 +0000 (16:07 +0000)
BUG=v8:4009
LOG=N
R=dslomov@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#28016}

src/messages.js
src/runtime/runtime-classes.cc
test/mjsunit/harmony/classes.js

index f50e8e7..0e48ae6 100644 (file)
@@ -157,6 +157,7 @@ var kMessages = {
   duplicate_export:              ["Duplicate export of '", "%0", "'"],
   unexpected_super:              ["'super' keyword unexpected here"],
   extends_value_not_a_function:  ["Class extends value ", "%0", " is not a function or null"],
+  extends_value_generator:       ["Class extends value ", "%0", " may not be a generator function"],
   prototype_parent_not_an_object: ["Class extends value does not have valid prototype property ", "%0"],
   duplicate_constructor:         ["A class may only have one constructor"],
   super_constructor_call:        ["A 'super' constructor call may only appear as the first statement of a function, and its arguments may not access 'this'. Other forms are not yet supported."],
index 167abcc..dafaacf 100644 (file)
@@ -119,6 +119,12 @@ RUNTIME_FUNCTION(Runtime_DefineClass) {
     if (super_class->IsNull()) {
       prototype_parent = isolate->factory()->null_value();
     } else if (super_class->IsSpecFunction()) {
+      if (Handle<JSFunction>::cast(super_class)->shared()->is_generator()) {
+        Handle<Object> args[1] = {super_class};
+        THROW_NEW_ERROR_RETURN_FAILURE(
+            isolate,
+            NewTypeError("extends_value_generator", HandleVector(args, 1)));
+      }
       ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
           isolate, prototype_parent,
           Runtime::GetObjectProperty(isolate, super_class,
index b74b288..9c09041 100644 (file)
     class C extends Math.abs {}
   }, TypeError);
   delete Math.abs.prototype;
+
+  assertThrows(function() {
+    function* g() {}
+    class C extends g {}
+  }, TypeError);
 })();