Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quickjspp v2 #45

Draft
wants to merge 52 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b029d16
qjs::shared_ptr
ftk Nov 27, 2021
8a4e7a8
qjs::shared_ptr test
ftk Nov 27, 2021
ffc7991
remove/break most of std::shared_ptr
ftk Nov 27, 2021
39c4030
Merge branch 'master' into sharedptr
ftk Nov 29, 2021
4900fe1
fix mark(WIP)
ftk Nov 29, 2021
34d58cd
restore construction
ftk Nov 29, 2021
35b18d6
replace the rest of std::shared_ptr
ftk Nov 29, 2021
60402bb
replace the rest of std::shared_ptr
ftk Nov 29, 2021
3f38a4b
restore inheritance
ftk Nov 30, 2021
45a8f96
update class example
ftk Nov 30, 2021
7040e79
enable_shared_from_this
ftk Nov 30, 2021
ab4b6d8
restore getter/setter
ftk Nov 30, 2021
2522501
Merge branch 'master' into sharedptr
ftk Dec 4, 2021
a965a1e
fix memory leak in Value::evalThis
ftk Dec 4, 2021
fa6c664
example of JS-overridden methods
ftk Dec 4, 2021
35005e3
minor cleanup
ftk Dec 4, 2021
0bafecb
catch exception in function:wrap
ftk Dec 4, 2021
6d15bf6
fix exception safety, memory leak in make_shared
ftk Dec 4, 2021
9eb2eb3
fix segfault in enable_shared_from_this
ftk Dec 4, 2021
bcda392
mark unimplemented traits as deleted
ftk Dec 5, 2021
0953d93
js_traits for T&
ftk Dec 5, 2021
9a1ca73
fix printf error in error handling
ftk Dec 13, 2021
e0cef4f
improve conversion test coverage
ftk Dec 13, 2021
68cbee1
detect gcc-8 in cmake
ftk Dec 17, 2021
b15e3f9
add support for downloading cross-compiled quickjs with cmake
ftk Dec 17, 2021
96fdd79
syntax error(?) fix
ftk Dec 17, 2021
47c9957
fix for MSVC
ftk Dec 17, 2021
43d0e6a
update CI
ftk Dec 17, 2021
71046d5
enable exception handling for MSVC
ftk Dec 17, 2021
1f56f4d
fix cmake compiler detection
ftk Dec 17, 2021
e2102e8
fix exceptions causing std::terminate during class registering
ftk Dec 18, 2021
91b5392
cmake CI install
ftk Dec 18, 2021
4f8deb8
comparison fix
ftk Dec 18, 2021
9f70ee8
update valgrind CI
ftk Dec 18, 2021
c62f91d
update quickjs dll CI
ftk Dec 18, 2021
cacdb63
add msvc patch
ftk Dec 18, 2021
7f76abd
Merge branch 'ci' into sharedptr
ftk Dec 18, 2021
ccf8074
fix MSVC compilation
ftk Dec 18, 2021
4572d24
add static assert for mark<>
ftk Dec 18, 2021
3ece2fb
Merge branch 'master' into sharedptr
ftk Feb 5, 2022
3742bf6
fix link in cmake, show message
ftk Apr 16, 2022
95db90d
msvc constexpr fix
ftk Apr 16, 2022
56278b2
add missing js_traits<T*>::wrap (#55)
ftk May 9, 2022
f0ed358
Merge branch 'master' into sharedptr
ftk Jul 3, 2022
5a36840
fix js inheritance example
ftk Jul 3, 2022
6f8d313
fix functions with arguments
ftk Jul 3, 2022
1ac22ad
example passing c++ objects to js code
ftk Jul 3, 2022
6965292
mark ESFT::shared_this in register_class instead of class_registrar
ftk Jul 21, 2022
8cfdb24
support for call and exotic methods
ftk Jul 21, 2022
5feb2b1
exotic class example
ftk Jul 21, 2022
592edbb
fix getclassid patch (JSValue->JSValueConst)
ftk Jul 21, 2022
7855b5a
add .static_fun to class_registrar for registering JS static properties
ftk Jul 22, 2022
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
41 changes: 32 additions & 9 deletions .github/workflows/cxx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
compiler: [linux-gcc,linux-clang,linux-gcc8,linux-gcc10,linux-gcc-ubsan,linux-gcc-asan,linux-gcc-32,linux-gcc-x32,linux-clang11,linux-clang12,macos-clang]
compiler: [ linux-gcc,linux-clang,linux-gcc8,linux-gcc10,linux-gcc-ubsan,linux-gcc-asan,linux-gcc-32,linux-gcc-x32,linux-clang11,linux-clang12,macos-clang,windows-msvc,windows-msvc-32,windows-clang,windows-clang-32 ]
build_type: [Debug]
include:
- compiler: linux-gcc
Expand All @@ -21,7 +21,7 @@ jobs:
- compiler: linux-gcc8
os: ubuntu-18.04
preconfigure: sudo apt-get update && sudo apt-get install -y gcc-8 g++-8
cmake_opts: -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_REQUIRED_LIBRARIES=stdc++fs
cmake_opts: -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8

- compiler: linux-gcc10
os: ubuntu-20.04
Expand Down Expand Up @@ -61,6 +61,20 @@ jobs:
- compiler: macos-clang
os: macos-latest

- compiler: windows-msvc
os: windows-latest

- compiler: windows-msvc-32
os: windows-latest
cmake_opts: -A Win32

- compiler: windows-clang
os: windows-latest
cmake_opts: -T ClangCL

- compiler: windows-clang-32
os: windows-latest
cmake_opts: -T ClangCL -A Win32
steps:
- uses: actions/checkout@v2
with:
Expand All @@ -70,15 +84,21 @@ jobs:
- name: configure
run: cmake -S . -B build_dir -Wdev -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_C_FLAGS="${{ matrix.cflags }}" -DCMAKE_CXX_FLAGS="${{ matrix.cflags }}" -DCMAKE_EXE_LINKER_FLAGS="${{ matrix.cflags }}" ${{ matrix.cmake_opts }}
- name: build
run: cmake --build build_dir --verbose
run: cmake --build build_dir --verbose --config ${{ matrix.build_type }}
- name: test
run: ctest --extra-verbose
run: ctest --extra-verbose --build-config ${{ matrix.build_type }}
working-directory: build_dir
env:
# extra options for address sanitizer
ASAN_OPTIONS: strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
- name: install
run: cmake --install build_dir --prefix install_prefix --config ${{ matrix.build_type }}
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.compiler }}
path: install_prefix

