Hide Symbol implementation in a closure.
authoryangguo <yangguo@chromium.org>
Fri, 13 Mar 2015 15:08:12 +0000 (08:08 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 13 Mar 2015 15:08:28 +0000 (15:08 +0000)
R=jkummerow@chromium.org

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

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

src/harmony-array.js
src/harmony-tostring.js
src/messages.js
src/mirror-debugger.js
src/string.js
src/symbol.js

index 72625a5..5152a55 100644 (file)
@@ -211,7 +211,7 @@ function ArrayOf() {
 function HarmonyArrayExtendSymbolPrototype() {
   %CheckIsBootstrapping();
 
-  InstallConstants($Symbol, $Array(
+  InstallConstants(global.Symbol, $Array(
     // TODO(dslomov, caitp): Move to symbol.js when shipping
    "isConcatSpreadable", symbolIsConcatSpreadable
   ));
index aed8ca0..4f4f986 100644 (file)
@@ -7,7 +7,6 @@
 // This file relies on the fact that the following declaration has been made
 // in runtime.js and symbol.js:
 // var $Object = global.Object;
-// var $Symbol = global.Symbol;
 
 DefaultObjectToString = ObjectToStringHarmony;
 // ES6 draft 08-24-14, section 19.1.3.6
@@ -26,7 +25,7 @@ function ObjectToStringHarmony() {
 function HarmonyToStringExtendSymbolPrototype() {
   %CheckIsBootstrapping();
 
-  InstallConstants($Symbol, $Array(
+  InstallConstants(global.Symbol, $Array(
     // TODO(dslomov, caitp): Move to symbol.js when shipping
    "toStringTag", symbolToStringTag
   ));
index 62429cf..1d4ad06 100644 (file)
@@ -235,7 +235,7 @@ function NoSideEffectToString(obj) {
     }
     return str;
   }
-  if (IS_SYMBOL(obj)) return %_CallFunction(obj, SymbolToString);
+  if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString);
   if (IS_OBJECT(obj)
       && %GetDataProperty(obj, "toString") === DefaultObjectToString) {
     var constructor = %GetDataProperty(obj, "constructor");
index 1848e4f..bfaac73 100644 (file)
@@ -657,7 +657,7 @@ SymbolMirror.prototype.description = function() {
 
 
 SymbolMirror.prototype.toText = function() {
-  return %_CallFunction(this.value_, builtins.SymbolToString);
+  return %_CallFunction(this.value_, builtins.$symbolToString);
 }
 
 
index 5b73961..421f905 100644 (file)
@@ -22,7 +22,7 @@ function StringConstructor(x) {
     %_SetValueOf(this, TO_STRING_INLINE(x));
   } else {
     return IS_SYMBOL(x) ?
-        %_CallFunction(x, SymbolToString) : TO_STRING_INLINE(x);
+        %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x);
   }
 }
 
index d9cf792..7a80815 100644 (file)
@@ -2,13 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-"use strict";
-
-// This file relies on the fact that the following declaration has been made
-// in runtime.js:
-// var $Array = global.Array;
-
-// And requires following symbols to be set in the bootstrapper during genesis:
+// Expects following symbols to be set in the bootstrapper during genesis:
 // - symbolHasInstance
 // - symbolIsConcatSpreadable
 // - symbolIsRegExp
 // - symbolToStringTag
 // - symbolUnscopables
 
-var $Symbol = global.Symbol;
+var $symbolToString;
+
+(function() {
+
+"use strict";
+
+%CheckIsBootstrapping();
+
+var GlobalArray = global.Array;
+var GlobalObject = global.Object;
+var GlobalSymbol = global.Symbol;
 
 // -------------------------------------------------------------------
 
@@ -77,46 +81,40 @@ function ObjectGetOwnPropertySymbols(obj) {
 
 //-------------------------------------------------------------------
 
-function SetUpSymbol() {
-  %CheckIsBootstrapping();
-
-  %SetCode($Symbol, SymbolConstructor);
-  %FunctionSetPrototype($Symbol, new $Object());
-
-  InstallConstants($Symbol, $Array(
-    // TODO(rossberg): expose when implemented.
-    // "hasInstance", symbolHasInstance,
-    // "isConcatSpreadable", symbolIsConcatSpreadable,
-    // "isRegExp", symbolIsRegExp,
-    "iterator", symbolIterator,
-    // TODO(dslomov, caitp): Currently defined in harmony-tostring.js ---
-    // Move here when shipping
-    // "toStringTag", symbolToStringTag,
-    "unscopables", symbolUnscopables
-  ));
-  InstallFunctions($Symbol, DONT_ENUM, $Array(
-    "for", SymbolFor,
-    "keyFor", SymbolKeyFor
-  ));
-
-  %AddNamedProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
-  %AddNamedProperty(
-      $Symbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY);
-  InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
-    "toString", SymbolToString,
-    "valueOf", SymbolValueOf
-  ));
-}
-
-SetUpSymbol();
-
-
-function ExtendObject() {
-  %CheckIsBootstrapping();
-
-  InstallFunctions($Object, DONT_ENUM, $Array(
-    "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
-  ));
-}
-
-ExtendObject();
+%SetCode(GlobalSymbol, SymbolConstructor);
+%FunctionSetPrototype(GlobalSymbol, new GlobalObject());
+
+InstallConstants(GlobalSymbol, GlobalArray(
+  // TODO(rossberg): expose when implemented.
+  // "hasInstance", symbolHasInstance,
+  // "isConcatSpreadable", symbolIsConcatSpreadable,
+  // "isRegExp", symbolIsRegExp,
+  "iterator", symbolIterator,
+  // TODO(dslomov, caitp): Currently defined in harmony-tostring.js ---
+  // Move here when shipping
+  // "toStringTag", symbolToStringTag,
+  "unscopables", symbolUnscopables
+));
+
+InstallFunctions(GlobalSymbol, DONT_ENUM, GlobalArray(
+  "for", SymbolFor,
+  "keyFor", SymbolKeyFor
+));
+
+%AddNamedProperty(
+    GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM);
+%AddNamedProperty(
+    GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY);
+
+InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, GlobalArray(
+  "toString", SymbolToString,
+  "valueOf", SymbolValueOf
+));
+
+InstallFunctions(GlobalObject, DONT_ENUM, GlobalArray(
+  "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
+));
+
+$symbolToString = SymbolToString;
+
+})();