├── thirdparty └── quickjs │ ├── quickjs │ ├── VERSION.txt │ ├── libregexp-opcode.h │ ├── libregexp.h │ ├── list.h │ ├── quickjs-debugger.h │ ├── libunicode.h │ ├── quickjs-atom.h │ └── cutils.h │ ├── README.md │ ├── quickjs_worker.h │ ├── quickjs_callable.h │ ├── quickjs_debugger.h │ ├── quickjs_callable.cpp │ ├── quickjs_builtin_binder.h │ ├── quickjs_debugger.cpp │ └── quickjs_worker.cpp ├── docs └── JavaScript.svg.licence ├── .gitignore ├── src ├── language │ ├── javascript_todo_multithread.cpp │ ├── templates │ │ ├── javascript_template_manager.cpp │ │ └── javascript_template_manager.h │ ├── javascript_todo_doctools.cpp │ ├── javascript_todo_profiling.cpp │ ├── javascript_templates.cpp │ ├── javascript_instance_binding_callbacks.cpp │ ├── javascript_todo_debugger.cpp │ ├── README.md │ ├── javascript_language.cpp │ ├── javascript_language_definitions.cpp │ ├── javascript_todo_texteditor.cpp │ └── javascript_language.h └── tests │ ├── test_manager.h │ └── UnitTest.js ├── misc ├── template-contents │ ├── empty.js │ └── default.js ├── generate │ ├── test_manager.py │ ├── bindings.py │ ├── editor_tools.py │ ├── templates.py │ └── generate_files.py └── typescript │ ├── decorators.ts │ └── godot.d.ts ├── config.py ├── register_types.h ├── .github ├── PULL_REQUEST_TEMPLATE.md ├── workflows │ ├── get_version.yml │ ├── ios_builds.yml │ ├── web_builds.yml │ ├── android_builds.yml │ ├── release_builds.yml │ ├── windows_builds.yml │ ├── static_checks.yml │ ├── macos_builds.yml │ ├── runner.yml │ └── linux_builds.yml └── ISSUE_TEMPLATE │ └── bug_report.yml ├── editor ├── workarounds │ ├── ignore-methods.cpp │ ├── missing-enums.cpp │ └── missing-constructors.cpp └── editor_tools.h ├── javascript_callable.h ├── tests └── test_javascript.h ├── doc_classes ├── JavaScript.xml └── JavaScriptModule.xml ├── LICENSE ├── javascript_instance.h ├── clang_format.sh ├── CONTRIBUTING.md ├── icons ├── JavaScript.svg └── JavaScriptModule.svg ├── .clang-tidy ├── javascript_instance.cpp ├── README.md ├── register_types.cpp ├── SCsub ├── javascript_binder.h ├── javascript_gc_handler.h ├── javascript.h ├── .clang-format └── generate_builtin_api.py /thirdparty/quickjs/quickjs/VERSION.txt: -------------------------------------------------------------------------------- 1 | 2020-07-05 2 | -------------------------------------------------------------------------------- /docs/JavaScript.svg.licence: -------------------------------------------------------------------------------- 1 | ../icon/JavaScript.svg: https://commons.wikimedia.org/wiki/File:Unofficial_JavaScript_logo.svg 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.obj 3 | *.lib 4 | *.d 5 | *.pyc 6 | *.bc 7 | *.os 8 | *.gen.cpp 9 | *.gen.json 10 | .vscode 11 | .idea 12 | /site 13 | venv 14 | -------------------------------------------------------------------------------- /src/language/javascript_todo_multithread.cpp: -------------------------------------------------------------------------------- 1 | /* Instantiates multi-thread functions for godot editor */ 2 | 3 | #include "javascript_language.h" 4 | 5 | void JavaScriptLanguage::thread_enter() {} 6 | void JavaScriptLanguage::thread_exit() {} -------------------------------------------------------------------------------- /misc/template-contents/empty.js: -------------------------------------------------------------------------------- 1 | export default class CLASS extends GODOT_OBJECT_NAME.BASE { 2 | // Declare member variables here. Examples: 3 | a = 2; 4 | b = "text"; 5 | 6 | constructor() { 7 | super(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/tests/test_manager.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TEST_MANAGER_H 3 | #define TEST_MANAGER_H 4 | 5 | #include "../../../../core/string/ustring.h" 6 | 7 | class TestManager { 8 | public: 9 | /* Strings will be generated by ./SCsub */ 10 | static String UNIT_TEST; 11 | }; 12 | 13 | #endif // TEST_MANAGER_H -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | def can_build(env, platform): 2 | return True 3 | 4 | 5 | def configure(env): 6 | pass 7 | 8 | 9 | def get_doc_classes(): 10 | return [ 11 | "JavaScript", 12 | "JavaScriptModule", 13 | ] 14 | 15 | 16 | def get_doc_path(): 17 | return "doc_classes" 18 | -------------------------------------------------------------------------------- /register_types.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef REGISTER_TYPES_H 3 | #define REGISTER_TYPES_H 4 | 5 | #include "modules/register_module_types.h" 6 | void initialize_javascript_module(ModuleInitializationLevel p_level); 7 | void uninitialize_javascript_module(ModuleInitializationLevel p_level); 8 | 9 | #endif // REGISTER_TYPES_H 10 | -------------------------------------------------------------------------------- /misc/template-contents/default.js: -------------------------------------------------------------------------------- 1 | export default class CLASS extends GODOT_OBJECT_NAME.BASE { 2 | constructor() { 3 | super(); 4 | } 5 | 6 | // Called when the node enters the scene tree for the first time. 7 | _ready() {} 8 | 9 | // Called every frame. 'delta' is the elapsed time since the previous frame. 10 | _process(delta) {} 11 | } 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Description 2 | 3 | 4 | 5 | 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: 6 | 7 | - [ ] format C++: from the root, run `bash ./misc/formatting/clang_format.sh`. 8 | -------------------------------------------------------------------------------- /thirdparty/quickjs/README.md: -------------------------------------------------------------------------------- 1 | # Quickjs 2 | 3 | [QuickJS](https://bellard.org/quickjs/) isn't maintained at the moment 09-26-23. 4 | 5 | Therefore, we cannot use `git submodule` or something similar. 6 | The files in this directory are self-maintained to fix some issues about [MVSC](https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-170). 7 | 8 | -------------------------------------------------------------------------------- /src/language/templates/javascript_template_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "javascript_template_manager.h" 2 | 3 | Vector JavaScriptLanguageManager::get_templates() { 4 | Vector templates; 5 | templates.append(JavaScriptLanguageManager::DEFAULT_TEMPLATE); 6 | templates.append(JavaScriptLanguageManager::EMPTY_TEMPLATE); 7 | return templates; 8 | }; -------------------------------------------------------------------------------- /src/language/javascript_todo_doctools.cpp: -------------------------------------------------------------------------------- 1 | /* Instantiates profiling functions for godot editor */ 2 | 3 | #include "javascript_language.h" 4 | 5 | void JavaScriptLanguage::get_public_functions(List *p_functions) const {} 6 | void JavaScriptLanguage::get_public_constants(List> *p_constants) const {} 7 | void JavaScriptLanguage::get_public_annotations(List *p_annotations) const {}; -------------------------------------------------------------------------------- /misc/generate/test_manager.py: -------------------------------------------------------------------------------- 1 | def get_test_manager_header(): 2 | return ( 3 | '/* THIS FILE IS GENERATED DO NOT EDIT */\n' 4 | '#include "test_manager.h"\n' 5 | 'String TestManager::{} = \n' 6 | '{};' 7 | ) 8 | 9 | 10 | def get_test_files(): 11 | return { 12 | "src/tests/godot.unit_test.gen.cpp": ( 13 | "UNIT_TEST", 14 | "src/tests/UnitTest.js", 15 | ), 16 | } 17 | -------------------------------------------------------------------------------- /src/language/javascript_todo_profiling.cpp: -------------------------------------------------------------------------------- 1 | /* Instantiates profiling functions for godot editor */ 2 | #include "javascript_language.h" 3 | 4 | void JavaScriptLanguage::profiling_start() {} 5 | void JavaScriptLanguage::profiling_stop() {} 6 | 7 | int JavaScriptLanguage::profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) { return -1; } 8 | int JavaScriptLanguage::profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) { return -1; } 9 | -------------------------------------------------------------------------------- /editor/workarounds/ignore-methods.cpp: -------------------------------------------------------------------------------- 1 | /* All types are generated in editor_tools, but some getters and setters are obsolete we need to ignore them. */ 2 | 3 | #include "../editor_tools.h" 4 | 5 | Array create_ignore_methods() { 6 | Array array = Array(); 7 | array.push_back("get_flag"); 8 | array.push_back("set_flag"); 9 | array.push_back("set_play_area_mode"); 10 | return array; 11 | } 12 | 13 | Array JavaScriptPlugin::IGNORE_METHODS = create_ignore_methods(); 14 | -------------------------------------------------------------------------------- /misc/generate/bindings.py: -------------------------------------------------------------------------------- 1 | def get_bindings_header(): 2 | return ( 3 | '/* THIS FILE IS GENERATED DO NOT EDIT */\n' 4 | '#include "../javascript_binder.h"\n' 5 | 'String JavaScriptBinder::{} = \n' 6 | '{};' 7 | ) 8 | 9 | 10 | def get_binding_files(): 11 | return { 12 | "misc/godot.binding_script.gen.cpp": ( 13 | "BINDING_SCRIPT_CONTENT", 14 | "misc/binding_script.js", 15 | ), 16 | } 17 | -------------------------------------------------------------------------------- /misc/generate/editor_tools.py: -------------------------------------------------------------------------------- 1 | def get_editor_tools_header(): 2 | return ( 3 | '/* THIS FILE IS GENERATED DO NOT EDIT */\n' 4 | '#include "editor_tools.h"\n' 5 | 'String JavaScriptPlugin::{} = \n' 6 | '{};' 7 | ) 8 | 9 | 10 | def get_editor_tools_files(): 11 | return { 12 | "editor/godot.d.ts.gen.cpp": ( 13 | "BUILTIN_DECLARATION_TEXT", 14 | "misc/typescript/godot.d.ts", 15 | ) 16 | } 17 | -------------------------------------------------------------------------------- /src/language/templates/javascript_template_manager.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef JAVASCRIPT_TEMPLATE_MANAGER_H 3 | #define JAVASCRIPT_TEMPLATE_MANAGER_H 4 | 5 | #include "../javascript_language.h" 6 | 7 | class JavaScriptLanguageManager { 8 | public: 9 | static ScriptLanguage::ScriptTemplate DEFAULT_TEMPLATE; 10 | static ScriptLanguage::ScriptTemplate EMPTY_TEMPLATE; 11 | 12 | static Vector get_templates(); 13 | }; 14 | 15 | #endif //JAVASCRIPT_TEMPLATE_MANAGER_H 16 | -------------------------------------------------------------------------------- /editor/workarounds/missing-enums.cpp: -------------------------------------------------------------------------------- 1 | /* All types are generated in editor_tools, but some enums are missing we need to add them manually. */ 2 | 3 | #include "../editor_tools.h" 4 | 5 | Dictionary create_missing_enums() { 6 | Dictionary dict; 7 | dict["Vector3"] = "\t\tenum Axis {\n" 8 | "\t\t\tAXIS_X = 0,\n" 9 | "\t\t\tAXIS_Y = 1,\n" 10 | "\t\t\tAXIS_Z = 2,\n" 11 | "\t\t}\n"; 12 | return dict; 13 | } 14 | 15 | Dictionary JavaScriptPlugin::DECLARATION_ENUMS = create_missing_enums(); 16 | -------------------------------------------------------------------------------- /javascript_callable.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef JAVASCRIPT_CALLABLE_H 3 | #define JAVASCRIPT_CALLABLE_H 4 | 5 | #include "core/variant/callable.h" 6 | #include "javascript_gc_handler.h" 7 | 8 | class JavaScriptCallable : public CallableCustom { 9 | protected: 10 | JavaScriptGCHandler js_function; 11 | 12 | public: 13 | JavaScriptCallable() {} 14 | JavaScriptCallable(const JavaScriptGCHandler &p_function) : 15 | js_function(p_function) {} 16 | virtual ~JavaScriptCallable() {} 17 | }; 18 | 19 | #endif // JAVASCRIPT_CALLABLE_H 20 | -------------------------------------------------------------------------------- /tests/test_javascript.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TEST_JAVASCRIPT_H 3 | #define TEST_JAVASCRIPT_H 4 | 5 | #include "../src/language/javascript_language.h" 6 | #include "../src/tests/test_manager.h" 7 | 8 | #include "tests/test_macros.h" 9 | 10 | namespace JavaScriptTests { 11 | 12 | TEST_CASE("[JavaScript] Test all") { 13 | JavaScriptLanguage::get_singleton()->init(); 14 | const String code = TestManager::UNIT_TEST; 15 | Error err = JavaScriptLanguage::get_singleton()->execute_file(code); 16 | CHECK(err == OK); 17 | } 18 | 19 | } // namespace JavaScriptTests 20 | 21 | #endif // TEST_JAVASCRIPT_H 22 | -------------------------------------------------------------------------------- /doc_classes/JavaScript.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | A JavaScript script resource for creating and managing JavaScript scripts in Godot. 5 | 6 | 7 | The JavaScript class provides a way to create and manage JavaScript scripts within the Godot game engine. It inherits from the Script class and allows you to write game logic using JavaScript as the scripting language. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/language/javascript_templates.cpp: -------------------------------------------------------------------------------- 1 | /* Instantiates template functions for godot editor */ 2 | 3 | #include "javascript_language.h" 4 | #include "templates/javascript_template_manager.h" 5 | 6 | Ref