build_windows:
build_mingw:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -90,9 +110,6 @@ jobs:
os: windows-2019
cmake_opts: -G "Ninja" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++

# - compiler: windows-msvs # not supported
# os: windows-latest

defaults:
run:
shell: msys2 {0}
Expand All @@ -117,4 +134,10 @@ jobs:
working-directory: build_dir
env:
# extra options for address sanitizer
ASAN_OPTIONS: strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
ASAN_OPTIONS: strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1
- name: install
run: cmake --install build_dir --prefix install_prefix
- uses: actions/upload-artifact@v2
with:
name: ${{ matrix.compiler }}-${{ matrix.build_type }}
path: install_prefix
6 changes: 5 additions & 1 deletion .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: install
run: sudo apt-get update; sudo apt-get install -y valgrind
- name: configure
run: echo 'include(Dart)' >> CMakeLists.txt && cmake -S . -B build_dir -Wdev -DCMAKE_BUILD_TYPE=Debug -DMEMORYCHECK_COMMAND_OPTIONS="--leak-check=full --track-origins=yes --error-exitcode=1"
run: echo 'include(Dart)' >> CMakeLists.txt && cmake -S . -B build_dir -Wdev -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DMEMORYCHECK_COMMAND_OPTIONS="--leak-check=full --track-origins=yes --error-exitcode=1"
- name: build
run: cmake --build build_dir --verbose
- name: test
Expand Down
17 changes: 11 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ project(quickjspp LANGUAGES CXX)
#set(CMAKE_CXX_STANDARD 17)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)

