Commit c6752179 authored by yangguo's avatar yangguo Committed by Commit bot

Hide Symbol implementation in a closure.

R=jkummerow@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27185}
parent 31f6142a
...@@ -211,7 +211,7 @@ function ArrayOf() { ...@@ -211,7 +211,7 @@ function ArrayOf() {
function HarmonyArrayExtendSymbolPrototype() { function HarmonyArrayExtendSymbolPrototype() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
InstallConstants($Symbol, $Array( InstallConstants(global.Symbol, $Array(
// TODO(dslomov, caitp): Move to symbol.js when shipping // TODO(dslomov, caitp): Move to symbol.js when shipping
"isConcatSpreadable", symbolIsConcatSpreadable "isConcatSpreadable", symbolIsConcatSpreadable
)); ));
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
// This file relies on the fact that the following declaration has been made // This file relies on the fact that the following declaration has been made
// in runtime.js and symbol.js: // in runtime.js and symbol.js:
// var $Object = global.Object; // var $Object = global.Object;
// var $Symbol = global.Symbol;
DefaultObjectToString = ObjectToStringHarmony; DefaultObjectToString = ObjectToStringHarmony;
// ES6 draft 08-24-14, section 19.1.3.6 // ES6 draft 08-24-14, section 19.1.3.6
...@@ -26,7 +25,7 @@ function ObjectToStringHarmony() { ...@@ -26,7 +25,7 @@ function ObjectToStringHarmony() {
function HarmonyToStringExtendSymbolPrototype() { function HarmonyToStringExtendSymbolPrototype() {
%CheckIsBootstrapping(); %CheckIsBootstrapping();
InstallConstants($Symbol, $Array( InstallConstants(global.Symbol, $Array(
// TODO(dslomov, caitp): Move to symbol.js when shipping // TODO(dslomov, caitp): Move to symbol.js when shipping
"toStringTag", symbolToStringTag "toStringTag", symbolToStringTag
)); ));
......
...@@ -235,7 +235,7 @@ function NoSideEffectToString(obj) { ...@@ -235,7 +235,7 @@ function NoSideEffectToString(obj) {
} }
return str; return str;
} }
if (IS_SYMBOL(obj)) return %_CallFunction(obj, SymbolToString); if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString);
if (IS_OBJECT(obj) if (IS_OBJECT(obj)
&& %GetDataProperty(obj, "toString") === DefaultObjectToString) { && %GetDataProperty(obj, "toString") === DefaultObjectToString) {
var constructor = %GetDataProperty(obj, "constructor"); var constructor = %GetDataProperty(obj, "constructor");
......
...@@ -657,7 +657,7 @@ SymbolMirror.prototype.description = function() { ...@@ -657,7 +657,7 @@ SymbolMirror.prototype.description = function() {
SymbolMirror.prototype.toText = function() { SymbolMirror.prototype.toText = function() {
return %_CallFunction(this.value_, builtins.SymbolToString); return %_CallFunction(this.value_, builtins.$symbolToString);
} }
......
...@@ -22,7 +22,7 @@ function StringConstructor(x) { ...@@ -22,7 +22,7 @@ function StringConstructor(x) {
%_SetValueOf(this, TO_STRING_INLINE(x)); %_SetValueOf(this, TO_STRING_INLINE(x));
} else { } else {
return IS_SYMBOL(x) ? return IS_SYMBOL(x) ?
%_CallFunction(x, SymbolToString) : TO_STRING_INLINE(x); %_CallFunction(x, $symbolToString) : TO_STRING_INLINE(x);
} }
} }
......
...@@ -2,13 +2,7 @@ ...@@ -2,13 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
"use strict"; // Expects following symbols to be set in the bootstrapper during genesis:
// 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:
// - symbolHasInstance // - symbolHasInstance
// - symbolIsConcatSpreadable // - symbolIsConcatSpreadable
// - symbolIsRegExp // - symbolIsRegExp
...@@ -16,7 +10,17 @@ ...@@ -16,7 +10,17 @@
// - symbolToStringTag // - symbolToStringTag
// - symbolUnscopables // - 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) { ...@@ -77,46 +81,40 @@ function ObjectGetOwnPropertySymbols(obj) {
//------------------------------------------------------------------- //-------------------------------------------------------------------
function SetUpSymbol() { %SetCode(GlobalSymbol, SymbolConstructor);
%CheckIsBootstrapping(); %FunctionSetPrototype(GlobalSymbol, new GlobalObject());
%SetCode($Symbol, SymbolConstructor); InstallConstants(GlobalSymbol, GlobalArray(
%FunctionSetPrototype($Symbol, new $Object()); // TODO(rossberg): expose when implemented.
// "hasInstance", symbolHasInstance,
InstallConstants($Symbol, $Array( // "isConcatSpreadable", symbolIsConcatSpreadable,
// TODO(rossberg): expose when implemented. // "isRegExp", symbolIsRegExp,
// "hasInstance", symbolHasInstance, "iterator", symbolIterator,
// "isConcatSpreadable", symbolIsConcatSpreadable, // TODO(dslomov, caitp): Currently defined in harmony-tostring.js ---
// "isRegExp", symbolIsRegExp, // Move here when shipping
"iterator", symbolIterator, // "toStringTag", symbolToStringTag,
// TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- "unscopables", symbolUnscopables
// Move here when shipping ));
// "toStringTag", symbolToStringTag,
"unscopables", symbolUnscopables InstallFunctions(GlobalSymbol, DONT_ENUM, GlobalArray(
)); "for", SymbolFor,
InstallFunctions($Symbol, DONT_ENUM, $Array( "keyFor", SymbolKeyFor
"for", SymbolFor, ));
"keyFor", SymbolKeyFor
)); %AddNamedProperty(
GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM);
%AddNamedProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); %AddNamedProperty(
%AddNamedProperty( GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY);
$Symbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY);
InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, GlobalArray(
"toString", SymbolToString, "toString", SymbolToString,
"valueOf", SymbolValueOf "valueOf", SymbolValueOf
)); ));
}
InstallFunctions(GlobalObject, DONT_ENUM, GlobalArray(
SetUpSymbol(); "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
));
function ExtendObject() { $symbolToString = SymbolToString;
%CheckIsBootstrapping();
})();
InstallFunctions($Object, DONT_ENUM, $Array(
"getOwnPropertySymbols", ObjectGetOwnPropertySymbols
));
}
ExtendObject();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment