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

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

Issue 332663004: For-of calls [Symbol.iterator]() on RHS to get iterator (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 6 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/ast.h » ('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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 7
8 // This file relies on the fact that the following declaration has been made 8 // This file relies on the fact that the following declaration has been made
9 // in runtime.js: 9 // in runtime.js:
10 // var $Array = global.Array; 10 // var $Array = global.Array;
11 11
12 12
13 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object"); 13 var arrayIteratorObjectSymbol = GLOBAL_PRIVATE("ArrayIterator#object");
14 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next"); 14 var arrayIteratorNextIndexSymbol = GLOBAL_PRIVATE("ArrayIterator#next");
15 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind"); 15 var arrayIterationKindSymbol = GLOBAL_PRIVATE("ArrayIterator#kind");
16 16
17 17
18 function ArrayIterator() {} 18 function ArrayIterator() {}
19 19
20 20
21 // TODO(wingo): Update section numbers when ES6 has stabilized. The
22 // section numbers below are already out of date as of the May 2014
23 // draft.
24
25
21 // 15.4.5.1 CreateArrayIterator Abstract Operation 26 // 15.4.5.1 CreateArrayIterator Abstract Operation
22 function CreateArrayIterator(array, kind) { 27 function CreateArrayIterator(array, kind) {
23 var object = ToObject(array); 28 var object = ToObject(array);
24 var iterator = new ArrayIterator; 29 var iterator = new ArrayIterator;
25 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, object); 30 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, object);
26 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0); 31 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0);
27 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind); 32 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind);
28 return iterator; 33 return iterator;
29 } 34 }
30 35
31 36
32 // 15.19.4.3.4 CreateItrResultObject 37 // 15.19.4.3.4 CreateItrResultObject
33 function CreateIteratorResultObject(value, done) { 38 function CreateIteratorResultObject(value, done) {
34 return {value: value, done: done}; 39 return {value: value, done: done};
35 } 40 }
36 41
37 42
43 // 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]
44 function ArrayIteratorIterator() {
45 return this;
46 }
47
48
38 // 15.4.5.2.2 ArrayIterator.prototype.next( ) 49 // 15.4.5.2.2 ArrayIterator.prototype.next( )
39 function ArrayIteratorNext() { 50 function ArrayIteratorNext() {
40 var iterator = ToObject(this); 51 var iterator = ToObject(this);
41 52
42 if (!HAS_PRIVATE(iterator, arrayIteratorObjectSymbol)) { 53 if (!HAS_PRIVATE(iterator, arrayIteratorObjectSymbol)) {
43 throw MakeTypeError('incompatible_method_receiver', 54 throw MakeTypeError('incompatible_method_receiver',
44 ['Array Iterator.prototype.next']); 55 ['Array Iterator.prototype.next']);
45 } 56 }
46 57
47 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); 58 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 102
92 function SetUpArrayIterator() { 103 function SetUpArrayIterator() {
93 %CheckIsBootstrapping(); 104 %CheckIsBootstrapping();
94 105
95 %FunctionSetPrototype(ArrayIterator, new $Object()); 106 %FunctionSetPrototype(ArrayIterator, new $Object());
96 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator'); 107 %FunctionSetInstanceClassName(ArrayIterator, 'Array Iterator');
97 108
98 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array( 109 InstallFunctions(ArrayIterator.prototype, DONT_ENUM, $Array(
99 'next', ArrayIteratorNext 110 'next', ArrayIteratorNext
100 )); 111 ));
112 %FunctionSetName(ArrayIteratorIterator, '[Symbol.iterator]');
113 %SetProperty(ArrayIterator.prototype, symbolIterator, ArrayIteratorIterator,
114 DONT_ENUM | DONT_DELETE | READ_ONLY);
101 } 115 }
102 SetUpArrayIterator(); 116 SetUpArrayIterator();
103 117
104 118
105 function ExtendArrayPrototype() { 119 function ExtendArrayPrototype() {
106 %CheckIsBootstrapping(); 120 %CheckIsBootstrapping();
107 121
108 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 122 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
109 'entries', ArrayEntries, 123 'entries', ArrayEntries,
110 'values', ArrayValues, 124 'values', ArrayValues,
111 'keys', ArrayKeys 125 'keys', ArrayKeys
112 )); 126 ));
113 } 127 }
114 ExtendArrayPrototype(); 128 ExtendArrayPrototype();
OLDNEW
« no previous file with comments | « src/arm64/full-codegen-arm64.cc ('k') | src/ast.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698