| 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 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 const $Set = global.Set; | 29 const $Set = global.Set; |
| 30 const $Map = global.Map; | 30 const $Map = global.Map; |
| 31 const $WeakMap = global.WeakMap; | 31 const $WeakMap = global.WeakMap; |
| 32 | 32 |
| 33 //------------------------------------------------------------------- | 33 //------------------------------------------------------------------- |
| 34 | 34 |
| 35 // Global sentinel to be used instead of undefined keys, which are not |
| 36 // supported internally but required for Harmony sets and maps. |
| 37 var undefined_sentinel = {}; |
| 38 |
| 39 |
| 35 function SetConstructor() { | 40 function SetConstructor() { |
| 36 if (%_IsConstructCall()) { | 41 if (%_IsConstructCall()) { |
| 37 %SetInitialize(this); | 42 %SetInitialize(this); |
| 38 } else { | 43 } else { |
| 39 return new $Set(); | 44 return new $Set(); |
| 40 } | 45 } |
| 41 } | 46 } |
| 42 | 47 |
| 43 | 48 |
| 44 function SetAdd(key) { | 49 function SetAdd(key) { |
| 50 if (IS_UNDEFINED(key)) { |
| 51 key = undefined_sentinel; |
| 52 } |
| 45 return %SetAdd(this, key); | 53 return %SetAdd(this, key); |
| 46 } | 54 } |
| 47 | 55 |
| 48 | 56 |
| 49 function SetHas(key) { | 57 function SetHas(key) { |
| 58 if (IS_UNDEFINED(key)) { |
| 59 key = undefined_sentinel; |
| 60 } |
| 50 return %SetHas(this, key); | 61 return %SetHas(this, key); |
| 51 } | 62 } |
| 52 | 63 |
| 53 | 64 |
| 54 function SetDelete(key) { | 65 function SetDelete(key) { |
| 66 if (IS_UNDEFINED(key)) { |
| 67 key = undefined_sentinel; |
| 68 } |
| 55 return %SetDelete(this, key); | 69 return %SetDelete(this, key); |
| 56 } | 70 } |
| 57 | 71 |
| 58 | 72 |
| 59 function MapConstructor() { | 73 function MapConstructor() { |
| 60 if (%_IsConstructCall()) { | 74 if (%_IsConstructCall()) { |
| 61 %MapInitialize(this); | 75 %MapInitialize(this); |
| 62 } else { | 76 } else { |
| 63 return new $Map(); | 77 return new $Map(); |
| 64 } | 78 } |
| 65 } | 79 } |
| 66 | 80 |
| 67 | 81 |
| 68 function MapGet(key) { | 82 function MapGet(key) { |
| 83 if (IS_UNDEFINED(key)) { |
| 84 key = undefined_sentinel; |
| 85 } |
| 69 return %MapGet(this, key); | 86 return %MapGet(this, key); |
| 70 } | 87 } |
| 71 | 88 |
| 72 | 89 |
| 73 function MapSet(key, value) { | 90 function MapSet(key, value) { |
| 91 if (IS_UNDEFINED(key)) { |
| 92 key = undefined_sentinel; |
| 93 } |
| 74 return %MapSet(this, key, value); | 94 return %MapSet(this, key, value); |
| 75 } | 95 } |
| 76 | 96 |
| 77 | 97 |
| 78 function MapHas(key) { | 98 function MapHas(key) { |
| 99 if (IS_UNDEFINED(key)) { |
| 100 key = undefined_sentinel; |
| 101 } |
| 79 return !IS_UNDEFINED(%MapGet(this, key)); | 102 return !IS_UNDEFINED(%MapGet(this, key)); |
| 80 } | 103 } |
| 81 | 104 |
| 82 | 105 |
| 83 function MapDelete(key) { | 106 function MapDelete(key) { |
| 107 if (IS_UNDEFINED(key)) { |
| 108 key = undefined_sentinel; |
| 109 } |
| 84 if (!IS_UNDEFINED(%MapGet(this, key))) { | 110 if (!IS_UNDEFINED(%MapGet(this, key))) { |
| 85 %MapSet(this, key, void 0); | 111 %MapSet(this, key, void 0); |
| 86 return true; | 112 return true; |
| 87 } else { | 113 } else { |
| 88 return false; | 114 return false; |
| 89 } | 115 } |
| 90 } | 116 } |
| 91 | 117 |
| 92 | 118 |
| 93 function WeakMapConstructor() { | 119 function WeakMapConstructor() { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); | 196 %SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM); |
| 171 | 197 |
| 172 // Set up the non-enumerable functions on the WeakMap prototype object. | 198 // Set up the non-enumerable functions on the WeakMap prototype object. |
| 173 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( | 199 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( |
| 174 "get", WeakMapGet, | 200 "get", WeakMapGet, |
| 175 "set", WeakMapSet, | 201 "set", WeakMapSet, |
| 176 "has", WeakMapHas, | 202 "has", WeakMapHas, |
| 177 "delete", WeakMapDelete | 203 "delete", WeakMapDelete |
| 178 )); | 204 )); |
| 179 })(); | 205 })(); |
| OLD | NEW |