Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/symbol.js

Issue 181453002: Reset trunk to 3.24.35.4 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/sweeper-thread.cc ('k') | src/type-info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 18 matching lines...) Expand all
29 29
30 // This file relies on the fact that the following declaration has been made 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js: 31 // in runtime.js:
32 // var $Array = global.Array; 32 // var $Array = global.Array;
33 33
34 var $Symbol = global.Symbol; 34 var $Symbol = global.Symbol;
35 35
36 // ------------------------------------------------------------------- 36 // -------------------------------------------------------------------
37 37
38 function SymbolConstructor(x) { 38 function SymbolConstructor(x) {
39 var value =
40 IS_SYMBOL(x) ? x : %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
39 if (%_IsConstructCall()) { 41 if (%_IsConstructCall()) {
40 throw MakeTypeError('not_constructor', ["Symbol"]); 42 %_SetValueOf(this, value);
43 } else {
44 return value;
41 } 45 }
42 // NOTE: Passing in a Symbol value will throw on ToString().
43 return %CreateSymbol(IS_UNDEFINED(x) ? x : ToString(x));
44 } 46 }
45 47
48 function SymbolGetName() {
49 var symbol = IS_SYMBOL_WRAPPER(this) ? %_ValueOf(this) : this;
50 if (!IS_SYMBOL(symbol)) {
51 throw MakeTypeError(
52 'incompatible_method_receiver', ["Symbol.prototype.name", this]);
53 }
54 return %SymbolName(symbol);
55 }
46 56
47 function SymbolToString() { 57 function SymbolToString() {
48 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { 58 throw MakeTypeError('symbol_to_string');
49 throw MakeTypeError(
50 'incompatible_method_receiver', ["Symbol.prototype.toString", this]);
51 }
52 var description = %SymbolDescription(%_ValueOf(this));
53 return "Symbol(" + (IS_UNDEFINED(description) ? "" : description) + ")";
54 } 59 }
55 60
56
57 function SymbolValueOf() { 61 function SymbolValueOf() {
58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { 62 // NOTE: Both Symbol objects and values can enter here as
63 // 'this'. This is not as dictated by ECMA-262.
64 if (!IS_SYMBOL(this) && !IS_SYMBOL_WRAPPER(this)) {
59 throw MakeTypeError( 65 throw MakeTypeError(
60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); 66 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
61 } 67 }
62 return %_ValueOf(this); 68 return %_ValueOf(this);
63 } 69 }
64 70
65 71
66 // ES6 19.1.2.8 72 // ES6 19.1.2.8
67 function ObjectGetOwnPropertySymbols(obj) { 73 function ObjectGetOwnPropertySymbols(obj) {
68 if (!IS_SPEC_OBJECT(obj)) { 74 if (!IS_SPEC_OBJECT(obj)) {
69 throw MakeTypeError("called_on_non_object", 75 throw MakeTypeError("called_on_non_object",
70 ["Object.getOwnPropertySymbols"]); 76 ["Object.getOwnPropertySymbols"]);
71 } 77 }
72 78
73 // TODO(arv): Proxies use a shared trap for String and Symbol keys. 79 // TODO(arv): Proxies use a shared trap for String and Symbol keys.
74 80
75 return ObjectGetOwnPropertyKeys(obj, true); 81 return ObjectGetOwnPropertyKeys(obj, true);
76 } 82 }
77 83
78 84
79 //------------------------------------------------------------------- 85 //-------------------------------------------------------------------
80 86
81 function SetUpSymbol() { 87 function SetUpSymbol() {
82 %CheckIsBootstrapping(); 88 %CheckIsBootstrapping();
83 89
84 %SetCode($Symbol, SymbolConstructor); 90 %SetCode($Symbol, SymbolConstructor);
85 %FunctionSetPrototype($Symbol, new $Object()); 91 %FunctionSetPrototype($Symbol, new $Symbol());
92 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM);
86 93
87 %SetProperty($Symbol.prototype, "constructor", $Symbol, DONT_ENUM); 94 InstallGetter($Symbol.prototype, "name", SymbolGetName);
88 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array( 95 InstallFunctions($Symbol.prototype, DONT_ENUM, $Array(
89 "toString", SymbolToString, 96 "toString", SymbolToString,
90 "valueOf", SymbolValueOf 97 "valueOf", SymbolValueOf
91 )); 98 ));
92 } 99 }
93 100
94 SetUpSymbol(); 101 SetUpSymbol();
95 102
96 103
97 function ExtendObject() { 104 function ExtendObject() {
98 %CheckIsBootstrapping(); 105 %CheckIsBootstrapping();
99 106
100 InstallFunctions($Object, DONT_ENUM, $Array( 107 InstallFunctions($Object, DONT_ENUM, $Array(
101 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols 108 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
102 )); 109 ));
103 } 110 }
104 111
105 ExtendObject(); 112 ExtendObject();
OLDNEW
« no previous file with comments | « src/sweeper-thread.cc ('k') | src/type-info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698