Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Unified Diff: src/symbol.js

Issue 203243004: Implement ES6 symbol registry and predefined symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixed bug Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/private.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/symbol.js
diff --git a/src/symbol.js b/src/symbol.js
index 8cb19271835f609b269af987a6cbeae8723b4048..49f909694c19f3ee44c60a39def7fbbd0f39c6a5 100644
--- a/src/symbol.js
+++ b/src/symbol.js
@@ -63,6 +63,46 @@ function SymbolValueOf() {
}
+function GetSymbolRegistry() {
+ var registry = %SymbolRegistry();
+ if (!('internal' in registry)) {
arv (Not doing code reviews) 2014/03/22 17:15:49 Maybe this could have been if (IS_UNDEFINED(regi
rossberg 2014/03/24 10:25:53 Done.
+ registry.internal = {__proto__: null};
+ registry.for = {__proto__: null};
+ registry.keyFor = {__proto__: null};
+ }
+ return registry;
+}
+
+
+function InternalSymbol(key) {
+ var registry = GetSymbolRegistry();
+ if (!(key in registry.internal)) {
+ registry.internal[key] = %CreateSymbol(key);
+ }
+ return registry.internal[key];
+}
+
+
+function SymbolFor(key) {
+ key = TO_STRING_INLINE(key);
+ var registry = GetSymbolRegistry();
+ if (!(key in registry.for)) {
+ var symbol = %CreateSymbol(key);
+ registry.for[key] = symbol;
+ registry.keyFor[symbol] = key;
+ }
+ return registry.for[key];
+}
+
+
+function SymbolKeyFor(symbol) {
+ if (!IS_SYMBOL(symbol)) {
+ throw MakeTypeError("not_a_symbol", [symbol]);
+ }
+ return GetSymbolRegistry().keyFor[symbol];
+}
+
+
// ES6 19.1.2.8
function ObjectGetOwnPropertySymbols(obj) {
if (!IS_SPEC_OBJECT(obj)) {
@@ -78,12 +118,36 @@ function ObjectGetOwnPropertySymbols(obj) {
//-------------------------------------------------------------------
+var symbolCreate = InternalSymbol("@@create");
arv (Not doing code reviews) 2014/03/22 17:15:49 Doesn't '@' in a property name cause the object to
rossberg 2014/03/24 10:25:53 Objects should be completely ignorant to symbol de
arv (Not doing code reviews) 2014/03/24 15:18:57 You use the key on line 80. If we have a non ident
rossberg 2014/03/24 15:37:56 You're right. The dot will have the same effect, t
+var symbolHasInstance = InternalSymbol("@@hasInstance");
+var symbolIsConcatSpreadable = InternalSymbol("@@isConcatSpreadable");
+var symbolIsRegExp = InternalSymbol("@@isRegExp");
+var symbolIterator = InternalSymbol("@@iterator");
+var symbolToStringTag = InternalSymbol("@@toStringTag");
+var symbolUnscopables = InternalSymbol("@@unscopables");
+
+
+//-------------------------------------------------------------------
+
function SetUpSymbol() {
%CheckIsBootstrapping();
%SetCode($Symbol, SymbolConstructor);
%FunctionSetPrototype($Symbol, new $Object());
+ %SetProperty($Symbol, "create", symbolCreate, DONT_ENUM);
arv (Not doing code reviews) 2014/03/22 17:15:49 Also, non writable, non configurable. http://peop
rossberg 2014/03/24 10:25:53 Done.
+ %SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM);
+ %SetProperty($Symbol, "isConcatSpreadable",
+ symbolIsConcatSpreadable, DONT_ENUM);
+ %SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM);
+ %SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM);
+ %SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM);
+ %SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM);
+ InstallFunctions($Symbol, DONT_ENUM, $Array(
+ "for", SymbolFor,
+ "keyFor", SymbolKeyFor
+ ));
+
%SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
"toString", SymbolToString,
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/harmony/private.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698