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

Side by Side Diff: src/symbol.js

Issue 208423013: Spec adjustments for well-known symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { 58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
59 throw MakeTypeError( 59 throw MakeTypeError(
60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); 60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
61 } 61 }
62 return %_ValueOf(this); 62 return %_ValueOf(this);
63 } 63 }
64 64
65 65
66 function GetSymbolRegistry() { 66 function GetSymbolRegistry() {
67 var registry = %SymbolRegistry(); 67 var registry = %SymbolRegistry();
68 if (!('internal' in registry)) { 68 if (IS_UNDEFINED(registry.internal)) {
69 registry.internal = {__proto__: null}; 69 registry.internal = {__proto__: null};
70 registry.for = {__proto__: null}; 70 registry.for = {__proto__: null};
71 registry.keyFor = {__proto__: null}; 71 registry.keyFor = {__proto__: null};
72 } 72 }
73 return registry; 73 return registry;
74 } 74 }
75 75
76 76
77 function InternalSymbol(key) { 77 function InternalSymbol(key) {
78 var registry = GetSymbolRegistry(); 78 var registry = GetSymbolRegistry();
79 if (!(key in registry.internal)) { 79 if (IS_UNDEFINED(registry.internal[key])) {
80 registry.internal[key] = %CreateSymbol(key); 80 registry.internal[key] = %CreateSymbol(key);
81 } 81 }
82 return registry.internal[key]; 82 return registry.internal[key];
83 } 83 }
84 84
85 85
86 function SymbolFor(key) { 86 function SymbolFor(key) {
87 key = TO_STRING_INLINE(key); 87 key = TO_STRING_INLINE(key);
88 var registry = GetSymbolRegistry(); 88 var registry = GetSymbolRegistry();
89 if (!(key in registry.for)) { 89 if (IS_UNDEFINED(registry.for[key])) {
90 var symbol = %CreateSymbol(key); 90 var symbol = %CreateSymbol(key);
91 registry.for[key] = symbol; 91 registry.for[key] = symbol;
92 registry.keyFor[symbol] = key; 92 registry.keyFor[symbol] = key;
93 } 93 }
94 return registry.for[key]; 94 return registry.for[key];
95 } 95 }
96 96
97 97
98 function SymbolKeyFor(symbol) { 98 function SymbolKeyFor(symbol) {
99 if (!IS_SYMBOL(symbol)) { 99 if (!IS_SYMBOL(symbol)) {
(...skipping 11 matching lines...) Expand all
111 } 111 }
112 112
113 // TODO(arv): Proxies use a shared trap for String and Symbol keys. 113 // TODO(arv): Proxies use a shared trap for String and Symbol keys.
114 114
115 return ObjectGetOwnPropertyKeys(obj, true); 115 return ObjectGetOwnPropertyKeys(obj, true);
116 } 116 }
117 117
118 118
119 //------------------------------------------------------------------- 119 //-------------------------------------------------------------------
120 120
121 var symbolCreate = InternalSymbol("@@create"); 121 var symbolCreate = InternalSymbol("Symbol.create");
122 var symbolHasInstance = InternalSymbol("@@hasInstance"); 122 var symbolHasInstance = InternalSymbol("Symbol.hasInstance");
123 var symbolIsConcatSpreadable = InternalSymbol("@@isConcatSpreadable"); 123 var symbolIsConcatSpreadable = InternalSymbol("Symbol.isConcatSpreadable");
124 var symbolIsRegExp = InternalSymbol("@@isRegExp"); 124 var symbolIsRegExp = InternalSymbol("Symbol.isRegExp");
125 var symbolIterator = InternalSymbol("@@iterator"); 125 var symbolIterator = InternalSymbol("Symbol.iterator");
126 var symbolToStringTag = InternalSymbol("@@toStringTag"); 126 var symbolToStringTag = InternalSymbol("Symbol.toStringTag");
127 var symbolUnscopables = InternalSymbol("@@unscopables"); 127 var symbolUnscopables = InternalSymbol("Symbol.unscopables");
128 128
129 129
130 //------------------------------------------------------------------- 130 //-------------------------------------------------------------------
131 131
132 function SetUpSymbol() { 132 function SetUpSymbol() {
133 %CheckIsBootstrapping(); 133 %CheckIsBootstrapping();
134 134
135 %SetCode($Symbol, SymbolConstructor); 135 %SetCode($Symbol, SymbolConstructor);
136 %FunctionSetPrototype($Symbol, new $Object()); 136 %FunctionSetPrototype($Symbol, new $Object());
137 137
138 %SetProperty($Symbol, "create", symbolCreate, DONT_ENUM); 138 InstallConstants($Symbol, $Array(
139 %SetProperty($Symbol, "hasInstance", symbolHasInstance, DONT_ENUM); 139 "create", symbolCreate,
140 %SetProperty($Symbol, "isConcatSpreadable", 140 "hasInstance", symbolHasInstance,
141 symbolIsConcatSpreadable, DONT_ENUM); 141 "isConcatSpreadable", symbolIsConcatSpreadable,
142 %SetProperty($Symbol, "isRegExp", symbolIsRegExp, DONT_ENUM); 142 "isRegExp", symbolIsRegExp,
143 %SetProperty($Symbol, "iterator", symbolIterator, DONT_ENUM); 143 "iterator", symbolIterator,
144 %SetProperty($Symbol, "toStringTag", symbolToStringTag, DONT_ENUM); 144 "toStringTag", symbolToStringTag,
145 %SetProperty($Symbol, "unscopables", symbolUnscopables, DONT_ENUM); 145 "unscopables", symbolUnscopables
146 ));
146 InstallFunctions($Symbol, DONT_ENUM, $Array( 147 InstallFunctions($Symbol, DONT_ENUM, $Array(
147 "for", SymbolFor, 148 "for", SymbolFor,
148 "keyFor", SymbolKeyFor 149 "keyFor", SymbolKeyFor
149 )); 150 ));
150 151
151 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); 152 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
152 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( 153 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
153 "toString", SymbolToString, 154 "toString", SymbolToString,
154 "valueOf", SymbolValueOf 155 "valueOf", SymbolValueOf
155 )); 156 ));
156 } 157 }
157 158
158 SetUpSymbol(); 159 SetUpSymbol();
159 160
160 161
161 function ExtendObject() { 162 function ExtendObject() {
162 %CheckIsBootstrapping(); 163 %CheckIsBootstrapping();
163 164
164 InstallFunctions($Object, DONT_ENUM, $Array( 165 InstallFunctions($Object, DONT_ENUM, $Array(
165 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols 166 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
166 )); 167 ));
167 } 168 }
168 169
169 ExtendObject(); 170 ExtendObject();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698