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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 } | 51 } |
52 | 52 |
53 | 53 |
54 function WeakMapSet(key, value) { | 54 function WeakMapSet(key, value) { |
55 if (!IS_SPEC_OBJECT(key)) { | 55 if (!IS_SPEC_OBJECT(key)) { |
56 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | 56 throw %MakeTypeError('invalid_weakmap_key', [this, key]); |
57 } | 57 } |
58 return %WeakMapSet(this, key, value); | 58 return %WeakMapSet(this, key, value); |
59 } | 59 } |
60 | 60 |
61 | |
62 function WeakMapHas(key) { | |
63 if (!IS_SPEC_OBJECT(key)) { | |
64 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | |
65 } | |
66 return !IS_UNDEFINED(%WeakMapGet(this, key)); | |
67 } | |
68 | |
69 | |
70 function WeakMapDelete(key) { | |
71 if (!IS_SPEC_OBJECT(key)) { | |
72 throw %MakeTypeError('invalid_weakmap_key', [this, key]); | |
73 } | |
74 if (!IS_UNDEFINED(%WeakMapGet(this, key))) { | |
75 %WeakMapSet(this, key, global.undefined); | |
rossberg
2011/08/04 11:05:09
Better use `void 0' to get undefined.
Michael Starzinger
2011/08/04 11:12:41
Done.
| |
76 return true; | |
77 } else { | |
78 return false; | |
79 } | |
80 } | |
81 | |
61 // ------------------------------------------------------------------- | 82 // ------------------------------------------------------------------- |
62 | 83 |
63 function SetupWeakMap() { | 84 function SetupWeakMap() { |
64 // Setup the non-enumerable functions on the WeakMap prototype object. | 85 // Setup the non-enumerable functions on the WeakMap prototype object. |
65 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( | 86 InstallFunctionsOnHiddenPrototype($WeakMap.prototype, DONT_ENUM, $Array( |
66 "get", WeakMapGet, | 87 "get", WeakMapGet, |
67 "set", WeakMapSet | 88 "set", WeakMapSet, |
89 "has", WeakMapHas, | |
90 "delete", WeakMapDelete | |
68 )); | 91 )); |
69 } | 92 } |
70 | 93 |
71 | 94 |
72 SetupWeakMap(); | 95 SetupWeakMap(); |
OLD | NEW |