Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
5fd05b6
Starting port to godot 4.0
Geequlim Aug 22, 2022
254fe19
Fix compile error for godot 4.0
Geequlim Aug 23, 2022
56016ee
Fix reference object constructor
Geequlim Aug 24, 2022
bb7a344
Improve RefCounted binding
Geequlim Aug 25, 2022
39421ba
Rename ECMAScript to JavaScript for godot 4
Geequlim Sep 2, 2022
98f6b3b
Fix compile error with non-editor build
Geequlim Sep 2, 2022
7c68bbe
Implement JavaScriptCallable for Signal & slot
Geequlim Sep 9, 2022
fbc40b6
Implement script workflow
Geequlim Sep 23, 2022
19b54c1
fix typo
Geequlim Sep 23, 2022
c21426e
[FIX] Failsafe env["TOOLS"] variable getter
why-try313 Feb 21, 2023
3314963
[FIX] Fixed missing comma
why-try313 Feb 21, 2023
1216d8d
[FIX] Adds GDNative to GDExtension migration changes
why-try313 Feb 21, 2023
9b16953
[FIX] Adds missing get_global_name method
why-try313 Feb 21, 2023
5cc9c4c
Merge pull request #148 from why-try313/gd4
Geequlim Mar 9, 2023
6bcd1fa
Updated JavaScript modules for Godot 4.0 branch
animanmaster Mar 15, 2023
2c325ea
Merge pull request #150 from V-Sekai/gd4
Geequlim Apr 23, 2023
783517a
Update README.md
ogrotten Oct 21, 2022
01457b9
Fix Godot 4.0 compile errors, update JavaScript integration, refactor…
fire Apr 23, 2023
398a108
Update generate_builtin_api.py, javascript.cpp, javascript.h, and 13 …
fire Jun 15, 2023
847fe10
Remove build_github_actions.py
fire Jun 15, 2023
caa8840
Update godot-javascript to better pass tests.
fire Jun 15, 2023
3f6a3b4
Remove pthread library and run format.
fire Jun 15, 2023
e547560
Format binding generator.
fire Jun 15, 2023
7655597
Apply formatting.
fire Jun 15, 2023
53f4051
Apply python formatting.
fire Jun 15, 2023
bcaa414
Add a condition to avoid building javascript on msvc.
fire Jun 15, 2023
e3e97ba
Disable unit tests.
fire Jun 15, 2023
4dad363
Remove c++ version check.
fire Jun 15, 2023
537e2b4
Avoid extras.
fire Jun 15, 2023
5261a4f
Only build windows and linux.
fire Jun 15, 2023
1c75361
Move versions back to 4.0.
fire Jun 18, 2023
9dabb22
Fix error in includes.
fire Jun 18, 2023
b87a29e
git subrepo pull (merge) modules/javascript
fire Jun 18, 2023
f430ed2
Handle cases that aren't supported.
fire Jun 18, 2023
f6687c5
git subrepo pull (merge) modules/javascript
fire Jun 18, 2023
245f8d0
Update scons.
fire Jun 18, 2023
166c796
Force a tag.
fire Jun 19, 2023
087e244
git subrepo pull (merge) modules/javascript
fire Jun 19, 2023
17caa75
Switch to match master.
fire Jun 19, 2023
23ba457
Update build scripts.
fire Jun 19, 2023
0919fc3
Add pthread for mingw.
fire Jun 19, 2023
78dbf97
If use mingw, use pthread.
fire Jun 19, 2023
eca30e6
Restore file format.
fire Jun 19, 2023
a91c1f4
Restore header guards too.
fire Jun 19, 2023
fdd5180
Fix include guards style.
fire Jun 19, 2023
8d976e4
Restore black format.
fire Jun 19, 2023
f4bc581
Restore all the scripts.
fire Jun 19, 2023
48305ba
Add python build.
fire Jun 19, 2023
01abd78
Remove python tests.
fire Jun 19, 2023
f648c5b
Disabled a few builds.
fire Jun 19, 2023
5b66370
feat: add icons
jaune Aug 19, 2023
2911768
Revert "Disabled a few builds."
fire Jun 19, 2023
d3ebf68
Update XML file paths for JavaScript and JavaScriptModule classes
fire Aug 20, 2023
007e94a
Refactor JavaScript bindings and fix file paths
fire Aug 20, 2023
dfbdf57
Format SCsub.
fire Aug 20, 2023
0fe880e
Update the readme.
fire Aug 20, 2023
1bb9edf
Format black_format.sh and SCsub scripts
fire Aug 20, 2023
0b9283b
Add XML schema for class documentation
fire Aug 20, 2023
5fd3ce9
Refactor static checks workflow
fire Aug 20, 2023
d5a9cf7
Refactor static checks workflow
fire Aug 20, 2023
6177b3e
Add .clang-format and .clang-tidy configuration files
fire Aug 24, 2023
94d95b5
Apply formatting.
fire Aug 24, 2023
76692da
Apply whitespace change.
fire Aug 24, 2023
3863950
Run spell checker.
fire Aug 24, 2023
ec74bb0
Refactor platform condition in config.py
fire Aug 24, 2023
5bf37c6
Remove JavaScript style checks
fire Aug 24, 2023
71c6704
Update JSValue typedef in quickjs.h to avoid error.
fire Aug 24, 2023
8d86711
Support MSVC builds without error in Github Actions.
fire Aug 24, 2023
221e358
Fix function name and use safer string formatting in JavaScript module
fire Aug 24, 2023
d487bcf
Format python files for automated tests.
fire Aug 24, 2023
b2cacc0
Fix gitub actions tests.
fire Aug 24, 2023
c2533ae
Fix tests.
fire Aug 24, 2023
60db283
Try to pass tests.
fire Aug 24, 2023
45ca44b
Exclude mono platform
fire Aug 24, 2023
483c70d
Apply xml docs fixes for tests.
fire Aug 24, 2023
ca34e79
Merge pull request #160 from jaune/gd4-icons
fire Aug 31, 2023
7160c86
Refactor JavaScript integration and improve code readability.
fire Oct 1, 2023
7fecf15
Merge pull request #164 from nmerget/fix-gd4-rebase-2
fire Oct 1, 2023
b23b482
Merge pull request #156 from Geequlim/gd4-rebase
fire Oct 1, 2023
dc296d9
Merge branch 'master' into 4.1
fire Oct 1, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor JavaScript integration and improve code readability.
We have refactored the JavaScript integration to make it more efficient. We have also improved the readability of the code by adding comments and restructuring the code blocks. This will make it easier for other developers to understand and contribute to the project.

