summaryrefslogtreecommitdiff
path: root/scripting
diff options
context:
space:
mode:
authoragirbal <antoine@10gen.com>2011-07-10 17:10:42 -0700
committeragirbal <antoine@10gen.com>2011-07-10 17:12:47 -0700
commit550af81d774215724b5e32a9927399b0376e8558 (patch)
treee6a6d946e36faf3d30370c5b5b5fcda80d02e84d /scripting
parent3731e71d77f63a78abf713f52a77bd019e59c3d2 (diff)
downloadmongo-550af81d774215724b5e32a9927399b0376e8558.tar.gz
- V8: use BSON data as is if an object was not modified
- unplug NumberInt from V8 until fixed (need to compare types with previous BSON) - better debug lines for read only objects
Diffstat (limited to 'scripting')
-rw-r--r--scripting/engine_v8.cpp62
-rw-r--r--scripting/engine_v8.h1
2 files changed, 46 insertions, 17 deletions
diff --git a/scripting/engine_v8.cpp b/scripting/engine_v8.cpp
index 7450778bc99..3909310d0e2 100644
--- a/scripting/engine_v8.cpp
+++ b/scripting/engine_v8.cpp
@@ -118,9 +118,12 @@ namespace mongo {
return val;
}
-// static Handle<v8::Value> namedSet(Local<v8::String> name, Local<v8::Value> value_obj, const v8::AccessorInfo& info) {
-// return Handle<Value>();
-// }
+ static Handle<v8::Value> namedSet(Local<v8::String> name, Local<v8::Value> value_obj, const v8::AccessorInfo& info) {
+ Local< External > scp = External::Cast( *info.Data() );
+ V8Scope* scope = (V8Scope*)(scp->Value());
+ info.This()->SetHiddenValue(scope->V8STR_MODIFIED, v8::Boolean::New(true));
+ return Handle<Value>();
+ }
static Handle<v8::Array> namedEnumerator(const AccessorInfo &info) {
BSONObj *obj = unwrapBSONObj(info.Holder());
@@ -138,6 +141,14 @@ namespace mongo {
return arr;
}
+ Handle<Boolean> namedDelete( Local<v8::String> property, const AccessorInfo& info ) {
+ Local< External > scp = External::Cast( *info.Data() );
+ V8Scope* scope = (V8Scope*)(scp->Value());
+ cout << "setting modded" << endl;
+ info.This()->SetHiddenValue(scope->V8STR_MODIFIED, v8::Boolean::New(true));
+ return Handle<Boolean>();
+ }
+
// v8::Handle<v8::Integer> namedQuery(Local<v8::String> property, const AccessorInfo& info) {
// string key = ToString(property);
// return v8::Integer::New(None);
@@ -170,6 +181,13 @@ namespace mongo {
return val;
}
+ Handle<Boolean> indexedDelete( uint32_t index, const AccessorInfo& info ) {
+ Local< External > scp = External::Cast( *info.Data() );
+ V8Scope* scope = (V8Scope*)(scp->Value());
+ info.This()->SetHiddenValue(scope->V8STR_MODIFIED, v8::Boolean::New(true));
+ return Handle<Boolean>();
+ }
+
static Handle<v8::Value> indexedGetRO(uint32_t index, const v8::AccessorInfo &info) {
StringBuilder ss;
ss << index;
@@ -193,9 +211,12 @@ namespace mongo {
return val;
}
-// static Handle<v8::Value> indexedSet(uint32_t index, Local<v8::Value> value_obj, const v8::AccessorInfo& info) {
-// return Handle<Value>();
-// }
+ static Handle<v8::Value> indexedSet(uint32_t index, Local<v8::Value> value_obj, const v8::AccessorInfo& info) {
+ Local< External > scp = External::Cast( *info.Data() );
+ V8Scope* scope = (V8Scope*)(scp->Value());
+ info.This()->SetHiddenValue(scope->V8STR_MODIFIED, v8::Boolean::New(true));
+ return Handle<Value>();
+ }
// static Handle<v8::Array> indexedEnumerator(const AccessorInfo &info) {
// BSONObj *obj = unwrapBSONObj(info.Holder());
@@ -212,22 +233,24 @@ namespace mongo {
// }
Handle<Value> NamedReadOnlySet( Local<v8::String> property, Local<Value> value, const AccessorInfo& info ) {
- cout << "cannot write to read-only object" << endl;
+ string key = toSTLString(property);
+ cout << "cannot write property " << key << " to read-only object" << endl;
return value;
}
Handle<Boolean> NamedReadOnlyDelete( Local<v8::String> property, const AccessorInfo& info ) {
- cout << "cannot delete from read-only object" << endl;
+ string key = toSTLString(property);
+ cout << "cannot delete property " << key << " from read-only object" << endl;
return Boolean::New( false );
}
Handle<Value> IndexedReadOnlySet( uint32_t index, Local<Value> value, const AccessorInfo& info ) {
- cout << "cannot write to read-only array" << endl;
+ cout << "cannot write property " << index << " to read-only array" << endl;
return value;
}
Handle<Boolean> IndexedReadOnlyDelete( uint32_t index, const AccessorInfo& info ) {
- cout << "cannot delete from read-only array" << endl;
+ cout << "cannot delete property " << index << " from read-only array" << endl;
return Boolean::New( false );
}
@@ -278,8 +301,8 @@ namespace mongo {
// initialize lazy object template
lzObjectTemplate = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
lzObjectTemplate->SetInternalFieldCount( 1 );
- lzObjectTemplate->SetNamedPropertyHandler(namedGet, 0, 0, 0, 0, v8::External::New(this));
- lzObjectTemplate->SetIndexedPropertyHandler(indexedGet, 0, 0, 0, 0, v8::External::New(this));
+ lzObjectTemplate->SetNamedPropertyHandler(namedGet, namedSet, 0, namedDelete, 0, v8::External::New(this));
+ lzObjectTemplate->SetIndexedPropertyHandler(indexedGet, indexedSet, 0, indexedDelete, 0, v8::External::New(this));
roObjectTemplate = Persistent<ObjectTemplate>::New(ObjectTemplate::New());
roObjectTemplate->SetInternalFieldCount( 1 );
@@ -318,6 +341,7 @@ namespace mongo {
V8STR_NATIVE_DATA = getV8Str( "_native_data" );
V8STR_V8_FUNC = getV8Str( "_v8_function" );
V8STR_RO = getV8Str( "_ro" );
+ V8STR_MODIFIED = getV8Str( "_mod" );
injectV8Function("print", Print);
injectV8Function("version", Version);
@@ -473,7 +497,7 @@ namespace mongo {
V8_SIMPLE_HEADER
// Set() accepts a ReadOnly parameter, but this just prevents the field itself
// from being overwritten and doesn't protect the object stored in 'field'.
- _global->Set( getV8Str( field ) , mongoToV8( obj, false, readOnly) );
+ _global->Set( getV8Str( field ) , mongoToLZV8( obj, false, readOnly) );
}
int V8Scope::type( const char *field ) {
@@ -491,6 +515,7 @@ namespace mongo {
return Array;
if ( v->IsBoolean() )
return Bool;
+ // needs to be explicit NumberInt to use integer
// if ( v->IsInt32() )
// return NumberInt;
if ( v->IsNumber() )
@@ -1290,9 +1315,10 @@ namespace mongo {
}
if ( value->IsNumber() ) {
- if ( value->IsInt32() )
- b.append( sname, int( value->ToInt32()->Value() ) );
- else
+ // needs to be explicit NumberInt to use integer
+// if ( value->IsInt32() )
+// b.append( sname, int( value->ToInt32()->Value() ) );
+// else
b.append( sname , value->ToNumber()->Value() );
return;
}
@@ -1408,8 +1434,10 @@ namespace mongo {
}
BSONObj V8Scope::v8ToMongo( v8::Handle<v8::Object> o , int depth ) {
- if ( !o->GetHiddenValue( V8STR_RO ).IsEmpty() ) {
+ if ( !o->GetHiddenValue( V8STR_RO ).IsEmpty() ||
+ (o->HasNamedLookupInterceptor() && o->GetHiddenValue( V8STR_MODIFIED ).IsEmpty()) ) {
// object was readonly, use bson as is
+ log(1) << "Using bson as is for v8ToMongo" << endl;
BSONObj* ro = unwrapBSONObj(o);
if (ro)
return *ro;
diff --git a/scripting/engine_v8.h b/scripting/engine_v8.h
index 2c7d238cf2e..1920a10a301 100644
--- a/scripting/engine_v8.h
+++ b/scripting/engine_v8.h
@@ -149,6 +149,7 @@ namespace mongo {
Handle<v8::String> V8STR_BINDATA;
Handle<v8::String> V8STR_WRAPPER;
Handle<v8::String> V8STR_RO;
+ Handle<v8::String> V8STR_MODIFIED;
private:
void _startCall();