OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 | 28 |
29 // This file relies on the fact that the following declaration has been made | 29 const $Set = global.Set; |
30 // in runtime.js: | 30 const $Map = global.Map; |
31 // const $Object = global.Object; | |
32 const $WeakMap = global.WeakMap; | 31 const $WeakMap = global.WeakMap; |
33 | 32 |
34 // ------------------------------------------------------------------- | 33 //------------------------------------------------------------------- |
| 34 |
| 35 function SetConstructor() { |
| 36 if (%_IsConstructCall()) { |
| 37 %SetInitialize(this); |
| 38 } else { |
| 39 return new $Set(); |
| 40 } |
| 41 } |
| 42 |
| 43 |
| 44 function SetAdd(key) { |
| 45 return %SetAdd(this, key); |
| 46 } |
| 47 |
| 48 |
| 49 function SetHas(key) { |
| 50 return %SetHas(this, key); |
| 51 } |
| 52 |
| 53 |
| 54 function SetDelete(key) { |
| 55 return %SetDelete(this, key); |
| 56 } |
| 57 |
| 58 |
| 59 function MapConstructor() { |
| 60 if (%_IsConstructCall()) { |
| 61 %MapInitialize(this); |
| 62 } else { |
| 63 return new $Map(); |
| 64 } |
| 65 } |
| 66 |
| 67 |
| 68 function MapGet(key) { |
| 69 return %MapGet(this, key); |
| 70 } |
| 71 |
| 72 |
| 73 function MapSet(key, value) { |
| 74 return %MapSet(this, key, value); |
| 75 } |
| 76 |
| 77 |
| 78 function MapHas(key) { |
| 79 return !IS_UNDEFINED(%MapGet(this, key)); |
| 80 } |
| 81 |
| 82 |
| 83 function MapDelete(key) { |
| 84 if (!IS_UNDEFINED(%MapGet(this, key))) { |
| 85 %MapSet(this, key, void 0); |
| 86 return true; |
| 87 } else { |
| 88 return false; |
| 89 } |
| 90 } |
| 91 |
35 | 92 |
36 function WeakMapConstructor() { | 93 function WeakMapConstructor() { |
37 if (%_IsConstructCall()) { | 94 if (%_IsConstructCall()) { |
38 %WeakMapInitialize(this); | 95 %WeakMapInitialize(this); |
39 } else { | 96 } else { |
40 return new $WeakMap(); | 97 return new $WeakMap(); |
41 } | 98 } |
42 } | 99 } |
43 | 100 |
44 | 101 |
(...skipping 30 matching lines...) Expand all Loading... |
75 return true; | 132 return true; |
76 } else { | 133 } else { |
77 return false; | 134 return false; |
78 } | 135 } |
79 } | 136 } |
80 | 137 |
81 // ------------------------------------------------------------------- | 138 // ------------------------------------------------------------------- |
82 | 139 |
83 (function () { | 140 (function () { |
84 %CheckIsBootstrapping(); | 141 %CheckIsBootstrapping(); |
| 142 |
| 143 // Set up the Set and Map constructor function. |
| 144 %SetCode($Set, SetConstructor); |
| 145 %SetCode($Map, MapConstructor); |
| 146 |
| 147 // Set up the constructor property on the Set and Map prototype object. |
| 148 %SetProperty($Set.prototype, "constructor", $Set, DONT_ENUM); |
| 149 %SetProperty($Map.prototype, "constructor", $Map, DONT_ENUM); |
| 150 |
| 151 // Set up the non-enumerable functions on the Set prototype object. |
| 152 InstallFunctionsOnHiddenPrototype($Set.prototype, DONT_ENUM, $Array( |
| 153 "add", SetAdd, |
| 154 "has", SetHas, |
| 155 "delete", SetDelete |
| 156 )); |
| 157 |
| 158 // Set up the non-enumerable functions on the Map prototype object. |
| 159 InstallFunctionsOnHiddenPrototype($Map.prototype, DONT_ENUM, $Array( |
| 160 "get", MapGet, |
| 161 "set", MapSet, |
| 162 "has", MapHas, |
| 163 "delete", MapDelete |
| 164 )); |
| 165 |
85 // Set up the WeakMap constructor function. | 166 // Set up the WeakMap constructor function. |
86 %SetCode($WeakMap, WeakMapConstructor); | 167 %SetCode($WeakMap, WeakMapConstructor); |
87 | 168 |
88 // Set up the constructor property on the WeakMap prototype object. | 169 // Set up the constructor property on the WeakMap prototype object. |
89 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); | 170 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
90 | 171 |
91 // Set up the non-enumerable functions on the WeakMap prototype object. | 172 // Set up the non-enumerable functions on the WeakMap prototype object. |
92 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( | 173 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( |
93 "get", WeakMapGet, | 174 "get", WeakMapGet, |
94 "set", WeakMapSet, | 175 "set", WeakMapSet, |
95 "has", WeakMapHas, | 176 "has", WeakMapHas, |
96 "delete", WeakMapDelete | 177 "delete", WeakMapDelete |
97 )); | 178 )); |
98 })(); | 179 })(); |
OLD | NEW |