Exemple #1
0
 void Scope::execCoreFiles() {
     execSetup(JSFiles::utils);
     execSetup(JSFiles::utils_sh);
     execSetup(JSFiles::utils_auth);
     execSetup(JSFiles::db);
     execSetup(JSFiles::mongo);
     execSetup(JSFiles::mr);
     execSetup(JSFiles::query);
     execSetup(JSFiles::bulk_api);
     execSetup(JSFiles::collection);
     execSetup(JSFiles::upgrade_check);
 }
Exemple #2
0
 void Scope::execCoreFiles() {
     execSetup(JSFiles::utils);
     execSetup(JSFiles::utils_sh);
     execSetup(JSFiles::db);
     execSetup(JSFiles::mongo);
     execSetup(JSFiles::mr);
     execSetup(JSFiles::query);
     execSetup(JSFiles::collection);
 }
Exemple #3
0
    void Scope::loadStored( bool ignoreNotConnected ){
        if ( _localDBName.size() == 0 ){
            if ( ignoreNotConnected )
                return;
            uassert( 10208 ,  "need to have locallyConnected already" , _localDBName.size() );
        }
        if ( _loadedVersion == _lastVersion )
            return;
        
        _loadedVersion = _lastVersion;

        string coll = _localDBName + ".system.js";
        
        static DBClientBase * db = createDirectClient();
        auto_ptr<DBClientCursor> c = db->query( coll , Query() );
        assert( c.get() );
        
        set<string> thisTime;
        
        while ( c->more() ){
            BSONObj o = c->next();

            BSONElement n = o["_id"];
            BSONElement v = o["value"];
            
            uassert( 10209 ,  "name has to be a string" , n.type() == String );
            uassert( 10210 ,  "value has to be set" , v.type() != EOO );
            
            setElement( n.valuestr() , v );

            thisTime.insert( n.valuestr() );
            _storedNames.insert( n.valuestr() );
            
        }

        // --- remove things from scope that were removed

        list<string> toremove;

        for ( set<string>::iterator i=_storedNames.begin(); i!=_storedNames.end(); i++ ){
            string n = *i;
            if ( thisTime.count( n ) == 0 )
                toremove.push_back( n );
        }
        
        for ( list<string>::iterator i=toremove.begin(); i!=toremove.end(); i++ ){
            string n = *i;
            _storedNames.erase( n );
            execSetup( (string)"delete " + n , "clean up scope" );
        }

    }
Exemple #4
0
    void Scope::loadStored(bool ignoreNotConnected) {
        if (_localDBName.size() == 0) {
            if (ignoreNotConnected)
                return;
            uassert(10208,  "need to have locallyConnected already", _localDBName.size());
        }

        if (_loadedVersion == _lastVersion)
            return;

        _loadedVersion = _lastVersion;
        string coll = _localDBName + ".system.js";

        DBClientBase* directDBClient = createDirectClient();
        auto_ptr<DBClientCursor> c = directDBClient->query(coll, Query(), 0, 0, NULL,
            QueryOption_SlaveOk, 0);
        massert(16669, "unable to get db client cursor from query", c.get());

        set<string> thisTime;
        while (c->more()) {
            BSONObj o = c->nextSafe();
            BSONElement n = o["_id"];
            BSONElement v = o["value"];

            uassert(10209, str::stream() << "name has to be a string: " << n, n.type() == String);
            uassert(10210, "value has to be set", v.type() != EOO);

            try {
                setElement(n.valuestr(), v);
                thisTime.insert(n.valuestr());
                _storedNames.insert(n.valuestr());
            }
            catch (const DBException& setElemEx) {
                log() << "unable to load stored JavaScript function " << n.valuestr()
                      << "(): " << setElemEx.what() << endl;
            }
        }

        // remove things from scope that were removed from the system.js collection
        for (set<string>::iterator i = _storedNames.begin(); i != _storedNames.end(); ) {
            if (thisTime.count(*i) == 0) {
                string toDelete = str::stream() << "delete " << *i;
                _storedNames.erase(i++);
                execSetup(toDelete, "clean up scope");
            }
            else {
                ++i;
            }
        }
    }
Exemple #5
0
MozJSImplScope::MozJSImplScope(MozJSScriptEngine* engine)
    : _engine(engine),
      _mr(),
      _runtime(_mr._runtime),
      _context(_mr._context),
      _globalProto(_context),
      _global(_globalProto.getProto()),
      _funcs(),
      _internedStrings(_context),
      _pendingKill(false),
      _opId(0),
      _opCtx(nullptr),
      _pendingGC(false),
      _connectState(ConnectState::Not),
      _status(Status::OK()),
      _quickExit(false),
      _generation(0),
      _binDataProto(_context),
      _bsonProto(_context),
      _countDownLatchProto(_context),
      _cursorProto(_context),
      _cursorHandleProto(_context),
      _dbCollectionProto(_context),
      _dbPointerProto(_context),
      _dbQueryProto(_context),
      _dbProto(_context),
      _dbRefProto(_context),
      _errorProto(_context),
      _jsThreadProto(_context),
      _maxKeyProto(_context),
      _minKeyProto(_context),
      _mongoExternalProto(_context),
      _mongoHelpersProto(_context),
      _mongoLocalProto(_context),
      _nativeFunctionProto(_context),
      _numberIntProto(_context),
      _numberLongProto(_context),
      _numberDecimalProto(_context),
      _objectProto(_context),
      _oidProto(_context),
      _regExpProto(_context),
      _timestampProto(_context) {
    kCurrentScope = this;

    // The default is quite low and doesn't seem to directly correlate with
    // malloc'd bytes.  Set it to MAX_INT here and catching things in the
    // jscustomallocator.cpp
    JS_SetGCParameter(_runtime, JSGC_MAX_BYTES, 0xffffffff);

    JS_SetInterruptCallback(_runtime, _interruptCallback);
    JS_SetGCCallback(_runtime, _gcCallback, this);
    JS_SetContextPrivate(_context, this);
    JSAutoRequest ar(_context);

    JS_SetErrorReporter(_runtime, _reportError);

    JSAutoCompartment ac(_context, _global);

    _checkErrorState(JS_InitStandardClasses(_context, _global));

    installBSONTypes();

    JS_FireOnNewGlobalObject(_context, _global);

    execSetup(JSFiles::assert);
    execSetup(JSFiles::types);

    // install process-specific utilities in the global scope (dependancy: types.js, assert.js)
    if (_engine->getScopeInitCallback())
        _engine->getScopeInitCallback()(*this);

    // install global utility functions
    installGlobalUtils(*this);
    _mongoHelpersProto.install(_global);
}