Changeset 181077 in webkit for trunk/Source/JavaScriptCore/builtins
- Timestamp:
- Mar 5, 2015, 6:57:17 AM (10 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/builtins/ArrayIterator.prototype.js
r181075 r181077 1 1 /* 2 * Copyright (C) 201 3 Apple, Inc. All rights reserved.2 * Copyright (C) 2015 Yusuke Suzuki <[email protected]>. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef ArrayIteratorPrototype_h 27 #define ArrayIteratorPrototype_h 26 function next() { 27 "use strict"; 28 28 29 #include "JSObject.h" 29 if (this == null) 30 throw new @TypeError("%ArrayIteratorPrototype%.next requires that |this| not be null or undefined"); 30 31 31 namespace JSC { 32 var itemKind = this.@arrayIterationKind; 33 if (itemKind === undefined) 34 throw new @TypeError("%ArrayIteratorPrototype%.next requires that |this| be Array Iterator Instance"); 32 35 33 class ArrayIteratorPrototype : public JSNonFinalObject { 34 public: 35 typedef JSNonFinalObject Base; 36 var done = true; 37 var value = undefined; 36 38 37 static ArrayIteratorPrototype* create(VM& vm, JSGlobalObject* globalObject, Structure* structure) 38 { 39 ArrayIteratorPrototype* prototype = new (NotNull, allocateCell<ArrayIteratorPrototype>(vm.heap)) ArrayIteratorPrototype(vm, structure); 40 prototype->finishCreation(vm, globalObject); 41 return prototype; 39 var array = this.@iteratedObject; 40 if (array !== undefined) { 41 var index = this.@arrayIteratorNextIndex; 42 var length = array.length >>> 0; 43 if (index >= length) { 44 this.@iteratedObject = undefined; 45 } else { 46 this.@arrayIteratorNextIndex = index + 1; 47 done = false; 48 if (itemKind === @arrayIterationKindKey) { 49 value = index; 50 } else if (itemKind === @arrayIterationKindValue) { 51 value = array[index]; 52 } else { 53 value = [ index, array[index] ]; 54 } 55 } 42 56 } 43 57 44 DECLARE_INFO; 45 46 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype) 47 { 48 return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info()); 49 } 50 51 private: 52 ArrayIteratorPrototype(VM& vm, Structure* structure) 53 : Base(vm, structure) 54 { 55 } 56 void finishCreation(VM&, JSGlobalObject*); 57 }; 58 58 return { 59 done: done, 60 value: value 61 }; 59 62 } 60 61 #endif // !defined(ArrayIteratorPrototype_h)
Note:
See TracChangeset
for help on using the changeset viewer.