Commit f7b59122 authored by mike's avatar mike Committed by Commit bot

[es6] Define generator prototype as writable prop

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}
parent a8d9c58b
...@@ -2205,9 +2205,11 @@ bool Genesis::InstallNatives() { ...@@ -2205,9 +2205,11 @@ bool Genesis::InstallNatives() {
Builtins::kIllegal, kUseStrictFunctionMap); Builtins::kIllegal, kUseStrictFunctionMap);
// Create maps for generator functions and their prototypes. Store those // Create maps for generator functions and their prototypes. Store those
// maps in the native context. Generator functions do not have writable // maps in the native context. The "prototype" property descriptor is
// prototypes, nor do they have "caller" or "arguments" accessors. // writable, non-enumerable, and non-configurable (as per ES6 draft
Handle<Map> strict_function_map(native_context()->strict_function_map()); // 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 = Handle<Map> sloppy_generator_function_map =
Map::Copy(strict_function_map, "SloppyGeneratorFunction"); Map::Copy(strict_function_map, "SloppyGeneratorFunction");
Map::SetPrototype(sloppy_generator_function_map, Map::SetPrototype(sloppy_generator_function_map,
......
...@@ -52,17 +52,10 @@ function TestGeneratorFunctionInstance() { ...@@ -52,17 +52,10 @@ function TestGeneratorFunctionInstance() {
var prop = f_own_property_names[i]; var prop = f_own_property_names[i];
var f_desc = Object.getOwnPropertyDescriptor(f, prop); var f_desc = Object.getOwnPropertyDescriptor(f, prop);
var g_desc = Object.getOwnPropertyDescriptor(g, 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.configurable, g_desc.configurable, prop);
assertEquals(f_desc.writable, g_desc.writable, prop); assertEquals(f_desc.writable, g_desc.writable, prop);
assertEquals(f_desc.enumerable, g_desc.enumerable, prop); assertEquals(f_desc.enumerable, g_desc.enumerable, prop);
} }
}
} }
TestGeneratorFunctionInstance(); TestGeneratorFunctionInstance();
...@@ -156,6 +149,13 @@ function TestGeneratorFunction() { ...@@ -156,6 +149,13 @@ function TestGeneratorFunction() {
assertTrue((new GeneratorFunction()) instanceof GeneratorFunction); assertTrue((new GeneratorFunction()) instanceof GeneratorFunction);
assertTrue(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(); TestGeneratorFunction();
......
...@@ -156,6 +156,7 @@ ...@@ -156,6 +156,7 @@
var GeneratorFunction = function*() {}.__proto__.constructor; var GeneratorFunction = function*() {}.__proto__.constructor;
var GeneratorPrototype = Object.getPrototypeOf(function*() {}).prototype;
function assertIteratorResult(value, done, result) { function assertIteratorResult(value, done, result) {
...@@ -215,6 +216,19 @@ 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() { (function TestGeneratorProto() {
var object = { var object = {
*method() {} *method() {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment