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

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

Issue 240323003: ES6: Add support for Map/Set forEach (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Explicit instantiate the functions instead Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/bootstrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 13 matching lines...) Expand all
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 'use strict'; 28 'use strict';
29 29
30 // This file relies on the fact that the following declaration has been made 30 // This file relies on the fact that the following declaration has been made
31 // in runtime.js: 31 // in runtime.js:
32 // var $Array = global.Array; 32 // var $Array = global.Array;
33 33
34 var ARRAY_ITERATOR_KIND_KEYS = 1;
35 var ARRAY_ITERATOR_KIND_VALUES = 2;
36 var ARRAY_ITERATOR_KIND_ENTRIES = 3;
37 // The spec draft also has "sparse" but it is never used.
38
39 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); 34 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object");
40 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); 35 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next");
41 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); 36 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind");
42 37
43 function ArrayIterator() {} 38 function ArrayIterator() {}
44 39
45 // 15.4.5.1 CreateArrayIterator Abstract Operation 40 // 15.4.5.1 CreateArrayIterator Abstract Operation
46 function CreateArrayIterator(array, kind) { 41 function CreateArrayIterator(array, kind) {
47 var object = ToObject(array); 42 var object = ToObject(array);
48 var iterator = new ArrayIterator; 43 var iterator = new ArrayIterator;
(...skipping 23 matching lines...) Expand all
72 67
73 // "sparse" is never used. 68 // "sparse" is never used.
74 69
75 if (index >= length) { 70 if (index >= length) {
76 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY); 71 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY);
77 return CreateIteratorResultObject(UNDEFINED, true); 72 return CreateIteratorResultObject(UNDEFINED, true);
78 } 73 }
79 74
80 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); 75 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
81 76
82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) 77 if (itemKind == ITERATOR_KIND_VALUES)
83 return CreateIteratorResultObject(array[index], false); 78 return CreateIteratorResultObject(array[index], false);
84 79
85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) 80 if (itemKind == ITERATOR_KIND_ENTRIES)
86 return CreateIteratorResultObject([index, array[index]], false); 81 return CreateIteratorResultObject([index, array[index]], false);
87 82
88 return CreateIteratorResultObject(index, false); 83 return CreateIteratorResultObject(index, false);
89 } 84 }
90 85
91 function ArrayEntries() { 86 function ArrayEntries() {
92 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_ENTRIES); 87 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES);
93 } 88 }
94 89
95 function ArrayValues() { 90 function ArrayValues() {
96 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_VALUES); 91 return CreateArrayIterator(this, ITERATOR_KIND_VALUES);
97 } 92 }
98 93
99 function ArrayKeys() { 94 function ArrayKeys() {
100 return CreateArrayIterator(this, ARRAY_ITERATOR_KIND_KEYS); 95 return CreateArrayIterator(this, ITERATOR_KIND_KEYS);
101 } 96 }
102 97
103 function SetUpArrayIterator() { 98 function SetUpArrayIterator() {
104 %CheckIsBootstrapping(); 99 %CheckIsBootstrapping();
105 100
106 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); 101 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator');
107 %FunctionSetReadOnlyPrototype(ArrayIterator); 102 %FunctionSetReadOnlyPrototype(ArrayIterator);
108 103
109 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( 104 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array(
110 'next', ArrayIteratorNext 105 'next', ArrayIteratorNext
111 )); 106 ));
112 } 107 }
113 108
114 SetUpArrayIterator(); 109 SetUpArrayIterator();
115 110
116 function ExtendArrayPrototype() { 111 function ExtendArrayPrototype() {
117 %CheckIsBootstrapping(); 112 %CheckIsBootstrapping();
118 113
119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 114 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
120 'entries', ArrayEntries, 115 'entries', ArrayEntries,
121 'values', ArrayValues, 116 'values', ArrayValues,
122 'keys', ArrayKeys 117 'keys', ArrayKeys
123 )); 118 ));
124 } 119 }
125 120
126 ExtendArrayPrototype(); 121 ExtendArrayPrototype();
OLDNEW
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/bootstrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698