OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
adamk
2014/05/29 00:07:14
Nit: I think you can use a short license header fo
| |
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 'use strict'; | |
29 | |
30 | |
31 // This file relies on the fact that the following declaration has been made | |
32 // in runtime.js: | |
33 // var $Set = global.Set; | |
34 // var $Map = global.Map; | |
35 | |
36 | |
37 function SetIteratorConstructor(set, kind) { | |
38 %SetIteratorInitialize(this, set, kind); | |
39 } | |
40 | |
41 | |
42 function SetIteratorNextJS() { | |
43 if (!IS_SET_ITERATOR(this)) { | |
44 throw MakeTypeError('incompatible_method_receiver', | |
45 ['Set Iterator.prototype.next', this]); | |
46 } | |
47 return %SetIteratorNext(this); | |
48 } | |
49 | |
50 | |
51 function SetEntries() { | |
52 if (!IS_SET(this)) { | |
53 throw MakeTypeError('incompatible_method_receiver', | |
54 ['Set.prototype.entries', this]); | |
55 } | |
56 return new SetIterator(this, ITERATOR_KIND_ENTRIES); | |
57 } | |
58 | |
59 | |
60 function SetValues() { | |
61 if (!IS_SET(this)) { | |
62 throw MakeTypeError('incompatible_method_receiver', | |
63 ['Set.prototype.values', this]); | |
64 } | |
65 return new SetIterator(this, ITERATOR_KIND_VALUES); | |
66 } | |
67 | |
68 | |
69 function SetUpSetIterator() { | |
70 %CheckIsBootstrapping(); | |
71 | |
72 %SetCode(SetIterator, SetIteratorConstructor); | |
73 %FunctionSetPrototype(SetIterator, new $Object()); | |
74 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator'); | |
75 InstallFunctions(SetIterator.prototype, DONT_ENUM, $Array( | |
76 'next', SetIteratorNextJS | |
77 )); | |
78 } | |
79 | |
80 SetUpSetIterator(); | |
81 | |
82 | |
83 function ExtendSetPrototype() { | |
84 %CheckIsBootstrapping(); | |
85 | |
86 InstallFunctions($Set.prototype, DONT_ENUM, $Array( | |
87 'entries', SetEntries, | |
88 'values', SetValues | |
89 )); | |
90 } | |
91 | |
92 ExtendSetPrototype(); | |
93 | |
94 | |
95 function MapIteratorConstructor(map, kind) { | |
96 %MapIteratorInitialize(this, map, kind); | |
97 } | |
98 | |
99 | |
100 function MapIteratorNextJS() { | |
101 if (!IS_MAP_ITERATOR(this)) { | |
102 throw MakeTypeError('incompatible_method_receiver', | |
103 ['Map Iterator.prototype.next', this]); | |
104 } | |
105 return %MapIteratorNext(this); | |
106 } | |
107 | |
108 | |
109 function MapEntries() { | |
110 if (!IS_MAP(this)) { | |
111 throw MakeTypeError('incompatible_method_receiver', | |
112 ['Map.prototype.entries', this]); | |
113 } | |
114 return new MapIterator(this, ITERATOR_KIND_ENTRIES); | |
115 } | |
116 | |
117 | |
118 function MapKeys() { | |
119 if (!IS_MAP(this)) { | |
120 throw MakeTypeError('incompatible_method_receiver', | |
121 ['Map.prototype.keys', this]); | |
122 } | |
123 return new MapIterator(this, ITERATOR_KIND_KEYS); | |
124 } | |
125 | |
126 | |
127 function MapValues() { | |
128 if (!IS_MAP(this)) { | |
129 throw MakeTypeError('incompatible_method_receiver', | |
130 ['Map.prototype.values', this]); | |
131 } | |
132 return new MapIterator(this, ITERATOR_KIND_VALUES); | |
133 } | |
134 | |
135 | |
136 function SetUpMapIterator() { | |
137 %CheckIsBootstrapping(); | |
138 | |
139 %SetCode(MapIterator, MapIteratorConstructor); | |
140 %FunctionSetPrototype(MapIterator, new $Object()); | |
141 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator'); | |
142 InstallFunctions(MapIterator.prototype, DONT_ENUM, $Array( | |
143 'next', MapIteratorNextJS | |
144 )); | |
145 } | |
146 | |
147 SetUpMapIterator(); | |
148 | |
149 | |
150 function ExtendMapPrototype() { | |
151 %CheckIsBootstrapping(); | |
152 | |
153 InstallFunctions($Map.prototype, DONT_ENUM, $Array( | |
154 'entries', MapEntries, | |
155 'keys', MapKeys, | |
156 'values', MapValues | |
157 )); | |
158 } | |
159 | |
160 ExtendMapPrototype(); | |
OLD | NEW |