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/weak-collection.js

Issue 2915793002: [api] Prototype WeakRef implementation
Patch Set: Created 3 years, 6 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/macros.py ('k') | src/objects.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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
11 // ------------------------------------------------------------------- 11 // -------------------------------------------------------------------
12 // Imports 12 // Imports
13 13
14 var GetExistingHash; 14 var GetExistingHash;
15 var GetHash; 15 var GetHash;
16 var GlobalObject = global.Object; 16 var GlobalObject = global.Object;
17 var GlobalWeakMap = global.WeakMap; 17 var GlobalWeakMap = global.WeakMap;
18 var GlobalWeakSet = global.WeakSet; 18 var GlobalWeakSet = global.WeakSet;
19 var GlobalWeakRef = global.WeakRef;
19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); 20 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
20 21
21 utils.Import(function(from) { 22 utils.Import(function(from) {
22 GetExistingHash = from.GetExistingHash; 23 GetExistingHash = from.GetExistingHash;
23 GetHash = from.GetHash; 24 GetHash = from.GetHash;
24 }); 25 });
25 26
26 // ------------------------------------------------------------------- 27 // -------------------------------------------------------------------
27 // Harmony WeakMap 28 // Harmony WeakMap
28 29
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet", 179 %AddNamedProperty(GlobalWeakSet.prototype, toStringTagSymbol, "WeakSet",
179 DONT_ENUM | READ_ONLY); 180 DONT_ENUM | READ_ONLY);
180 181
181 // Set up the non-enumerable functions on the WeakSet prototype object. 182 // Set up the non-enumerable functions on the WeakSet prototype object.
182 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [ 183 utils.InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [
183 "add", WeakSetAdd, 184 "add", WeakSetAdd,
184 "has", WeakSetHas, 185 "has", WeakSetHas,
185 "delete", WeakSetDelete 186 "delete", WeakSetDelete
186 ]); 187 ]);
187 188
189 function WeakRefConstructor(target, finalizer, holdings) {
190 if (IS_UNDEFINED(new.target)) {
191 throw %make_type_error(kConstructorNotFunction, "WeakRef");
192 }
193
194 if (typeof target !== 'object') {
195 throw %make_type_error(kInvalidArgument);
196 }
197 if (typeof finalizer !== 'function') {
198 throw %make_type_error(kInvalidArgument);
199 }
200
201 %WeakRefInitialize(this, target, finalizer, holdings);
202 }
203
204 function WeakRefValue() {
205 if (!IS_WEAKREF(this)) {
206 throw %make_type_error(kIncompatibleMethodReceiver,
207 'WeakRef.prototype.value', this);
208 }
209 return %WeakRefValue(this);
210 }
211 function WeakRefClear() {
212 if (!IS_WEAKREF(this)) {
213 throw %make_type_error(kIncompatibleMethodReceiver,
214 'WeakRef.prototype.clear', this);
215 }
216 return %WeakRefClear(this);
217 }
218 %SetCode(GlobalWeakRef, WeakRefConstructor);
219 %FunctionSetLength(GlobalWeakRef, 0);
220 %FunctionSetPrototype(GlobalWeakRef, new GlobalObject());
221 %AddNamedProperty(GlobalWeakRef.prototype, "constructor", GlobalWeakRef,
222 DONT_ENUM);
223 %AddNamedProperty(GlobalWeakRef.prototype, toStringTagSymbol, "WeakRef",
224 DONT_ENUM | READ_ONLY);
225
226 // Set up the non-enumerable functions on the WeakSet prototype object.
227 utils.InstallFunctions(GlobalWeakRef.prototype, DONT_ENUM, [
228 "get", WeakRefValue,
229 "clear", WeakRefClear
230 ]);
231
188 }) 232 })
OLDNEW
« no previous file with comments | « src/js/macros.py ('k') | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698