Simplify collections.js now that it's wrapped in an IIFE
authoradamk <adamk@chromium.org>
Tue, 7 Apr 2015 19:00:34 +0000 (12:00 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 7 Apr 2015 19:00:40 +0000 (19:00 +0000)
Also wrap templates.js in an IIFE to avoid unnecessary pollution
of the builtins object.

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

Cr-Commit-Position: refs/heads/master@{#27638}

src/collection.js
src/templates.js

index 537dbd6..928670c 100644 (file)
@@ -12,13 +12,10 @@ var $Set = global.Set;
 var $Map = global.Map;
 
 
-// Used by harmony-templates.js
-var $MapGet;
-var $MapSet;
-
-
 (function() {
 
+%CheckIsBootstrapping();
+
 
 function HashToEntry(table, hash, numBuckets) {
   var bucket = ORDERED_HASH_TABLE_HASH_TO_BUCKET(hash, numBuckets);
@@ -238,31 +235,23 @@ function SetForEach(f, receiver) {
 }
 
 
-// -------------------------------------------------------------------
+%SetCode($Set, SetConstructor);
+%FunctionSetPrototype($Set, new $Object());
+%AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
+%AddNamedProperty(
+    $Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY);
 
-function SetUpSet() {
-  %CheckIsBootstrapping();
-
-  %SetCode($Set, SetConstructor);
-  %FunctionSetPrototype($Set, new $Object());
-  %AddNamedProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
-  %AddNamedProperty(
-      $Set.prototype, symbolToStringTag, "Set", DONT_ENUM | READ_ONLY);
-
-  %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", SetClearJS,
-    "forEach", SetForEach
-  ));
-}
+%FunctionSetLength(SetForEach, 1);
 
-SetUpSet();
+// 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", SetClearJS,
+  "forEach", SetForEach
+));
 
 
 // -------------------------------------------------------------------
@@ -434,34 +423,23 @@ function MapForEach(f, receiver) {
 }
 
 
-// -------------------------------------------------------------------
-
-function SetUpMap() {
-  %CheckIsBootstrapping();
-
-  %SetCode($Map, MapConstructor);
-  %FunctionSetPrototype($Map, new $Object());
-  %AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
-  %AddNamedProperty(
-      $Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY);
-
-  %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(
-    "get", MapGet,
-    "set", MapSet,
-    "has", MapHas,
-    "delete", MapDelete,
-    "clear", MapClearJS,
-    "forEach", MapForEach
-  ));
-
-  $MapGet = MapGet;
-  $MapSet = MapSet;
-}
-
-SetUpMap();
+%SetCode($Map, MapConstructor);
+%FunctionSetPrototype($Map, new $Object());
+%AddNamedProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
+%AddNamedProperty(
+    $Map.prototype, symbolToStringTag, "Map", DONT_ENUM | READ_ONLY);
+
+%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(
+  "get", MapGet,
+  "set", MapSet,
+  "has", MapHas,
+  "delete", MapDelete,
+  "clear", MapClearJS,
+  "forEach", MapForEach
+));
 
 })();
index feb5b06..6dae189 100644 (file)
@@ -4,7 +4,17 @@
 
 "use strict";
 
+// Called from a desugaring in the parser.
+var GetTemplateCallSite;
+
+(function() {
+
+%CheckIsBootstrapping();
+
 var callSiteCache = new $Map;
+var mapGetFn = $Map.prototype.get;
+var mapSetFn = $Map.prototype.set;
+
 
 function SameCallSiteElements(rawStrings, other) {
   var length = rawStrings.length;
@@ -21,7 +31,7 @@ function SameCallSiteElements(rawStrings, other) {
 
 
 function GetCachedCallSite(siteObj, hash) {
-  var obj = %_CallFunction(callSiteCache, hash, $MapGet);
+  var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
 
   if (IS_UNDEFINED(obj)) return;
 
@@ -33,13 +43,13 @@ function GetCachedCallSite(siteObj, hash) {
 
 
 function SetCachedCallSite(siteObj, hash) {
-  var obj = %_CallFunction(callSiteCache, hash, $MapGet);
+  var obj = %_CallFunction(callSiteCache, hash, mapGetFn);
   var array;
 
   if (IS_UNDEFINED(obj)) {
     array = new InternalArray(1);
     array[0] = siteObj;
-    %_CallFunction(callSiteCache, hash, array, $MapSet);
+    %_CallFunction(callSiteCache, hash, array, mapSetFn);
   } else {
     obj.push(siteObj);
   }
@@ -48,7 +58,7 @@ function SetCachedCallSite(siteObj, hash) {
 }
 
 
-function GetTemplateCallSite(siteObj, rawStrings, hash) {
+GetTemplateCallSite = function(siteObj, rawStrings, hash) {
   var cached = GetCachedCallSite(rawStrings, hash);
 
   if (!IS_UNDEFINED(cached)) return cached;
@@ -58,3 +68,5 @@ function GetTemplateCallSite(siteObj, rawStrings, hash) {
 
   return SetCachedCallSite(%ObjectFreeze(siteObj), hash);
 }
+
+})();