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

Unified Diff: src/collection.js

Issue 238063009: ES6: Add support for Map/Set forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Remove explicit instantiation of private and functions in objects-inl.h Created 6 years, 8 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/bootstrapper.cc ('k') | src/contexts.h » ('j') | src/objects-printer.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index 9054187a12d0372ef1e028569a197059579f26ba..f2b481b8e73e4b85bb08a73636865e1806de3ccc 100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -113,8 +113,29 @@ function SetClear() {
throw MakeTypeError('incompatible_method_receiver',
['Set.prototype.clear', this]);
}
- // Replace the internal table with a new empty table.
- %SetInitialize(this);
+ %SetClear(this);
+}
+
+
+function SetForEach(f, receiver) {
+ if (!IS_SET(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['Set.prototype.forEach', this]);
+ }
+
+ if (!IS_SPEC_FUNCTION(f)) {
+ throw MakeTypeError('called_non_callable', [f]);
+ }
+
+ var iterator = %SetCreateIterator(this, ITERATOR_KIND_VALUES);
+ var entry;
+ try {
+ while (!(entry = %SetIteratorNext(iterator)).done) {
+ %_CallFunction(receiver, entry.value, entry.value, this, f);
+ }
+ } finally {
+ %SetIteratorClose(iterator);
+ }
}
@@ -127,13 +148,16 @@ function SetUpSet() {
%FunctionSetPrototype($Set, new $Object());
%SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
+ %FunctionSetLength(SetForEach, 1);
+
// Set up the non-enumerable functions on the Set prototype object.
InstallGetter($Set.prototype, "size", SetGetSize);
InstallFunctions($Set.prototype, DONT_ENUM, $Array(
"add", SetAdd,
"has", SetHas,
"delete", SetDelete,
- "clear", SetClear
+ "clear", SetClear,
+ "forEach", SetForEach
));
}
@@ -202,8 +226,29 @@ function MapClear() {
throw MakeTypeError('incompatible_method_receiver',
['Map.prototype.clear', this]);
}
- // Replace the internal table with a new empty table.
- %MapInitialize(this);
+ %MapClear(this);
+}
+
+
+function MapForEach(f, receiver) {
+ if (!IS_MAP(this)) {
+ throw MakeTypeError('incompatible_method_receiver',
+ ['Map.prototype.forEach', this]);
+ }
+
+ if (!IS_SPEC_FUNCTION(f)) {
+ throw MakeTypeError('called_non_callable', [f]);
+ }
+
+ var iterator = %MapCreateIterator(this, ITERATOR_KIND_ENTRIES);
+ var entry;
+ try {
+ while (!(entry = %MapIteratorNext(iterator)).done) {
+ %_CallFunction(receiver, entry.value[1], entry.value[0], this, f);
+ }
+ } finally {
+ %MapIteratorClose(iterator);
+ }
}
@@ -216,6 +261,8 @@ function SetUpMap() {
%FunctionSetPrototype($Map, new $Object());
%SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
+ %FunctionSetLength(MapForEach, 1);
+
// Set up the non-enumerable functions on the Map prototype object.
InstallGetter($Map.prototype, "size", MapGetSize);
InstallFunctions($Map.prototype, DONT_ENUM, $Array(
@@ -223,7 +270,8 @@ function SetUpMap() {
"set", MapSet,
"has", MapHas,
"delete", MapDelete,
- "clear", MapClear
+ "clear", MapClear,
+ "forEach", MapForEach
));
}
« no previous file with comments | « src/bootstrapper.cc ('k') | src/contexts.h » ('j') | src/objects-printer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698