From 4e4dd60185ba8f9b181cfacc4e218ea8d09da511 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Tue, 9 Jun 2009 15:17:50 -0400 Subject: [PATCH] add "this" as a LocalRoot SERVER-102 --- scripting/engine_spidermonkey.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripting/engine_spidermonkey.cpp b/scripting/engine_spidermonkey.cpp index 017faf1bae5..cfc1eba763e 100644 --- a/scripting/engine_spidermonkey.cpp +++ b/scripting/engine_spidermonkey.cpp @@ -785,6 +785,9 @@ namespace mongo { for ( list::iterator i=_roots.begin(); i != _roots.end(); i++ ){ JS_RemoveRoot( _context , *i ); } + + if ( _this ) + JS_RemoveRoot( _context , &_this ); if ( _convertor ){ delete _convertor; @@ -899,9 +902,14 @@ namespace mongo { jsval v = BOOLEAN_TO_JSVAL( val ); assert( JS_SetProperty( _context , _global , field , &v ) ); } - + void setThis( const BSONObj * obj ){ + if ( _this ) + JS_RemoveRoot( _context , &_this ); + _this = _convertor->toJSObject( obj ); + + JS_AddNamedRoot( _context , &_this , "scope this" ); } // ---- functions -----