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

Side by Side Diff: src/collection.js

Issue 14125004: Move global code for builtins into setup functions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Andreas Rossberg. Created 7 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 | Annotate | Revision Log
« no previous file with comments | « src/array.js ('k') | src/date.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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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
31 // in runtime.js:
32 // var $Array = global.Array;
33
30 var $Set = global.Set; 34 var $Set = global.Set;
31 var $Map = global.Map; 35 var $Map = global.Map;
32 var $WeakMap = global.WeakMap; 36 var $WeakMap = global.WeakMap;
33 37
34 //-------------------------------------------------------------------
35
36 // Global sentinel to be used instead of undefined keys, which are not 38 // Global sentinel to be used instead of undefined keys, which are not
37 // supported internally but required for Harmony sets and maps. 39 // supported internally but required for Harmony sets and maps.
38 var undefined_sentinel = {}; 40 var undefined_sentinel = {};
39 41
42 // -------------------------------------------------------------------
43 // Harmony Set
40 44
41 function SetConstructor() { 45 function SetConstructor() {
42 if (%_IsConstructCall()) { 46 if (%_IsConstructCall()) {
43 %SetInitialize(this); 47 %SetInitialize(this);
44 } else { 48 } else {
45 return new $Set(); 49 return new $Set();
46 } 50 }
47 } 51 }
48 52
49 53
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 function SetClear() { 104 function SetClear() {
101 if (!IS_SET(this)) { 105 if (!IS_SET(this)) {
102 throw MakeTypeError('incompatible_method_receiver', 106 throw MakeTypeError('incompatible_method_receiver',
103 ['Set.prototype.clear', this]); 107 ['Set.prototype.clear', this]);
104 } 108 }
105 // Replace the internal table with a new empty table. 109 // Replace the internal table with a new empty table.
106 %SetInitialize(this); 110 %SetInitialize(this);
107 } 111 }
108 112
109 113
114 // -------------------------------------------------------------------
115
116 function SetUpSet() {
117 %CheckIsBootstrapping();
118
119 %SetCode($Set, SetConstructor);
120 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
121
122 // Set up the non-enumerable functions on the Set prototype object.
123 InstallGetter($Set.prototype, "size", SetGetSize);
124 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
125 "add", SetAdd,
126 "has", SetHas,
127 "delete", SetDelete,
128 "clear", SetClear
129 ));
130 }
131
132 SetUpSet();
133
134
135 // -------------------------------------------------------------------
136 // Harmony Map
137
110 function MapConstructor() { 138 function MapConstructor() {
111 if (%_IsConstructCall()) { 139 if (%_IsConstructCall()) {
112 %MapInitialize(this); 140 %MapInitialize(this);
113 } else { 141 } else {
114 return new $Map(); 142 return new $Map();
115 } 143 }
116 } 144 }
117 145
118 146
119 function MapGet(key) { 147 function MapGet(key) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 function MapClear() { 204 function MapClear() {
177 if (!IS_MAP(this)) { 205 if (!IS_MAP(this)) {
178 throw MakeTypeError('incompatible_method_receiver', 206 throw MakeTypeError('incompatible_method_receiver',
179 ['Map.prototype.clear', this]); 207 ['Map.prototype.clear', this]);
180 } 208 }
181 // Replace the internal table with a new empty table. 209 // Replace the internal table with a new empty table.
182 %MapInitialize(this); 210 %MapInitialize(this);
183 } 211 }
184 212
185 213
214 // -------------------------------------------------------------------
215
216 function SetUpMap() {
217 %CheckIsBootstrapping();
218
219 %SetCode($Map, MapConstructor);
220 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
221
222 // Set up the non-enumerable functions on the Map prototype object.
223 InstallGetter($Map.prototype, "size", MapGetSize);
224 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
225 "get", MapGet,
226 "set", MapSet,
227 "has", MapHas,
228 "delete", MapDelete,
229 "clear", MapClear
230 ));
231 }
232
233 SetUpMap();
234
235
236 // -------------------------------------------------------------------
237 // Harmony WeakMap
238
186 function WeakMapConstructor() { 239 function WeakMapConstructor() {
187 if (%_IsConstructCall()) { 240 if (%_IsConstructCall()) {
188 %WeakMapInitialize(this); 241 %WeakMapInitialize(this);
189 } else { 242 } else {
190 return new $WeakMap(); 243 return new $WeakMap();
191 } 244 }
192 } 245 }
193 246
194 247
195 function WeakMapGet(key) { 248 function WeakMapGet(key) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!IS_WEAKMAP(this)) { 285 if (!IS_WEAKMAP(this)) {
233 throw MakeTypeError('incompatible_method_receiver', 286 throw MakeTypeError('incompatible_method_receiver',
234 ['WeakMap.prototype.delete', this]); 287 ['WeakMap.prototype.delete', this]);
235 } 288 }
236 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) { 289 if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
237 throw %MakeTypeError('invalid_weakmap_key', [this, key]); 290 throw %MakeTypeError('invalid_weakmap_key', [this, key]);
238 } 291 }
239 return %WeakMapDelete(this, key); 292 return %WeakMapDelete(this, key);
240 } 293 }
241 294
295
242 // ------------------------------------------------------------------- 296 // -------------------------------------------------------------------
243 297
244 (function () { 298 function SetUpWeakMap() {
245 %CheckIsBootstrapping(); 299 %CheckIsBootstrapping();
246 300
247 // Set up the Set and Map constructor function.
248 %SetCode($Set, SetConstructor);
249 %SetCode($Map, MapConstructor);
250
251 // Set up the constructor property on the Set and Map prototype object.
252 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM);
253 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM);
254
255 // Set up the non-enumerable functions on the Set prototype object.
256 InstallGetter($Set.prototype, "size", SetGetSize);
257 InstallFunctions($Set.prototype, DONT_ENUM, $Array(
258 "add", SetAdd,
259 "has", SetHas,
260 "delete", SetDelete,
261 "clear", SetClear
262 ));
263
264 // Set up the non-enumerable functions on the Map prototype object.
265 InstallGetter($Map.prototype, "size", MapGetSize);
266 InstallFunctions($Map.prototype, DONT_ENUM, $Array(
267 "get", MapGet,
268 "set", MapSet,
269 "has", MapHas,
270 "delete", MapDelete,
271 "clear", MapClear
272 ));
273
274 // Set up the WeakMap constructor function.
275 %SetCode($WeakMap, WeakMapConstructor); 301 %SetCode($WeakMap, WeakMapConstructor);
276
277 // Set up the constructor property on the WeakMap prototype object.
278 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); 302 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
279 303
280 // Set up the non-enumerable functions on the WeakMap prototype object. 304 // Set up the non-enumerable functions on the WeakMap prototype object.
281 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array( 305 InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
282 "get", WeakMapGet, 306 "get", WeakMapGet,
283 "set", WeakMapSet, 307 "set", WeakMapSet,
284 "has", WeakMapHas, 308 "has", WeakMapHas,
285 "delete", WeakMapDelete 309 "delete", WeakMapDelete
286 )); 310 ));
287 })(); 311 }
312
313 SetUpWeakMap();
OLDNEW
« no previous file with comments | « src/array.js ('k') | src/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698