mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-28 18:52:08 +00:00
Support new SpiderMonkey API.
wposix: Define int8_t compatibly with SpiderMonkey. Remove unused camera, lightenv JS interfaces. Remove most of vector JS interface. Remove some of the redundant JS string conversion functions. Remove unneeded vmem, _lodBias functions. Clean up some formatting. This was SVN commit r8629.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2009 Wildfire Games.
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -40,81 +40,85 @@ JSPropertySpec JSI_Console::JSI_props[] =
|
||||
|
||||
JSFunctionSpec JSI_Console::JSI_methods[] =
|
||||
{
|
||||
{ "write", JSI_Console::writeConsole, 1, 0, 0 },
|
||||
{ "write", JSI_Console::writeConsole, 1, 0 },
|
||||
{ 0 },
|
||||
};
|
||||
|
||||
JSBool JSI_Console::getProperty( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval id, jsval* vp )
|
||||
JSBool JSI_Console::getProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, jsval* vp)
|
||||
{
|
||||
if( !JSVAL_IS_INT( id ) )
|
||||
return( JS_TRUE );
|
||||
if (!JSID_IS_INT(id))
|
||||
return JS_TRUE;
|
||||
|
||||
int i = JSVAL_TO_INT( id );
|
||||
int i = JSID_TO_INT(id);
|
||||
|
||||
switch( i )
|
||||
switch (i)
|
||||
{
|
||||
case console_visible:
|
||||
*vp = BOOLEAN_TO_JSVAL( g_Console->IsActive() ); return( JS_TRUE );
|
||||
*vp = BOOLEAN_TO_JSVAL(g_Console->IsActive());
|
||||
return JS_TRUE;
|
||||
default:
|
||||
*vp = JSVAL_NULL; return( JS_TRUE );
|
||||
}
|
||||
*vp = JSVAL_NULL;
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
JSBool JSI_Console::setProperty( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval id, jsval* vp )
|
||||
JSBool JSI_Console::setProperty(JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsid id, jsval* vp)
|
||||
{
|
||||
if( !JSVAL_IS_INT( id ) )
|
||||
return( JS_TRUE );
|
||||
if (!JSID_IS_INT(id))
|
||||
return JS_TRUE;
|
||||
|
||||
int i = JSVAL_TO_INT( id );
|
||||
int i = JSID_TO_INT(id);
|
||||
|
||||
switch( i )
|
||||
switch (i)
|
||||
{
|
||||
case console_visible:
|
||||
try
|
||||
{
|
||||
g_Console->SetVisible( ToPrimitive<bool>( *vp ) );
|
||||
return( JS_TRUE );
|
||||
g_Console->SetVisible(ToPrimitive<bool> (*vp));
|
||||
return JS_TRUE;
|
||||
}
|
||||
catch( PSERROR_Scripting_ConversionFailed )
|
||||
catch (PSERROR_Scripting_ConversionFailed)
|
||||
{
|
||||
return( JS_TRUE );
|
||||
return JS_TRUE;
|
||||
}
|
||||
default:
|
||||
return( JS_TRUE );
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
void JSI_Console::init()
|
||||
{
|
||||
g_ScriptingHost.DefineCustomObjectType( &JSI_class, NULL, 0, JSI_props, JSI_methods, NULL, NULL );
|
||||
g_ScriptingHost.DefineCustomObjectType(&JSI_class, NULL, 0, JSI_props, JSI_methods, NULL, NULL);
|
||||
}
|
||||
|
||||
JSBool JSI_Console::getConsole( JSContext* cx, JSObject* UNUSED(obj), jsval UNUSED(id), jsval* vp )
|
||||
JSBool JSI_Console::getConsole(JSContext* cx, JSObject* UNUSED(obj), jsid UNUSED(id), jsval* vp)
|
||||
{
|
||||
JSObject* console = JS_NewObject( cx, &JSI_Console::JSI_class, NULL, NULL );
|
||||
*vp = OBJECT_TO_JSVAL( console );
|
||||
return( JS_TRUE );
|
||||
JSObject* console = JS_NewObject(cx, &JSI_Console::JSI_class, NULL, NULL);
|
||||
*vp = OBJECT_TO_JSVAL(console);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
JSBool JSI_Console::writeConsole( JSContext* UNUSED(context), JSObject* UNUSED(globalObject), uintN argc, jsval* argv, jsval* UNUSED(rval) )
|
||||
JSBool JSI_Console::writeConsole(JSContext* cx, uintN argc, jsval* vp)
|
||||
{
|
||||
debug_assert( argc >= 1 );
|
||||
UNUSED2(cx);
|
||||
|
||||
CStrW output;
|
||||
for( unsigned int i = 0; i < argc; i++ )
|
||||
for (uintN i = 0; i < argc; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
CStrW arg = g_ScriptingHost.ValueToUCString( argv[i] );
|
||||
CStrW arg = g_ScriptingHost.ValueToUCString(JS_ARGV(cx, vp)[i]);
|
||||
output += arg;
|
||||
}
|
||||
catch( PSERROR_Scripting_ConversionFailed )
|
||||
catch (PSERROR_Scripting_ConversionFailed)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: What if the console has been destroyed already?
|
||||
if (g_Console)
|
||||
g_Console->InsertMessage( L"%ls", output.c_str() );
|
||||
g_Console->InsertMessage(L"%ls", output.c_str());
|
||||
|
||||
return( JS_TRUE );
|
||||
JS_SET_RVAL(cx, vp, JSVAL_VOID);
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user