diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-06-08 10:54:55 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-06-08 10:54:55 -0400 |
commit | d5122c9b90ef1f45585e09c45610488ff76894cf (patch) | |
tree | 594907f6b0c1283cae0b45d50a3f2425ab8f7399 /scripting | |
parent | b6e455fd69c2cb9d2bb12b39c8cc721f2e5c3f61 (diff) | |
download | mongo-d5122c9b90ef1f45585e09c45610488ff76894cf.tar.gz |
change Map to use Map.get Map.put Map[] won't work
more tests for group
Diffstat (limited to 'scripting')
-rw-r--r-- | scripting/sm_db.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp index acb13b38777..d76faf801bf 100644 --- a/scripting/sm_db.cpp +++ b/scripting/sm_db.cpp @@ -499,6 +499,48 @@ namespace mongo { { 0 } }; + // Map + + bool specialMapString( const string& s ){ + return s == "put" || s == "get" || s == "_get" || s == "values" || s == "_data" || s == "constructor" ; + } + + JSBool map_constructor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval ){ + if ( argc > 0 ){ + JS_ReportError( cx , "Map takes no arguments" ); + return JS_FALSE; + } + + JSObject * array = JS_NewArrayObject( cx , 0 , 0 ); + assert( array ); + + jsval a = OBJECT_TO_JSVAL( array ); + JS_SetProperty( cx , obj , "_data" , &a ); + + return JS_TRUE; + } + + JSBool map_prop( JSContext *cx, JSObject *obj, jsval idval, jsval *vp ){ + Convertor c(cx); + if ( specialMapString( c.toString( idval ) ) ) + return JS_TRUE; + + log() << "illegal prop access: " << c.toString( idval ) << endl; + JS_ReportError( cx , "can't use array access with Map" ); + return JS_FALSE; + } + + JSClass map_class = { + "Map" , JSCLASS_HAS_PRIVATE , + map_prop, JS_PropertyStub, map_prop, map_prop, + JS_EnumerateStub, JS_ResolveStub , JS_ConvertStub, JS_FinalizeStub, + JSCLASS_NO_OPTIONAL_MEMBERS + }; + + JSFunctionSpec map_functions[] = { + { 0 } + }; + // ----- @@ -601,6 +643,8 @@ namespace mongo { assert( JS_InitClass( cx , global , 0 , ×tamp_class , 0 , 0 , 0 , 0 , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &minkey_class , 0 , 0 , 0 , 0 , 0 , 0 ) ); assert( JS_InitClass( cx , global , 0 , &maxkey_class , 0 , 0 , 0 , 0 , 0 , 0 ) ); + + assert( JS_InitClass( cx , global , 0 , &map_class , map_constructor , 0 , 0 , map_functions , 0 , 0 ) ); scope->exec( jsconcatcode ); } |