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() {
function HarmonyArrayExtendSymbolPrototype() {
%CheckIsBootstrapping();
InstallConstants($Symbol, $Array(
InstallConstants(global.Symbol, $Array(
// TODO(dslomov, caitp): Move to symbol.js when shipping
"isConcatSpreadable", symbolIsConcatSpreadable
));
......
......@@ -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
));
......
......@@ -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");
......
......@@ -657,7 +657,7 @@ SymbolMirror.prototype.description = function() {
SymbolMirror.prototype.toText = function() {
return %_CallFunction(this.value_, builtins.SymbolToString);
return %_CallFunction(this.value_, builtins.$symbolToString);
}
......
......@@ -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);
}
}
......
......@@ -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
......@@ -16,7 +10,17 @@
// - 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;
})();
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