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 // Expects following symbols to be set in the bootstrapper during genesis: | 5 // Expects following symbols to be set in the bootstrapper during genesis: |
6 // - symbolHasInstance | 6 // - symbolHasInstance |
7 // - symbolIsConcatSpreadable | 7 // - symbolIsConcatSpreadable |
8 // - symbolIsRegExp | 8 // - symbolIsRegExp |
9 // - symbolIterator | 9 // - symbolIterator |
10 // - symbolToStringTag | 10 // - symbolToStringTag |
11 // - symbolUnscopables | 11 // - symbolUnscopables |
12 | 12 |
13 var $symbolToString; | 13 var $symbolToString; |
14 | 14 |
15 (function() { | 15 (function() { |
16 | 16 |
17 "use strict"; | 17 "use strict"; |
18 | 18 |
19 %CheckIsBootstrapping(); | 19 %CheckIsBootstrapping(); |
20 | 20 |
21 var GlobalArray = global.Array; | |
22 var GlobalObject = global.Object; | 21 var GlobalObject = global.Object; |
23 var GlobalSymbol = global.Symbol; | 22 var GlobalSymbol = global.Symbol; |
24 | 23 |
25 // ------------------------------------------------------------------- | 24 // ------------------------------------------------------------------- |
26 | 25 |
27 function SymbolConstructor(x) { | 26 function SymbolConstructor(x) { |
28 if (%_IsConstructCall()) { | 27 if (%_IsConstructCall()) { |
29 throw MakeTypeError('not_constructor', ["Symbol"]); | 28 throw MakeTypeError('not_constructor', ["Symbol"]); |
30 } | 29 } |
31 // NOTE: Passing in a Symbol value will throw on ToString(). | 30 // NOTE: Passing in a Symbol value will throw on ToString(). |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 76 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
78 | 77 |
79 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); | 78 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); |
80 } | 79 } |
81 | 80 |
82 //------------------------------------------------------------------- | 81 //------------------------------------------------------------------- |
83 | 82 |
84 %SetCode(GlobalSymbol, SymbolConstructor); | 83 %SetCode(GlobalSymbol, SymbolConstructor); |
85 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); | 84 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); |
86 | 85 |
87 InstallConstants(GlobalSymbol, GlobalArray( | 86 InstallConstants(GlobalSymbol, [ |
88 // TODO(rossberg): expose when implemented. | 87 // TODO(rossberg): expose when implemented. |
89 // "hasInstance", symbolHasInstance, | 88 // "hasInstance", symbolHasInstance, |
90 // "isConcatSpreadable", symbolIsConcatSpreadable, | 89 // "isConcatSpreadable", symbolIsConcatSpreadable, |
91 // "isRegExp", symbolIsRegExp, | 90 // "isRegExp", symbolIsRegExp, |
92 "iterator", symbolIterator, | 91 "iterator", symbolIterator, |
93 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- | 92 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- |
94 // Move here when shipping | 93 // Move here when shipping |
95 // "toStringTag", symbolToStringTag, | 94 // "toStringTag", symbolToStringTag, |
96 "unscopables", symbolUnscopables | 95 "unscopables", symbolUnscopables |
97 )); | 96 ]); |
98 | 97 |
99 InstallFunctions(GlobalSymbol, DONT_ENUM, GlobalArray( | 98 InstallFunctions(GlobalSymbol, DONT_ENUM, [ |
100 "for", SymbolFor, | 99 "for", SymbolFor, |
101 "keyFor", SymbolKeyFor | 100 "keyFor", SymbolKeyFor |
102 )); | 101 ]); |
103 | 102 |
104 %AddNamedProperty( | 103 %AddNamedProperty( |
105 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); | 104 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); |
106 %AddNamedProperty( | 105 %AddNamedProperty( |
107 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); | 106 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); |
108 | 107 |
109 InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, GlobalArray( | 108 InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, [ |
110 "toString", SymbolToString, | 109 "toString", SymbolToString, |
111 "valueOf", SymbolValueOf | 110 "valueOf", SymbolValueOf |
112 )); | 111 ]); |
113 | 112 |
114 InstallFunctions(GlobalObject, DONT_ENUM, GlobalArray( | 113 InstallFunctions(GlobalObject, DONT_ENUM, [ |
115 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 114 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
116 )); | 115 ]); |
117 | 116 |
118 $symbolToString = SymbolToString; | 117 $symbolToString = SymbolToString; |
119 | 118 |
120 })(); | 119 })(); |
OLD | NEW |