diff options
Diffstat (limited to 'platform/javascript/javascript_eval.cpp')
-rw-r--r-- | platform/javascript/javascript_eval.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/platform/javascript/javascript_eval.cpp b/platform/javascript/javascript_eval.cpp index d84c8bf040..897c2276bb 100644 --- a/platform/javascript/javascript_eval.cpp +++ b/platform/javascript/javascript_eval.cpp @@ -31,16 +31,20 @@ #include "javascript_eval.h" #include "emscripten.h" -JavaScript *JavaScript::singleton=NULL; +JavaScript *JavaScript::singleton = NULL; JavaScript *JavaScript::get_singleton() { return singleton; } -Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { +Variant JavaScript::eval(const String &p_code, bool p_use_global_exec_context) { - union { int i; double d; char* s; } js_data[4]; + union { + int i; + double d; + char *s; + } js_data[4]; /* clang-format off */ Variant::Type return_type = static_cast<Variant::Type>(EM_ASM_INT({ @@ -127,21 +131,20 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { }, js_data, sizeof *js_data, p_code.utf8().get_data(), p_use_global_exec_context)); /* clang-format on */ - switch(return_type) { + switch (return_type) { case Variant::BOOL: return !!js_data->i; case Variant::INT: return js_data->i; case Variant::REAL: return js_data->d; - case Variant::STRING: - { - String str = String::utf8(js_data->s); - /* clang-format off */ + case Variant::STRING: { + String str = String::utf8(js_data->s); + /* clang-format off */ EM_ASM_({ _free($0); }, js_data->s); - /* clang-format on */ - return str; - } + /* clang-format on */ + return str; + } case Variant::VECTOR2: return Vector2(js_data[0].d, js_data[1].d); case Variant::VECTOR3: @@ -149,7 +152,7 @@ Variant JavaScript::eval(const String& p_code, bool p_use_global_exec_context) { case Variant::RECT2: return Rect2(js_data[0].d, js_data[1].d, js_data[2].d, js_data[3].d); case Variant::COLOR: - return Color(js_data[0].d/255., js_data[1].d/255., js_data[2].d/255., js_data[3].d); + return Color(js_data[0].d / 255., js_data[1].d / 255., js_data[2].d / 255., js_data[3].d); } return Variant(); } @@ -166,7 +169,6 @@ JavaScript::JavaScript() { } JavaScript::~JavaScript() { - } #endif // JAVASCRIPT_EVAL_ENABLED |