OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 "use strict"; | 5 "use strict"; |
6 | 6 |
7 // This file relies on the fact that the following declaration has been made | 7 // This file relies on the fact that the following declaration has been made |
8 // in runtime.js: | 8 // in runtime.js: |
9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
10 | 10 |
| 11 // And requires following symbols to be set in the bootstrapper during genesis: |
| 12 // - symbolHasInstance |
| 13 // - symbolIsConcatSpreadable |
| 14 // - symbolIsRegExp |
| 15 // - symbolIterator |
| 16 // - symbolToStringTag |
| 17 // - symbolUnscopables |
| 18 |
11 var $Symbol = global.Symbol; | 19 var $Symbol = global.Symbol; |
12 | 20 |
13 // ------------------------------------------------------------------- | 21 // ------------------------------------------------------------------- |
14 | 22 |
15 function SymbolConstructor(x) { | 23 function SymbolConstructor(x) { |
16 if (%_IsConstructCall()) { | 24 if (%_IsConstructCall()) { |
17 throw MakeTypeError('not_constructor', ["Symbol"]); | 25 throw MakeTypeError('not_constructor', ["Symbol"]); |
18 } | 26 } |
19 // NOTE: Passing in a Symbol value will throw on ToString(). | 27 // NOTE: Passing in a Symbol value will throw on ToString(). |
20 return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); | 28 return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 41 |
34 function SymbolValueOf() { | 42 function SymbolValueOf() { |
35 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { | 43 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { |
36 throw MakeTypeError( | 44 throw MakeTypeError( |
37 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); | 45 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); |
38 } | 46 } |
39 return %_ValueOf(this); | 47 return %_ValueOf(this); |
40 } | 48 } |
41 | 49 |
42 | 50 |
43 function InternalSymbol(key) { | |
44 var internal_registry = %SymbolRegistry().for_intern; | |
45 if (IS_UNDEFINED(internal_registry[key])) { | |
46 internal_registry[key] = %CreateSymbol(key); | |
47 } | |
48 return internal_registry[key]; | |
49 } | |
50 | |
51 | |
52 function SymbolFor(key) { | 51 function SymbolFor(key) { |
53 key = TO_STRING_INLINE(key); | 52 key = TO_STRING_INLINE(key); |
54 var registry = %SymbolRegistry(); | 53 var registry = %SymbolRegistry(); |
55 if (IS_UNDEFINED(registry.for[key])) { | 54 if (IS_UNDEFINED(registry.for[key])) { |
56 var symbol = %CreateSymbol(key); | 55 var symbol = %CreateSymbol(key); |
57 registry.for[key] = symbol; | 56 registry.for[key] = symbol; |
58 registry.keyFor[symbol] = key; | 57 registry.keyFor[symbol] = key; |
59 } | 58 } |
60 return registry.for[key]; | 59 return registry.for[key]; |
61 } | 60 } |
62 | 61 |
63 | 62 |
64 function SymbolKeyFor(symbol) { | 63 function SymbolKeyFor(symbol) { |
65 if (!IS_SYMBOL(symbol)) throw MakeTypeError("not_a_symbol", [symbol]); | 64 if (!IS_SYMBOL(symbol)) throw MakeTypeError("not_a_symbol", [symbol]); |
66 return %SymbolRegistry().keyFor[symbol]; | 65 return %SymbolRegistry().keyFor[symbol]; |
67 } | 66 } |
68 | 67 |
69 | 68 |
70 // ES6 19.1.2.8 | 69 // ES6 19.1.2.8 |
71 function ObjectGetOwnPropertySymbols(obj) { | 70 function ObjectGetOwnPropertySymbols(obj) { |
72 obj = ToObject(obj); | 71 obj = ToObject(obj); |
73 | 72 |
74 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 73 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
75 | 74 |
76 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); | 75 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); |
77 } | 76 } |
78 | 77 |
79 | |
80 //------------------------------------------------------------------- | |
81 | |
82 var symbolHasInstance = InternalSymbol("Symbol.hasInstance"); | |
83 var symbolIsConcatSpreadable = InternalSymbol("Symbol.isConcatSpreadable"); | |
84 var symbolIsRegExp = InternalSymbol("Symbol.isRegExp"); | |
85 var symbolIterator = InternalSymbol("Symbol.iterator"); | |
86 var symbolToStringTag = InternalSymbol("Symbol.toStringTag"); | |
87 var symbolUnscopables = InternalSymbol("Symbol.unscopables"); | |
88 | |
89 | |
90 //------------------------------------------------------------------- | 78 //------------------------------------------------------------------- |
91 | 79 |
92 function SetUpSymbol() { | 80 function SetUpSymbol() { |
93 %CheckIsBootstrapping(); | 81 %CheckIsBootstrapping(); |
94 | 82 |
95 %SetCode($Symbol, SymbolConstructor); | 83 %SetCode($Symbol, SymbolConstructor); |
96 %FunctionSetPrototype($Symbol, new $Object()); | 84 %FunctionSetPrototype($Symbol, new $Object()); |
97 | 85 |
98 InstallConstants($Symbol, $Array( | 86 InstallConstants($Symbol, $Array( |
99 // TODO(rossberg): expose when implemented. | 87 // TODO(rossberg): expose when implemented. |
(...skipping 25 matching lines...) Expand all Loading... |
125 | 113 |
126 function ExtendObject() { | 114 function ExtendObject() { |
127 %CheckIsBootstrapping(); | 115 %CheckIsBootstrapping(); |
128 | 116 |
129 InstallFunctions($Object, DONT_ENUM, $Array( | 117 InstallFunctions($Object, DONT_ENUM, $Array( |
130 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 118 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
131 )); | 119 )); |
132 } | 120 } |
133 | 121 |
134 ExtendObject(); | 122 ExtendObject(); |
OLD | NEW |