Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/collection-iterator.js

Issue 1398733002: Move builtin JavaScript sources into own directory. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Also move macros.py file. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/collection.js ('k') | src/d8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var $mapEntries;
6 var $mapIteratorNext;
7 var $setIteratorNext;
8 var $setValues;
9
10 (function(global, utils) {
11
12 "use strict";
13
14 %CheckIsBootstrapping();
15
16 var GlobalMap = global.Map;
17 var GlobalSet = global.Set;
18 var iteratorSymbol = utils.ImportNow("iterator_symbol");
19 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol");
20
21 // -------------------------------------------------------------------
22
23 function SetIteratorConstructor(set, kind) {
24 %SetIteratorInitialize(this, set, kind);
25 }
26
27
28 function SetIteratorNextJS() {
29 if (!IS_SET_ITERATOR(this)) {
30 throw MakeTypeError(kIncompatibleMethodReceiver,
31 'Set Iterator.prototype.next', this);
32 }
33
34 var value_array = [UNDEFINED, UNDEFINED];
35 var result = %_CreateIterResultObject(value_array, false);
36 switch (%SetIteratorNext(this, value_array)) {
37 case 0:
38 result.value = UNDEFINED;
39 result.done = true;
40 break;
41 case ITERATOR_KIND_VALUES:
42 result.value = value_array[0];
43 break;
44 case ITERATOR_KIND_ENTRIES:
45 value_array[1] = value_array[0];
46 break;
47 }
48
49 return result;
50 }
51
52
53 function SetEntries() {
54 if (!IS_SET(this)) {
55 throw MakeTypeError(kIncompatibleMethodReceiver,
56 'Set.prototype.entries', this);
57 }
58 return new SetIterator(this, ITERATOR_KIND_ENTRIES);
59 }
60
61
62 function SetValues() {
63 if (!IS_SET(this)) {
64 throw MakeTypeError(kIncompatibleMethodReceiver,
65 'Set.prototype.values', this);
66 }
67 return new SetIterator(this, ITERATOR_KIND_VALUES);
68 }
69
70 // -------------------------------------------------------------------
71
72 %SetCode(SetIterator, SetIteratorConstructor);
73 %FunctionSetPrototype(SetIterator, {__proto__: $iteratorPrototype});
74 %FunctionSetInstanceClassName(SetIterator, 'Set Iterator');
75 utils.InstallFunctions(SetIterator.prototype, DONT_ENUM, [
76 'next', SetIteratorNextJS
77 ]);
78
79 %AddNamedProperty(SetIterator.prototype, toStringTagSymbol,
80 "Set Iterator", READ_ONLY | DONT_ENUM);
81
82 utils.InstallFunctions(GlobalSet.prototype, DONT_ENUM, [
83 'entries', SetEntries,
84 'keys', SetValues,
85 'values', SetValues
86 ]);
87
88 %AddNamedProperty(GlobalSet.prototype, iteratorSymbol, SetValues, DONT_ENUM);
89
90 $setIteratorNext = SetIteratorNextJS;
91 $setValues = SetValues;
92
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(kIncompatibleMethodReceiver,
103 'Map Iterator.prototype.next', this);
104 }
105
106 var value_array = [UNDEFINED, UNDEFINED];
107 var result = %_CreateIterResultObject(value_array, false);
108 switch (%MapIteratorNext(this, value_array)) {
109 case 0:
110 result.value = UNDEFINED;
111 result.done = true;
112 break;
113 case ITERATOR_KIND_KEYS:
114 result.value = value_array[0];
115 break;
116 case ITERATOR_KIND_VALUES:
117 result.value = value_array[1];
118 break;
119 // ITERATOR_KIND_ENTRIES does not need any processing.
120 }
121
122 return result;
123 }
124
125
126 function MapEntries() {
127 if (!IS_MAP(this)) {
128 throw MakeTypeError(kIncompatibleMethodReceiver,
129 'Map.prototype.entries', this);
130 }
131 return new MapIterator(this, ITERATOR_KIND_ENTRIES);
132 }
133
134
135 function MapKeys() {
136 if (!IS_MAP(this)) {
137 throw MakeTypeError(kIncompatibleMethodReceiver,
138 'Map.prototype.keys', this);
139 }
140 return new MapIterator(this, ITERATOR_KIND_KEYS);
141 }
142
143
144 function MapValues() {
145 if (!IS_MAP(this)) {
146 throw MakeTypeError(kIncompatibleMethodReceiver,
147 'Map.prototype.values', this);
148 }
149 return new MapIterator(this, ITERATOR_KIND_VALUES);
150 }
151
152 // -------------------------------------------------------------------
153
154 %SetCode(MapIterator, MapIteratorConstructor);
155 %FunctionSetPrototype(MapIterator, {__proto__: $iteratorPrototype});
156 %FunctionSetInstanceClassName(MapIterator, 'Map Iterator');
157 utils.InstallFunctions(MapIterator.prototype, DONT_ENUM, [
158 'next', MapIteratorNextJS
159 ]);
160
161 %AddNamedProperty(MapIterator.prototype, toStringTagSymbol,
162 "Map Iterator", READ_ONLY | DONT_ENUM);
163
164
165 utils.InstallFunctions(GlobalMap.prototype, DONT_ENUM, [
166 'entries', MapEntries,
167 'keys', MapKeys,
168 'values', MapValues
169 ]);
170
171 %AddNamedProperty(GlobalMap.prototype, iteratorSymbol, MapEntries, DONT_ENUM);
172
173 $mapEntries = MapEntries;
174 $mapIteratorNext = MapIteratorNextJS;
175
176 })
OLDNEW
« no previous file with comments | « src/collection.js ('k') | src/d8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698