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

Side by Side Diff: src/js/symbol.js

Issue 2126453002: [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix noi18n build (narf) Created 4 years, 5 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
« no previous file with comments | « src/js/string.js ('k') | src/js/v8natives.js » ('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 // 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 (function(global, utils) { 5 (function(global, utils) {
6 6
7 "use strict"; 7 "use strict";
8 8
9 %CheckIsBootstrapping(); 9 %CheckIsBootstrapping();
10 10
(...skipping 14 matching lines...) Expand all
25 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol"); 25 var toPrimitiveSymbol = utils.ImportNow("to_primitive_symbol");
26 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 26 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
27 var unscopablesSymbol = utils.ImportNow("unscopables_symbol"); 27 var unscopablesSymbol = utils.ImportNow("unscopables_symbol");
28 28
29 utils.Import(function(from) { 29 utils.Import(function(from) {
30 MakeTypeError = from.MakeTypeError; 30 MakeTypeError = from.MakeTypeError;
31 }); 31 });
32 32
33 // ------------------------------------------------------------------- 33 // -------------------------------------------------------------------
34 34
35 // 19.4.3.4 Symbol.prototype [ @@toPrimitive ] ( hint )
36 function SymbolToPrimitive(hint) {
37 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
38 throw MakeTypeError(kIncompatibleMethodReceiver,
39 "Symbol.prototype [ @@toPrimitive ]", this);
40 }
41 return %_ValueOf(this);
42 }
43
44
45 function SymbolToString() {
46 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
47 throw MakeTypeError(kIncompatibleMethodReceiver,
48 "Symbol.prototype.toString", this);
49 }
50 return %SymbolDescriptiveString(%_ValueOf(this));
51 }
52
53
54 function SymbolValueOf() {
55 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
56 throw MakeTypeError(kIncompatibleMethodReceiver,
57 "Symbol.prototype.valueOf", this);
58 }
59 return %_ValueOf(this);
60 }
61
62
63 function SymbolFor(key) { 35 function SymbolFor(key) {
64 key = TO_STRING(key); 36 key = TO_STRING(key);
65 var registry = %SymbolRegistry(); 37 var registry = %SymbolRegistry();
66 if (IS_UNDEFINED(registry.for[key])) { 38 if (IS_UNDEFINED(registry.for[key])) {
67 var symbol = %CreateSymbol(key); 39 var symbol = %CreateSymbol(key);
68 registry.for[key] = symbol; 40 registry.for[key] = symbol;
69 registry.keyFor[symbol] = key; 41 registry.keyFor[symbol] = key;
70 } 42 }
71 return registry.for[key]; 43 return registry.for[key];
72 } 44 }
(...skipping 18 matching lines...) Expand all
91 "toPrimitive", toPrimitiveSymbol, 63 "toPrimitive", toPrimitiveSymbol,
92 "toStringTag", toStringTagSymbol, 64 "toStringTag", toStringTagSymbol,
93 "unscopables", unscopablesSymbol, 65 "unscopables", unscopablesSymbol,
94 ]); 66 ]);
95 67
96 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ 68 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [
97 "for", SymbolFor, 69 "for", SymbolFor,
98 "keyFor", SymbolKeyFor 70 "keyFor", SymbolKeyFor
99 ]); 71 ]);
100 72
101 %AddNamedProperty(
102 GlobalSymbol.prototype, toStringTagSymbol, "Symbol", DONT_ENUM | READ_ONLY);
103
104 utils.InstallFunctions(GlobalSymbol.prototype, DONT_ENUM | READ_ONLY, [
105 toPrimitiveSymbol, SymbolToPrimitive
106 ]);
107
108 utils.InstallFunctions(GlobalSymbol.prototype, DONT_ENUM, [
109 "toString", SymbolToString,
110 "valueOf", SymbolValueOf
111 ]);
112
113 // -------------------------------------------------------------------
114 // Exports
115
116 utils.Export(function(to) {
117 to.SymbolToString = SymbolToString;
118 }) 73 })
119
120 })
OLDNEW
« no previous file with comments | « src/js/string.js ('k') | src/js/v8natives.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698