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 12 matching lines...) Expand all Loading... | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 "use strict"; | 28 "use strict"; |
29 | 29 |
30 var $Symbol = global.Symbol; | 30 var $Symbol = global.Symbol; |
31 | 31 |
32 function SymbolConstructor(x) { | 32 function SymbolConstructor(x) { |
33 var value = IS_SYMBOL(x) ? x : %CreateSymbol(); | 33 var value = |
34 IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x)); | |
34 if (%_IsConstructCall()) { | 35 if (%_IsConstructCall()) { |
35 %_SetValueOf(this, value); | 36 %_SetValueOf(this, value); |
36 } else { | 37 } else { |
37 return value; | 38 return value; |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
42 function SymbolGetName() { | |
43 var symbol = IS_SYMBOL_WRAPPER(this) ? %_ValueOf(this) : this; | |
44 if (!IS_SYMBOL(symbol)) { | |
45 throw new $TypeError("Symbol.prototype.name is not generic"); | |
Michael Starzinger
2013/03/22 12:03:25
Use MakeTypeError here, see my comments in the pre
rossberg
2013/03/22 13:02:42
Done.
| |
46 } | |
47 return %SymbolName(symbol); | |
48 } | |
49 | |
41 function SymbolToString() { | 50 function SymbolToString() { |
42 throw new $TypeError("Symbol.prototype.toString is not allowed"); | 51 throw new $TypeError("Symbol.prototype.toString is not allowed"); |
43 } | 52 } |
44 | 53 |
45 function SymbolValueOf() { | 54 function SymbolValueOf() { |
46 // NOTE: Both Symbol objects and values can enter here as | 55 // NOTE: Both Symbol objects and values can enter here as |
47 // 'this'. This is not as dictated by ECMA-262. | 56 // 'this'. This is not as dictated by ECMA-262. |
48 if (!IS_SYMBOL(this) && !IS_SYMBOL_WRAPPER(this)) { | 57 if (!IS_SYMBOL(this) && !IS_SYMBOL_WRAPPER(this)) { |
49 throw new $TypeError("Symbol.prototype.valueOf is not generic"); | 58 throw new $TypeError("Symbol.prototype.valueOf is not generic"); |
50 } | 59 } |
51 return %_ValueOf(this); | 60 return %_ValueOf(this); |
52 } | 61 } |
53 | 62 |
54 //------------------------------------------------------------------- | 63 //------------------------------------------------------------------- |
55 | 64 |
56 function SetUpSymbol() { | 65 function SetUpSymbol() { |
57 %CheckIsBootstrapping(); | 66 %CheckIsBootstrapping(); |
58 | 67 |
59 %SetCode($Symbol, SymbolConstructor); | 68 %SetCode($Symbol, SymbolConstructor); |
60 %FunctionSetPrototype($Symbol, new $Symbol()); | 69 %FunctionSetPrototype($Symbol, new $Symbol()); |
61 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); | 70 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); |
62 | 71 |
72 InstallGetter($Symbol.prototype, "name", SymbolGetName); | |
63 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( | 73 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( |
64 "toString", SymbolToString, | 74 "toString", SymbolToString, |
65 "valueOf", SymbolValueOf | 75 "valueOf", SymbolValueOf |
66 )); | 76 )); |
67 } | 77 } |
68 | 78 |
69 SetUpSymbol(); | 79 SetUpSymbol(); |
OLD | NEW |