From 7ea06d81b263d23bbe3cb5a4480e63857cb36f0f Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 26 Oct 2014 23:51:44 +0000 Subject: implemented setting/getting host variables, including host functions but not yet host objects git-svn-id: file:///var/local/svn/basicwriter@81 daaaf23c-2e50-4459-9457-1e69db5a47bf --- src/plugins/mozjs/MozJsScriptEngine.hpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'src/plugins/mozjs/MozJsScriptEngine.hpp') diff --git a/src/plugins/mozjs/MozJsScriptEngine.hpp b/src/plugins/mozjs/MozJsScriptEngine.hpp index f98c871..02797bc 100644 --- a/src/plugins/mozjs/MozJsScriptEngine.hpp +++ b/src/plugins/mozjs/MozJsScriptEngine.hpp @@ -51,7 +51,8 @@ private: JS::RootedObject *parent; public: - MozJsScriptEngineFunction(MozJsScriptEngineScope &scope, JS::Value &fun, JSObject *parent); + MozJsScriptEngineFunction(MozJsScriptEngineScope &scope, JS::Value &fun, + JSObject *parent); ~MozJsScriptEngineFunction(); @@ -61,8 +62,7 @@ public: }; class MozJsScriptEngineScope : public ScriptEngineScope { - -friend MozJsScriptEngineFunction; + friend MozJsScriptEngineFunction; private: JSRuntime *rt; @@ -72,6 +72,19 @@ private: void handleErr(bool ok = false); +protected: + Variant doRun(const std::string &code) override; + void doSetVariable(const std::string &name, const Variant &var, + bool constant) override; + Variant doGetVariable(const std::string &name) override; + +public: + MozJsScriptEngineScope(JSRuntime *rt); + + ~MozJsScriptEngineScope() override; + + /* JS -> Host */ + Variant arrayToVariant(JSObject *obj); Variant objectToVariant(JSObject *obj); @@ -82,16 +95,12 @@ private: std::string toString(JSString *str); -protected: - Variant doRun(const std::string &code) override; - void doSetVariable(const std::string &name, const Variant &val, - bool constant) override; - Variant doGetVariable(const std::string &name) override; + /* Host -> JS */ -public: - MozJsScriptEngineScope(JSRuntime *rt); + void variantToValue(const Variant &var, JS::RootedValue &val); - ~MozJsScriptEngineScope() override; + void setObjectProperty(JS::RootedObject &obj, const std::string &name, + const Variant &var, bool constant); }; class MozJsScriptEngine : public ScriptEngine { -- cgit v1.2.3