Bläddra i källkod

Merge branch 'release/v0.6.5+2014.01.13' into develop

* release/v0.6.5+2014.01.13:
  Refs #4915: fix bad and unnecessary manipulation in Cursor
  Refs #4900. Updated async to IE10 compatible version.
Super-User 11 år sedan
förälder
incheckning
7e8e039546
1 ändrade filer med 6 tillägg och 4 borttagningar
  1. 6 4
      lib/Cursor.js

+ 6 - 4
lib/Cursor.js

@@ -6,19 +6,21 @@
  **/
 var klass = module.exports = function Cursor(items){
 	if (!(items instanceof Array)) throw new Error("arg `items` must be an Array");
-	this.cachedData = items.slice(0);	// keep a copy
+	this.cachedData = items.slice(0);	// keep a copy so array changes when using async doc srcs do not cause side effects
+	this.length = items.length;
+	this.offset = 0;
 }, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 proto.ok = function ok(){
-	return this.cachedData.length > 0 || this.hasOwnProperty("curr");
+	return (this.offset < this.length) || this.hasOwnProperty("curr");
 };
 
 proto.advance = function advance(){
-	if (this.cachedData.length === 0){
+	if (this.offset >= this.length){
 		delete this.curr;
 		return false;
 	}
-	this.curr = this.cachedData.shift();
+	this.curr = this.cachedData[this.offset++];
 	return this.curr;
 };