|
|
@@ -1,12 +1,20 @@
|
|
|
-"use strict"
|
|
|
-
|
|
|
-
|
|
|
+"use strict";
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * This documentation was automatically generated. Please update when you touch this function.
|
|
|
+ * @method WhereMatchExpression
|
|
|
+ * @param WHERE
|
|
|
+ *
|
|
|
+ */
|
|
|
// Autogenerated by cport.py on 2013-09-17 14:37
|
|
|
-var WhereMatchExpression = module.exports = function (){
|
|
|
-
|
|
|
-}, klass = WhereMatchExpression, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
+var WhereMatchExpression = module.exports = function() {
|
|
|
+ this._func = 0;
|
|
|
+}, klass = WhereMatchExpression, base = Object, proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
+// DEPENDENCIES
|
|
|
+var errors = require("../../Errors.js"),
|
|
|
+ ErrorCodes = errors.ErrorCodes;
|
|
|
|
|
|
// File: expression_where.cpp lines: 55-55
|
|
|
// string _code;
|
|
|
@@ -67,214 +75,134 @@ proto._scope = undefined;
|
|
|
|
|
|
proto._userScope = undefined;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- *
|
|
|
- * This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method WhereMatchExpression
|
|
|
- * @param
|
|
|
*
|
|
|
- */
|
|
|
-proto.WhereMatchExpression = function WhereMatchExpression( /* WHERE */ ){
|
|
|
-
|
|
|
-// File: expression_where.cpp lines: 33-32
|
|
|
-// WhereMatchExpression() : MatchExpression( WHERE ){ _func = 0; }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
* This documentation was automatically generated. Please update when you touch this function.
|
|
|
* @method debugString
|
|
|
- * @param
|
|
|
+ * @param debug
|
|
|
+ * @param level
|
|
|
*
|
|
|
*/
|
|
|
-proto.debugString = function debugString( /* StringBuilder& debug, int level */ ){
|
|
|
+proto.debugString = function debugString( debug, level){
|
|
|
|
|
|
// File: expression_where.cpp lines: 113-124
|
|
|
-// void WhereMatchExpression::debugString( StringBuilder& debug, int level ) const {
|
|
|
-// _debugAddSpace( debug, level );
|
|
|
-// debug << "$where\n";
|
|
|
-//
|
|
|
-// _debugAddSpace( debug, level + 1 );
|
|
|
-// debug << "ns: " << _ns << "\n";
|
|
|
-//
|
|
|
-// _debugAddSpace( debug, level + 1 );
|
|
|
-// debug << "code: " << _code << "\n";
|
|
|
-//
|
|
|
-// _debugAddSpace( debug, level + 1 );
|
|
|
-// debug << "scope: " << _userScope << "\n";
|
|
|
-// }
|
|
|
+ /*
|
|
|
+ proto._debugAddSpace( debug, level );
|
|
|
+ debug = debug + "$where\n";
|
|
|
|
|
|
+ proto._debugAddSpace( debug, level + 1 );
|
|
|
+ debug = debug + "ns: " + proto._ns + "\n";
|
|
|
|
|
|
+ proto._debugAddSpace( debug, level + 1 );
|
|
|
+ debug = debug + "code: " + proto._code + "\n";
|
|
|
|
|
|
-}
|
|
|
+ proto._debugAddSpace( debug, level + 1 );
|
|
|
+ debug = debug + "scope: " + proto._userScope + "\n";
|
|
|
+ console.log(debug);
|
|
|
+ */
|
|
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
* This documentation was automatically generated. Please update when you touch this function.
|
|
|
* @method equivalent
|
|
|
- * @param
|
|
|
+ * @param other
|
|
|
*
|
|
|
*/
|
|
|
-proto.equivalent = function equivalent( /* const MatchExpression* other */ ){
|
|
|
+proto.equivalent = function equivalent(other){
|
|
|
|
|
|
// File: expression_where.cpp lines: 127-134
|
|
|
-// bool WhereMatchExpression::equivalent( const MatchExpression* other ) const {
|
|
|
-// if ( matchType() != other->matchType() )
|
|
|
-// return false;
|
|
|
-// const WhereMatchExpression* realOther = static_cast<const WhereMatchExpression*>(other);
|
|
|
-// return
|
|
|
-// _ns == realOther->_ns &&
|
|
|
-// _code == realOther->_code &&
|
|
|
-// _userScope == realOther->_userScope;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+ if ( this.matchType() != other.matchType() ) return false;
|
|
|
+ var realOther = new WhereMatchExpression(other);
|
|
|
+ return (this._ns == realOther._ns && this._code == realOther._code && this._userScope == realOther._userScope);
|
|
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method init
|
|
|
- * @param
|
|
|
*
|
|
|
- */
|
|
|
-proto.init = function init( /* const StringData& ns,$/;" */ ){
|
|
|
-
|
|
|
-// File: expression_where.cpp lines: 62-86
|
|
|
-// Status WhereMatchExpression::init( const StringData& ns,
|
|
|
-// const StringData& theCode,
|
|
|
-// const BSONObj& scope ) {
|
|
|
-//
|
|
|
-// if ( ns.size() == 0 )
|
|
|
-// return Status( ErrorCodes::BadValue, "ns for $where cannot be empty" );
|
|
|
-//
|
|
|
-// if ( theCode.size() == 0 )
|
|
|
-// return Status( ErrorCodes::BadValue, "code for $where cannot be empty" );
|
|
|
-//
|
|
|
-// _ns = ns.toString();
|
|
|
-// _code = theCode.toString();
|
|
|
-// _userScope = scope.getOwned();
|
|
|
-//
|
|
|
-// NamespaceString nswrapper( _ns );
|
|
|
-// const string userToken = ClientBasic::getCurrent()->getAuthorizationSession()
|
|
|
-// ->getAuthenticatedUserNamesToken();
|
|
|
-// _scope = globalScriptEngine->getPooledScope( nswrapper.db().toString(),
|
|
|
-// "where" + userToken );
|
|
|
-// _func = _scope->createFunction( _code.c_str() );
|
|
|
-//
|
|
|
-// if ( !_func )
|
|
|
-// return Status( ErrorCodes::BadValue, "$where compile error" );
|
|
|
-//
|
|
|
-// return Status::OK();
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-/**
|
|
|
- *
|
|
|
* This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method matches
|
|
|
- * @param
|
|
|
+ * @method init
|
|
|
+ * @param string ns
|
|
|
+ * @param theCode
|
|
|
+ * @param scope
|
|
|
*
|
|
|
*/
|
|
|
-proto.matches = function matches( /* const MatchableDocument* doc, MatchDetails* details */ ){
|
|
|
-
|
|
|
-// File: expression_where.cpp lines: 89-110
|
|
|
-// bool WhereMatchExpression::matches( const MatchableDocument* doc, MatchDetails* details ) const {
|
|
|
-// verify( _func );
|
|
|
-// BSONObj obj = doc->toBSON();
|
|
|
-//
|
|
|
-// if ( ! _userScope.isEmpty() ) {
|
|
|
-// _scope->init( &_userScope );
|
|
|
-// }
|
|
|
-// _scope->setObject( "obj", const_cast< BSONObj & >( obj ) );
|
|
|
-// _scope->setBoolean( "fullObject" , true ); // this is a hack b/c fullObject used to be relevant
|
|
|
-//
|
|
|
-// int err = _scope->invoke( _func, 0, &obj, 1000 * 60, false );
|
|
|
-// if ( err == -3 ) { // INVOKE_ERROR
|
|
|
-// stringstream ss;
|
|
|
-// ss << "error on invocation of $where function:\n"
|
|
|
-// << _scope->getError();
|
|
|
-// uassert( 16812, ss.str(), false);
|
|
|
-// }
|
|
|
-// else if ( err != 0 ) { // ! INVOKE_SUCCESS
|
|
|
-// uassert( 16813, "unknown error in invocation of $where function", false);
|
|
|
-// }
|
|
|
-//
|
|
|
-// return _scope->getBoolean( "__returnValue" ) != 0;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+proto.init = function init(ns, theCode, scope){
|
|
|
+ // File: expression_where.cpp lines: 62-86
|
|
|
+ if ( ns.size() === 0 )
|
|
|
+ return {code:ErrorCodes.BAD_VALUE, description:"ns for $where cannot be empty"};
|
|
|
|
|
|
+ if ( theCode.size() === 0 )
|
|
|
+ return {code:ErrorCodes.BAD_VALUE, description:"code for $where cannot be empty"};
|
|
|
|
|
|
-/**
|
|
|
- *
|
|
|
- * This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method matchesSingleElement
|
|
|
- * @param
|
|
|
- *
|
|
|
- */
|
|
|
-proto.matchesSingleElement = function matchesSingleElement( /* const BSONElement& e */ ){
|
|
|
+ this._ns = ns;
|
|
|
+ this._code = theCode.toString();
|
|
|
+ this._userScope = scope.getOwned();
|
|
|
|
|
|
-// File: expression_where.cpp lines: 40-41
|
|
|
-// virtual bool matchesSingleElement( const BSONElement& e ) const {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
+ // we don't have authentication yet
|
|
|
+ // var userToken = ClientBasic::getCurrent().getAuthorizationSession().getAuthenticatedUserNamesToken();
|
|
|
|
|
|
+ this._scope = globalScriptEngine.getPooledScope( this._ns.substr(0, this._ns.indexOf('.')), "where" + userToken );
|
|
|
+ this._func = this._scope.createFunction( this._code.c_str() );
|
|
|
|
|
|
+ if ( !this._func )
|
|
|
+ return {code:ErrorCodes.BAD_VALUE, description:"$where compile error"};
|
|
|
|
|
|
-}
|
|
|
+ return {code:ErrorCodes.OK};
|
|
|
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
+ *
|
|
|
* This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method shallowClone
|
|
|
- * @param
|
|
|
+ * @method matches
|
|
|
+ * @param doc
|
|
|
+ * @param details
|
|
|
*
|
|
|
*/
|
|
|
-proto.shallowClone = function shallowClone( /* */ ){
|
|
|
-
|
|
|
-// File: expression_where.cpp lines: 44-47
|
|
|
-// virtual MatchExpression* shallowClone() const {
|
|
|
-// WhereMatchExpression* e = new WhereMatchExpression();
|
|
|
-// e->init(_ns, _code, _userScope);
|
|
|
-// return e;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
+proto.matches = function matches(doc /*, details */){
|
|
|
+ // File: expression_where.cpp lines: 89-110
|
|
|
+ verify( this._func );
|
|
|
+
|
|
|
+ if ( ! this._userScope.isEmpty() ) {
|
|
|
+ this._scope.init( this._userScope );
|
|
|
+ }
|
|
|
+ this._scope.setObject("obj", doc);
|
|
|
+ this._scope.setBoolean("fullObject", true); // this is a hack b/c fullObject used to be relevant
|
|
|
+
|
|
|
+ err = this._scope.invoke(this._func, 0, obj, 1000 * 60, false);
|
|
|
+ if ( err == -3 ) { // INVOKE_ERROR
|
|
|
+ throw new Error("16812 error on invocation of $where function:\n" + this._scope.getError().name);
|
|
|
+ }
|
|
|
+ else if ( err != 0 ) { // ! INVOKE_SUCCESS
|
|
|
+ throw new Error("16813 unknown error in invocation of $where function");
|
|
|
+ }
|
|
|
+
|
|
|
+ return this._scope.getBoolean("__returnValue") != 0;
|
|
|
+};
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
- * This documentation was automatically generated. Please update when you touch this function.
|
|
|
- * @method ~WhereMatchExpression
|
|
|
- * @param
|
|
|
+ *
|
|
|
+ * WhereMatchExpression never matches a single element
|
|
|
+ * @method matchesSingleElement
|
|
|
+ * @param e
|
|
|
*
|
|
|
*/
|
|
|
-proto.~WhereMatchExpression = function ~WhereMatchExpression( /* */ ){
|
|
|
-
|
|
|
-// File: expression_where.cpp lines: 34-33
|
|
|
-// virtual ~WhereMatchExpression(){}
|
|
|
+proto.matchesSingleElement = function matchesSingleElement(e){
|
|
|
+ // File: expression_where.cpp lines: 40-41
|
|
|
+ return false;
|
|
|
+};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * Create a new WhereMatchExpression and initialize it with our property values
|
|
|
+ * @method shallowClone
|
|
|
+ *
|
|
|
+ */
|
|
|
+proto.shallowClone = function shallowClone(){
|
|
|
+ // File: expression_where.cpp lines: 44-47
|
|
|
+ e = new WhereMatchExpression();
|
|
|
+ e.init(this._ns, this._code, this._userScope);
|
|
|
+ return e;
|
|
|
+};
|