diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index 9bd6db5475..962eced810 100755 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -231,7 +231,7 @@ JSObject * ScriptingHost::CreateCustomObject(const std::string & typeName) throw std::string("Tried to create a type that doesn't exist"); } - return JS_NewObject(m_Context, (*it).second.m_Class, (*it).second.m_Object, NULL); + return JS_ConstructObject(m_Context, (*it).second.m_Class, (*it).second.m_Object, NULL); } @@ -247,6 +247,18 @@ jsval ScriptingHost::GetObjectProperty( JSObject* object, const std::string& pro return( vp ); } +void ScriptingHost::SetGlobal(const std::string &globalName, jsval value) +{ + JS_SetProperty(m_Context, m_GlobalObject, globalName.c_str(), &value); +} + +jsval ScriptingHost::GetGlobal(const std::string &globalName) +{ + jsval vp; + JS_GetProperty(m_Context, m_GlobalObject, globalName.c_str(), &vp); + return vp; +} + int ScriptingHost::ValueToInt(const jsval value) { int32 i = 0; @@ -298,13 +310,16 @@ double ScriptingHost::ValueToDouble(const jsval value) void ScriptingHost::ErrorReporter(JSContext * context, const char * message, JSErrorReport * report) { - g_Console->InsertMessage( L"%S ( %d )", report->filename, report->lineno ); - if( message ) + if (g_Console) { - g_Console->InsertMessage( L"%S", message ); + g_Console->InsertMessage( L"%S ( %d )", report->filename, report->lineno ); + if( message ) + { + g_Console->InsertMessage( L"%S", message ); + } + else + g_Console->InsertMessage( L"No error message available" ); } - else - g_Console->InsertMessage( L"No error message available" ); if (report->filename != NULL) { diff --git a/source/scripting/ScriptingHost.h b/source/scripting/ScriptingHost.h index e90a049986..4bd8e24ece 100755 --- a/source/scripting/ScriptingHost.h +++ b/source/scripting/ScriptingHost.h @@ -72,6 +72,9 @@ public: void SetObjectProperty(JSObject * object, const std::string & propertyName, jsval value); jsval GetObjectProperty( JSObject* object, const std::string& propertyName ); + void SetGlobal(const std::string& globalName, jsval value); + jsval GetGlobal(const std::string& globalName); + int ValueToInt(const jsval value); bool ValueToBool(const jsval value); std::string ValueToString(const jsval value);