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

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

Issue 48923002: Provide private symbols through internal APIs (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Mo comments Created 7 years, 1 month 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/api.cc ('k') | src/factory.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 // 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 18 matching lines...) Expand all
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; 34 var ARRAY_ITERATOR_KIND_KEYS = 1;
35 var ARRAY_ITERATOR_KIND_VALUES = 2; 35 var ARRAY_ITERATOR_KIND_VALUES = 2;
36 var ARRAY_ITERATOR_KIND_ENTRIES = 3; 36 var ARRAY_ITERATOR_KIND_ENTRIES = 3;
37 // The spec draft also has "sparse" but it is never used. 37 // The spec draft also has "sparse" but it is never used.
38 38
39 var iteratorObjectSymbol = %CreateSymbol(UNDEFINED); 39 var iteratorObjectSymbol = NEW_PRIVATE("iterator_object");
40 var arrayIteratorNextIndexSymbol = %CreateSymbol(UNDEFINED); 40 var arrayIteratorNextIndexSymbol = NEW_PRIVATE("iterator_next");
41 var arrayIterationKindSymbol = %CreateSymbol(UNDEFINED); 41 var arrayIterationKindSymbol = NEW_PRIVATE("iterator_kind");
42 42
43 function ArrayIterator() {} 43 function ArrayIterator() {}
44 44
45 // 15.4.5.1 CreateArrayIterator Abstract Operation 45 // 15.4.5.1 CreateArrayIterator Abstract Operation
46 function CreateArrayIterator(array, kind) { 46 function CreateArrayIterator(array, kind) {
47 var object = ToObject(array); 47 var object = ToObject(array);
48 var iterator = new ArrayIterator; 48 var iterator = new ArrayIterator;
49 iterator[iteratorObjectSymbol] = object; 49 SET_PRIVATE(iterator, iteratorObjectSymbol, object);
50 iterator[arrayIteratorNextIndexSymbol] = 0; 50 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, 0);
51 iterator[arrayIterationKindSymbol] = kind; 51 SET_PRIVATE(iterator, arrayIterationKindSymbol, kind);
52 return iterator; 52 return iterator;
53 } 53 }
54 54
55 // 15.19.4.3.4 CreateItrResultObject 55 // 15.19.4.3.4 CreateItrResultObject
56 function CreateIteratorResultObject(value, done) { 56 function CreateIteratorResultObject(value, done) {
57 return {value: value, done: done}; 57 return {value: value, done: done};
58 } 58 }
59 59
60 // 15.4.5.2.2 ArrayIterator.prototype.next( ) 60 // 15.4.5.2.2 ArrayIterator.prototype.next( )
61 function ArrayIteratorNext() { 61 function ArrayIteratorNext() {
62 var iterator = ToObject(this); 62 var iterator = ToObject(this);
63 var array = iterator[iteratorObjectSymbol]; 63 var array = GET_PRIVATE(iterator, iteratorObjectSymbol);
64 if (!array) { 64 if (!array) {
65 throw MakeTypeError('incompatible_method_receiver', 65 throw MakeTypeError('incompatible_method_receiver',
66 ['Array Iterator.prototype.next']); 66 ['Array Iterator.prototype.next']);
67 } 67 }
68 68
69 var index = iterator[arrayIteratorNextIndexSymbol]; 69 var index = GET_PRIVATE(iterator, arrayIteratorNextIndexSymbol);
70 var itemKind = iterator[arrayIterationKindSymbol]; 70 var itemKind = GET_PRIVATE(iterator, arrayIterationKindSymbol);
71 var length = TO_UINT32(array.length); 71 var length = TO_UINT32(array.length);
72 72
73 // "sparse" is never used. 73 // "sparse" is never used.
74 74
75 if (index >= length) { 75 if (index >= length) {
76 iterator[arrayIteratorNextIndexSymbol] = 1 / 0; // Infinity 76 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, INFINITY);
77 return CreateIteratorResultObject(UNDEFINED, true); 77 return CreateIteratorResultObject(UNDEFINED, true);
78 } 78 }
79 79
80 iterator[arrayIteratorNextIndexSymbol] = index + 1; 80 SET_PRIVATE(iterator, arrayIteratorNextIndexSymbol, index + 1);
81 81
82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES) 82 if (itemKind == ARRAY_ITERATOR_KIND_VALUES)
83 return CreateIteratorResultObject(array[index], false); 83 return CreateIteratorResultObject(array[index], false);
84 84
85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES) 85 if (itemKind == ARRAY_ITERATOR_KIND_ENTRIES)
86 return CreateIteratorResultObject([index, array[index]], false); 86 return CreateIteratorResultObject([index, array[index]], false);
87 87
88 return CreateIteratorResultObject(index, false); 88 return CreateIteratorResultObject(index, false);
89 } 89 }
90 90
(...skipping 26 matching lines...) Expand all
117 %CheckIsBootstrapping(); 117 %CheckIsBootstrapping();
118 118
119 InstallFunctions($Array.prototype, DONT_ENUM, $Array( 119 InstallFunctions($Array.prototype, DONT_ENUM, $Array(
120 'entries', ArrayEntries, 120 'entries', ArrayEntries,
121 'values', ArrayValues, 121 'values', ArrayValues,
122 'keys', ArrayKeys 122 'keys', ArrayKeys
123 )); 123 ));
124 } 124 }
125 125
126 ExtendArrayPrototype(); 126 ExtendArrayPrototype();
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698