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

Side by Side Diff: src/symbol.js

Issue 196103004: Add support for per-isolate private symbols (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: More comments; force dictionary mode 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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 function SymbolValueOf() { 57 function SymbolValueOf() {
58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) { 58 if (!(IS_SYMBOL(this) || IS_SYMBOL_WRAPPER(this))) {
59 throw MakeTypeError( 59 throw MakeTypeError(
60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]); 60 'incompatible_method_receiver', ["Symbol.prototype.valueOf", this]);
61 } 61 }
62 return %_ValueOf(this); 62 return %_ValueOf(this);
63 } 63 }
64 64
65 65
66 function GetSymbolRegistry() {
67 var registry = %SymbolRegistry();
68 if (!('internal' in registry)) {
69 registry.internal = {__proto__: null};
70 registry.for = {__proto__: null};
71 registry.keyFor = {__proto__: null};
72 }
73 return registry;
74 }
75
76
77 function InternalSymbol(key) { 66 function InternalSymbol(key) {
78 var registry = GetSymbolRegistry(); 67 var internal_registry = %SymbolRegistry().for_intern;
79 if (!(key in registry.internal)) { 68 if (IS_UNDEFINED(internal_registry[key])) {
80 registry.internal[key] = %CreateSymbol(key); 69 internal_registry[key] = %CreateSymbol(key);
81 } 70 }
82 return registry.internal[key]; 71 return internal_registry[key];
83 } 72 }
84 73
85 74
86 function SymbolFor(key) { 75 function SymbolFor(key) {
87 key = TO_STRING_INLINE(key); 76 key = TO_STRING_INLINE(key);
88 var registry = GetSymbolRegistry(); 77 var registry = %SymbolRegistry();
89 if (!(key in registry.for)) { 78 if (IS_UNDEFINED(registry.for[key])) {
90 var symbol = %CreateSymbol(key); 79 var symbol = %CreateSymbol(key);
91 registry.for[key] = symbol; 80 registry.for[key] = symbol;
92 registry.keyFor[symbol] = key; 81 registry.keyFor[symbol] = key;
93 } 82 }
94 return registry.for[key]; 83 return registry.for[key];
95 } 84 }
96 85
97 86
98 function SymbolKeyFor(symbol) { 87 function SymbolKeyFor(symbol) {
99 if (!IS_SYMBOL(symbol)) { 88 if (!IS_SYMBOL(symbol)) throw MakeTypeError("not_a_symbol", [symbol]);
100 throw MakeTypeError("not_a_symbol", [symbol]); 89 return %SymbolRegistry().keyFor[symbol];
101 }
102 return GetSymbolRegistry().keyFor[symbol];
103 } 90 }
104 91
105 92
106 // ES6 19.1.2.8 93 // ES6 19.1.2.8
107 function ObjectGetOwnPropertySymbols(obj) { 94 function ObjectGetOwnPropertySymbols(obj) {
108 if (!IS_SPEC_OBJECT(obj)) { 95 if (!IS_SPEC_OBJECT(obj)) {
109 throw MakeTypeError("called_on_non_object", 96 throw MakeTypeError("called_on_non_object",
110 ["Object.getOwnPropertySymbols"]); 97 ["Object.getOwnPropertySymbols"]);
111 } 98 }
112 99
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 147
161 function ExtendObject() { 148 function ExtendObject() {
162 %CheckIsBootstrapping(); 149 %CheckIsBootstrapping();
163 150
164 InstallFunctions($Object, DONT_ENUM, $Array( 151 InstallFunctions($Object, DONT_ENUM, $Array(
165 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols 152 "getOwnPropertySymbols", ObjectGetOwnPropertySymbols
166 )); 153 ));
167 } 154 }
168 155
169 ExtendObject(); 156 ExtendObject();
OLDNEW
« src/isolate.cc ('K') | « src/runtime.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698