diff --git a/.github/workflows/linux_builds.yml b/.github/workflows/linux_builds.yml index b1ee98cc..d180139c 100644 --- a/.github/workflows/linux_builds.yml +++ b/.github/workflows/linux_builds.yml @@ -33,46 +33,11 @@ jobs: proj-conv: true artifact: true - - name: Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold) - cache-name: linux-editor-double-sanitizers - target: editor - tests: true - # Debug symbols disabled as they're huge on this build and we hit the 14 GB limit for runners. - sconsflags: dev_build=yes debug_symbols=no precision=double use_asan=yes use_ubsan=yes linker=gold - proj-test: true - # Can be turned off for PRs that intentionally break compat with godot-cpp, - # until both the upstream PR and the matching godot-cpp changes are merged. - godot-cpp-test: true - bin: "./bin/godot.linuxbsd.editor.dev.double.x86_64.san" - build-mono: false - # Skip 2GiB artifact speeding up action. - artifact: false - - - name: Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld) - cache-name: linux-editor-llvm-sanitizers - target: editor - tests: true - sconsflags: dev_build=yes use_asan=yes use_ubsan=yes use_llvm=yes linker=lld - bin: "./bin/godot.linuxbsd.editor.dev.x86_64.llvm.san" - build-mono: false - # Skip 2GiB artifact speeding up action. - artifact: false - - - name: Template w/ Mono (target=template_release) - cache-name: linux-template-mono - target: template_release - tests: false - sconsflags: module_mono_enabled=yes - build-mono: false - artifact: true - - - name: Minimal template (target=template_release, everything disabled) - cache-name: linux-template-minimal - target: template_release - tests: false - sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no minizip=no - artifact: true - + - name: Minimal template (target=template_release, everything disabled) + cache-name: linux-template-minimal + target: template_release + tests: false + sconsflags: modules_enabled_by_default=no disable_3d=yes disable_advanced_gui=yes deprecated=no steps: - name: Checkout Godot uses: actions/checkout@v2 @@ -185,40 +150,8 @@ jobs: xvfb-run ${{ matrix.bin }} 40 --audio-driver Dummy --path test_project 2>&1 | tee sanitizers_log.txt || true misc/scripts/check_ci_log.py sanitizers_log.txt - # Checkout godot-cpp - - name: Checkout godot-cpp - if: ${{ matrix.godot-cpp-test }} - uses: actions/checkout@v3 - with: - repository: godotengine/godot-cpp - ref: ${{ env.GODOT_BASE_BRANCH }} - submodules: 'recursive' - path: 'godot-cpp' - - # Dump GDExtension interface and API - - name: Dump GDExtension interface and API for godot-cpp build - if: ${{ matrix.godot-cpp-test }} - run: | - ${{ matrix.bin }} --headless --dump-gdextension-interface --dump-extension-api - cp -f gdextension_interface.h godot-cpp/gdextension/ - cp -f extension_api.json godot-cpp/gdextension/ - - # Build godot-cpp test extension - - name: Build godot-cpp test extension - if: ${{ matrix.godot-cpp-test }} - run: | - cd godot-cpp/test - scons target=template_debug dev_build=yes - cd ../.. - - - name: Prepare artifact - if: ${{ matrix.artifact }} - run: | - strip bin/godot.* - chmod +x bin/godot.* - - - name: Upload artifact - uses: ./.github/actions/upload-artifact - if: ${{ matrix.artifact }} - with: - name: ${{ matrix.cache-name }} + - name: Upload artifact + uses: ./.github/actions/upload-artifact + if: ${{ matrix.artifact }} + with: + name: ${{ matrix.cache-name }} diff --git a/README.md b/README.md index a57f7b4d..0261ca5d 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,10 @@ You can try demos in the [ECMAScriptDemos](https://github.com/Geequlim/ECMAScrip ## Developer notes - This package is not compatible with MSVC, you will get build errors in quickjs. +- To update the github actions scripts we have the file `build_github_actions.py`. This script will copy the actions from the godot repo (usually at `../../`) and modify them to fix the requirements of quickjs and this repo. + \*\* If you are updating this repo's compatibility, you should run that script (a brief description is at the top of the script) and it will re-create the actions `.yml` files for you. - The script also build the `on_tag.yml` script which automates the github release publishing. \*\* The `on_tag.yml` functionality tries to sleep until all jobs with the same `sha` are completed. It should be fine to run whenever, but depending on how github actions culls long running jobs you might want to make sure that all/(most of) the builds look good before tagging. +- Linux ubsan asan build woes: +- The godot repo has ubsan and asan builds that we can't build from. Currently we skip them (get removed via the `build_github_actions.py` script). - They should definitely be fixed & enabled at some point, **so please submit a PR if you have any ideas of how to do that!** diff --git a/SCsub b/SCsub index bf47ffe5..1efe9a28 100644 --- a/SCsub +++ b/SCsub @@ -7,10 +7,6 @@ env_module = env_modules.Clone() JS_ENGINE = "quickjs" TOOLS = "editor" == env_module["target"] -if env["platform"] == "windows": - if env["use_mingw"]: - env.Append(LIBS=["pthread"]) - def open_file(path, mode): if platform.python_version() > "3": @@ -41,27 +37,20 @@ if JS_ENGINE == "quickjs": 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.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'}) - quickjs_env.Append(CPPDEFINES=["CONFIG_BIGNUM"]) - if "release" not in (quickjs_env["target"] or ""): - quickjs_env.Append(CPPDEFINES={"DUMP_LEAKS": 1}) - if not env.msvc: - env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1}) - quickjs_env.Append(CPPPATH=["thirdparty/quickjs/quickjs"]) - quickjs_env.Append(CPPPATH=["thirdparty/quickjs"]) - quickjs_env.disable_warnings() - quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs_builtin_binder.gen.cpp") - quickjs_env.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp") - - env_thirdparty = quickjs_env.Clone() - if env.msvc: - env_thirdparty.AppendUnique(CCFLAGS=["/TC"]) - - # TODO: find a better way to remove /std:c++17 - del env_thirdparty["CCFLAGS"][0] - env_thirdparty.Prepend(CCFLAGS=["/std:c11"]) - env_thirdparty.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs/*.c") + env_module.Append(CPPDEFINES={"QUICKJS_CONFIG_VERSION": '"' + version + '"'}) + env_module.Append(CPPDEFINES=["CONFIG_BIGNUM"]) + if "release" not in (env_module["target"] or ""): + env_module.Append(CPPDEFINES={"DUMP_LEAKS": 1}) + env_module.Append(CPPDEFINES={"QUICKJS_WITH_DEBUGGER": 1}) + env_module.Append(CPPPATH=["thirdparty/quickjs/quickjs"]) + env_module.Append(CPPPATH=["thirdparty/quickjs"]) + + if TOOLS: + env_module.add_source_files(env.modules_sources, "tools/editor_tools.cpp") + env_module.add_source_files(env.modules_sources, "thirdparty/quickjs/quickjs_builtin_binder.gen.cpp") + env_module.add_source_files(env.modules_sources, "thirdparty/quickjs/*.cpp") + env_module.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: @@ -81,19 +70,19 @@ if TOOLS: '/* THIS FILE IS GENERATED DO NOT EDIT */\n#include "editor_tools.h"\nString JavaScriptPlugin::{} = \n{};' ) tool_fns = { - "editor/godot.d.ts.gen.cpp": ( + "tools/godot.d.ts.gen.cpp": ( "BUILTIN_DECLARATION_TEXT", dump_text_file_to_cpp("misc/godot.d.ts"), ), - "editor/tsconfig.json.gen.cpp": ( + "tools/tsconfig.json.gen.cpp": ( "TSCONFIG_CONTENT", dump_text_file_to_cpp("misc/tsconfig.json"), ), - "editor/decorators.ts.gen.cpp": ( + "tools/decorators.ts.gen.cpp": ( "TS_DECORATORS_CONTENT", dump_text_file_to_cpp("misc/decorators.ts"), ), - "editor/package.json.gen.cpp": ( + "tools/package.json.gen.cpp": ( "PACKAGE_JSON_CONTENT", dump_text_file_to_cpp("misc/package.json"), ), diff --git a/config.py b/config.py index 8e323971..951e814f 100644 --- a/config.py +++ b/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return not platform == "android" and not platform == "mono" + return not (platform == "windows" and not env["use_mingw"]) def configure(env): diff --git a/doc_classes/JavaScript.xml b/doc_classes/JavaScript.xml index 88bc9a12..ca3f4659 100644 --- a/doc_classes/JavaScript.xml +++ b/doc_classes/JavaScript.xml @@ -1,5 +1,5 @@ - + A JavaScript script resource for creating and managing JavaScript scripts in Godot. diff --git a/doc_classes/JavaScriptModule.xml b/doc_classes/JavaScriptModule.xml index 878c6d1b..c9f1c7f9 100644 --- a/doc_classes/JavaScriptModule.xml +++ b/doc_classes/JavaScriptModule.xml @@ -1,5 +1,5 @@ - + A JavaScript module resource for managing JavaScript source code and bytecode. diff --git a/editor/editor_tools.h b/editor/editor_tools.h deleted file mode 100644 index 6b38fcc8..00000000 --- a/editor/editor_tools.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************/ -/* editor_tools.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef EDITOR_TOOLS_H -#define EDITOR_TOOLS_H - -#include "editor/editor_node.h" -#include "editor/editor_plugin.h" -#include "editor/gui/editor_file_dialog.h" - -class DocTools; -class EditorFileDialog; -class JavaScriptPlugin : public EditorPlugin { - GDCLASS(JavaScriptPlugin, EditorPlugin); - - enum MenuItem { - ITEM_GEN_DECLARE_FILE, - ITEM_GEN_TYPESCRIPT_PROJECT, - ITEM_GEN_ENUM_BINDING_SCRIPT, - }; - - EditorFileDialog *declaration_file_dialog; - EditorFileDialog *enumberation_file_dialog; - const Dictionary *modified_api; - -protected: - static String BUILTIN_DECLARATION_TEXT; - static String TSCONFIG_CONTENT; - static String TS_DECORATORS_CONTENT; - static String PACKAGE_JSON_CONTENT; - - static void _bind_methods(); - - void _notification(int p_what); - void _on_menu_item_pressed(int item); - void _export_typescript_declare_file(const String &p_path); - void _export_enumeration_binding_file(const String &p_path); - void _generate_typescript_project(); - -public: - virtual String get_name() const override { return "JavaScriptPlugin"; } - JavaScriptPlugin(EditorNode *p_node); -}; - -#endif // EDITOR_TOOLS_H diff --git a/javascript_language.cpp b/javascript_language.cpp index 382f7740..ae69e781 100644 --- a/javascript_language.cpp +++ b/javascript_language.cpp @@ -33,7 +33,7 @@ #include "core/object/class_db.h" #include "javascript_binder.h" -#include "thirdparty/quickjs/quickjs_binder.h" +#include "quickjs_binder.h" JavaScriptLanguage *JavaScriptLanguage::singleton = nullptr; diff --git a/misc/godot.d.ts b/misc/godot.d.ts index 5066a2b1..e4d3f8a2 100644 --- a/misc/godot.d.ts +++ b/misc/godot.d.ts @@ -56,7 +56,7 @@ declare module globalThis { * * Workers run in another global context that is different from the current context. * - * You can run whatever code you like inside the worker thread. All of the godot API are available inside workers. + * You can run whatever code you like inside the worker thread. All of the godot API are avaliable inside workers. * * Data is sent between workers and the main thread via a system of messages — both sides send their messages using the `postMessage()` method, and respond to messages via the `onmessage` event handler (the message is contained within the Message event's data attribute.) The data is copied rather than shared. * diff --git a/quickjs/quickjs_callable.cpp b/quickjs/quickjs_callable.cpp index 037fd5b2..9e7e59a1 100644 --- a/quickjs/quickjs_callable.cpp +++ b/quickjs/quickjs_callable.cpp @@ -32,6 +32,7 @@ #include "../../quickjs_binder.h" #include "../javascript_language.h" #include "quickjs/quickjs.h" +#include "../../quickjs_binder.h" bool QuickJSCallable::compare_equal(const CallableCustom *p_a, const CallableCustom *p_b) { const QuickJSCallable *a = static_cast(p_a); diff --git a/register_types.h b/register_types.h index 885dc929..18785d49 100644 --- a/register_types.h +++ b/register_types.h @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#ifndef REGISTER_TYPES_H -#define REGISTER_TYPES_H +#ifndef JAVASCRIPT_REGISTER_TYPES_H +#define JAVASCRIPT_REGISTER_TYPES_H #include "modules/register_module_types.h" void initialize_javascript_module(ModuleInitializationLevel p_level); void uninitialize_javascript_module(ModuleInitializationLevel p_level); -#endif // REGISTER_TYPES_H +#endif // JAVASCRIPT_REGISTER_TYPES_H diff --git a/tests/UnitTest.js.disabled b/tests/UnitTest.js.disabled index 57773554..c9699d38 100644 --- a/tests/UnitTest.js.disabled +++ b/tests/UnitTest.js.disabled @@ -29,7 +29,7 @@ test('Object.prototype.connect', () => { let obj = new godot.Object(); obj.connect('script_changed', (...args)=> { - console.log(`signal 'script_changed' emitted with:`, ...args); + console.log(`signal 'script_changed' emited with:`, ...args); ok = true; }); obj.emit_signal('script_changed', 123, 'hello'); @@ -39,19 +39,19 @@ test('Object.prototype.connect', () => { // --------------------------- Unit Test Implementation ------------------------ -function test(description, block, group = 'default') { +function test(description, blcok, group = 'default') { const entries = TEST_ENTRIES.get(group) || []; - entries.push({ description, block }); + entries.push({ description, blcok }); TEST_ENTRIES.set(group, entries); } function runEntry(entry) { return new Promise((resolve, reject) => { - switch (typeof (entry.block)) { + switch (typeof (entry.blcok)) { case 'boolean': - return resolve(entry.block); + return resolve(entry.blcok); case 'function': { try { - resolve(entry.block()); + resolve(entry.blcok()); } catch (error) { console.error(error); resolve(false); @@ -59,8 +59,8 @@ function runEntry(entry) { } break; case 'object': - if (entry.block instanceof Promise) { - entry.block.then(() => { + if (entry.blcok instanceof Promise) { + entry.blcok.then(() => { resolve(true); }).catch(err => { resolve(false); diff --git a/thirdparty/quickjs/quickjs/cutils.h b/thirdparty/quickjs/quickjs/cutils.h index b0c7a262..09be07a9 100644 --- a/thirdparty/quickjs/quickjs/cutils.h +++ b/thirdparty/quickjs/quickjs/cutils.h @@ -31,7 +31,7 @@ /* set if CPU is big endian */ #undef WORDS_BIGENDIAN -#if (defined(_MSC_VER) || !defined(__MINGW32__)) && !defined(LINUX_ENABLED) && !defined(MACOS_ENABLED) +#if defined(_MSC_VER) || !defined(__MINGW32__) #define likely(x) (x) #define unlikely(x) (x) #define force_inline __forceinline @@ -119,53 +119,6 @@ static inline int64_t min_int64(int64_t a, int64_t b) return b; } - - -#ifdef _MSC_VER -#include - -static inline int __builtin_ctz(unsigned x) -{ - return (int)_tzcnt_u32(x); -} - -static inline int __builtin_ctzll(unsigned long long x) -{ -#ifdef _WIN64 - return (int)_tzcnt_u64(x); -#else - return !!unsigned(x) ? __builtin_ctz((unsigned)x) : 32 + __builtin_ctz((unsigned)(x >> 32)); -#endif -} - -static inline int __builtin_ctzl(unsigned long x) -{ - return sizeof(x) == 8 ? __builtin_ctzll(x) : __builtin_ctz((unsigned)x); -} - -static inline int __builtin_clz(unsigned x) -{ - return (int)_lzcnt_u32(x); -} - -static inline int __builtin_clzll(unsigned long long x) -{ -#ifdef _WIN64 - return (int)_lzcnt_u64(x); -#else - return !!unsigned(x >> 32) ? __builtin_clz((unsigned)(x >> 32)) : 32 + __builtin_clz((unsigned)x); -#endif -} - -static inline int __builtin_clzl(unsigned long x) -{ - return sizeof(x) == 8 ? __builtin_clzll(x) : __builtin_clz((unsigned)x); -} -#endif - - - - /* WARNING: undefined if a = 0 */ static inline int clz32(unsigned int a) { diff --git a/thirdparty/quickjs/quickjs/quickjs-debugger.c b/thirdparty/quickjs/quickjs/quickjs-debugger.c index 6bffc4bc..f7557064 100644 --- a/thirdparty/quickjs/quickjs/quickjs-debugger.c +++ b/thirdparty/quickjs/quickjs/quickjs-debugger.c @@ -36,14 +36,12 @@ static int js_transport_write_fully(JSDebuggerInfo *info, const char *buffer, si return 1; } -#define JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH 10 - static int js_transport_write_message_newline(JSDebuggerInfo *info, const char* value, size_t len) { // length prefix is 8 hex followed by newline = 012345678\n // not efficient, but protocol is then human readable. - char message_length[JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH]; + char message_length[10]; message_length[9] = '\0'; - snprintf(message_length, JS_TRANSPORT_WRITE_MESSAGE_NEWLINE_MESSAGE_LENGTH, "%08x\n", (int)len + 1); + sprintf(message_length, "%08x\n", (int)len + 1); if (!js_transport_write_fully(info, message_length, 9)) return 0; int ret = js_transport_write_fully(info, value, len); @@ -146,7 +144,7 @@ static void js_debugger_get_variable_type(JSContext *ctx, JSObject *p = JS_VALUE_GET_OBJ(var_val); // todo: xor the the two dwords to get a better hash? - uintptr_t pl = (uintptr_t)p; + uint32_t pl = (uint32_t)p; JSValue found = JS_GetPropertyUint32(ctx, state->variable_pointers, pl); if (JS_IsUndefined(found)) { reference = state->variable_reference_count++; diff --git a/thirdparty/quickjs/quickjs/quickjs.c b/thirdparty/quickjs/quickjs/quickjs.c index 9a4a55ef..99b6be9e 100644 --- a/thirdparty/quickjs/quickjs/quickjs.c +++ b/thirdparty/quickjs/quickjs/quickjs.c @@ -28,13 +28,7 @@ #include #include #include -#include -#if defined(_WIN32) -// import struct timeval -#include -#else #include -#endif #include #include #include @@ -57,7 +51,7 @@ #define OPTIMIZE 1 #define SHORT_OPCODES 1 -#if defined(EMSCRIPTEN) || defined(_MSC_VER) +#if defined(EMSCRIPTEN) #define DIRECT_DISPATCH 0 #else #define DIRECT_DISPATCH 1 @@ -76,7 +70,7 @@ /* define to include Atomics.* operations which depend on the OS threads */ -#if !(defined(EMSCRIPTEN) || defined(_MSC_VER)) +#if !defined(EMSCRIPTEN) #define CONFIG_ATOMICS #endif @@ -211,11 +205,7 @@ typedef enum JSErrorEnum { #define JS_STACK_SIZE_MAX 65536 #define JS_STRING_LEN_MAX ((1 << 30) - 1) -#if defined(_MSC_VER) -#define __exception -#else #define __exception __attribute__((warn_unused_result)) -#endif typedef struct JSShape JSShape; typedef struct JSString JSString; @@ -1023,9 +1013,7 @@ static __exception int JS_ToArrayLengthFree(JSContext *ctx, uint32_t *plen, JSValue val); static JSValue JS_EvalObject(JSContext *ctx, JSValueConst this_obj, JSValueConst val, int flags, int scope_idx); - -JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...); - +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...); static __maybe_unused void JS_DumpAtoms(JSRuntime *rt); static __maybe_unused void JS_DumpString(JSRuntime *rt, const JSString *p); @@ -6193,7 +6181,7 @@ void JS_DumpMemoryUsage(FILE *fp, const JSMemoryUsage *s, JSRuntime *rt) "BigNum " #endif "2020-09-06" " version, %d-bit, malloc limit: %"PRId64"\n\n", - (int)sizeof(void *) * 8, s->malloc_limit); + (int)sizeof(void *) * 8, (int64_t)(ssize_t)s->malloc_limit); #if 1 if (rt) { static const struct { @@ -6605,7 +6593,7 @@ static JSValue JS_ThrowError(JSContext *ctx, JSErrorEnum error_num, return JS_ThrowError2(ctx, error_num, fmt, ap, add_backtrace); } -JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...) +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowSyntaxError(JSContext *ctx, const char *fmt, ...) { JSValue val; va_list ap; @@ -6616,7 +6604,7 @@ JSValue __js_printf_like(2, 3) JS_ThrowSyntaxError(JSContext *ctx, const char *f return val; } -JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...) +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowTypeError(JSContext *ctx, const char *fmt, ...) { JSValue val; va_list ap; @@ -6627,7 +6615,7 @@ JSValue __js_printf_like(2, 3) JS_ThrowTypeError(JSContext *ctx, const char *fmt return val; } -static int __js_printf_like(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int flags, const char *fmt, ...) +static int __attribute__((format(printf, 3, 4))) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int flags, const char *fmt, ...) { va_list ap; @@ -6643,7 +6631,7 @@ static int __js_printf_like(3, 4) JS_ThrowTypeErrorOrFalse(JSContext *ctx, int f } /* never use it directly */ -static JSValue __js_printf_like(3, 4) __JS_ThrowTypeErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...) +static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowTypeErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...) { char buf[ATOM_GET_STR_BUF_SIZE]; return JS_ThrowTypeError(ctx, fmt, @@ -6651,7 +6639,7 @@ static JSValue __js_printf_like(3, 4) __JS_ThrowTypeErrorAtom(JSContext *ctx, JS } /* never use it directly */ -static JSValue __js_printf_like(3, 4) __JS_ThrowSyntaxErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...) +static JSValue __attribute__((format(printf, 3, 4))) __JS_ThrowSyntaxErrorAtom(JSContext *ctx, JSAtom atom, const char *fmt, ...) { char buf[ATOM_GET_STR_BUF_SIZE]; return JS_ThrowSyntaxError(ctx, fmt, @@ -6674,7 +6662,7 @@ static int JS_ThrowTypeErrorReadOnly(JSContext *ctx, int flags, JSAtom atom) } } -JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...) +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowReferenceError(JSContext *ctx, const char *fmt, ...) { JSValue val; va_list ap; @@ -6685,7 +6673,7 @@ JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, const char return val; } -JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...) +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...) { JSValue val; va_list ap; @@ -6696,7 +6684,7 @@ JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fm return val; } -JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...) +JSValue __attribute__((format(printf, 2, 3))) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...) { JSValue val; va_list ap; @@ -7221,7 +7209,7 @@ static int JS_DefinePrivateField(JSContext *ctx, JSValueConst obj, JS_ThrowTypeErrorNotASymbol(ctx); goto fail; } - prop = js_symbol_to_atom(ctx, name); + prop = js_symbol_to_atom(ctx, (JSValue)name); p = JS_VALUE_GET_OBJ(obj); prs = find_own_property(&pr, p, prop); if (prs) { @@ -7252,7 +7240,7 @@ static JSValue JS_GetPrivateField(JSContext *ctx, JSValueConst obj, /* safety check */ if (unlikely(JS_VALUE_GET_TAG(name) != JS_TAG_SYMBOL)) return JS_ThrowTypeErrorNotASymbol(ctx); - prop = js_symbol_to_atom(ctx, name); + prop = js_symbol_to_atom(ctx, (JSValue)name); p = JS_VALUE_GET_OBJ(obj); prs = find_own_property(&pr, p, prop); if (!prs) { @@ -7279,7 +7267,7 @@ static int JS_SetPrivateField(JSContext *ctx, JSValueConst obj, JS_ThrowTypeErrorNotASymbol(ctx); goto fail; } - prop = js_symbol_to_atom(ctx, name); + prop = js_symbol_to_atom(ctx, (JSValue)name); p = JS_VALUE_GET_OBJ(obj); prs = find_own_property(&pr, p, prop); if (!prs) { @@ -7369,7 +7357,7 @@ static int JS_CheckBrand(JSContext *ctx, JSValueConst obj, JSValueConst func) if (unlikely(JS_VALUE_GET_TAG(obj) != JS_TAG_OBJECT)) goto not_obj; p = JS_VALUE_GET_OBJ(obj); - prs = find_own_property(&pr, p, js_symbol_to_atom(ctx, brand)); + prs = find_own_property(&pr, p, js_symbol_to_atom(ctx, (JSValue)brand)); if (!prs) { JS_ThrowTypeError(ctx, "invalid brand on object"); return -1; @@ -10204,7 +10192,7 @@ static JSValue js_atof(JSContext *ctx, const char *str, const char **pp, } else #endif { - double d = HUGE_VAL; + double d = 1.0 / 0.0; if (is_neg) d = -d; val = JS_NewFloat64(ctx, d); @@ -15959,7 +15947,7 @@ static JSValue js_call_c_function(JSContext *ctx, JSValueConst func_obj, #else sf->js_mode = 0; #endif - sf->cur_func = func_obj; + sf->cur_func = (JSValue)func_obj; sf->arg_count = argc; arg_buf = argv; @@ -16223,7 +16211,7 @@ static JSValue JS_CallInternal(JSContext *caller_ctx, JSValueConst func_obj, sf->js_mode = b->js_mode; arg_buf = argv; sf->arg_count = argc; - sf->cur_func = func_obj; + sf->cur_func = (JSValue)func_obj; init_list_head(&sf->var_ref_list); var_refs = p->u.func.var_refs; @@ -20188,7 +20176,7 @@ static void free_token(JSParseState *s, JSToken *token) } } -static void __js_unused dump_token(JSParseState *s, +static void __attribute((unused)) dump_token(JSParseState *s, const JSToken *token) { switch(token->val) { @@ -20249,7 +20237,7 @@ static void __js_unused dump_token(JSParseState *s, } } -int __js_printf_like(2, 3) js_parse_error(JSParseState *s, const char *fmt, ...) +int __attribute__((format(printf, 2, 3))) js_parse_error(JSParseState *s, const char *fmt, ...) { JSContext *ctx = s->ctx; va_list ap; @@ -34517,7 +34505,7 @@ typedef struct BCReaderState { } BCReaderState; #ifdef DUMP_READ_OBJECT -static void __js_printf_like(2, 3) bc_read_trace(BCReaderState *s, const char *fmt, ...) { +static void __attribute__((format(printf, 2, 3))) bc_read_trace(BCReaderState *s, const char *fmt, ...) { va_list ap; int i, n, n0; @@ -38897,8 +38885,8 @@ static int64_t JS_FlattenIntoArray(JSContext *ctx, JSValueConst target, if (!JS_IsUndefined(mapperFunction)) { JSValueConst args[3] = { element, JS_NewInt64(ctx, sourceIndex), source }; element = JS_Call(ctx, mapperFunction, thisArg, 3, args); - JS_FreeValue(ctx, args[0]); - JS_FreeValue(ctx, args[1]); + JS_FreeValue(ctx, (JSValue)args[0]); + JS_FreeValue(ctx, (JSValue)args[1]); if (JS_IsException(element)) return -1; } @@ -40356,7 +40344,7 @@ static JSValue js_string_match(JSContext *ctx, JSValueConst this_val, str = JS_NewString(ctx, "g"); if (JS_IsException(str)) goto fail; - args[args_len++] = str; + args[args_len++] = (JSValueConst)str; } rx = JS_CallConstructor(ctx, ctx->regexp_ctor, args_len, args); JS_FreeValue(ctx, str); @@ -41412,7 +41400,7 @@ static JSValue js_math_min_max(JSContext *ctx, JSValueConst this_val, uint32_t tag; if (unlikely(argc == 0)) { - return __JS_NewFloat64(ctx, is_max ? DBL_MAX : HUGE_VAL); + return __JS_NewFloat64(ctx, is_max ? -1.0 / 0.0 : 1.0 / 0.0); } tag = JS_VALUE_GET_TAG(argv[0]); @@ -41652,30 +41640,6 @@ static JSValue js___date_now(JSContext *ctx, JSValueConst this_val, } #endif -#if defined(_MSC_VER) -int gettimeofday(struct timeval * tp, struct timezone * tzp) -{ - // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's - // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) - // until 00:00:00 January 1, 1970 - static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); - - SYSTEMTIME system_time; - FILETIME file_time; - uint64_t time; - - GetSystemTime( &system_time ); - SystemTimeToFileTime( &system_time, &file_time ); - time = ((uint64_t)file_time.dwLowDateTime ) ; - time += ((uint64_t)file_time.dwHighDateTime) << 32; - - tp->tv_sec = (long) ((time - EPOCH) / 10000000L); - tp->tv_usec = (long) (system_time.wMilliseconds * 1000); - return 0; -} -#endif - - /* OS dependent: return the UTC time in microseconds since 1970. */ static JSValue js___date_clock(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) @@ -45401,7 +45365,7 @@ static JSMapRecord *map_add_record(JSContext *ctx, JSMapState *s, } else { JS_DupValue(ctx, key); } - mr->key = key; + mr->key = (JSValue)key; h = map_hash_key(ctx, key) & (s->hash_size - 1); list_add_tail(&mr->hash_link, &s->hash_table[h]); list_add_tail(&mr->link, &s->records); @@ -45623,7 +45587,7 @@ static JSValue js_map_forEach(JSContext *ctx, JSValueConst this_val, args[0] = args[1]; else args[0] = JS_DupValue(ctx, mr->value); - args[2] = this_val; + args[2] = (JSValue)this_val; ret = JS_Call(ctx, func, this_arg, 3, (JSValueConst *)args); JS_FreeValue(ctx, args[0]); if (!magic) @@ -46601,7 +46565,7 @@ static JSValue js_promise_all(JSContext *ctx, JSValueConst this_val, goto fail_reject; } resolve_element_data[0] = JS_NewBool(ctx, FALSE); - resolve_element_data[1] = JS_NewInt32(ctx, index); + resolve_element_data[1] = (JSValueConst)JS_NewInt32(ctx, index); resolve_element_data[2] = values; resolve_element_data[3] = resolving_funcs[is_promise_any]; resolve_element_data[4] = resolve_element_env; @@ -46971,7 +46935,7 @@ static JSValue js_async_from_sync_iterator_unwrap_func_create(JSContext *ctx, { JSValueConst func_data[1]; - func_data[0] = JS_NewBool(ctx, done); + func_data[0] = (JSValueConst)JS_NewBool(ctx, done); return JS_NewCFunctionData(ctx, js_async_from_sync_iterator_unwrap, 1, 0, 1, func_data); } @@ -47276,7 +47240,7 @@ static int isURIReserved(int c) { return c < 0x100 && memchr(";/?:@&=+$,#", c, sizeof(";/?:@&=+$,#") - 1) != NULL; } -static int __js_printf_like(2, 3) js_throw_URIError(JSContext *ctx, const char *fmt, ...) +static int __attribute__((format(printf, 2, 3))) js_throw_URIError(JSContext *ctx, const char *fmt, ...) { va_list ap; @@ -52322,8 +52286,8 @@ static int js_TA_cmp_generic(const void *a, const void *b, void *opaque) { psc->exception = 1; } done: - JS_FreeValue(ctx, argv[0]); - JS_FreeValue(ctx, argv[1]); + JS_FreeValue(ctx, (JSValue)argv[0]); + JS_FreeValue(ctx, (JSValue)argv[1]); } return cmp; } diff --git a/thirdparty/quickjs/quickjs/quickjs.h b/thirdparty/quickjs/quickjs/quickjs.h index c77e3a1c..6d130152 100644 --- a/thirdparty/quickjs/quickjs/quickjs.h +++ b/thirdparty/quickjs/quickjs/quickjs.h @@ -43,13 +43,11 @@ extern "C" { #define js_unlikely(x) __builtin_expect(!!(x), 0) #define js_force_inline inline __attribute__((always_inline)) #define __js_printf_like(f, a) __attribute__((format(printf, f, a))) -#define __js_unused __attribute((unused)) #else #define js_likely(x) (x) #define js_unlikely(x) (x) #define js_force_inline INLINE_FUNC #define __js_printf_like(a, b) -#define __js_unused #endif #define JS_BOOL int @@ -137,7 +135,7 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v) #elif defined(JS_NAN_BOXING) -// typedef uint64_t JSValue; +typedef uint64_t JSValue; #define JSValueConst JSValue @@ -223,26 +221,8 @@ typedef struct JSValue { #define JS_VALUE_GET_FLOAT64(v) ((v).u.float64) #define JS_VALUE_GET_PTR(v) ((v).u.ptr) -JSValue INLINE_FUNC _JS_MKVAL_INT32(int64_t tag, int32_t val) { - JSValue v; - - v.u.int32 = val; - v.tag = tag; - - return v; -} - -JSValue INLINE_FUNC _JS_MKPTR(int64_t tag, void* ptr) { - JSValue v; - - v.u.ptr = ptr; - v.tag = tag; - - return v; -} - -#define JS_MKVAL(tag, val) _JS_MKVAL_INT32(tag, val) -#define JS_MKPTR(tag, p) _JS_MKPTR(tag, p) +#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag } +#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag } #define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64) @@ -688,7 +668,7 @@ static inline JSValue JS_DupValue(JSContext *ctx, JSValueConst v) JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); p->ref_count++; } - return v; + return (JSValue)v; } static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v) @@ -697,7 +677,7 @@ static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValueConst v) JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); p->ref_count++; } - return v; + return (JSValue)v; } int JS_ToBool(JSContext *ctx, JSValueConst val); /* return -1 for JS_EXCEPTION */ diff --git a/thirdparty/quickjs/quickjs_binder.cpp b/thirdparty/quickjs/quickjs_binder.cpp index 977bd858..518b7632 100644 --- a/thirdparty/quickjs/quickjs_binder.cpp +++ b/thirdparty/quickjs/quickjs_binder.cpp @@ -11,8 +11,9 @@ #include "editor/editor_settings.h" #endif -#include "../../javascript_instance.h" -#include "../../javascript_language.h" +#include "javascript.h" +#include "javascript_instance.h" +#include "javascript_language.h" #include "quickjs_binder.h" #include "quickjs_callable.h" #include "quickjs_worker.h" @@ -686,7 +687,7 @@ JSModuleDef *QuickJSBinder::js_module_loader(JSContext *ctx, const char *module_ module.hash = hash_var.hash(); module.module = m; module.res = res; - module.res->reference(); // Avoid auto release as module don't release automatically + module.res->reference(); // Avoid auto release as module don't release automaticly module.res_value = val; module.flags = MODULE_FLAG_RESOURCE; module.module = m; @@ -1100,7 +1101,7 @@ void QuickJSBinder::add_godot_globals() { const int value = CoreConstants::get_global_constant_value(i); JSAtom js_const_name = JS_NewAtom(ctx, const_name); - JS_DefinePropertyValue(ctx, godot_object, js_const_name, JS_NewInt64(ctx, value), QuickJSBinder::PROP_DEF_DEFAULT); + JS_DefinePropertyValue(ctx, godot_object, js_const_name, JS_MKVAL(JS_TAG_INT, value), QuickJSBinder::PROP_DEF_DEFAULT); JS_FreeAtom(ctx, js_const_name); if (HashMap *consts = global_constants.getptr(enum_name)) { @@ -1280,7 +1281,7 @@ void QuickJSBinder::initialize() { if (List::Element *E = args.find("--js-debugger-connect")) { if (E->next() && E->next()->get().find(":") != -1) { String address = E->next()->get(); - Error err = debugger->connect_debugger(ctx, address); + Error err = debugger->connect(ctx, address); if (err != OK) { ERR_PRINT(vformat("Failed to connect to JavaScript debugger at %s", address)); } @@ -1485,9 +1486,7 @@ Error QuickJSBinder::safe_eval_text(const String &p_source, EvalType type, const } JSValue ret = JS_Eval(ctx, code, utf8_str.length(), filename, flags); r_ret.context = ctx; - if (JS_VALUE_GET_TAG(ret) == JS_TAG_OBJECT) { - r_ret.javascript_object = JS_VALUE_GET_PTR(ret); - } + r_ret.javascript_object = JS_VALUE_GET_PTR(ret); if (JS_IsException(ret)) { JSValue e = JS_GetException(ctx); JavaScriptError err; diff --git a/thirdparty/quickjs/quickjs_binder.h b/thirdparty/quickjs/quickjs_binder.h index 831e960c..1d003dd1 100644 --- a/thirdparty/quickjs/quickjs_binder.h +++ b/thirdparty/quickjs/quickjs_binder.h @@ -80,7 +80,7 @@ class QuickJSBinder : public JavaScriptBinder { enum { __JS_ATOM_NULL = JS_ATOM_NULL, -#if !(defined(EMSCRIPTEN) || defined(_MSC_VER)) +#if !defined(EMSCRIPTEN) #define CONFIG_ATOMICS #endif #define DEF(name, str) JS_ATOM_##name, diff --git a/thirdparty/quickjs/quickjs_builtin_binder.cpp b/thirdparty/quickjs/quickjs_builtin_binder.cpp index d06e65e7..34aa19d8 100644 --- a/thirdparty/quickjs/quickjs_builtin_binder.cpp +++ b/thirdparty/quickjs/quickjs_builtin_binder.cpp @@ -5,6 +5,7 @@ #include +#include "javascript_binder.h" #include "quickjs_binder.h" #include "quickjs_builtin_binder.h" diff --git a/thirdparty/quickjs/quickjs_callable.cpp b/thirdparty/quickjs/quickjs_callable.cpp index 99f7b825..07336d54 100644 --- a/thirdparty/quickjs/quickjs_callable.cpp +++ b/thirdparty/quickjs/quickjs_callable.cpp @@ -1,8 +1,9 @@ #include "quickjs_callable.h" +#include "javascript_language.h" #include "quickjs/quickjs.h" + #include "quickjs_binder.h" #include "quickjs_builtin_binder.h" -#include "../../javascript_language.h" bool QuickJSCallable::compare_equal(const CallableCustom *p_a, const CallableCustom *p_b) { const QuickJSCallable *a = static_cast(p_a); diff --git a/thirdparty/quickjs/quickjs_callable.h b/thirdparty/quickjs/quickjs_callable.h index 7b2b2d55..48050cd2 100644 --- a/thirdparty/quickjs/quickjs_callable.h +++ b/thirdparty/quickjs/quickjs_callable.h @@ -1,9 +1,6 @@ #ifndef QUICKJS_CALLABLE_H #define QUICKJS_CALLABLE_H - -#include "core/variant/callable.h" -#include "../../javascript_callable.h" - +#include "javascript_callable.h" #include "quickjs/quickjs.h" #if !defined(JS_NAN_BOXING) diff --git a/thirdparty/quickjs/quickjs_debugger.cpp b/thirdparty/quickjs/quickjs_debugger.cpp index 366a31c6..36a54765 100644 --- a/thirdparty/quickjs/quickjs_debugger.cpp +++ b/thirdparty/quickjs/quickjs_debugger.cpp @@ -79,7 +79,7 @@ Error QuickJSDebugger::attach_js_debugger(JSContext *ctx, Ref p_p return ERR_CANT_CONNECT; } -Error QuickJSDebugger::connect_debugger(JSContext *ctx, const String &address) { +Error QuickJSDebugger::connect(JSContext *ctx, const String &address) { this->ctx = ctx; this->runtime = JS_GetRuntime(ctx);