00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #pragma once
00019
00020 #include "engine.h"
00021
00022
00023
00024 #if defined( MOZJS )
00025
00026 #define MOZILLA_1_8_BRANCH
00027
00028 #include "mozjs/jsapi.h"
00029 #include "mozjs/jsdate.h"
00030 #include "mozjs/jsregexp.h"
00031
00032 #warning if you are using an ubuntu version of spider monkey, we recommend installing spider monkey from source
00033
00034 #elif defined( OLDJS )
00035
00036 #ifdef WIN32
00037 #include "jstypes.h"
00038 #undef JS_PUBLIC_API
00039 #undef JS_PUBLIC_DATA
00040 #define JS_PUBLIC_API(t) t __cdecl
00041 #define JS_PUBLIC_DATA(t) t
00042 #endif
00043
00044 #include "jsapi.h"
00045 #include "jsobj.h"
00046 #include "jsdate.h"
00047 #include "jsregexp.h"
00048
00049 #else
00050
00051 #include "js/jsapi.h"
00052 #include "js/jsobj.h"
00053 #include "js/jsdate.h"
00054 #include "js/jsregexp.h"
00055
00056 #endif
00057
00058
00059
00060
00061 #ifndef JSCLASS_GLOBAL_FLAGS
00062
00063 #warning old version of spider monkey ( probably 1.6 ) you should upgrade to at least 1.7
00064
00065 #define JSCLASS_GLOBAL_FLAGS 0
00066
00067 JSBool JS_CStringsAreUTF8() {
00068 return false;
00069 }
00070
00071 #define SM16
00072
00073 #endif
00074
00075
00076 #ifdef JSVAL_IS_TRACEABLE
00077 #define SM18
00078 #endif
00079
00080 #ifdef XULRUNNER
00081 #define SM181
00082 #endif
00083
00084 namespace mongo {
00085
00086 class SMScope;
00087 class Convertor;
00088
00089 extern JSClass bson_class;
00090 extern JSClass bson_ro_class;
00091
00092 extern JSClass object_id_class;
00093 extern JSClass dbpointer_class;
00094 extern JSClass dbref_class;
00095 extern JSClass bindata_class;
00096 extern JSClass timestamp_class;
00097 extern JSClass numberlong_class;
00098 extern JSClass minkey_class;
00099 extern JSClass maxkey_class;
00100
00101
00102 void dontDeleteScope( SMScope * s ) {}
00103 void errorReporter( JSContext *cx, const char *message, JSErrorReport *report );
00104 extern boost::thread_specific_ptr<SMScope> currentScope;
00105
00106
00107 JSBool resolveBSONField( JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp );
00108
00109
00110
00111 void initMongoJS( SMScope * scope , JSContext * cx , JSObject * global , bool local );
00112 bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , jsval val , JSObject * o );
00113
00114 #define JSVAL_IS_OID(v) ( JSVAL_IS_OBJECT( v ) && JS_InstanceOf( cx , JSVAL_TO_OBJECT( v ) , &object_id_class , 0 ) )
00115
00116 bool isDate( JSContext * cx , JSObject * o );
00117
00118
00119 struct BinDataHolder {
00120 BinDataHolder( const char *c, int copyLen = -1 ) :
00121 c_( const_cast< char * >( c ) ),
00122 iFree_( copyLen != -1 ) {
00123 if ( copyLen != -1 ) {
00124 c_ = (char*)malloc( copyLen );
00125 memcpy( c_, c, copyLen );
00126 }
00127 }
00128 ~BinDataHolder() {
00129 if ( iFree_ )
00130 free( c_ );
00131 }
00132 char *c_;
00133 bool iFree_;
00134 };
00135 }