Co-Authored-By: NicolasMerget <Nicolas.Merget@deutschebahn.com>
  • Loading branch information
fire and nmerget committed Oct 1, 2023
commit 7160c86266c584e2129e7bb71bb07ba396ec67f3
87 changes: 10 additions & 77 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!**
47 changes: 18 additions & 29 deletions SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand All @@ -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"),
),
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion doc_classes/JavaScript.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JavaScript" inherits="Script" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="JavaScript" inherits="Script" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A JavaScript script resource for creating and managing JavaScript scripts in Godot.
</brief_description>
Expand Down
2 changes: 1 addition & 1 deletion doc_classes/JavaScriptModule.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="JavaScriptModule" inherits="Resource" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<class name="JavaScriptModule" inherits="Resource" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A JavaScript module resource for managing JavaScript source code and bytecode.
</brief_description>
Expand Down
72 changes: 0 additions & 72 deletions editor/editor_tools.h

This file was deleted.

2 changes: 1 addition & 1 deletion javascript_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion misc/godot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions quickjs/quickjs_callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const QuickJSCallable *>(p_a);
Expand Down
6 changes: 3 additions & 3 deletions register_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions tests/UnitTest.js.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -39,28 +39,28 @@ 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);
}
}
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);
Expand Down
Loading