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

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

Issue 268363011: Array Iterator next should check for own property (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Use HAS_PRIVATE Created 6 years, 7 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 | « no previous file | test/mjsunit/harmony/array-iterator.js » ('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;
(...skipping 20 matching lines...) Expand all
31 31
32 // 15.19.4.3.4 CreateItrResultObject 32 // 15.19.4.3.4 CreateItrResultObject
33 function CreateIteratorResultObject(value, done) { 33 function CreateIteratorResultObject(value, done) {
34 return {value: value, done: done}; 34 return {value: value, done: done};
35 } 35 }
36 36
37 37
38 // 15.4.5.2.2 ArrayIterator.prototype.next( ) 38 // 15.4.5.2.2 ArrayIterator.prototype.next( )
39 function ArrayIteratorNext() { 39 function ArrayIteratorNext() {
40 var iterator = ToObject(this); 40 var iterator = ToObject(this);
41 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol); 41
42 if (!array) { 42 if (!HAS_PRIVATE(iterator, arrayIteratorObjectSymbol)) {
43 throw MakeTypeError('incompatible_method_receiver', 43 throw MakeTypeError('incompatible_method_receiver',
44 ['Array Iterator.prototype.next']); 44 ['Array Iterator.prototype.next']);
45 } 45 }
46 46
47 var array = GET_PRIVATE(iterator, arrayIteratorObjectSymbol);
48 if (IS_UNDEFINED(array)) {
49 return CreateIteratorResultObject(UNDEFINED, true);
50 }
51
47 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol); 52 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol);
48 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol); 53 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol);
49 var length = TO_UINT32(array.length); 54 var length = TO_UINT32(array.length);
50 55
51 // "sparse" is never used. 56 // "sparse" is never used.
52 57
53 if (index >= length) { 58 if (index >= length) {
54 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY); 59 SET_PRIVATE(iterator, arrayIteratorObjectSymbol, UNDEFINED);
55 return CreateIteratorResultObject(UNDEFINED, true); 60 return CreateIteratorResultObject(UNDEFINED, true);
56 } 61 }
57 62
58 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1); 63 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
59 64
60 if (itemKind == ITERATOR_KIND_VALUES) 65 if (itemKind == ITERATOR_KIND_VALUES) {
61 return CreateIteratorResultObject(array[index], false); 66 return CreateIteratorResultObject(array[index], false);
67 }
62 68
63 if (itemKind == ITERATOR_KIND_ENTRIES) 69 if (itemKind == ITERATOR_KIND_ENTRIES) {
64 return CreateIteratorResultObject([index, array[index]], false); 70 return CreateIteratorResultObject([index, array[index]], false);
71 }
65 72
66 return CreateIteratorResultObject(index, false); 73 return CreateIteratorResultObject(index, false);
67 } 74 }
68 75
69 76
70 function ArrayEntries() { 77 function ArrayEntries() {
71 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES); 78 return CreateArrayIterator(this, ITERATOR_KIND_ENTRIES);
72 } 79 }
73 80
74 81
(...skipping 23 matching lines...) Expand all
98 function ExtendArrayPrototype() { 105 function ExtendArrayPrototype() {
99 %CheckIsBootstrapping(); 106 %CheckIsBootstrapping();
100 107
101 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 108 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
102 'entries', ArrayEntries, 109 'entries', ArrayEntries,
103 'values', ArrayValues, 110 'values', ArrayValues,
104 'keys', ArrayKeys 111 'keys', ArrayKeys
105 )); 112 ));
106 } 113 }
107 ExtendArrayPrototype(); 114 ExtendArrayPrototype();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/harmony/array-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698