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

Side by Side Diff: src/weak_collection.js

Issue 201593004: Stage ES6 promises and weak collections (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comment 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
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/es6/promises.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 "use strict"; 28 "use strict";
29 29
30 // This file relies on the fact that the following declaration has been made 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js: 31 // in runtime.js:
32 // var $Array = global.Array; 32 // var $Array = global.Array;
33 33
34 var $Set = global.Set;
35 var $Map = global.Map;
36 var $WeakMap = global.WeakMap; 34 var $WeakMap = global.WeakMap;
37 var $WeakSet = global.WeakSet; 35 var $WeakSet = global.WeakSet;
38 36
39 // Global sentinel to be used instead of undefined keys, which are not
40 // supported internally but required for Harmony sets and maps.
41 var undefined_sentinel = {};
42
43
44 // Map and Set uses SameValueZero which means that +0 and -0 should be treated
45 // as the same value.
46 function NormalizeKey(key) {
47 if (IS_UNDEFINED(key)) {
48 return undefined_sentinel;
49 }
50
51 if (key === 0) {
52 return 0;
53 }
54
55 return key;
56 }
57
58
59 // -------------------------------------------------------------------
60 // Harmony Set
61
62 function SetConstructor() {
63 if (%_IsConstructCall()) {
64 %SetInitialize(this);
65 } else {
66 throw MakeTypeError('constructor_not_function', ['Set']);
67 }
68 }
69
70
71 function SetAdd(key) {
72 if (!IS_SET(this)) {
73 throw MakeTypeError('incompatible_method_receiver',
74 ['Set.prototype.add', this]);
75 }
76 return %SetAdd(this, NormalizeKey(key));
77 }
78
79
80 function SetHas(key) {
81 if (!IS_SET(this)) {
82 throw MakeTypeError('incompatible_method_receiver',
83 ['Set.prototype.has', this]);
84 }
85 return %SetHas(this, NormalizeKey(key));
86 }
87
88
89 function SetDelete(key) {
90 if (!IS_SET(this)) {
91 throw MakeTypeError('incompatible_method_receiver',
92 ['Set.prototype.delete', this]);
93 }
94 key = NormalizeKey(key);
95 if (%SetHas(this, key)) {
96 %SetDelete(this, key);
97 return true;
98 } else {
99 return false;
100 }
101 }
102
103
104 function SetGetSize() {
105 if (!IS_SET(this)) {
106 throw MakeTypeError('incompatible_method_receiver',
107 ['Set.prototype.size', this]);
108 }
109 return %SetGetSize(this);
110 }
111
112
113 function SetClear() {
114 if (!IS_SET(this)) {
115 throw MakeTypeError('incompatible_method_receiver',
116 ['Set.prototype.clear', this]);
117 }
118 // Replace the internal table with a new empty table.
119 %SetInitialize(this);
120 }
121
122
123 // -------------------------------------------------------------------
124
125 function SetUpSet() {
126 %CheckIsBootstrapping();
127
128 %SetCode($Set, SetConstructor);
129 %FunctionSetPrototype($Set, new $Object());
130 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
131
132 // Set up the non-enumerable functions on the Set prototype object.
133 InstallGetter($Set.prototype, "size", SetGetSize);
134 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
135 "add", SetAdd,
136 "has", SetHas,
137 "delete", SetDelete,
138 "clear", SetClear
139 ));
140 }
141
142 SetUpSet();
143
144
145 // -------------------------------------------------------------------
146 // Harmony Map
147
148 function MapConstructor() {
149 if (%_IsConstructCall()) {
150 %MapInitialize(this);
151 } else {
152 throw MakeTypeError('constructor_not_function', ['Map']);
153 }
154 }
155
156
157 function MapGet(key) {
158 if (!IS_MAP(this)) {
159 throw MakeTypeError('incompatible_method_receiver',
160 ['Map.prototype.get', this]);
161 }
162 return %MapGet(this, NormalizeKey(key));
163 }
164
165
166 function MapSet(key, value) {
167 if (!IS_MAP(this)) {
168 throw MakeTypeError('incompatible_method_receiver',
169 ['Map.prototype.set', this]);
170 }
171 return %MapSet(this, NormalizeKey(key), value);
172 }
173
174
175 function MapHas(key) {
176 if (!IS_MAP(this)) {
177 throw MakeTypeError('incompatible_method_receiver',
178 ['Map.prototype.has', this]);
179 }
180 return %MapHas(this, NormalizeKey(key));
181 }
182
183
184 function MapDelete(key) {
185 if (!IS_MAP(this)) {
186 throw MakeTypeError('incompatible_method_receiver',
187 ['Map.prototype.delete', this]);
188 }
189 return %MapDelete(this, NormalizeKey(key));
190 }
191
192
193 function MapGetSize() {
194 if (!IS_MAP(this)) {
195 throw MakeTypeError('incompatible_method_receiver',
196 ['Map.prototype.size', this]);
197 }
198 return %MapGetSize(this);
199 }
200
201
202 function MapClear() {
203 if (!IS_MAP(this)) {
204 throw MakeTypeError('incompatible_method_receiver',
205 ['Map.prototype.clear', this]);
206 }
207 // Replace the internal table with a new empty table.
208 %MapInitialize(this);
209 }
210
211
212 // -------------------------------------------------------------------
213
214 function SetUpMap() {
215 %CheckIsBootstrapping();
216
217 %SetCode($Map, MapConstructor);
218 %FunctionSetPrototype($Map, new $Object());
219 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
220
221 // Set up the non-enumerable functions on the Map prototype object.
222 InstallGetter($Map.prototype, "size", MapGetSize);
223 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
224 "get", MapGet,
225 "set", MapSet,
226 "has", MapHas,
227 "delete", MapDelete,
228 "clear", MapClear
229 ));
230 }
231
232 SetUpMap();
233
234 37
235 // ------------------------------------------------------------------- 38 // -------------------------------------------------------------------
236 // Harmony WeakMap 39 // Harmony WeakMap
237 40
238 function WeakMapConstructor() { 41 function WeakMapConstructor() {
239 if (%_IsConstructCall()) { 42 if (%_IsConstructCall()) {
240 %WeakCollectionInitialize(this); 43 %WeakCollectionInitialize(this);
241 } else { 44 } else {
242 throw MakeTypeError('constructor_not_function', ['WeakMap']); 45 throw MakeTypeError('constructor_not_function', ['WeakMap']);
243 } 46 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // Set up the non-enumerable functions on the WeakSet prototype object. 197 // Set up the non-enumerable functions on the WeakSet prototype object.
395 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array( 198 InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array(
396 "add", WeakSetAdd, 199 "add", WeakSetAdd,
397 "has", WeakSetHas, 200 "has", WeakSetHas,
398 "delete", WeakSetDelete, 201 "delete", WeakSetDelete,
399 "clear", WeakSetClear 202 "clear", WeakSetClear
400 )); 203 ));
401 } 204 }
402 205
403 SetUpWeakSet(); 206 SetUpWeakSet();
OLDNEW
« no previous file with comments | « src/flag-definitions.h ('k') | test/mjsunit/es6/promises.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698