[es6] Define generator prototype as writable prop
authormike <mike@mikepennisi.com>
Tue, 26 May 2015 18:31:35 +0000 (11:31 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 26 May 2015 18:31:49 +0000 (18:31 +0000)
The April 14 2015 final draft of the ES6 specification states that the
`prototype` property of generator function instances should be writable.

BUG=v8:4140, v8:4140
LOG=N
R=arv@chromium.org

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

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

src/bootstrapper.cc
test/mjsunit/es6/generators-runtime.js
test/mjsunit/harmony/object-literals-method.js

index eee9bd3..dd6310b 100644 (file)
@@ -2205,9 +2205,11 @@ bool Genesis::InstallNatives() {
                     Builtins::kIllegal, kUseStrictFunctionMap);
 
     // Create maps for generator functions and their prototypes.  Store those
-    // maps in the native context. Generator functions do not have writable
-    // prototypes, nor do they have "caller" or "arguments" accessors.
-    Handle<Map> strict_function_map(native_context()->strict_function_map());
+    // maps in the native context. The "prototype" property descriptor is
+    // writable, non-enumerable, and non-configurable (as per ES6 draft
+    // 04-14-15, section 25.2.4.3).
+    Handle<Map> strict_function_map(strict_function_map_writable_prototype_);
+    // Generator functions do not have "caller" or "arguments" accessors.
     Handle<Map> sloppy_generator_function_map =
         Map::Copy(strict_function_map, "SloppyGeneratorFunction");
     Map::SetPrototype(sloppy_generator_function_map,
index 72a47d0..98015b7 100644 (file)
@@ -52,16 +52,9 @@ function TestGeneratorFunctionInstance() {
     var prop = f_own_property_names[i];
     var f_desc = Object.getOwnPropertyDescriptor(f, prop);
     var g_desc = Object.getOwnPropertyDescriptor(g, prop);
-    if (prop === "prototype") {
-      // ES6 draft 03-17-2015 section 25.2.2.2
-      assertFalse(g_desc.writable, prop);
-      assertFalse(g_desc.enumerable, prop);
-      assertFalse(g_desc.configurable, prop);
-    } else {
-      assertEquals(f_desc.configurable, g_desc.configurable, prop);
-      assertEquals(f_desc.writable, g_desc.writable, prop);
-      assertEquals(f_desc.enumerable, g_desc.enumerable, prop);
-    }
+    assertEquals(f_desc.configurable, g_desc.configurable, prop);
+    assertEquals(f_desc.writable, g_desc.writable, prop);
+    assertEquals(f_desc.enumerable, g_desc.enumerable, prop);
   }
 }
 TestGeneratorFunctionInstance();
@@ -156,6 +149,13 @@ function TestGeneratorFunction() {
 
   assertTrue((new GeneratorFunction()) instanceof GeneratorFunction);
   assertTrue(GeneratorFunction() instanceof GeneratorFunction);
+
+  // ES6 draft 04-14-15, section 25.2.2.2
+  var prototype_desc = Object.getOwnPropertyDescriptor(GeneratorFunction,
+      "prototype");
+  assertFalse(prototype_desc.writable);
+  assertFalse(prototype_desc.enumerable);
+  assertFalse(prototype_desc.configurable);
 }
 TestGeneratorFunction();
 
index 535231e..d2879ad 100644 (file)
 
 
 var GeneratorFunction = function*() {}.__proto__.constructor;
+var GeneratorPrototype = Object.getPrototypeOf(function*() {}).prototype;
 
 
 function assertIteratorResult(value, done, result) {
@@ -215,6 +216,19 @@ function assertIteratorResult(value, done, result) {
 })();
 
 
+(function TestGeneratorPrototypeDescriptor() {
+  var object = {
+    *method() {}
+  };
+
+  var desc = Object.getOwnPropertyDescriptor(object.method, 'prototype');
+  assertFalse(desc.enumerable);
+  assertFalse(desc.configurable);
+  assertTrue(desc.writable);
+  assertEquals(GeneratorPrototype, Object.getPrototypeOf(desc.value));
+})();
+
+
 (function TestGeneratorProto() {
   var object = {
     *method() {}