Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 | 56 |
| 57 function SymbolValueOf() { | 57 function SymbolValueOf() { |
| 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() { | |
| 67 var registry = %SymbolRegistry(); | |
| 68 if (!('internal' in registry)) { | |
| 69 registry.internal = {__proto__: null}; | |
| 70 registry.for = {__proto__: null}; | |
| 71 registry.keyFor = {__proto__: null}; | |
| 72 } | |
| 73 return registry; | |
| 74 } | |
| 75 | |
| 76 | |
| 77 function InternalSymbol(key) { | 66 function InternalSymbol(key) { |
| 78 var registry = GetSymbolRegistry(); | 67 var registry = %SymbolRegistry().for_intern; |
|
Michael Starzinger
2014/03/24 15:17:19
nit: The usage of the local variable "registry" is
rossberg
2014/03/24 15:54:46
Done.
| |
| 79 if (!(key in registry.internal)) { | 68 if (IS_UNDEFINED(registry[key])) registry[key] = %CreateSymbol(key); |
| 80 registry.internal[key] = %CreateSymbol(key); | 69 return registry[key]; |
| 81 } | |
| 82 return registry.internal[key]; | |
| 83 } | 70 } |
| 84 | 71 |
| 85 | 72 |
| 86 function SymbolFor(key) { | 73 function SymbolFor(key) { |
| 87 key = TO_STRING_INLINE(key); | 74 key = TO_STRING_INLINE(key); |
| 88 var registry = GetSymbolRegistry(); | 75 var registry = %SymbolRegistry(); |
| 89 if (!(key in registry.for)) { | 76 if (IS_UNDEFINED(registry.for[key])) { |
| 90 var symbol = %CreateSymbol(key); | 77 var symbol = %CreateSymbol(key); |
| 91 registry.for[key] = symbol; | 78 registry.for[key] = symbol; |
| 92 registry.keyFor[symbol] = key; | 79 registry.keyFor[symbol] = key; |
| 93 } | 80 } |
| 94 return registry.for[key]; | 81 return registry.for[key]; |
| 95 } | 82 } |
| 96 | 83 |
| 97 | 84 |
| 98 function SymbolKeyFor(symbol) { | 85 function SymbolKeyFor(symbol) { |
| 99 if (!IS_SYMBOL(symbol)) { | 86 if (!IS_SYMBOL(symbol)) throw MakeTypeError("not_a_symbol", [symbol]); |
| 100 throw MakeTypeError("not_a_symbol", [symbol]); | 87 return %SymbolRegistry().keyFor[symbol]; |
| 101 } | |
| 102 return GetSymbolRegistry().keyFor[symbol]; | |
| 103 } | 88 } |
| 104 | 89 |
| 105 | 90 |
| 106 // ES6 19.1.2.8 | 91 // ES6 19.1.2.8 |
| 107 function ObjectGetOwnPropertySymbols(obj) { | 92 function ObjectGetOwnPropertySymbols(obj) { |
| 108 if (!IS_SPEC_OBJECT(obj)) { | 93 if (!IS_SPEC_OBJECT(obj)) { |
| 109 throw MakeTypeError("called_on_non_object", | 94 throw MakeTypeError("called_on_non_object", |
| 110 ["Object.getOwnPropertySymbols"]); | 95 ["Object.getOwnPropertySymbols"]); |
| 111 } | 96 } |
| 112 | 97 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 | 145 |
| 161 function ExtendObject() { | 146 function ExtendObject() { |
| 162 %CheckIsBootstrapping(); | 147 %CheckIsBootstrapping(); |
| 163 | 148 |
| 164 InstallFunctions($Object, DONT_ENUM, $Array( | 149 InstallFunctions($Object, DONT_ENUM, $Array( |
| 165 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 150 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
| 166 )); | 151 )); |
| 167 } | 152 } |
| 168 | 153 |
| 169 ExtendObject(); | 154 ExtendObject(); |
| OLD | NEW |