18 #include "precompiled.h"
65 filename =
"unspecified file";
72 JSBool ok = JS_EvaluateScript(
m_Context, globalObject, script, (uintN)size, filename, line, &rval);
84 shared_ptr<u8> buf;
size_t size;
88 std::wstring scriptw =
wstring_from_utf8(std::string(buf.get(), buf.get() + size));
92 JSBool ok = JS_EvaluateUCScript(
m_Context, globalObject,
93 reinterpret_cast<const jschar*>(script.c_str()), (uintN)script.size(),
105 reinterpret_cast<const jschar*>(script.utf16().c_str()), (
int)script.length(),
106 calledFrom.ToUTF8().c_str(), 1, &rval);
108 if (!ok)
return JSVAL_NULL;
115 std::string typeName = clasp->name;
125 constructor, minArgs,
127 static_ps, static_fs);
147 return JS_ConstructObject(
m_Context, (*it).second.m_Class, (*it).second.m_Object, NULL);
155 JS_SetProperty(
m_Context,
object, propertyName.c_str(), &value);
161 JS_GetProperty(
m_Context,
object, propertyName.c_str(), &vp );
170 if (! JS_NewNumberValue(
m_Context, value, &v))
173 if (! JS_SetProperty(
m_Context,
object, propertyName, &v))
182 if (! JS_GetProperty(
m_Context,
object, propertyName, &v))
184 if (! JS_ValueToNumber(
m_Context, v, &d))
204 JSString*
string = JS_ValueToString(
m_Context, value);
209 const jschar *strptr = JS_GetStringCharsAndLength(
m_Context,
string, &length);
213 return std::wstring(strptr, strptr+length);
JSObject * CreateCustomObject(const std::string &typeName)
static void FinalShutdown()
std::string utf8_from_wstring(const std::wstring &src, Status *err)
opposite of wstring_from_utf8
void SetObjectProperty_Double(JSObject *object, const char *propertyName, double value)
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)
const String & string() const
void RunScript(const VfsPath &filename, JSObject *globalObject=0)
std::map< std::string, CustomType > m_CustomObjectTypes
std::wstring wstring_from_utf8(const std::string &src, Status *err)
convert UTF-8 to a wide string (UTF-16 or UCS-4, depending on the platform's wchar_t).
void RunMemScript(const char *script, size_t size, const char *filename=0, int line=0, JSObject *globalObject=0)
JSFunctionSpec ScriptFunctionTable[]
ScriptInterface & GetScriptInterface()
std::basic_string< utf16_t, utf16_traits > utf16string
double GetObjectProperty_Double(JSObject *object, const char *propertyName)
CStrW ValueToUCString(const jsval value)
ScriptInterface * m_ScriptInterface
Abstraction around a SpiderMonkey JSContext.
jsval ExecuteScript(const CStrW &script, const CStrW &calledFrom=L"Console", JSObject *contextObject=NULL)
static shared_ptr< ScriptRuntime > CreateRuntime(int runtimeSize=DEFAULT_RUNTIME_SIZE)
Returns a runtime, which can used to initialise any number of ScriptInterfaces contexts.
JSContext * GetContext() const
void DefineCustomObjectType(JSClass *clasp, JSNative constructor, uintN nargs, JSPropertySpec *ps, JSFunctionSpec *fs, JSPropertySpec *static_ps, JSFunctionSpec *static_fs)
JSObject * m_GlobalObject