2009-05-05 16:43:54 +02:00
|
|
|
// engine_spidermonkey.h
|
|
|
|
|
2009-10-27 20:58:27 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "engine.h"
|
|
|
|
|
2009-07-24 14:26:35 +02:00
|
|
|
// START inc hacking
|
|
|
|
|
2009-05-11 19:10:26 +02:00
|
|
|
#if defined( MOZJS )
|
2009-05-05 16:43:54 +02:00
|
|
|
|
2009-05-29 22:26:59 +02:00
|
|
|
#define MOZILLA_1_8_BRANCH
|
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
#include "mozjs/jsapi.h"
|
2009-05-07 04:11:45 +02:00
|
|
|
#include "mozjs/jsdate.h"
|
2009-07-24 14:26:35 +02:00
|
|
|
#include "mozjs/jsregexp.h"
|
2009-05-11 19:10:26 +02:00
|
|
|
|
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
|
|
|
|
2009-05-11 19:10:26 +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
|
|
|
|
|
2009-05-11 19:10:26 +02:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jsdate.h"
|
2009-07-24 14:26:35 +02:00
|
|
|
#include "jsregexp.h"
|
2009-05-11 19:10:26 +02:00
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
#else
|
2009-05-11 19:10:26 +02:00
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
#include "js/jsapi.h"
|
2009-10-10 22:52:46 +02:00
|
|
|
#include "js/jsobj.h"
|
2009-05-07 04:11:45 +02:00
|
|
|
#include "js/jsdate.h"
|
2009-07-24 14:26:35 +02:00
|
|
|
#include "js/jsregexp.h"
|
2009-05-11 19:10:26 +02:00
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
#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
|
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
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;
|
2009-05-06 18:48:19 +02:00
|
|
|
extern JSClass bson_ro_class;
|
2009-05-15 14:31:11 +02:00
|
|
|
|
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;
|
2009-05-15 14:31:11 +02:00
|
|
|
extern JSClass timestamp_class;
|
2010-01-21 00:02:46 +01:00
|
|
|
extern JSClass numberlong_class;
|
2009-05-15 14:31:11 +02:00
|
|
|
extern JSClass minkey_class;
|
|
|
|
extern JSClass maxkey_class;
|
2009-05-06 18:48:19 +02:00
|
|
|
|
2009-05-05 16:43:54 +02:00
|
|
|
// 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 );
|
2009-06-03 19:18:50 +02:00
|
|
|
|
|
|
|
#define JSVAL_IS_OID(v) ( JSVAL_IS_OBJECT( v ) && JS_InstanceOf( cx , JSVAL_TO_OBJECT( v ) , &object_id_class , 0 ) )
|
|
|
|
|
2009-07-13 18:49:29 +02:00
|
|
|
bool isDate( JSContext * cx , JSObject * o );
|
2010-01-25 23:07:02 +01:00
|
|
|
|
|
|
|
// JS private data must be 2byte aligned, so we use a holder to refer to an unaligned pointer.
|
2010-01-26 00:45:53 +01:00
|
|
|
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_;
|
|
|
|
};
|
2009-05-05 16:43:54 +02:00
|
|
|
}
|