Commit a76fe0a2 authored by wingo@igalia.com's avatar wingo@igalia.com

Enable ES6 generators

R=rossberg@chromium.org

BUG=v8:2355
LOG=Y

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23974 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d20bd6da
......@@ -189,6 +189,7 @@ action("js2c") {
"src/regexp.js",
"src/arraybuffer.js",
"src/typedarray.js",
"src/generator.js",
"src/object-observe.js",
"src/collection.js",
"src/weak-collection.js",
......
......@@ -126,7 +126,7 @@ char* Bootstrapper::AllocateAutoDeletedArray(int bytes) {
void Bootstrapper::TearDown() {
if (delete_these_non_arrays_on_tear_down_ != NULL) {
int len = delete_these_non_arrays_on_tear_down_->length();
DCHECK(len < 27); // Don't use this mechanism for unbounded allocations.
DCHECK(len < 28); // Don't use this mechanism for unbounded allocations.
for (int i = 0; i < len; i++) {
delete delete_these_non_arrays_on_tear_down_->at(i);
delete_these_non_arrays_on_tear_down_->at(i) = NULL;
......@@ -203,7 +203,6 @@ class Genesis BASE_EMBEDDED {
// New context initialization. Used for creating a context from scratch.
void InitializeGlobal(Handle<GlobalObject> global_object,
Handle<JSFunction> empty_function);
void InitializeExperimentalGlobal();
// Installs the contents of the native .js files on the global objects.
// Used for creating a context from scratch.
void InstallNativeFunctions();
......@@ -1352,74 +1351,6 @@ void Genesis::InstallTypedArray(
}
void Genesis::InitializeExperimentalGlobal() {
// TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no
// longer need to live behind flags, so functions get added to the snapshot.
if (FLAG_harmony_generators) {
// Create generator meta-objects and install them on the builtins object.
Handle<JSObject> builtins(native_context()->builtins());
Handle<JSObject> generator_object_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
Handle<JSFunction> generator_function_prototype = InstallFunction(
builtins, "GeneratorFunctionPrototype", JS_FUNCTION_TYPE,
JSFunction::kHeaderSize, generator_object_prototype,
Builtins::kIllegal);
InstallFunction(builtins, "GeneratorFunction",
JS_FUNCTION_TYPE, JSFunction::kSize,
generator_function_prototype, Builtins::kIllegal);
// Create maps for generator functions and their prototypes. Store those
// maps in the native context.
Handle<Map> sloppy_function_map(native_context()->sloppy_function_map());
Handle<Map> generator_function_map = Map::Copy(sloppy_function_map);
generator_function_map->set_prototype(*generator_function_prototype);
native_context()->set_sloppy_generator_function_map(
*generator_function_map);
// The "arguments" and "caller" instance properties aren't specified, so
// technically we could leave them out. They make even less sense for
// generators than for functions. Still, the same argument that it makes
// sense to keep them around but poisoned in strict mode applies to
// generators as well. With poisoned accessors, naive callers can still
// iterate over the properties without accessing them.
//
// We can't use PoisonArgumentsAndCaller because that mutates accessor pairs
// in place, and the initial state of the generator function map shares the
// accessor pair with sloppy functions. Also the error message should be
// different. Also unhappily, we can't use the API accessors to implement
// poisoning, because API accessors present themselves as data properties,
// not accessor properties, and so getOwnPropertyDescriptor raises an
// exception as it tries to get the values. Sadness.
Handle<AccessorPair> poison_pair(factory()->NewAccessorPair());
PropertyAttributes rw_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
Handle<JSFunction> poison_function = GetGeneratorPoisonFunction();
poison_pair->set_getter(*poison_function);
poison_pair->set_setter(*poison_function);
ReplaceAccessors(generator_function_map, factory()->arguments_string(),
rw_attribs, poison_pair);
ReplaceAccessors(generator_function_map, factory()->caller_string(),
rw_attribs, poison_pair);
Handle<Map> strict_function_map(native_context()->strict_function_map());
Handle<Map> strict_generator_function_map = Map::Copy(strict_function_map);
// "arguments" and "caller" already poisoned.
strict_generator_function_map->set_prototype(*generator_function_prototype);
native_context()->set_strict_generator_function_map(
*strict_generator_function_map);
Handle<JSFunction> object_function(native_context()->object_function());
Handle<Map> generator_object_prototype_map = Map::Create(
object_function, 0);
generator_object_prototype_map->set_prototype(
*generator_object_prototype);
native_context()->set_generator_object_prototype_map(
*generator_object_prototype_map);
}
}
bool Genesis::CompileBuiltin(Isolate* isolate, int index) {
Vector<const char> name = Natives::GetScriptName(index);
Handle<String> source_code =
......@@ -1923,6 +1854,67 @@ bool Genesis::InstallNatives() {
map_iterator_function->initial_map());
}
{
// Create generator meta-objects and install them on the builtins object.
Handle<JSObject> builtins(native_context()->builtins());
Handle<JSObject> generator_object_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
Handle<JSFunction> generator_function_prototype =
InstallFunction(builtins, "GeneratorFunctionPrototype",
JS_FUNCTION_TYPE, JSFunction::kHeaderSize,
generator_object_prototype, Builtins::kIllegal);
InstallFunction(builtins, "GeneratorFunction", JS_FUNCTION_TYPE,
JSFunction::kSize, generator_function_prototype,
Builtins::kIllegal);
// Create maps for generator functions and their prototypes. Store those
// maps in the native context.
Handle<Map> generator_function_map =
Map::Copy(sloppy_function_map_writable_prototype_);
generator_function_map->set_prototype(*generator_function_prototype);
native_context()->set_sloppy_generator_function_map(
*generator_function_map);
// The "arguments" and "caller" instance properties aren't specified, so
// technically we could leave them out. They make even less sense for
// generators than for functions. Still, the same argument that it makes
// sense to keep them around but poisoned in strict mode applies to
// generators as well. With poisoned accessors, naive callers can still
// iterate over the properties without accessing them.
//
// We can't use PoisonArgumentsAndCaller because that mutates accessor pairs
// in place, and the initial state of the generator function map shares the
// accessor pair with sloppy functions. Also the error message should be
// different. Also unhappily, we can't use the API accessors to implement
// poisoning, because API accessors present themselves as data properties,
// not accessor properties, and so getOwnPropertyDescriptor raises an
// exception as it tries to get the values. Sadness.
Handle<AccessorPair> poison_pair(factory()->NewAccessorPair());
PropertyAttributes rw_attribs =
static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE);
Handle<JSFunction> poison_function = GetGeneratorPoisonFunction();
poison_pair->set_getter(*poison_function);
poison_pair->set_setter(*poison_function);
ReplaceAccessors(generator_function_map, factory()->arguments_string(),
rw_attribs, poison_pair);
ReplaceAccessors(generator_function_map, factory()->caller_string(),
rw_attribs, poison_pair);
Handle<Map> strict_function_map(native_context()->strict_function_map());
Handle<Map> strict_generator_function_map = Map::Copy(strict_function_map);
// "arguments" and "caller" already poisoned.
strict_generator_function_map->set_prototype(*generator_function_prototype);
native_context()->set_strict_generator_function_map(
*strict_generator_function_map);
Handle<JSFunction> object_function(native_context()->object_function());
Handle<Map> generator_object_prototype_map =
Map::Create(object_function, 0);
generator_object_prototype_map->set_prototype(*generator_object_prototype);
native_context()->set_generator_object_prototype_map(
*generator_object_prototype_map);
}
if (FLAG_disable_native_files) {
PrintF("Warning: Running without installed natives!\n");
return true;
......@@ -2096,7 +2088,6 @@ bool Genesis::InstallExperimentalNatives() {
i < ExperimentalNatives::GetBuiltinsCount();
i++) {
INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js")
INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js")
INSTALL_EXPERIMENTAL_NATIVE(i, strings, "harmony-string.js")
INSTALL_EXPERIMENTAL_NATIVE(i, arrays, "harmony-array.js")
INSTALL_EXPERIMENTAL_NATIVE(i, classes, "harmony-classes.js")
......@@ -2657,8 +2648,7 @@ Genesis::Genesis(Isolate* isolate,
isolate->counters()->contexts_created_from_scratch()->Increment();
}
// Initialize experimental globals and install experimental natives.
InitializeExperimentalGlobal();
// Install experimental natives.
if (!InstallExperimentalNatives()) return;
// We can't (de-)serialize typed arrays currently, but we are lucky: The state
......
......@@ -154,7 +154,6 @@ DEFINE_BOOL(harmony_scoping, false, "enable harmony block scoping")
DEFINE_BOOL(harmony_modules, false,
"enable harmony modules (implies block scoping)")
DEFINE_BOOL(harmony_proxies, false, "enable harmony proxies")
DEFINE_BOOL(harmony_generators, false, "enable harmony generators")
DEFINE_BOOL(harmony_numeric_literals, false,
"enable harmony numeric literals (0o77, 0b11)")
DEFINE_BOOL(harmony_strings, false, "enable harmony string")
......@@ -178,7 +177,6 @@ DEFINE_IMPLICATION(harmony, harmony_object_literals)
DEFINE_IMPLICATION(harmony_modules, harmony_scoping)
DEFINE_IMPLICATION(harmony, es_staging)
DEFINE_IMPLICATION(es_staging, harmony_generators)
// Flags for experimental implementation features.
DEFINE_BOOL(compiled_keyed_generic_loads, false,
......
......@@ -755,7 +755,6 @@ Parser::Parser(CompilationInfo* info, ParseInfo* parse_info)
set_allow_modules(!info->is_native() && FLAG_harmony_modules);
set_allow_natives_syntax(FLAG_allow_natives_syntax || info->is_native());
set_allow_lazy(false); // Must be explicitly enabled.
set_allow_generators(FLAG_harmony_generators);
set_allow_arrow_functions(FLAG_harmony_arrow_functions);
set_allow_harmony_numeric_literals(FLAG_harmony_numeric_literals);
set_allow_classes(FLAG_harmony_classes);
......@@ -1893,7 +1892,7 @@ Statement* Parser::ParseFunctionDeclaration(
// '{' FunctionBody '}'
Expect(Token::FUNCTION, CHECK_OK);
int pos = position();
bool is_generator = allow_generators() && Check(Token::MUL);
bool is_generator = Check(Token::MUL);
bool is_strict_reserved = false;
const AstRawString* name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK);
......@@ -3767,7 +3766,6 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
reusable_preparser_->set_allow_modules(allow_modules());
reusable_preparser_->set_allow_natives_syntax(allow_natives_syntax());
reusable_preparser_->set_allow_lazy(true);
reusable_preparser_->set_allow_generators(allow_generators());
reusable_preparser_->set_allow_arrow_functions(allow_arrow_functions());
reusable_preparser_->set_allow_harmony_numeric_literals(
allow_harmony_numeric_literals());
......
......@@ -332,7 +332,7 @@ PreParser::Statement PreParser::ParseFunctionDeclaration(bool* ok) {
// '{' FunctionBody '}'
Expect(Token::FUNCTION, CHECK_OK);
int pos = position();
bool is_generator = allow_generators() && Check(Token::MUL);
bool is_generator = Check(Token::MUL);
bool is_strict_reserved = false;
Identifier name = ParseIdentifierOrStrictReservedWord(
&is_strict_reserved, CHECK_OK);
......
......@@ -83,7 +83,6 @@ class ParserBase : public Traits {
stack_overflow_(false),
allow_lazy_(false),
allow_natives_syntax_(false),
allow_generators_(false),
allow_arrow_functions_(false),
allow_harmony_object_literals_(false),
zone_(zone),
......@@ -93,7 +92,6 @@ class ParserBase : public Traits {
// allowed to be parsed by this instance of the parser.
bool allow_lazy() const { return allow_lazy_; }
bool allow_natives_syntax() const { return allow_natives_syntax_; }
bool allow_generators() const { return allow_generators_; }
bool allow_arrow_functions() const { return allow_arrow_functions_; }
bool allow_modules() const { return scanner()->HarmonyModules(); }
bool allow_harmony_scoping() const { return scanner()->HarmonyScoping(); }
......@@ -109,7 +107,6 @@ class ParserBase : public Traits {
// allowed to be parsed by this instance of the parser.
void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; }
void set_allow_generators(bool allow) { allow_generators_ = allow; }
void set_allow_arrow_functions(bool allow) { allow_arrow_functions_ = allow; }
void set_allow_modules(bool allow) { scanner()->SetHarmonyModules(allow); }
void set_allow_harmony_scoping(bool allow) {
......@@ -583,7 +580,6 @@ class ParserBase : public Traits {
bool allow_lazy_;
bool allow_natives_syntax_;
bool allow_generators_;
bool allow_arrow_functions_;
bool allow_harmony_object_literals_;
......@@ -2416,7 +2412,7 @@ ParserBase<Traits>::ParseMemberExpression(bool* ok) {
if (peek() == Token::FUNCTION) {
Consume(Token::FUNCTION);
int function_token_position = position();
bool is_generator = allow_generators() && Check(Token::MUL);
bool is_generator = Check(Token::MUL);
IdentifierT name = this->EmptyIdentifier();
bool is_strict_reserved_name = false;
Scanner::Location function_name_location = Scanner::Location::invalid();
......
......@@ -1214,7 +1214,6 @@ enum ParserFlag {
kAllowNativesSyntax,
kAllowHarmonyScoping,
kAllowModules,
kAllowGenerators,
kAllowHarmonyNumericLiterals,
kAllowArrowFunctions,
kAllowClasses,
......@@ -1235,7 +1234,6 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_natives_syntax(flags.Contains(kAllowNativesSyntax));
parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
parser->set_allow_modules(flags.Contains(kAllowModules));
parser->set_allow_generators(flags.Contains(kAllowGenerators));
parser->set_allow_harmony_numeric_literals(
flags.Contains(kAllowHarmonyNumericLiterals));
parser->set_allow_harmony_object_literals(
......@@ -1450,10 +1448,9 @@ TEST(ParserSync) {
i::GetCurrentStackPosition() - 128 * 1024);
static const ParserFlag flags1[] = {
kAllowLazy, kAllowHarmonyScoping,
kAllowModules, kAllowGenerators,
kAllowArrowFunctions, kAllowHarmonyNumericLiterals,
kAllowHarmonyObjectLiterals};
kAllowLazy, kAllowHarmonyScoping,
kAllowModules, kAllowArrowFunctions,
kAllowHarmonyNumericLiterals, kAllowHarmonyObjectLiterals};
for (int i = 0; context_data[i][0] != NULL; ++i) {
for (int j = 0; statement_data[j] != NULL; ++j) {
for (int k = 0; termination_data[k] != NULL; ++k) {
......@@ -1528,11 +1525,10 @@ void RunParserSyncTest(const char* context_data[][2],
i::GetCurrentStackPosition() - 128 * 1024);
static const ParserFlag default_flags[] = {
kAllowArrowFunctions, kAllowClasses,
kAllowGenerators, kAllowHarmonyNumericLiterals,
kAllowHarmonyObjectLiterals, kAllowHarmonyScoping,
kAllowLazy, kAllowModules,
kAllowNativesSyntax,
kAllowArrowFunctions, kAllowClasses,
kAllowHarmonyNumericLiterals, kAllowHarmonyObjectLiterals,
kAllowHarmonyScoping, kAllowLazy,
kAllowModules, kAllowNativesSyntax,
};
ParserFlag* generated_flags = NULL;
if (flags == NULL) {
......@@ -1894,10 +1890,7 @@ TEST(NoErrorsYieldSloppyGeneratorsEnabled) {
NULL
};
// This test requires kAllowGenerators to succeed.
static const ParserFlag always_true_flags[] = { kAllowGenerators };
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_true_flags, 1);
RunParserSyncTest(context_data, statement_data, kSuccess);
}
......@@ -1990,12 +1983,7 @@ TEST(NoErrorsGenerator) {
NULL
};
// This test requires kAllowGenerators to succeed.
static const ParserFlag always_true_flags[] = {
kAllowGenerators
};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_true_flags, 1);
RunParserSyncTest(context_data, statement_data, kSuccess);
}
......@@ -2106,12 +2094,7 @@ TEST(NoErrorsNameOfStrictGenerator) {
NULL
};
// This test requires kAllowGenerators to succeed.
static const ParserFlag always_true_flags[] = {
kAllowGenerators
};
RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
always_true_flags, 1);
RunParserSyncTest(context_data, statement_data, kSuccess);
}
......@@ -3310,9 +3293,7 @@ TEST(ErrorsArrowFunctions) {
};
// The test is quite slow, so run it with a reduced set of flags.
static const ParserFlag flags[] = {
kAllowLazy, kAllowHarmonyScoping, kAllowGenerators
};
static const ParserFlag flags[] = {kAllowLazy, kAllowHarmonyScoping};
static const ParserFlag always_flags[] = { kAllowArrowFunctions };
RunParserSyncTest(context_data, statement_data, kError, flags,
arraysize(flags), always_flags, arraysize(always_flags));
......
......@@ -59,7 +59,7 @@ for (i = 0; i < scripts.length; i++) {
}
// This has to be updated if the number of native scripts change.
assertTrue(named_native_count == 25 || named_native_count == 26);
assertTrue(named_native_count == 26 || named_native_count == 27);
// Only the 'gc' extension is loaded.
assertEquals(1, extension_count);
// This script and mjsunit.js has been loaded. If using d8, d8 loads
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --harmony-generators
// Flags: --expose-debug-as debug
var Debug = debug.Debug;
var LiveEdit = Debug.LiveEdit;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --harmony-generators
// Flags: --expose-debug-as debug
var Debug = debug.Debug;
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators --expose-gc
// Flags: --expose-gc
// Test generator iteration.
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators --harmony-scoping --allow-natives-syntax
// Flags: --harmony-scoping --allow-natives-syntax
// Test instantations of generators.
......
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators
// Test basic generator syntax.
// Yield statements.
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-generators
function assertIteratorResult(value, done, result) {
assertEquals({value: value, done: done}, result);
}
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --harmony-generators
// Flags: --expose-debug-as debug
var Debug = debug.Debug;
......
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators
// Test aspects of the generator runtime.
// See:
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators --harmony-scoping --harmony-proxies
// Flags: --harmony-scoping --harmony-proxies
// Test for-of semantics.
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-gc --noincremental-marking --harmony-generators
// Flags: --expose-gc --noincremental-marking
// Check that we are not flushing code for generators.
......
......@@ -25,8 +25,6 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-generators
// Check that yield* on non-objects raises a TypeError.
assertThrows('(function*() { yield* 10 })().next()', TypeError);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --harmony-generators --expose-debug-as debug
// Flags: --expose-debug-as debug
var Debug = debug.Debug;
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --expose-debug-as debug --harmony-generators
// Flags: --expose-debug-as debug
Debug = debug.Debug
......
......@@ -1521,6 +1521,7 @@
'../../src/regexp.js',
'../../src/arraybuffer.js',
'../../src/typedarray.js',
'../../src/generator.js',
'../../src/object-observe.js',
'../../src/collection.js',
'../../src/weak-collection.js',
......
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