mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-470 MINOR abstract shell init functionality so v8_utils need not link with shell
This commit is contained in:
parent
d1e3f2afe5
commit
8573d53da7
@ -47,7 +47,7 @@ namespace JSTests {
|
||||
public:
|
||||
void run(){
|
||||
auto_ptr<Scope> s;
|
||||
s.reset( globalScriptEngine->createScope() );
|
||||
s.reset( globalScriptEngine->newScope() );
|
||||
|
||||
s->setNumber( "x" , 5 );
|
||||
ASSERT( 5 == s->getNumber( "x" ) );
|
||||
@ -74,7 +74,7 @@ namespace JSTests {
|
||||
// Not worrying about this for now SERVER-446.
|
||||
/*
|
||||
auto_ptr<Scope> s;
|
||||
s.reset( globalScriptEngine->createScope() );
|
||||
s.reset( globalScriptEngine->newScope() );
|
||||
|
||||
s->setBoolean( "x" , true );
|
||||
ASSERT( s->getBoolean( "x" ) );
|
||||
@ -88,7 +88,7 @@ namespace JSTests {
|
||||
class FalseTests {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
ASSERT( ! s->getBoolean( "x" ) );
|
||||
|
||||
@ -103,7 +103,7 @@ namespace JSTests {
|
||||
class SimpleFunctions {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
s->invoke( "x=5;" , BSONObj() );
|
||||
ASSERT( 5 == s->getNumber( "x" ) );
|
||||
@ -132,7 +132,7 @@ namespace JSTests {
|
||||
class ObjectMapping {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
BSONObj o = BSON( "x" << 17 << "y" << "eliot" << "z" << "sara" );
|
||||
s->setObject( "blah" , o );
|
||||
@ -189,7 +189,7 @@ namespace JSTests {
|
||||
class ObjectDecoding {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
s->invoke( "z = { num : 1 };" , BSONObj() );
|
||||
BSONObj out = s->getObject( "z" );
|
||||
@ -214,7 +214,7 @@ namespace JSTests {
|
||||
public:
|
||||
void run(){
|
||||
#ifdef MOZJS
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
s->localConnect( "blah" );
|
||||
|
||||
@ -247,7 +247,7 @@ namespace JSTests {
|
||||
class SetImplicit {
|
||||
public:
|
||||
void run() {
|
||||
Scope *s = globalScriptEngine->createScope();
|
||||
Scope *s = globalScriptEngine->newScope();
|
||||
|
||||
BSONObj o = BSON( "foo" << "bar" );
|
||||
s->setObject( "a.b", o );
|
||||
@ -268,7 +268,7 @@ namespace JSTests {
|
||||
class ObjectModReadonlyTests {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
BSONObj o = BSON( "x" << 17 << "y" << "eliot" << "z" << "sara" << "zz" << BSONObj() );
|
||||
s->setObject( "blah" , o , true );
|
||||
@ -315,7 +315,7 @@ namespace JSTests {
|
||||
class OtherJSTypes {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
{ // date
|
||||
BSONObj o;
|
||||
@ -382,7 +382,7 @@ namespace JSTests {
|
||||
class SpecialDBTypes {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
BSONObjBuilder b;
|
||||
b.appendTimestamp( "a" , 123456789 );
|
||||
@ -418,7 +418,7 @@ namespace JSTests {
|
||||
class TypeConservation {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
// -- A --
|
||||
|
||||
@ -527,7 +527,7 @@ namespace JSTests {
|
||||
}
|
||||
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
s->localConnect( "blah" );
|
||||
|
||||
@ -600,7 +600,7 @@ namespace JSTests {
|
||||
class CodeTests {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
{
|
||||
BSONObjBuilder b;
|
||||
@ -687,7 +687,7 @@ namespace JSTests {
|
||||
}
|
||||
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
s->localConnect( "asd" );
|
||||
const char * foo = "asdas\0asdasd";
|
||||
|
||||
@ -721,7 +721,7 @@ namespace JSTests {
|
||||
class VarTests {
|
||||
public:
|
||||
void run(){
|
||||
Scope * s = globalScriptEngine->createScope();
|
||||
Scope * s = globalScriptEngine->newScope();
|
||||
|
||||
ASSERT( s->exec( "a = 5;" , "a" , false , true , false ) );
|
||||
ASSERT_EQUALS( 5 , s->getNumber("a" ) );
|
||||
|
@ -380,7 +380,7 @@ namespace mongo {
|
||||
|
||||
Scope * s = scopeCache->get( pool );
|
||||
if ( ! s ){
|
||||
s = createScope();
|
||||
s = newScope();
|
||||
}
|
||||
|
||||
auto_ptr<Scope> p;
|
||||
|
@ -122,7 +122,12 @@ namespace mongo {
|
||||
ScriptEngine();
|
||||
virtual ~ScriptEngine();
|
||||
|
||||
virtual Scope * createScope() = 0;
|
||||
virtual Scope * newScope() {
|
||||
Scope *s = createScope();
|
||||
if ( s && _scopeInitCallback )
|
||||
_scopeInitCallback( *s );
|
||||
return s;
|
||||
}
|
||||
|
||||
virtual void runTest() = 0;
|
||||
|
||||
@ -134,8 +139,15 @@ namespace mongo {
|
||||
void threadDone();
|
||||
|
||||
struct Unlocker { virtual ~Unlocker() {} };
|
||||
|
||||
virtual auto_ptr<Unlocker> newThreadUnlocker() { return auto_ptr< Unlocker >( new Unlocker ); }
|
||||
|
||||
void setScopeInitCallback( void ( *func )( Scope & ) ) { _scopeInitCallback = func; }
|
||||
|
||||
protected:
|
||||
virtual Scope * createScope() = 0;
|
||||
|
||||
private:
|
||||
void ( *_scopeInitCallback )( Scope & );
|
||||
};
|
||||
|
||||
extern ScriptEngine * globalScriptEngine;
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <boost/thread/xtime.hpp>
|
||||
#include "engine_v8.h"
|
||||
#include <shell/utils.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace v8;
|
||||
@ -191,9 +190,7 @@ namespace mongo {
|
||||
Handle< v8::Function > fun;
|
||||
auto_ptr< V8Scope > scope;
|
||||
if ( config_.newScope_ ) {
|
||||
scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->createScope() ) );
|
||||
// these lines duplicated from dbshell, extract to common location.
|
||||
mongo::shellUtils::initScope( *scope );
|
||||
scope.reset( dynamic_cast< V8Scope * >( globalScriptEngine->newScope() ) );
|
||||
context = scope->context();
|
||||
// A v8::Function tracks the context in which it was created, so we have to
|
||||
// create a new function in the new context.
|
||||
|
@ -255,7 +255,8 @@ int _main(int argc, char* argv[]) {
|
||||
mongo::shellUtils::RecordMyLocation( argv[ 0 ] );
|
||||
|
||||
mongo::ScriptEngine::setup();
|
||||
auto_ptr< mongo::Scope > scope( mongo::globalScriptEngine->createScope() );
|
||||
mongo::globalScriptEngine->setScopeInitCallback( mongo::shellUtils::initScope );
|
||||
auto_ptr< mongo::Scope > scope( mongo::globalScriptEngine->newScope() );
|
||||
|
||||
string url = "test";
|
||||
string dbhost;
|
||||
@ -357,8 +358,6 @@ int _main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
mongo::shellUtils::initScope( *scope );
|
||||
|
||||
cout << "MongoDB shell version: " << mongo::versionString << endl;
|
||||
|
||||
mongo::UnitTest::runTests();
|
||||
|
Loading…
Reference in New Issue
Block a user