OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2011 the V8 project authors. All rights reserved. | |
2 // Redistribution and use in source and binary forms, with or without | |
3 // modification, are permitted provided that the following conditions are | |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
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. | |
27 | |
28 | |
29 // This file relies on the fact that the following declaration has been made | |
30 // in runtime.js: | |
31 // const $Object = global.Object; | |
rossberg
2011/10/24 15:44:11
Not needed?
Michael Starzinger
2011/10/25 11:17:26
Done.
| |
32 const $Set = global.Set; | |
33 const $Map = global.Map; | |
34 | |
35 //------------------------------------------------------------------- | |
36 | |
37 function SetConstructor() { | |
38 if (%_IsConstructCall()) { | |
39 %SetInitialize(this); | |
40 } else { | |
41 return new $Set(); | |
42 } | |
43 } | |
44 | |
45 | |
46 function SetAdd(key) { | |
47 return %SetAccess(this, key, SET_ACCESS_ADD); | |
48 } | |
49 | |
50 | |
51 function SetHas(key) { | |
52 return %SetAccess(this, key, SET_ACCESS_HAS); | |
53 } | |
54 | |
55 | |
56 function SetDelete(key) { | |
57 return %SetAccess(this, key, SET_ACCESS_DELETE); | |
58 } | |
59 | |
60 | |
61 function MapConstructor() { | |
62 if (%_IsConstructCall()) { | |
63 %MapInitialize(this); | |
64 } else { | |
65 return new $Map(); | |
66 } | |
67 } | |
68 | |
69 | |
70 function MapGet(key) { | |
71 return %MapGet(this, key); | |
72 } | |
73 | |
74 | |
75 function MapSet(key, value) { | |
76 return %MapSet(this, key, value); | |
77 } | |
78 | |
79 | |
80 function MapHas(key) { | |
81 return !IS_UNDEFINED(%MapGet(this, key)); | |
82 } | |
83 | |
84 | |
85 function MapDelete(key) { | |
86 if (!IS_UNDEFINED(%MapGet(this, key))) { | |
87 %MapSet(this, key, void 0); | |
88 return true; | |
89 } else { | |
90 return false; | |
91 } | |
92 } | |
93 | |
94 // ------------------------------------------------------------------- | |
95 | |
96 (function () { | |
97 %CheckIsBootstrapping(); | |
98 | |
99 // Set up the Set and Map constructor function. | |
100 %SetCode($Set, SetConstructor); | |
101 %SetCode($Map, MapConstructor); | |
102 | |
103 // Set up the constructor property on the Set and Map prototype object. | |
104 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); | |
105 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); | |
106 | |
107 // Set up the non-enumerable functions on the Set prototype object. | |
108 InstallFunctionsOnHiddenPrototype($Set.prototype, DONT_ENUM, $Array( | |
109 "add", SetAdd, | |
110 "has", SetHas, | |
111 "delete", SetDelete | |
112 )); | |
113 | |
114 // Set up the non-enumerable functions on the Map prototype object. | |
115 InstallFunctionsOnHiddenPrototype($Map.prototype, DONT_ENUM, $Array( | |
116 "get", MapGet, | |
117 "set", MapSet, | |
118 "has", MapHas, | |
119 "delete", MapDelete | |
120 )); | |
121 })(); | |
OLD | NEW |