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