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

Side by Side Diff: src/weak-collection.js

Issue 1094563002: Wrap map and set implementation in functions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 8 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/templates.js ('k') | no next file » | 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() {
6
5 "use strict"; 7 "use strict";
6 8
7 // This file relies on the fact that the following declaration has been made 9 %CheckIsBootstrapping();
8 // in runtime.js:
9 // var $Array = global.Array;
10 10
11 var $WeakMap = global.WeakMap; 11 var GlobalObject = global.Object;
12 var $WeakSet = global.WeakSet; 12 var GlobalWeakMap = global.WeakMap;
13 13 var GlobalWeakSet = global.WeakSet;
14 14
15 // ------------------------------------------------------------------- 15 // -------------------------------------------------------------------
16 // Harmony WeakMap 16 // Harmony WeakMap
17 17
18 function WeakMapConstructor(iterable) { 18 function WeakMapConstructor(iterable) {
19 if (!%_IsConstructCall()) { 19 if (!%_IsConstructCall()) {
20 throw MakeTypeError('constructor_not_function', ['WeakMap']); 20 throw MakeTypeError('constructor_not_function', ['WeakMap']);
21 } 21 }
22 22
23 %WeakCollectionInitialize(this); 23 %WeakCollectionInitialize(this);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 throw MakeTypeError('incompatible_method_receiver', 74 throw MakeTypeError('incompatible_method_receiver',
75 ['WeakMap.prototype.delete', this]); 75 ['WeakMap.prototype.delete', this]);
76 } 76 }
77 if (!IS_SPEC_OBJECT(key)) return false; 77 if (!IS_SPEC_OBJECT(key)) return false;
78 return %WeakCollectionDelete(this, key); 78 return %WeakCollectionDelete(this, key);
79 } 79 }
80 80
81 81
82 // ------------------------------------------------------------------- 82 // -------------------------------------------------------------------
83 83
84 function SetUpWeakMap() { 84 %SetCode(GlobalWeakMap, WeakMapConstructor);
85 %CheckIsBootstrapping(); 85 %FunctionSetLength(GlobalWeakMap, 0);
86 %FunctionSetPrototype(GlobalWeakMap, new GlobalObject());
87 %AddNamedProperty(GlobalWeakMap.prototype, "constructor", GlobalWeakMap,
88 DONT_ENUM);
89 %AddNamedProperty(GlobalWeakMap.prototype, symbolToStringTag, "WeakMap",
90 DONT_ENUM | READ_ONLY);
86 91
87 %SetCode($WeakMap, WeakMapConstructor); 92 // Set up the non-enumerable functions on the WeakMap prototype object.
88 %FunctionSetLength($WeakMap, 0); 93 InstallFunctions(GlobalWeakMap.prototype, DONT_ENUM, [
89 %FunctionSetPrototype($WeakMap, new $Object()); 94 "get", WeakMapGet,
90 %AddNamedProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 95 "set", WeakMapSet,
91 %AddNamedProperty( 96 "has", WeakMapHas,
92 $WeakMap.prototype, symbolToStringTag, "WeakMap", DONT_ENUM | READ_ONLY); 97 "delete", WeakMapDelete
93 98 ]);
94 // Set up the non-enumerable functions on the WeakMap prototype object.
95 InstallFunctions($WeakMap.prototype, DONT_ENUM, [
96 "get", WeakMapGet,
97 "set", WeakMapSet,
98 "has", WeakMapHas,
99 "delete", WeakMapDelete
100 ]);
101 }
102
103 SetUpWeakMap();
104
105 99
106 // ------------------------------------------------------------------- 100 // -------------------------------------------------------------------
107 // Harmony WeakSet 101 // Harmony WeakSet
108 102
109 function WeakSetConstructor(iterable) { 103 function WeakSetConstructor(iterable) {
110 if (!%_IsConstructCall()) { 104 if (!%_IsConstructCall()) {
111 throw MakeTypeError('constructor_not_function', ['WeakSet']); 105 throw MakeTypeError('constructor_not_function', ['WeakSet']);
112 } 106 }
113 107
114 %WeakCollectionInitialize(this); 108 %WeakCollectionInitialize(this);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 throw MakeTypeError('incompatible_method_receiver', 146 throw MakeTypeError('incompatible_method_receiver',
153 ['WeakSet.prototype.delete', this]); 147 ['WeakSet.prototype.delete', this]);
154 } 148 }
155 if (!IS_SPEC_OBJECT(value)) return false; 149 if (!IS_SPEC_OBJECT(value)) return false;
156 return %WeakCollectionDelete(this, value); 150 return %WeakCollectionDelete(this, value);
157 } 151 }
158 152
159 153
160 // ------------------------------------------------------------------- 154 // -------------------------------------------------------------------
161 155
162 function SetUpWeakSet() { 156 %SetCode(GlobalWeakSet, WeakSetConstructor);
163 %CheckIsBootstrapping(); 157 %FunctionSetLength(GlobalWeakSet, 0);
158 %FunctionSetPrototype(GlobalWeakSet, new GlobalObject());
159 %AddNamedProperty(GlobalWeakSet.prototype, "constructor", GlobalWeakSet,
160 DONT_ENUM);
161 %AddNamedProperty(GlobalWeakSet.prototype, symbolToStringTag, "WeakSet",
162 DONT_ENUM | READ_ONLY);
164 163
165 %SetCode($WeakSet, WeakSetConstructor); 164 // Set up the non-enumerable functions on the WeakSet prototype object.
166 %FunctionSetLength($WeakSet, 0); 165 InstallFunctions(GlobalWeakSet.prototype, DONT_ENUM, [
167 %FunctionSetPrototype($WeakSet, new $Object()); 166 "add", WeakSetAdd,
168 %AddNamedProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM); 167 "has", WeakSetHas,
169 %AddNamedProperty( 168 "delete", WeakSetDelete
170 $WeakSet.prototype, symbolToStringTag, "WeakSet", DONT_ENUM | READ_ONLY); 169 ]);
171 170
172 // Set up the non-enumerable functions on the WeakSet prototype object. 171 })();
173 InstallFunctions($WeakSet.prototype, DONT_ENUM, [
174 "add", WeakSetAdd,
175 "has", WeakSetHas,
176 "delete", WeakSetDelete
177 ]);
178 }
179
180 SetUpWeakSet();
OLDNEW
« no previous file with comments | « src/templates.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698