summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-05-28 10:54:48 -0400
committerEliot Horowitz <eliot@10gen.com>2009-05-28 10:54:48 -0400
commit31c52cba69d122146c00d47a72a361d39412d775 (patch)
tree8a3dca9d602a55dd9d98f827beb44c469c9c25ee
parente8a92a31f47eed060d2e056a54b334a4e7423aa9 (diff)
downloadmongo-31c52cba69d122146c00d47a72a361d39412d775.tar.gz
make "new ObjectId()" and "ObjectId()" both work for backwards compatability
-rw-r--r--jstests/objid4.js14
-rw-r--r--scripting/sm_db.cpp9
2 files changed, 21 insertions, 2 deletions
diff --git a/jstests/objid4.js b/jstests/objid4.js
new file mode 100644
index 00000000000..c574fa18008
--- /dev/null
+++ b/jstests/objid4.js
@@ -0,0 +1,14 @@
+
+
+
+o = new ObjectId();
+assert( o.str );
+
+a = new ObjectId( o.str );
+assert.eq( o.str , a.str );
+assert.eq( a.str , a.str.toString() )
+
+b = ObjectId( o.str );
+assert.eq( o.str , b.str );
+assert.eq( b.str , b.str.toString() )
+
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp
index edf7b245f74..a27d7438b1e 100644
--- a/scripting/sm_db.cpp
+++ b/scripting/sm_db.cpp
@@ -390,7 +390,6 @@ namespace mongo {
// -------------- object id -------------
JSBool object_id_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){
-
Convertor c( cx );
OID oid;
@@ -401,7 +400,13 @@ namespace mongo {
uassert( "object_id_constructor can't take more than 1 param" , argc == 1 );
oid.init( c.toString( argv[0] ) );
}
-
+
+ if ( ! JS_InstanceOf( cx , obj , &object_id_class , 0 ) ){
+ obj = JS_NewObject( cx , &object_id_class , 0 , 0 );
+ assert( obj );
+ *rval = OBJECT_TO_JSVAL( obj );
+ }
+
jsval v = c.toval( oid.str().c_str() );
assert( JS_SetProperty( cx , obj , "str" , &v ) );