Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion ES6: Add support for Set and Map clear method (issue 11409002)

Received: by 10.224.219.144 with SMTP id hu16mr5561737qab.1.1352409389986;
        Thu, 08 Nov 2012 13:16:29 -0800 (PST)
X-BeenThere: v8-dev@googlegroups.com
Received: by 10.229.76.209 with SMTP id d17ls6014031qck.6.gmail; Thu, 08 Nov
 2012 13:16:29 -0800 (PST)
Received: by 10.224.207.66 with SMTP id fx2mr5566644qab.7.1352409389043;
        Thu, 08 Nov 2012 13:16:29 -0800 (PST)
Received: by 10.224.207.66 with SMTP id fx2mr5566643qab.7.1352409389001;
        Thu, 08 Nov 2012 13:16:29 -0800 (PST)
Return-Path: <3LCGcUBUJAGkJOYVTPbTJVKLYLcPLd-OYNTHPS....@2uix4h7xygsz66weerlq.apphosting.bounces.google.com>
Received: from mail-qc0-f198.google.com (mail-qc0-f198.google.com [209.85.216.198])
        by gmr-mx.google.com with ESMTPS id f17si6101248qck.1.2012.11.08.13.16.28
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 08 Nov 2012 13:16:28 -0800 (PST)
Received-SPF: pass (google.com: domain of 3LCGcUBUJAGkJOYVTPbTJVKLYLcPLd-OYNTHPS....@2uix4h7xygsz66weerlq.apphosting.bounces.google.com designates 209.85.216.198 as permitted sender) client-ip=209.85.216.198;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of 3LCGcUBUJAGkJOYVTPbTJVKLYLcPLd-OYNTHPS....@2uix4h7xygsz66weerlq.apphosting.bounces.google.com designates 209.85.216.198 as permitted sender) smtp.mail=3LCGcUBUJAGkJOYVTPbTJVKLYLcPLd-OYNTHPS....@2uix4h7xygsz66weerlq.apphosting.bounces.google.com; dkim=pass header...@chromium.org
Received: by mail-qc0-f198.google.com with SMTP id e13so5539069qcs.1
        for <v8-dev@googlegroups.com>; Thu, 08 Nov 2012 13:16:28 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=chromium.org; s=google;
        h=mime-version:reply-to:x-google-appengine-app-id:message-id:date
         :subject:from:to:cc:content-type;
        bh=p6pABe7kq6qO8jWO8fZzy4tWDUS6s6lXSoJtpgwwJYw=;
        b=GL7qaLntkh5PC5dErpnDKYPDIjj3UUIh/CWklzasWwJypkzNB7U78BV5lfpnEqMZO7
         ukEWrFyxdOV8xuxjnT0nOx9OgDZ5QeQO39cWpgoOYUqEDMa72TnxzsaZufDa9rO7pwyz
         pei6yqMVFTpk6M1CYNrKnuOmlwJEb+QdCkN1Q=
MIME-Version: 1.0
Received: by 10.58.147.42 with SMTP id th10mr1599798veb.23.1352409388826; Thu,
 08 Nov 2012 13:16:28 -0800 (PST)
Reply-To: a...@chromium.org, mstarzin...@chromium.org, rossb...@chromium.org, 
	v8-dev@googlegroups.com
Message-ID: <047d7b67734c36446004ce025...@google.com>
Date: Thu, 08 Nov 2012 21:16:28 +0000
Subject: ES6: Add support for Set and Map clear method (issue 11409002)
From: a...@chromium.org
To: mstarzin...@chromium.org, rossb...@chromium.org
Cc: v8-dev@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes

Reviewers: Michael Starzinger, rossberg,


https://codereview.chromium.org/11409002/diff/1/src/collection.js
File src/collection.js (right):

https://codereview.chromium.org/11409002/diff/1/src/collection.js#newcode106
src/collection.js:106: %SetInitialize(this);
I first added a %SetClear before I realized that it would do exactly the
same as %SetInitialize. It might be less confusing to have SetClear?
WDYT?

Description:
ES6: Add support for Set and Map clear method

http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts, section
15.14.5.3 and 15.14.5.2

BUG=2400


Please review this at https://codereview.chromium.org/11409002/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
   M src/collection.js
   M test/mjsunit/harmony/collections.js


Index: src/collection.js
diff --git a/src/collection.js b/src/collection.js
index  
d5a8fe21a456c3d99bd6572853a9dddc82a04fcd..b3c2db72d792732be2ae8f8caf9554df8c34ffaa  
100644
--- a/src/collection.js
+++ b/src/collection.js
@@ -97,6 +97,16 @@ function SetGetSize() {
  }


+function SetClear() {
+  if (!IS_SET(this)) {
+    throw MakeTypeError('incompatible_method_receiver',
+                        ['Set.prototype.clear', this]);
+  }
+  // Replace the internal table with a new empty table.
+  %SetInitialize(this);
+}
+
+
  function MapConstructor() {
    if (%_IsConstructCall()) {
      %MapInitialize(this);
@@ -163,6 +173,16 @@ function MapGetSize() {
  }


+function MapClear() {
+  if (!IS_MAP(this)) {
+    throw MakeTypeError('incompatible_method_receiver',
+                        ['Map.prototype.clear', this]);
+  }
+  // Replace the internal table with a new empty table.
+  %MapInitialize(this);
+}
+
+
  function WeakMapConstructor() {
    if (%_IsConstructCall()) {
      %WeakMapInitialize(this);
@@ -237,7 +257,8 @@ function WeakMapDelete(key) {
    InstallFunctions($Set.prototype, DONT_ENUM, $Array(
      "add", SetAdd,
      "has", SetHas,
-    "delete", SetDelete
+    "delete", SetDelete,
+    "clear", SetClear
    ));

    // Set up the non-enumerable functions on the Map prototype object.
@@ -246,7 +267,8 @@ function WeakMapDelete(key) {
      "get", MapGet,
      "set", MapSet,
      "has", MapHas,
-    "delete", MapDelete
+    "delete", MapDelete,
+    "clear", MapClear
    ));

    // Set up the WeakMap constructor function.
Index: test/mjsunit/harmony/collections.js
diff --git a/test/mjsunit/harmony/collections.js  
b/test/mjsunit/harmony/collections.js
index  
6698a334882f53ae80653b6491cbd2e3f521a313..0219f39364d97a6859037a3f48de87dcefcd8ae3  
100644
--- a/test/mjsunit/harmony/collections.js
+++ b/test/mjsunit/harmony/collections.js
@@ -355,3 +355,18 @@ for (var i = 9; i >= 0; i--) {
    m.delete(i);
    assertEquals(i, m.size);
  }
+
+// Test clear
+var a = new Set();
+s.add(42);
+assertTrue(s.has(42));
+s.clear();
+assertFalse(s.has(42));
+assertEquals(0, s.size);
+
+var m = new Map();
+m.set(42, true);
+assertTrue(m.has(42));
+m.clear();
+assertFalse(m.has(42));
+assertEquals(0, m.size);