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

Unified Diff: src/bootstrapper.cc

Issue 2348493003: [builtins] move String.prototype[@@iterator] to C++ builtin (Closed)
Patch Set: V8 (rebase + fix bytecode expectations) Created 4 years, 3 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/ast/ast-types.cc ('k') | src/builtins/builtins.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index e5745e400a5f0bf8f51e2ce46ee85b47abf01e07..42a064c823aee39503716702bc1d4c0dd6886adc 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -660,6 +660,16 @@ void Genesis::CreateIteratorMaps(Handle<JSFunction> empty) {
// Create iterator-related meta-objects.
Handle<JSObject> iterator_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
+
+ Handle<JSFunction> iterator_prototype_iterator = SimpleCreateFunction(
+ isolate(), factory()->NewStringFromAsciiChecked("[Symbol.iterator]"),
+ Builtins::kIteratorPrototypeIterator, 0, false);
+ iterator_prototype_iterator->shared()->set_native(true);
+
+ JSObject::AddProperty(iterator_prototype, factory()->iterator_symbol(),
+ iterator_prototype_iterator, DONT_ENUM);
+ native_context()->set_initial_iterator_prototype(*iterator_prototype);
+
Handle<JSObject> generator_object_prototype =
factory()->NewJSObject(isolate()->object_function(), TENURED);
native_context()->set_initial_generator_prototype(
@@ -1408,6 +1418,38 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
Builtins::kStringPrototypeTrimRight, 0, false);
SimpleInstallFunction(prototype, "valueOf",
Builtins::kStringPrototypeValueOf, 0, true);
+
+ Handle<JSFunction> iterator = SimpleCreateFunction(
+ isolate, factory->NewStringFromAsciiChecked("[Symbol.iterator]"),
+ Builtins::kStringPrototypeIterator, 0, true);
+ iterator->shared()->set_native(true);
+ JSObject::AddProperty(prototype, factory->iterator_symbol(), iterator,
+ static_cast<PropertyAttributes>(DONT_ENUM));
+ }
+
+ { // --- S t r i n g I t e r a t o r ---
+ Handle<JSObject> iterator_prototype(
+ native_context()->initial_iterator_prototype());
+
+ Handle<JSObject> string_iterator_prototype =
+ factory->NewJSObject(isolate->object_function(), TENURED);
+ JSObject::ForceSetPrototype(string_iterator_prototype, iterator_prototype);
+
+ JSObject::AddProperty(
+ string_iterator_prototype, factory->to_string_tag_symbol(),
+ factory->NewStringFromAsciiChecked("String Iterator"),
+ static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY));
+
+ InstallFunction(string_iterator_prototype, "next", JS_OBJECT_TYPE,
+ JSObject::kHeaderSize, MaybeHandle<JSObject>(),
+ Builtins::kStringIteratorPrototypeNext);
+
+ Handle<JSFunction> string_iterator_function = CreateFunction(
+ isolate, factory->NewStringFromAsciiChecked("StringIterator"),
+ JS_STRING_ITERATOR_TYPE, JSStringIterator::kSize,
+ string_iterator_prototype, Builtins::kIllegal);
+ native_context()->set_string_iterator_map(
+ string_iterator_function->initial_map());
}
{
@@ -2468,17 +2510,12 @@ void Bootstrapper::ExportFromRuntime(Isolate* isolate,
native_context->set_object_to_string(*to_string);
}
- Handle<JSObject> iterator_prototype;
-
- {
- PrototypeIterator iter(native_context->generator_object_prototype_map());
- iter.Advance(); // Advance to the prototype of generator_object_prototype.
- iterator_prototype = Handle<JSObject>(iter.GetCurrent<JSObject>());
+ Handle<JSObject> iterator_prototype(
+ native_context->initial_iterator_prototype());
- JSObject::AddProperty(container,
- factory->InternalizeUtf8String("IteratorPrototype"),
- iterator_prototype, NONE);
- }
+ JSObject::AddProperty(container,
+ factory->InternalizeUtf8String("IteratorPrototype"),
+ iterator_prototype, NONE);
{
PrototypeIterator iter(native_context->sloppy_generator_function_map());
« no previous file with comments | « src/ast/ast-types.cc ('k') | src/builtins/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698