diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 37cd5d15..e2cd00ae 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,4 +4,4 @@ Make sure to follow the PR preparation steps in [CONTRIBUTING.md](https://github.com/godotjs/javascript/blob/master/CONTRIBUTING.md#preparing-your-pr) before submitting your PR: -- [ ] format the codebase: from the root, run `bash ./clang_format.sh`. +- [ ] format C++: from the root, run `bash ./misc/formatting/clang_format.sh`. diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml index 4fac1fad..9d9e1874 100644 --- a/.github/workflows/static_checks.yml +++ b/.github/workflows/static_checks.yml @@ -31,7 +31,7 @@ jobs: - name: Checkout workaround run: | mv tmp/misc/scripts misc/scripts - cp clang_format.sh misc/scripts/clang_format.sh + cp misc/formatting/clang_format.sh misc/scripts/clang_format.sh - name: Install APT dependencies uses: awalsh128/cache-apt-pkgs-action@latest @@ -66,14 +66,6 @@ jobs: run: | bash ./misc/scripts/header_guards.sh changed.txt - - name: Python style checks via black (black_format.sh) - run: | - if grep -qE '\.py$|SConstruct|SCsub' changed.txt || [ -z "$(cat changed.txt)" ]; then - bash ./misc/scripts/black_format.sh - else - echo "Skipping Python formatting as no Python files were changed." - fi - - name: Python scripts static analysis (mypy_check.sh) run: | if grep -qE '\.py$|SConstruct|SCsub' changed.txt || [ -z "$(cat changed.txt)" ]; then @@ -86,19 +78,3 @@ jobs: run: | clang-format --version bash ./misc/scripts/clang_format.sh changed.txt - - - name: Style checks via dotnet format (dotnet_format.sh) - run: | - if grep -q "modules/mono" changed.txt || [ -z "$(cat changed.txt)" ]; then - bash ./misc/scripts/dotnet_format.sh - else - echo "Skipping dotnet format as no C# files were changed." - fi - - - name: Spell checks via codespell - if: github.event_name == 'pull_request' && env.CHANGED_FILES != '' - uses: codespell-project/actions-codespell@v2 - with: - skip: "./bin,./thirdparty,*.desktop,*.svg,*.gen.*,*.po,*.pot,*.rc,./AUTHORS.md,./COPYRIGHT.txt,./DONORS.md,./core/input/gamecontrollerdb.txt,./core/string/locales.h,./editor/project_converter_3_to_4.cpp,./misc/scripts/codespell.sh,./platform/android/java/lib/src/com,./platform/web/node_modules,./platform/web/package-lock.json" - ignore_words_list: "breaked,checkin,curvelinear,doubleclick,expct,findn,gird,hel,inout,labelin,lod,mis,nd,numer,ot,pointin,requestor,te,textin,thirdparty,vai" - path: ${{ env.CHANGED_FILES }} diff --git a/.github/workflows/windows_builds.yml b/.github/workflows/windows_builds.yml index d403efaa..e3d612b5 100644 --- a/.github/workflows/windows_builds.yml +++ b/.github/workflows/windows_builds.yml @@ -78,7 +78,7 @@ jobs: run: | ${{ matrix.bin }} --version ${{ matrix.bin }} --help - ${{ matrix.bin }} --test + ${{ matrix.bin }} --test --force-colors - name: Prepare artifact run: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bf976e2e..b3aae617 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,11 +2,30 @@ ## Project Structure -TODO +- [Clang](https://clang.llvm.org/): Code formatting + - ``.clang-format`` + - ``.clang-tidy`` + - ``clang-format.sh`` +- [Custom Modules in C++](https://docs.godotengine.org/en/stable/contributing/development/core_and_modules/custom_modules_in_cpp.html#custom-modules-in-c) + - ``config.py``: Configs for this module + - ``doc``: For showing documentation in editor + - ``doc_classes``: For showing documentation in editor + - ``icons``: For showing icons in editor + - ``SCsub``: Will be called from Godots `SConstruct` during build + - ``editor``: Custom `.cpp` only bundled for `target=editor` + - ``misc``: Scripts and other files, which aren't related to `c++` + - ``tests``: Some testcases to run in CICD + - ``thirdparty``: Dependencies or libraries which shouldn't be analysed by static checks +- GodotJS custom data + - ``.github``: Runs custom CI/CD in GitHub + - ``docs``: Add some additional stuff for README.md + - ``src``: Contains custom C++ code + ## Preparing your PR -The project is using [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) to format most files. You need to run `bash ./clang_format.sh` before your PR for a successful pipeline. +The project is using [`clang-format`](https://clang.llvm.org/docs/ClangFormat.html) to format C++ files. +You need to run `bash ./misc/formatting/clang_format.sh` before your PR for a successful pipeline. Furthermore, there is an `utf-8` and `LF` checker to fix file formats. Additionally, some spellchecks run inside the [pipeline](.github/workflows/static_checks.yml). diff --git a/README.md b/README.md index 3efa9505..a3211c52 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ Download the binaries from the [release page](https://github.com/GodotExplorer/E - Use `scons` with those additional options `warnings=extra werror=yes module_text_server_fb_enabled=yes` to show all potential errors: - Windows: `scons platform=windows warnings=extra werror=yes module_text_server_fb_enabled=yes` - MacOS: `scons platform=macos arch=arm64 warnings=extra werror=yes module_text_server_fb_enabled=yes` + - **Hint**: To enable unit tests you need to add ``tests=true`` to `scons` arguments ## Documentation, Tutorials & Demos diff --git a/SCsub b/SCsub index 4c82ba81..5b87ceee 100644 --- a/SCsub +++ b/SCsub @@ -1,47 +1,32 @@ #!/usr/bin/env python -import platform, os, sys +import os + +from misc.generate.generate_files import generate Import("env") Import("env_modules") -env_module = env_modules.Clone() + +env_javascript = env_modules.Clone() + +# Default engine to use we might add some more in the future like node or v8 JS_ENGINE = "quickjs" -TOOLS = "editor" == env_module["target"] +javascript_dir = os.path.join(GetLaunchDir(), "modules", os.path.basename(os.getcwd())) +# Windows workaround if env["platform"] == "windows": if env["use_mingw"]: env.Append(LIBS=["pthread"]) - -def open_file(path, mode): - if platform.python_version() > "3": - return open(path, mode, encoding="utf8") - else: - return open(path, mode) - - -def dump_text_file_to_cpp(file): - source = open_file(file, "r").read() - lines = source.split("\n") - source = "" - length = len(lines) - for i in range(length): - line = lines[i].replace('"', '\\"') - line = '\t"' + line + '\\n"' - if i < length - 1: - line += "\n" - source += line - return source - - +# Add required files for quickjs into godot if JS_ENGINE == "quickjs": import generate_builtin_api - generate_builtin_api.generate_api_json(os.path.join(GetLaunchDir(), "modules", os.path.basename(os.getcwd()))) + generate_builtin_api.generate_api_json(javascript_dir) import thirdparty.quickjs.builtin_binding_generator thirdparty.quickjs.builtin_binding_generator.generate_builtin_bindings() version = open("thirdparty/quickjs/quickjs/VERSION.txt", "r").read().split("\n")[0] - quickjs_env = env_modules.Clone() + quickjs_env = env_javascript.Clone() quickjs_env.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'}) quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"]) if "release" not in (quickjs_env["target"] or ""): @@ -55,50 +40,50 @@ if JS_ENGINE == "quickjs": quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp") quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c") -# Binding script to run at engine initializing -with open("misc/godot.binding_script.gen.cpp", "w") as f: - text = '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "../javascript_binder.h"\nString JavaScriptBinder::BINDING_SCRIPT_CONTENT = \n${source};' - f.write(text.replace("${source}", dump_text_file_to_cpp("misc/binding_script.js"))) +# If target=editor is provided via scons +if env.editor_build: + env_javascript.add_source_files(env.modules_sources, "editor/workarounds/*.cpp") + env_javascript.add_source_files(env.modules_sources, "editor/*.cpp") + + # --- Generate editor tool files --- + from misc.generate.editor_tools import get_editor_tools_files + from misc.generate.editor_tools import get_editor_tools_header + + files = get_editor_tools_files() + generate(javascript_dir, get_editor_tools_header(), files) + env_javascript.add_source_files(env.modules_sources, files.keys()) + +# If tests=yes flag is provided via scons +if env["tests"]: + env_javascript.Append(CPPDEFINES=["TESTS_ENABLED"]) + + # --- Generate test files --- + from misc.generate.test_manager import get_test_files + from misc.generate.test_manager import get_test_manager_header + + files = get_test_files() + generate(javascript_dir, get_test_manager_header(), files) + env_javascript.add_source_files(env.modules_sources, files.keys()) + +# --- Files inside editor & targets --- sources = [ "register_types.cpp", "javascript_language.cpp", "javascript_instance.cpp", "javascript.cpp", - "misc/godot.binding_script.gen.cpp", ] -if TOOLS: - base_text = ( - '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};' - ) - tool_fns = { - "editor/godot.d.ts.gen.cpp": ( - "BUILTIN_DECLARATION_TEXT", - dump_text_file_to_cpp("misc/godot.d.ts"), - ), - "editor/tsconfig.json.gen.cpp": ( - "TSCONFIG_CONTENT", - dump_text_file_to_cpp("misc/tsconfig.json"), - ), - "editor/decorators.ts.gen.cpp": ( - "TS_DECORATORS_CONTENT", - dump_text_file_to_cpp("misc/decorators.ts"), - ), - "editor/package.json.gen.cpp": ( - "PACKAGE_JSON_CONTENT", - dump_text_file_to_cpp("misc/package.json"), - ), - } - for fn, subs in tool_fns.items(): - with open_file(fn, "w") as fh: - fh.write(base_text.format(*subs)) - env_module.add_source_files(env.modules_sources, fn) - - -env_module.Append(CPPPATH=["#modules/javascript"]) -env_module.add_source_files(env.modules_sources, sources) +# Add all required files for "Javascript" language into godot +env_javascript.Append(CPPPATH=["#modules/javascript"]) +env_javascript.add_source_files(env.modules_sources, sources) -if env.editor_build: - env_module.add_source_files(env.modules_sources, "editor/workarounds/*.cpp") - env_module.add_source_files(env.modules_sources, "editor/*.cpp") +# --- Generate binding files --- +# Binding script to run at engine initializing +# The bindings add some functionality for `this.connect(...)` +from misc.generate.bindings import get_bindings_header +from misc.generate.bindings import get_binding_files + +files = get_binding_files() +generate(javascript_dir, get_bindings_header(), files) +env_javascript.add_source_files(env.modules_sources, files.keys()) diff --git a/generate_builtin_api.py b/generate_builtin_api.py index 839d5560..5a822a80 100755 --- a/generate_builtin_api.py +++ b/generate_builtin_api.py @@ -372,11 +372,11 @@ def parse_class(cls): ) -def generate_api_json(MODULE_DIR): - DOCS_DIR = os.path.abspath(os.path.join(MODULE_DIR, "../../doc/classes")) +def generate_api_json(MODULES_DIR): + DOCS_DIR = os.path.abspath(os.path.join(MODULES_DIR, "../../doc/classes")) if not os.path.isdir(DOCS_DIR) and len(sys.argv) > 1: DOCS_DIR = sys.argv[-1] - OUTPUT_FILE = os.path.join(MODULE_DIR, "builtin_api.gen.json") + OUTPUT_FILE = os.path.join(MODULES_DIR, "builtin_api.gen.json") classes = [] for cls in BUILTIN_CLASSES: diff --git a/javascript_language.cpp b/javascript_language.cpp index 5afd7e3e..aa041490 100644 --- a/javascript_language.cpp +++ b/javascript_language.cpp @@ -56,7 +56,6 @@ JavaScriptLanguage::~JavaScriptLanguage() { void JavaScriptLanguage::init() { ERR_FAIL_NULL(main_binder); main_binder->initialize(); - execute_file("modules/javascript/tests/UnitTest.js"); } void JavaScriptLanguage::finish() { @@ -65,14 +64,10 @@ void JavaScriptLanguage::finish() { main_binder->language_finalize(); } -Error JavaScriptLanguage::execute_file(const String &p_path) { +Error JavaScriptLanguage::execute_file(const String &code) { ERR_FAIL_NULL_V(main_binder, ERR_BUG); - Error err; - String code = FileAccess::get_file_as_string(p_path, &err); - if (err == OK) { - JavaScriptGCHandler eval_ret; - err = main_binder->eval_string(code, JavaScriptBinder::EVAL_TYPE_GLOBAL, p_path, eval_ret); - } + JavaScriptGCHandler eval_ret; + const Error err = main_binder->eval_string(code, JavaScriptBinder::EVAL_TYPE_GLOBAL, "test.js", eval_ret); return err; } diff --git a/javascript_language.h b/javascript_language.h index 8c3f12fd..76f029c1 100644 --- a/javascript_language.h +++ b/javascript_language.h @@ -56,7 +56,13 @@ class JavaScriptLanguage : public ScriptLanguage { virtual void init() override; virtual void finish() override; - virtual Error execute_file(const String &p_path); + + /** + * Executes a js file with JavaScriptBinder - currently used via init() for testing the editor in cicd + * @param code Code as string which should be executed + * @return + */ + virtual Error execute_file(const String &code); virtual void get_reserved_words(List *p_words) const override; virtual bool is_control_flow_keyword(String p_keywords) const override; diff --git a/clang_format.sh b/misc/formatting/clang_format.sh similarity index 100% rename from clang_format.sh rename to misc/formatting/clang_format.sh diff --git a/misc/generate/bindings.py b/misc/generate/bindings.py new file mode 100644 index 00000000..bb2e260e --- /dev/null +++ b/misc/generate/bindings.py @@ -0,0 +1,13 @@ +def get_bindings_header(): + return ( + '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "../javascript_binder.h"\nString JavaScriptBinder::{} = \n{};' + ) + + +def get_binding_files(): + return { + "misc/godot.binding_script.gen.cpp": ( + "BINDING_SCRIPT_CONTENT", + "misc/binding_script.js", + ), + } diff --git a/misc/generate/editor_tools.py b/misc/generate/editor_tools.py new file mode 100644 index 00000000..8b42e57f --- /dev/null +++ b/misc/generate/editor_tools.py @@ -0,0 +1,25 @@ +def get_editor_tools_header(): + return ( + '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};' + ) + + +def get_editor_tools_files(): + return { + "editor/godot.d.ts.gen.cpp": ( + "BUILTIN_DECLARATION_TEXT", + "misc/typescript/godot.d.ts", + ), + "editor/tsconfig.json.gen.cpp": ( + "TSCONFIG_CONTENT", + "misc/typescript/tsconfig.json", + ), + "editor/decorators.ts.gen.cpp": ( + "TS_DECORATORS_CONTENT", + "misc/typescript/decorators.ts", + ), + "editor/package.json.gen.cpp": ( + "PACKAGE_JSON_CONTENT", + "misc/typescript/package.json", + ), + } diff --git a/misc/generate/generate_files.py b/misc/generate/generate_files.py new file mode 100644 index 00000000..a6a58ebf --- /dev/null +++ b/misc/generate/generate_files.py @@ -0,0 +1,37 @@ +import platform, os + + +def get_path(javascript_dir, path): + return os.path.abspath(os.path.join(javascript_dir, path)) + + +def open_file(javascript_dir, path, mode): + file = get_path(javascript_dir, path) + if platform.python_version() > "3": + return open(file, mode, encoding="utf8") + else: + return open(file, mode) + + +def dump_text_file_to_cpp(javascript_dir, path): + source = open_file(javascript_dir, path, "r").read() + lines = source.split("\n") + source = "" + length = len(lines) + for i in range(length): + line = lines[i].replace('"', '\\"') + line = '\t"' + line + '\\n"' + if i < length - 1: + line += "\n" + source += line + return source + + +def generate(javascript_dir, header, tool_fns): + for fn, subs in tool_fns.items(): + with open_file(javascript_dir, fn, "w") as fh: + name = subs[0] + file = dump_text_file_to_cpp(javascript_dir, subs[1]) + fh.write(header.format(name, file)) + + diff --git a/misc/generate/test_manager.py b/misc/generate/test_manager.py new file mode 100644 index 00000000..78215830 --- /dev/null +++ b/misc/generate/test_manager.py @@ -0,0 +1,13 @@ +def get_test_manager_header(): + return ( + '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "test_manager.h"\nString TestManager::{} = \n{};' + ) + + +def get_test_files(): + return { + "src/tests/godot.unit_test.gen.cpp": ( + "UNIT_TEST", + "src/tests/UnitTest.js", + ), + } diff --git a/misc/decorators.ts b/misc/typescript/decorators.ts similarity index 100% rename from misc/decorators.ts rename to misc/typescript/decorators.ts diff --git a/misc/godot.d.ts b/misc/typescript/godot.d.ts similarity index 100% rename from misc/godot.d.ts rename to misc/typescript/godot.d.ts diff --git a/misc/package.json b/misc/typescript/package.json similarity index 100% rename from misc/package.json rename to misc/typescript/package.json diff --git a/misc/tsconfig.json b/misc/typescript/tsconfig.json similarity index 100% rename from misc/tsconfig.json rename to misc/typescript/tsconfig.json diff --git a/src/tests/UnitTest.js b/src/tests/UnitTest.js new file mode 100644 index 00000000..9634748e --- /dev/null +++ b/src/tests/UnitTest.js @@ -0,0 +1,99 @@ +// @ts-nocheck +/** + * All Tests + * @type {Map} + */ +const TEST_ENTRIES = new Map(); + +test("godot", () => typeof godot === "object", "core"); +test( + "new Object", + () => { + let obj = new godot.Object(); + let ok = obj && obj instanceof godot.Object; + obj.free(); + return ok; + }, + "core", +); + +test( + "new Resource", + () => { + let obj = new godot.Resource(); + let ok = obj && obj.get_class() === "Resource"; + return ok; + }, + "core", +); + +test( + "Object.prototype.get_class", + () => { + let obj = new godot.Object(); + let ok = obj.get_class() === "Object"; + obj.free(); + return ok; + }, + "core", +); + +test( + "Object.prototype.connect", + () => { + let ok = typeof godot.Object.prototype.connect === "function"; + if (!ok) return ok; + + let obj = new godot.Object(); + obj.connect("script_changed", (...args) => { + const [firstNumber, secondString] = args; + ok = firstNumber === 123 && secondString === "hello"; + }); + obj.emit_signal("script_changed", 123, "hello"); + obj.free(); + return ok; + }, + "core", +); + +// --------------------------- Unit Test Implementation ------------------------ + +/** + * Add test to runner + * @param title {string} + * @param block {function} + * @param group {string} + */ +function test(title, block, group = "default") { + const entries = TEST_ENTRIES.get(group) || []; + entries.push({ title, block }); + TEST_ENTRIES.set(group, entries); +} + +function run() { + let count = 0; + let passed = 0; + for (const [group, entries] of TEST_ENTRIES) { + console.log(`Start test ${group}`); + count += entries.length; + for (const { description, block } of entries) { + try { + const ok = block(); + if (ok) { + passed++; + } + } catch (e) { + console.error(description, e); + } + } + } + + const ok = passed === count; + const logFunc = ok ? console.log : console.warn; + logFunc(`Test complete: ${passed}/${count} passed`); + if (!ok) { + throw "JavaScript unit tests have failed"; + } +} + +run(); diff --git a/src/tests/test_manager.h b/src/tests/test_manager.h new file mode 100644 index 00000000..c220bfd4 --- /dev/null +++ b/src/tests/test_manager.h @@ -0,0 +1,13 @@ + +#ifndef TEST_MANAGER_H +#define TEST_MANAGER_H + +#include "../../../../core/string/ustring.h" + +class TestManager { +public: + /* Strings will be generated by ./SCsub */ + static String UNIT_TEST; +}; + +#endif // TEST_MANAGER_H \ No newline at end of file diff --git a/tests/UnitTest.js.disabled b/tests/UnitTest.js.disabled deleted file mode 100644 index 57773554..00000000 --- a/tests/UnitTest.js.disabled +++ /dev/null @@ -1,100 +0,0 @@ -// @ts-nocheck -const TEST_ENTRIES = new Map(); - - -test('godot', typeof godot === 'object', 'core'); -test('new Object', () => { - let obj = new godot.Object(); - let ok = obj && obj instanceof godot.Object; - obj.free(); - return ok; -}, 'core'); - -test('new Resource', () => { - let obj = new godot.Resource(); - let ok = obj && obj.get_class() === 'Resource'; - return ok; -}, 'core'); - -test('Object.prototype.get_class', () => { - let obj = new godot.Object(); - let ok = obj.get_class() === 'Object'; - obj.free(); - return ok; -}, 'core') - -test('Object.prototype.connect', () => { - let ok = typeof godot.Object.prototype.connect === 'function'; - if (!ok) return ok; - - let obj = new godot.Object(); - obj.connect('script_changed', (...args)=> { - console.log(`signal 'script_changed' emitted with:`, ...args); - ok = true; - }); - obj.emit_signal('script_changed', 123, 'hello'); - obj.free(); - return ok; -}, 'core') - - -// --------------------------- Unit Test Implementation ------------------------ -function test(description, block, group = 'default') { - const entries = TEST_ENTRIES.get(group) || []; - entries.push({ description, block }); - TEST_ENTRIES.set(group, entries); -} -function runEntry(entry) { - return new Promise((resolve, reject) => { - switch (typeof (entry.block)) { - case 'boolean': - return resolve(entry.block); - case 'function': { - try { - resolve(entry.block()); - } catch (error) { - console.error(error); - resolve(false); - } - } - break; - case 'object': - if (entry.block instanceof Promise) { - entry.block.then(() => { - resolve(true); - }).catch(err => { - resolve(false); - }); - } - break; - default: - return resolve(false); - } - }); -} -async function run() { - let count = 0; - let passed = 0; - for (const [group, entries] of TEST_ENTRIES) { - console.log(`Start test ${group}`); - count += entries.length; - let groupCount = 0; - for (let i = 0; i < entries.length; i++) { - const entry = entries[i]; - const ret = await runEntry(entry); - if (ret) { - passed++; - groupCount++; - console.log(`\t[${i + 1}/${entries.length}][ √ ] ${entry.description}`); - } - else { - console.error(`\t[${i + 1}/${entries.length}][ X ] ${entry.description}`); - } - } - const logFunc2 = groupCount == entries.length ? console.log : console.warn; - logFunc2(`\tTest ${group} finished: ${groupCount}/${entries.length} passed`); - } - const logFunc = passed == count ? console.log : console.warn; - logFunc(`Test complete: ${passed}/${count} passed`); -} -const _ = run(); // QuickJS BUG ? 返回的是一个 Promise 对象,不赋给临时变量,会导致 Promise 对象无法被 GC diff --git a/tests/test_javascript.h b/tests/test_javascript.h new file mode 100644 index 00000000..ebb43674 --- /dev/null +++ b/tests/test_javascript.h @@ -0,0 +1,21 @@ + +#ifndef TEST_JAVASCRIPT_H +#define TEST_JAVASCRIPT_H + +#include "../javascript_language.h" +#include "../src/tests/test_manager.h" + +#include "tests/test_macros.h" + +namespace JavaScriptTests { + +TEST_CASE("[JavaScript] Test all") { + JavaScriptLanguage::get_singleton()->init(); + String code = TestManager::UNIT_TEST; + Error err = JavaScriptLanguage::get_singleton()->execute_file(code); + CHECK(err == OK); +} + +} // namespace JavaScriptTests + +#endif // TEST_JAVASCRIPT_H diff --git a/thirdparty/quickjs/quickjs_binder.cpp b/thirdparty/quickjs/quickjs_binder.cpp index 8062be7c..7126ea81 100644 --- a/thirdparty/quickjs/quickjs_binder.cpp +++ b/thirdparty/quickjs/quickjs_binder.cpp @@ -233,12 +233,12 @@ JSValue QuickJSBinder::object_indexed_property(JSContext *ctx, JSValue this_val, Vector QuickJSBinder::get_function_args(JSContext *ctx, const JSValue p_val) { Vector args; if (JS_IsFunction(ctx, p_val)) { - const auto function = String(var_to_variant(ctx, p_val)); // Returns function as string - const auto start = function.find_char('(') + 1; - const auto end = function.find_char(')'); + const String function = String(var_to_variant(ctx, p_val)); // Returns function as string + const int start = function.find_char('(') + 1; + const int end = function.find_char(')'); const String argsAsString = function.substr(start, end - start); - const auto resolvedArgs = argsAsString.split(",", false); - for (const auto &resolved_arg : resolvedArgs) { + const Vector resolvedArgs = argsAsString.split(",", false); + for (const String &resolved_arg : resolvedArgs) { args.push_back(resolved_arg.strip_edges()); } } @@ -1272,7 +1272,7 @@ void QuickJSBinder::initialize() { // binding script String script_binding_error; JavaScriptGCHandler eval_ret; - if (OK == safe_eval_text(JavaScriptBinder::BINDING_SCRIPT_CONTENT, JavaScriptBinder::EVAL_TYPE_GLOBAL, "", script_binding_error, eval_ret)) { + if (OK == safe_eval_text(BINDING_SCRIPT_CONTENT, EVAL_TYPE_GLOBAL, "", script_binding_error, eval_ret)) { #ifdef TOOLS_ENABLED if (eval_ret.javascript_object) { JSValue ret = JS_MKPTR(JS_TAG_OBJECT, eval_ret.javascript_object); @@ -1888,8 +1888,8 @@ const JavaScriptClassInfo *QuickJSBinder::register_javascript_class(const JSValu MethodInfo mi; mi.name = method_name; - if (auto args = get_function_args(ctx, value); args.size() > 0) { - for (auto &arg : args) { + if (Vector args = get_function_args(ctx, value); args.size() > 0) { + for (String &arg : args) { // TODO: How do we resolve the type??? mi.arguments.push_back(PropertyInfo(Variant::NIL, arg)); }