# Fixed some warnings and potentially misleading code

* Removed ToJSVal<jsval> because it's treated as ToJSVal<long> and
causes minor confusion and/or compiler errors.
   Changed script interface functions to return either C++ types or a
jsval_t wrapper.
 * Replaced some C casts with static_cast to avoid significant confusion
and to cause compiler errors instead.
 * Removed some redundant argument-checking code. Simplified some
string-generating code.
 * Fixed some "dereferencing type-punned pointer will break
strict-aliasing rules" warnings (from `g++ -O3`).

This was SVN commit r5115.
This commit is contained in:
Ykkrosh
2007-05-29 19:01:21 +00:00
parent 5919fc7877
commit fba692c8b5
30 changed files with 261 additions and 253 deletions
+8 -15
View File
@@ -163,10 +163,10 @@ CScriptEvent::CScriptEvent( const CStrW& Type, unsigned int TypeCode, bool Cance
void CScriptEvent::ScriptingInit()
{
AddMethod<jsval, &CScriptEvent::ToString>( "toString", 0 );
AddMethod<jsval, &CScriptEvent::PreventDefault>( "preventDefault", 0 );
AddMethod<jsval, &CScriptEvent::PreventDefault>( "cancel", 0 );
AddMethod<jsval, &CScriptEvent::StopPropagation>( "stopPropagation", 0 );
AddMethod<CStr, &CScriptEvent::ToString>( "toString", 0 );
AddMethod<void, &CScriptEvent::PreventDefault>( "preventDefault", 0 );
AddMethod<void, &CScriptEvent::PreventDefault>( "cancel", 0 );
AddMethod<void, &CScriptEvent::StopPropagation>( "stopPropagation", 0 );
AddProperty( L"type", &CScriptEvent::m_Type, true );
AddProperty( L"cancelable", &CScriptEvent::m_Cancelable, true );
@@ -176,26 +176,19 @@ void CScriptEvent::ScriptingInit()
CJSObject<CScriptEvent>::ScriptingInit( "Event" );
}
jsval CScriptEvent::PreventDefault( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
void CScriptEvent::PreventDefault( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
if( m_Cancelable )
m_Cancelled = true;
return( JSVAL_VOID );
}
jsval CScriptEvent::StopPropagation( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
void CScriptEvent::StopPropagation( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
if( m_Blockable )
m_Blocked = true;
return( JSVAL_VOID );
}
jsval CScriptEvent::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
CStr CScriptEvent::ToString( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
wchar_t buffer[256];
swprintf( buffer, 256, L"[object Event: %ls]", m_Type.c_str() );
buffer[255] = 0;
utf16string str16=utf16string(buffer, buffer+wcslen(buffer));
return( STRING_TO_JSVAL( JS_NewUCStringCopyZ( cx, str16.c_str() ) ) );
return "[object Event: " + CStr(m_Type) + "]";
}