0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/scripting/engine_spidermonkey.h

135 lines
3.3 KiB
C
Raw Normal View History

// engine_spidermonkey.h
/* Copyright 2009 10gen Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "engine.h"
2009-07-24 14:26:35 +02:00
// START inc hacking
#if defined( MOZJS )
2009-05-29 22:26:59 +02:00
#define MOZILLA_1_8_BRANCH
#include "mozjs/jsapi.h"
#include "mozjs/jsdate.h"
2009-07-24 14:26:35 +02:00
#include "mozjs/jsregexp.h"
2009-06-04 23:10:21 +02:00
#warning if you are using an ubuntu version of spider monkey, we recommend installing spider monkey from source
2009-06-04 23:04:30 +02:00
#elif defined( OLDJS )
2009-05-13 20:20:20 +02:00
#ifdef WIN32
#include "jstypes.h"
#undef JS_PUBLIC_API
#undef JS_PUBLIC_DATA
#define JS_PUBLIC_API(t) t
#define JS_PUBLIC_DATA(t) t
#endif
#include "jsapi.h"
#include "jsdate.h"
2009-07-24 14:26:35 +02:00
#include "jsregexp.h"
#else
#include "js/jsapi.h"
2009-10-10 22:52:46 +02:00
#include "js/jsobj.h"
#include "js/jsdate.h"
2009-07-24 14:26:35 +02:00
#include "js/jsregexp.h"
#endif
2009-07-24 14:26:35 +02:00
// END inc hacking
2009-05-28 19:54:47 +02:00
// -- SM 1.6 hacks ---
#ifndef JSCLASS_GLOBAL_FLAGS
#warning old version of spider monkey ( probably 1.6 ) you should upgrade to at least 1.7
#define JSCLASS_GLOBAL_FLAGS 0
JSBool JS_CStringsAreUTF8(){
return false;
}
2009-06-01 18:59:07 +02:00
#define SM16
2009-06-01 17:34:11 +02:00
2009-05-28 19:54:47 +02:00
#endif
// -- END SM 1.6 hacks ---
2009-07-24 14:26:35 +02:00
#ifdef JSVAL_IS_TRACEABLE
#define SM18
#endif
2009-08-28 20:03:08 +02:00
#ifdef XULRUNNER
#define SM181
#endif
namespace mongo {
class SMScope;
2009-05-08 17:02:12 +02:00
class Convertor;
2009-05-10 04:07:36 +02:00
extern JSClass bson_class;
extern JSClass bson_ro_class;
2009-05-06 23:33:00 +02:00
extern JSClass object_id_class;
2009-10-02 22:38:20 +02:00
extern JSClass dbpointer_class;
2009-10-02 23:07:07 +02:00
extern JSClass dbref_class;
2009-06-05 15:54:35 +02:00
extern JSClass bindata_class;
extern JSClass timestamp_class;
2010-01-21 00:02:46 +01:00
extern JSClass numberlong_class;
extern JSClass minkey_class;
extern JSClass maxkey_class;
// internal things
void dontDeleteScope( SMScope * s ){}
void errorReporter( JSContext *cx, const char *message, JSErrorReport *report );
extern boost::thread_specific_ptr<SMScope> currentScope;
// bson
JSBool resolveBSONField( JSContext *cx, JSObject *obj, jsval id, uintN flags, JSObject **objp );
// mongo
2009-05-15 22:32:31 +02:00
void initMongoJS( SMScope * scope , JSContext * cx , JSObject * global , bool local );
2009-07-24 14:26:35 +02:00
bool appendSpecialDBObject( Convertor * c , BSONObjBuilder& b , const string& name , jsval val , JSObject * o );
#define JSVAL_IS_OID(v) ( JSVAL_IS_OBJECT( v ) && JS_InstanceOf( cx , JSVAL_TO_OBJECT( v ) , &object_id_class , 0 ) )
bool isDate( JSContext * cx , JSObject * o );
// JS private data must be 2byte aligned, so we use a holder to refer to an unaligned pointer.
struct BinDataHolder {
BinDataHolder( const char *c, int copyLen = -1 ) :
c_( const_cast< char * >( c ) ),
iFree_( copyLen != -1 ) {
if ( copyLen != -1 ) {
c_ = (char*)malloc( copyLen );
memcpy( c_, c, copyLen );
}
}
~BinDataHolder() {
if ( iFree_ )
free( c_ );
}
char *c_;
bool iFree_;
};
}