From 20ce33094fc82e801b8f64eb79c3ab73ca290073 Mon Sep 17 00:00:00 2001 From: MarkT Date: Tue, 18 Jan 2005 10:49:06 +0000 Subject: [PATCH] This was SVN commit r1735. --- source/ps/scripting/JSCollection.h | 43 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/source/ps/scripting/JSCollection.h b/source/ps/scripting/JSCollection.h index 0cde09cd4c..6af0976c6f 100755 --- a/source/ps/scripting/JSCollection.h +++ b/source/ps/scripting/JSCollection.h @@ -41,7 +41,7 @@ private: static JSBool GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp ); static JSBool SetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp ); static void Finalize( JSContext* cx, JSObject* obj ); - static T* GetNative( jsval m ); + static bool GetNative( jsval m, T& Storage ); public: static void Init( const char* ClassName ); @@ -105,14 +105,14 @@ template JSBool CJSCollection::A JS_ReportError( cx, "Cannot create a property at that subscript" ); return( JS_FALSE ); } - - T* m = GetNative( *vp ); + + T m; - if( !m ) - return( JS_TRUE ); // GetNative will report the error if it can't be put in this collection. + if( !GetNative( *vp, m ) ) + return( JS_TRUE ); set->resize( index + 1 ); - set->at( index ) = *m; + set->at( index ) = m; return( JS_TRUE ); } @@ -181,11 +181,12 @@ template JSBool CJSCollection::S return( JS_TRUE ); } - T* m = GetNative( *vp ); - if( !m ) - return( JS_TRUE ); // GetNative will report the error if that can't be put in this collection. - - set->at( index ) = *m; + T m; + + if( !GetNative( *vp, m ) ) + return( JS_TRUE ); + + set->at( index ) = m; return( JS_TRUE ); } @@ -219,12 +220,13 @@ template void CJSCollection::Ini g_ScriptingHost.DefineCustomObjectType( &JSI_class, NULL, 0, JSI_props, JSI_methods, NULL, NULL ); } -template T* CJSCollection::GetNative( jsval m ) +template bool CJSCollection::GetNative( jsval m, T& Storage ) { - T* Native = ToNative( m ); - if( !Native ) - JS_ReportError( g_ScriptingHost.GetContext(), "Only objects of type %s can be stored in this collection.", ScriptType->name ); - return( Native ); + if( ToPrimitive( g_ScriptingHost.GetContext(), m, Storage ) ) + return( true ); + + JS_ReportError( g_ScriptingHost.GetContext(), "Only objects of type %s can be stored in this collection.", ScriptType->name ); + return( false ); } @@ -294,9 +296,9 @@ template JSBool CJSCollection::P for( int i = 0; i < (int)argc; i++ ) { - T* m = GetNative( argv[i] ); - if( m ) - Set->push_back( *m ); + T m; + if( GetNative( argv[i], m ) ) + Set->push_back( m ); } *rval = INT_TO_JSVAL( Set->size() ); @@ -354,5 +356,6 @@ template JSBool CJSCollection::R } #define EntityCollection CJSCollection - +#define PlayerCollection CJSCollection + #endif