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(global, utils) { | 15 (function(global, utils) { |
16 | 16 |
17 "use strict"; | 17 "use strict"; |
18 | 18 |
19 %CheckIsBootstrapping(); | 19 %CheckIsBootstrapping(); |
20 | 20 |
21 // ------------------------------------------------------------------- | |
22 // Imports | |
23 | |
24 var GlobalObject = global.Object; | 21 var GlobalObject = global.Object; |
25 var GlobalSymbol = global.Symbol; | 22 var GlobalSymbol = global.Symbol; |
26 | 23 |
27 var ObjectGetOwnPropertyKeys; | |
28 | |
29 utils.Import(function(from) { | |
30 ObjectGetOwnPropertyKeys = from.ObjectGetOwnPropertyKeys; | |
31 }); | |
32 | |
33 // ------------------------------------------------------------------- | 24 // ------------------------------------------------------------------- |
34 | 25 |
35 function SymbolConstructor(x) { | 26 function SymbolConstructor(x) { |
36 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol"); | 27 if (%_IsConstructCall()) throw MakeTypeError(kNotConstructor, "Symbol"); |
37 // NOTE: Passing in a Symbol value will throw on ToString(). | 28 // NOTE: Passing in a Symbol value will throw on ToString(). |
38 return %CreateSymbol(IS_UNDEFINED(x) ? x : $toString(x)); | 29 return %CreateSymbol(IS_UNDEFINED(x) ? x : $toString(x)); |
39 } | 30 } |
40 | 31 |
41 | 32 |
42 function SymbolToString() { | 33 function SymbolToString() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 return %SymbolRegistry().keyFor[symbol]; | 66 return %SymbolRegistry().keyFor[symbol]; |
76 } | 67 } |
77 | 68 |
78 | 69 |
79 // ES6 19.1.2.8 | 70 // ES6 19.1.2.8 |
80 function ObjectGetOwnPropertySymbols(obj) { | 71 function ObjectGetOwnPropertySymbols(obj) { |
81 obj = $toObject(obj); | 72 obj = $toObject(obj); |
82 | 73 |
83 // TODO(arv): Proxies use a shared trap for String and Symbol keys. | 74 // TODO(arv): Proxies use a shared trap for String and Symbol keys. |
84 | 75 |
85 return ObjectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); | 76 return $objectGetOwnPropertyKeys(obj, PROPERTY_ATTRIBUTES_STRING); |
86 } | 77 } |
87 | 78 |
88 //------------------------------------------------------------------- | 79 //------------------------------------------------------------------- |
89 | 80 |
90 %SetCode(GlobalSymbol, SymbolConstructor); | 81 %SetCode(GlobalSymbol, SymbolConstructor); |
91 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); | 82 %FunctionSetPrototype(GlobalSymbol, new GlobalObject()); |
92 | 83 |
93 utils.InstallConstants(GlobalSymbol, [ | 84 $installConstants(GlobalSymbol, [ |
94 // TODO(rossberg): expose when implemented. | 85 // TODO(rossberg): expose when implemented. |
95 // "hasInstance", symbolHasInstance, | 86 // "hasInstance", symbolHasInstance, |
96 // "isConcatSpreadable", symbolIsConcatSpreadable, | 87 // "isConcatSpreadable", symbolIsConcatSpreadable, |
97 // "isRegExp", symbolIsRegExp, | 88 // "isRegExp", symbolIsRegExp, |
98 "iterator", symbolIterator, | 89 "iterator", symbolIterator, |
99 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- | 90 // TODO(dslomov, caitp): Currently defined in harmony-tostring.js --- |
100 // Move here when shipping | 91 // Move here when shipping |
101 // "toStringTag", symbolToStringTag, | 92 // "toStringTag", symbolToStringTag, |
102 "unscopables", symbolUnscopables | 93 "unscopables", symbolUnscopables |
103 ]); | 94 ]); |
104 | 95 |
105 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ | 96 $installFunctions(GlobalSymbol, DONT_ENUM, [ |
106 "for", SymbolFor, | 97 "for", SymbolFor, |
107 "keyFor", SymbolKeyFor | 98 "keyFor", SymbolKeyFor |
108 ]); | 99 ]); |
109 | 100 |
110 %AddNamedProperty( | 101 %AddNamedProperty( |
111 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); | 102 GlobalSymbol.prototype, "constructor", GlobalSymbol, DONT_ENUM); |
112 %AddNamedProperty( | 103 %AddNamedProperty( |
113 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); | 104 GlobalSymbol.prototype, symbolToStringTag, "Symbol", DONT_ENUM | READ_ONLY); |
114 | 105 |
115 utils.InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, [ | 106 $installFunctions(GlobalSymbol.prototype, DONT_ENUM, [ |
116 "toString", SymbolToString, | 107 "toString", SymbolToString, |
117 "valueOf", SymbolValueOf | 108 "valueOf", SymbolValueOf |
118 ]); | 109 ]); |
119 | 110 |
120 utils.InstallFunctions(GlobalObject, DONT_ENUM, [ | 111 $installFunctions(GlobalObject, DONT_ENUM, [ |
121 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols | 112 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols |
122 ]); | 113 ]); |
123 | 114 |
124 $symbolToString = SymbolToString; | 115 $symbolToString = SymbolToString; |
125 | 116 |
126 }) | 117 }) |
OLD | NEW |