if(CMAKE_COMPILER_IS_GNUCC)
add_compile_options(-Wall -Wno-unused-parameter)
endif()

add_subdirectory(quickjs)

add_library(quickjspp INTERFACE)
target_link_libraries(quickjspp INTERFACE quickjs ${CMAKE_REQUIRED_LIBRARIES})
target_compile_features(quickjspp INTERFACE cxx_std_17)
target_link_libraries(quickjspp INTERFACE quickjs)
target_compile_features(quickjspp INTERFACE cxx_std_20)
target_include_directories(quickjspp INTERFACE .)
set_target_properties(quickjspp PROPERTIES PUBLIC_HEADER quickjspp.hpp)

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(quickjspp INTERFACE -Wall -Wno-unused-parameter) # enable warnings
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
target_link_libraries(quickjspp INTERFACE stdc++fs) # required for gcc-8
endif()
elseif(MSVC)
add_compile_options(/EHsc) # enable exceptions
endif()

add_executable(qjs qjs.cpp)
target_link_libraries(qjs quickjspp)

Expand Down
74 changes: 54 additions & 20 deletions quickjs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,61 @@
project(quickjs LANGUAGES C)

file(STRINGS VERSION version)
if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(arch 64)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(arch 32)
endif()

set(quickjs_src quickjs.c libbf.c libunicode.c libregexp.c cutils.c quickjs-libc.c)
set(quickjs_def CONFIG_VERSION="${version}" _GNU_SOURCE CONFIG_BIGNUM)
message(VERBOSE "Compiling QuickJS with MSVC is not supported")
message(VERBOSE "However we can download QuickJS DLL that was cross-compiled with MinGW-w64 by GH-action")
message(VERBOSE "https://nightly.link/ftk/quickjspp/workflows/quickjsdll/master/")
message(VERBOSE "If you don't want to download DLLs from the internet, see .github/workflows/quickjsdll.yml for instructions on how to compile it yourself")

add_library(quickjs ${quickjs_src})
target_compile_definitions(quickjs PRIVATE ${quickjs_def} )
set_target_properties(quickjs PROPERTIES PUBLIC_HEADER "quickjs.h;quickjs-libc.h")
if(NOT EXISTS ${CMAKE_BINARY_DIR}/libquickjs${arch}.dll)
cmake_minimum_required(VERSION 3.18)
file(DOWNLOAD
"https://nightly.link/ftk/quickjspp/workflows/quickjsdll/ci/dlls%20-flto%20-O3%20-DNDEBUG.zip"
libquickjs.zip
TLS_VERIFY ON SHOW_PROGRESS)
file(ARCHIVE_EXTRACT INPUT libquickjs.zip DESTINATION ${CMAKE_BINARY_DIR})
endif()
add_library(quickjs SHARED IMPORTED GLOBAL)
add_library(quickjs-dumpleaks ALIAS quickjs)
set_target_properties(quickjs PROPERTIES
IMPORTED_LOCATION ${CMAKE_BINARY_DIR}/libquickjs${arch}.dll
IMPORTED_IMPLIB ${CMAKE_BINARY_DIR}/libquickjs${arch}.a
)
include(GNUInstallDirs)
install(FILES quickjs.h quickjs-libc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/quickjs)
install(FILES ${CMAKE_BINARY_DIR}/libquickjs32.dll ${CMAKE_BINARY_DIR}/libquickjs64.dll
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_BINARY_DIR}/libquickjs32.a ${CMAKE_BINARY_DIR}/libquickjs64.a
DESTINATION ${CMAKE_INSTALL_LIBDIR}/quickjs)
else(MSVC)
# compile quickjs
file(STRINGS VERSION version)
set(quickjs_src quickjs.c libbf.c libunicode.c libregexp.c cutils.c quickjs-libc.c)
set(quickjs_def CONFIG_VERSION="${version}" _GNU_SOURCE CONFIG_BIGNUM)

