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

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

Issue 2117273002: Revert of [intrinsic] Drop the %_ValueOf intrinsic. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
35 function SymbolFor(key) { 63 function SymbolFor(key) {
36 key = TO_STRING(key); 64 key = TO_STRING(key);
37 var registry = %SymbolRegistry(); 65 var registry = %SymbolRegistry();
38 if (IS_UNDEFINED(registry.for[key])) { 66 if (IS_UNDEFINED(registry.for[key])) {
39 var symbol = %CreateSymbol(key); 67 var symbol = %CreateSymbol(key);
40 registry.for[key] = symbol; 68 registry.for[key] = symbol;
41 registry.keyFor[symbol] = key; 69 registry.keyFor[symbol] = key;
42 } 70 }
43 return registry.for[key]; 71 return registry.for[key];
44 } 72 }
(...skipping 18 matching lines...) Expand all
63 "toPrimitive", toPrimitiveSymbol, 91 "toPrimitive", toPrimitiveSymbol,
64 "toStringTag", toStringTagSymbol, 92 "toStringTag", toStringTagSymbol,
65 "unscopables", unscopablesSymbol, 93 "unscopables", unscopablesSymbol,
66 ]); 94 ]);
67 95
68 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [ 96 utils.InstallFunctions(GlobalSymbol, DONT_ENUM, [
69 "for", SymbolFor, 97 "for", SymbolFor,
70 "keyFor", SymbolKeyFor 98 "keyFor", SymbolKeyFor
71 ]); 99 ]);
72 100
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;
73 }) 118 })
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