瀏覽代碼

Merge pull request #97 from RiveraGroup/feature/mongo_2.6.5_matcher_ArrayFilterEntries

EAGLESIX-2653 updated ArrayFilterEntries to mongo 2.6.5
Chris Sexton 11 年之前
父節點
當前提交
263fdfff0d
共有 1 個文件被更改,包括 26 次插入30 次删除
  1. 26 30
      lib/pipeline/matcher/ArrayFilterEntries.js

+ 26 - 30
lib/pipeline/matcher/ArrayFilterEntries.js

@@ -1,7 +1,7 @@
 "use strict";
-var Value = require('../Value');
+var Value = require('../Value'),
+	ErrorCodes = require('../../Errors').ErrorCodes;
 
-// Autogenerated by cport.py on 2013-09-17 14:37
 var ArrayFilterEntries = module.exports = function ArrayFilterEntries(){
 	this._hasNull = false;
 	this._hasEmptyArray = false;
@@ -10,19 +10,12 @@ var ArrayFilterEntries = module.exports = function ArrayFilterEntries(){
 }, klass = ArrayFilterEntries, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
 
 
-// File: expression_leaf.h lines: 266-266
 proto._equalities = undefined;
 
-
-// File: expression_leaf.h lines: 265-265
 proto._hasEmptyArray = undefined;
 
-
-// File: expression_leaf.h lines: 264-264
 proto._hasNull = undefined;
 
-
-// File: expression_leaf.h lines: 267-267
 proto._regexes = undefined;
 
 
@@ -34,14 +27,12 @@ proto._regexes = undefined;
  *
  */
 proto.addEquality = function addEquality(e) {
-	//File expression_leaf.cpp lines 369-387
-
-	if(e instanceof Object && Object.keys(e)[0][0] === '$'){
-		return {'code':'BAD_VALUE', 'desc':'cannot next $ under $in'};
-	}
-
 	if( e instanceof RegExp ) {
-		return {'code': 'BAD_VALUE', 'desc':'ArrayFilterEntries equality cannot be a regex'};
+		return {'code': ErrorCodes.BAD_VALUE, 'desc':'ArrayFilterEntries equality cannot be a regex'};
+	}
+	
+	if (e === undefined) {
+		return {'code': ErrorCodes.BAD_VALUE, 'desc':'ArrayFilterEntries equality cannot be undefined'};
 	}
 
 	if( e === null ) {
@@ -53,7 +44,7 @@ proto.addEquality = function addEquality(e) {
 	}
 
 	this._equalities.push( e );
-	return {'code':'OK'};
+	return {'code':ErrorCodes.OK};	
 };
 
 /**
@@ -64,9 +55,8 @@ proto.addEquality = function addEquality(e) {
  *
  */
 proto.addRegex = function addRegex(expr) {
-	// File: expression_leaf.cpp lines: 389-391
 	this._regexes.push( expr );
-	return {'code':'OK'};
+	return {'code':ErrorCodes.OK};
 };
 
 /**
@@ -77,7 +67,6 @@ proto.addRegex = function addRegex(expr) {
  *
  */
 proto.contains = function contains(elem) {
-	// File: expression_leaf.h lines: 249-248
 	for (var i = 0; i < this._equalities.length; i++) {
 		if(typeof(elem) == typeof(this._equalities[i])){
 			if(Value.compare(elem, this._equalities[i]) === 0) {
@@ -100,9 +89,13 @@ proto.copyTo = function copyTo(toFillIn) {
 	toFillIn._hasNull = this._hasNull;
 	toFillIn._hasEmptyArray = this._hasEmptyArray;
 	toFillIn._equalities = this._equalities.slice(0); // Copy array
+	
 	toFillIn._regexes = this._regexes.slice(0); // Copy array
+	for (var i = 0; i < this._regexes.length; i++){
+		toFillIn._regexes.push(this._regexes[i].shallowClone());
+	}
 };
-
+    
 /**
  *
  * Return the _equalities property
@@ -110,7 +103,6 @@ proto.copyTo = function copyTo(toFillIn) {
  *
  */
 proto.equalities = function equalities(){
-	// File: expression_leaf.h lines: 248-247
 	return this._equalities;
 };
 
@@ -122,9 +114,8 @@ proto.equalities = function equalities(){
  *
  */
 proto.equivalent = function equivalent(other) {
-	// File: expression_leaf.cpp lines: 394-404
 	if (this._hasNull != other._hasNull) {return false;}
-	if (this._regexes.length != other._regexes.length) {return false;}
+	if (this.size() != other.size()) {return false;}
 
 	for (var i = 0; i < this._regexes.length; i++) {
 		if ( !this._regexes[i].equivalent( other._regexes[i] ) ) {
@@ -141,7 +132,6 @@ proto.equivalent = function equivalent(other) {
  *
  */
 proto.hasEmptyArray = function hasEmptyArray(){
-	// File: expression_leaf.h lines: 256-255
 	return this._hasEmptyArray;
 };
 
@@ -152,7 +142,6 @@ proto.hasEmptyArray = function hasEmptyArray(){
  *
  */
 proto.hasNull = function hasNull(){
-	// File: expression_leaf.h lines: 254-253
 	return this._hasNull;
 };
 
@@ -163,7 +152,6 @@ proto.hasNull = function hasNull(){
  *
  */
 proto.numRegexes = function numRegexes(){
-	// File: expression_leaf.h lines: 251-250
 	return this._regexes.length;
 };
 
@@ -175,7 +163,6 @@ proto.numRegexes = function numRegexes(){
  *
  */
 proto.regex = function regex(idx) {
-	// File: expression_leaf.h lines: 252-251
 	return this._regexes[idx];
 };
 
@@ -186,7 +173,6 @@ proto.regex = function regex(idx) {
  *
  */
 proto.singleNull = function singleNull(){
-	// File: expression_leaf.h lines: 255-254
 	return this.size() == 1 && this._hasNull;
 };
 
@@ -197,7 +183,17 @@ proto.singleNull = function singleNull(){
  *
  */
 proto.size = function size(){
-	// File: expression_leaf.h lines: 257-256
 	return this._equalities.length + this._regexes.length;
 };
 
+proto.debugString = function debugString(){
+	var debug = "[ ";
+	for (var i = 0; i < this._equalities.length; i++){
+		debug += this._equalities[i].toString() + " ";
+	}
+	for (var j = 0; j < this._regexes.length; j++){
+		debug += this._regexes[j].shortDebugString() + " ";
+	}
+	debug += "]";
+	return debug;
+};