add_library(quickjs-dumpleaks ${quickjs_src})
target_compile_definitions(quickjs-dumpleaks PRIVATE ${quickjs_def} DUMP_LEAKS=1)
add_library(quickjs ${quickjs_src})
target_compile_definitions(quickjs PRIVATE ${quickjs_def})
set_target_properties(quickjs PROPERTIES PUBLIC_HEADER "quickjs.h;quickjs-libc.h")

if(UNIX OR MINGW)
find_package(Threads)
target_link_libraries(quickjs ${CMAKE_DL_LIBS} m Threads::Threads)
target_link_libraries(quickjs-dumpleaks ${CMAKE_DL_LIBS} m Threads::Threads)
endif()
add_library(quickjs-dumpleaks ${quickjs_src})
target_compile_definitions(quickjs-dumpleaks PRIVATE ${quickjs_def} DUMP_LEAKS=1)

# install
include(GNUInstallDirs)
install(TARGETS quickjs
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/quickjs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/quickjs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/quickjs
)
if(UNIX OR MINGW)
find_package(Threads)
target_link_libraries(quickjs ${CMAKE_DL_LIBS} m Threads::Threads)
target_link_libraries(quickjs-dumpleaks ${CMAKE_DL_LIBS} m Threads::Threads)
endif()

# install
include(GNUInstallDirs)
install(TARGETS quickjs
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/quickjs
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/quickjs
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/quickjs
)
endif(MSVC)
2 changes: 1 addition & 1 deletion quickjs/patches/getclassid.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ index 48aeffc62..8afc4caa1 100644
#endif
}
+
+JSClassID JS_GetClassID(JSValue v)
+JSClassID JS_GetClassID(JSValueConst v)
+{
+ JSObject *p;
+
Expand Down
25 changes: 25 additions & 0 deletions quickjs/patches/msvc-header-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git a/quickjs/quickjs.h b/quickjs/quickjs.h
--- a/quickjs/quickjs.h (revision 96fdd7947760bed361be7ea1c749f41c4a3ab62e)
+++ b/quickjs/quickjs.h (revision 47c9957e9b830cfcde70aebf6005a26f45ec0bbe)
@@ -215,12 +215,18 @@
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)

+#ifdef __cplusplus
+#define JS_MKVAL(tag, val) JSValue{ JSValueUnion{ .int32 = val }, tag }
+#define JS_MKPTR(tag, p) JSValue{ JSValueUnion{ .ptr = p }, tag }
+#define JS_NAN JSValue{ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
+#else
#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)
-
#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
+#endif
+
+#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)
+

static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
{
2 changes: 1 addition & 1 deletion quickjs/quickjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -54083,7 +54083,7 @@ void JS_AddIntrinsicTypedArrays(JSContext *ctx)
#endif
}

JSClassID JS_GetClassID(JSValue v)
JSClassID JS_GetClassID(JSValueConst v)
{
JSObject *p;

Expand Down
8 changes: 7 additions & 1 deletion quickjs/quickjs.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,18 @@ typedef struct JSValue {
#define JS_VALUE_GET_FLOAT64(v) ((v).u.float64)
#define JS_VALUE_GET_PTR(v) ((v).u.ptr)

#ifdef __cplusplus
#define JS_MKVAL(tag, val) JSValue{ JSValueUnion{ .int32 = val }, tag }
#define JS_MKPTR(tag, p) JSValue{ JSValueUnion{ .ptr = p }, tag }
#define JS_NAN JSValue{ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
#else
#define JS_MKVAL(tag, val) (JSValue){ (JSValueUnion){ .int32 = val }, tag }
#define JS_MKPTR(tag, p) (JSValue){ (JSValueUnion){ .ptr = p }, tag }
#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }
#endif

#define JS_TAG_IS_FLOAT64(tag) ((unsigned)(tag) == JS_TAG_FLOAT64)

#define JS_NAN (JSValue){ .u.float64 = JS_FLOAT64_NAN, JS_TAG_FLOAT64 }

static inline JSValue __JS_NewFloat64(JSContext *ctx, double d)
{
Expand Down
Loading