Skip to content

Commit

Permalink
Merge branch 'master' into prototype-inline-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
yang.zhao2 committed Jan 16, 2025
2 parents 7826ad8 + a7914d1 commit 3639c24
Show file tree
Hide file tree
Showing 39 changed files with 4,047 additions and 5,022 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ jobs:
git submodule update --init --checkout --depth 1
time make test262
- name: test standalone
run: |
./build/qjs -c examples/hello.js -o hello
./hello
windows-msvc:
runs-on: windows-latest
strategy:
Expand All @@ -184,6 +189,10 @@ jobs:
build\${{matrix.buildType}}\qjs.exe examples\test_point.js
build\${{matrix.buildType}}\run-test262.exe -c tests.conf
build\${{matrix.buildType}}\function_source.exe
- name: test standalone
run: |
build\${{matrix.buildType}}\qjs.exe -c examples\hello.js -o hello.exe
.\hello.exe
- name: Set up Visual Studio shell
uses: egor-tensin/vs-shell@v2
with:
Expand Down Expand Up @@ -351,6 +360,10 @@ jobs:
- name: test
run: |
make test
- name: test standalone
run: |
./build/qjs -c examples/hello.js -o hello.exe
./hello
windows-mingw-shared:
runs-on: windows-latest
defaults:
Expand Down Expand Up @@ -385,7 +398,7 @@ jobs:
run: emcc -v
- name: build
run: |
emcmake cmake -B build
emcmake cmake -B build -DBUILD_QJS_LIBC=ON
emmake make -C build qjs_wasm -j$(getconf _NPROCESSORS_ONLN)
- name: result
run: ls -lh build
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.arch == 'x86' && 'mingw32' || 'mingw64' }}
msystem: ${{ matrix.arch == 'x86' && 'mingw32' || 'ucrt64' }}
install: >-
git
make
Expand All @@ -90,6 +90,7 @@ jobs:
mv build/qjsc.exe build/qjsc-windows-${{matrix.arch}}.exe
- name: check
run: |
file build/qjs-windows-${{matrix.arch}}.exe
ldd build/qjs-windows-${{matrix.arch}}.exe build/qjsc-windows-${{matrix.arch}}.exe
- name: upload
uses: actions/upload-artifact@v4
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
.obj/
build/
unicode/
test262_*.txt
.idea
cmake-*
.vs
out/
CMakeUserPresets.json
fuzz
.vscode/
15 changes: 6 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ endif()

if(CONFIG_UBSAN)
message(STATUS "Building with UBSan")
# __has_feature(undefined_sanitizer) or __SANITIZE_UNDEFINED__ don't exist
add_compile_definitions(
__UBSAN__=1
)
add_compile_options(
-fsanitize=undefined
-fno-sanitize-recover=all
Expand Down Expand Up @@ -212,7 +208,10 @@ find_package(Threads)
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
list(APPEND qjs_libs ${CMAKE_THREAD_LIBS_INIT})
endif()
if(NOT MSVC)

# try to find libm
find_library(M_LIBRARIES m)
if(M_LIBRARIES OR CMAKE_C_COMPILER_ID STREQUAL "TinyCC")
list(APPEND qjs_libs m)
endif()

Expand Down Expand Up @@ -259,6 +258,7 @@ target_link_libraries(qjsc qjs)

add_executable(qjs_exe
gen/repl.c
gen/standalone.c
qjs.c
)
add_qjs_libc_if_needed(qjs_exe)
Expand Down Expand Up @@ -370,10 +370,6 @@ if(BUILD_EXAMPLES)
target_link_libraries(test_fib qjs)
endif()

add_executable(test_conv
tests/test_conv.c
)

# Install target
#

Expand All @@ -392,6 +388,7 @@ if(NOT IOS)
install(FILES quickjs-libc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
install(TARGETS qjs_exe RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS qjsc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS qjs EXPORT qjsConfig
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# QuickJS Javascript Engine
#
#
# Copyright (c) 2017-2021 Fabrice Bellard
# Copyright (c) 2017-2021 Charlie Gordon
# Copyright (c) 2023 Ben Noordhuis
Expand All @@ -26,6 +26,7 @@

BUILD_DIR=build
BUILD_TYPE?=Release
INSTALL_PREFIX?=/usr/local

QJS=$(BUILD_DIR)/qjs
QJSC=$(BUILD_DIR)/qjsc
Expand All @@ -49,26 +50,23 @@ fuzz:
./fuzz

$(BUILD_DIR):
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)

$(QJS): $(BUILD_DIR)
cmake --build $(BUILD_DIR) -j $(JOBS)

$(QJSC): $(BUILD_DIR)
cmake --build $(BUILD_DIR) --target qjsc -j $(JOBS)

$(BUILD_DIR)/test_conv: $(BUILD_DIR) tests/test_conv.c
cmake --build $(BUILD_DIR) --target test_conv

install: $(QJS) $(QJSC)
cmake --build $(BUILD_DIR) --target install

clean:
@rm -f v8.txt[1-9]*
cmake --build $(BUILD_DIR) --target clean

codegen: $(QJSC)
$(QJSC) -ss -o gen/repl.c -m repl.js
$(QJSC) -ss -o gen/standalone.c -m standalone.js
$(QJSC) -e -o gen/function_source.c tests/function_source.js
$(QJSC) -e -o gen/hello.c examples/hello.js
$(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js
Expand Down Expand Up @@ -98,9 +96,6 @@ cxxtest: cxxtest.cc quickjs.h
test: $(QJS)
$(RUN262) -c tests.conf

testconv: $(BUILD_DIR)/test_conv
$(BUILD_DIR)/test_conv

test262: $(QJS)
$(RUN262) -m -c test262.conf -a

Expand Down
24 changes: 15 additions & 9 deletions cutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#pragma GCC visibility push(default)
#endif

void pstrcpy(char *buf, int buf_size, const char *str)
void js__pstrcpy(char *buf, int buf_size, const char *str)
{
int c;
char *q = buf;
Expand All @@ -59,16 +59,16 @@ void pstrcpy(char *buf, int buf_size, const char *str)
}

/* strcat and truncate. */
char *pstrcat(char *buf, int buf_size, const char *s)
char *js__pstrcat(char *buf, int buf_size, const char *s)
{
int len;
len = strlen(buf);
if (len < buf_size)
pstrcpy(buf + len, buf_size - len, s);
js__pstrcpy(buf + len, buf_size - len, s);
return buf;
}

int strstart(const char *str, const char *val, const char **ptr)
int js__strstart(const char *str, const char *val, const char **ptr)
{
const char *p, *q;
p = str;
Expand All @@ -84,7 +84,7 @@ int strstart(const char *str, const char *val, const char **ptr)
return 1;
}

int has_suffix(const char *str, const char *suffix)
int js__has_suffix(const char *str, const char *suffix)
{
size_t len = strlen(str);
size_t slen = strlen(suffix);
Expand Down Expand Up @@ -125,7 +125,7 @@ int dbuf_realloc(DynBuf *s, size_t new_size)
new_size = size;
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
if (!new_buf) {
s->error = TRUE;
s->error = true;
return -1;
}
s->buf = new_buf;
Expand Down Expand Up @@ -590,7 +590,13 @@ size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_
*/

/* 2 <= base <= 36 */
char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
char const digits36[36] = {
'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z'
};


#define USE_SPECIAL_RADIX_10 1 // special case base 10 radix conversions
#define USE_SINGLE_CASE_FAST 1 // special case single digit numbers
Expand Down Expand Up @@ -1203,12 +1209,12 @@ typedef struct {
js__once_cb callback;
} js__once_data_t;

static BOOL WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
static int WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
js__once_data_t *data = param;

data->callback();

return TRUE;
return 1;
}

void js_once(js_once_t *guard, js__once_cb callback) {
Expand Down
42 changes: 11 additions & 31 deletions cutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#ifndef CUTILS_H
#define CUTILS_H

#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
Expand Down Expand Up @@ -54,14 +55,6 @@ extern "C" {
#include <pthread.h>
#endif

#if defined(__SANITIZE_ADDRESS__)
# define __ASAN__ 1
#elif defined(__has_feature)
# if __has_feature(address_sanitizer)
# define __ASAN__ 1
# endif
#endif

#if defined(_MSC_VER) && !defined(__clang__)
# define likely(x) (x)
# define unlikely(x) (x)
Expand All @@ -70,10 +63,6 @@ extern "C" {
# define __maybe_unused
# define __attribute__(x)
# define __attribute(x)
# include <intrin.h>
static void *__builtin_frame_address(unsigned int level) {
return (void *)((char*)_AddressOfReturnAddress() - sizeof(int *) - level * sizeof(int *));
}
#else
# define likely(x) __builtin_expect(!!(x), 1)
# define unlikely(x) __builtin_expect(!!(x), 0)
Expand Down Expand Up @@ -124,19 +113,10 @@ static void *__builtin_frame_address(unsigned int level) {
#define minimum_length(n) static n
#endif

typedef int BOOL;

#ifndef FALSE
enum {
FALSE = 0,
TRUE = 1,
};
#endif

void pstrcpy(char *buf, int buf_size, const char *str);
char *pstrcat(char *buf, int buf_size, const char *s);
int strstart(const char *str, const char *val, const char **ptr);
int has_suffix(const char *str, const char *suffix);
void js__pstrcpy(char *buf, int buf_size, const char *str);
char *js__pstrcat(char *buf, int buf_size, const char *s);
int js__strstart(const char *str, const char *val, const char **ptr);
int js__has_suffix(const char *str, const char *suffix);

static inline uint8_t is_be(void) {
union {
Expand Down Expand Up @@ -440,7 +420,7 @@ typedef struct DynBuf {
uint8_t *buf;
size_t size;
size_t allocated_size;
BOOL error; /* true if a memory allocation error occurred */
bool error; /* true if a memory allocation error occurred */
DynBufReallocFunc *realloc_func;
void *opaque; /* for realloc_func */
} DynBuf;
Expand Down Expand Up @@ -468,12 +448,12 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
FORMAT_STRING(const char *fmt), ...);
void dbuf_free(DynBuf *s);
static inline BOOL dbuf_error(DynBuf *s) {
static inline bool dbuf_error(DynBuf *s) {
return s->error;
}
static inline void dbuf_set_error(DynBuf *s)
{
s->error = TRUE;
s->error = true;
}

/*---- UTF-8 and UTF-16 handling ----*/
Expand All @@ -497,17 +477,17 @@ size_t utf8_decode_buf16(uint16_t *dest, size_t dest_len, const char *src, size_
size_t utf8_encode_buf8(char *dest, size_t dest_len, const uint8_t *src, size_t src_len);
size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_t src_len);

static inline BOOL is_surrogate(uint32_t c)
static inline bool is_surrogate(uint32_t c)
{
return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
}

static inline BOOL is_hi_surrogate(uint32_t c)
static inline bool is_hi_surrogate(uint32_t c)
{
return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
}

static inline BOOL is_lo_surrogate(uint32_t c)
static inline bool is_lo_surrogate(uint32_t c)
{
return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
}
Expand Down
4 changes: 2 additions & 2 deletions dirent_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ dirent_next(
} else if (dirp->handle != INVALID_HANDLE_VALUE) {

/* Get the next directory entry from stream */
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
if (FindNextFileW (dirp->handle, &dirp->data) != 0) {
/* Got a file */
p = &dirp->data;
} else {
Expand Down Expand Up @@ -1163,4 +1163,4 @@ dirent_set_errno(
#ifdef __cplusplus
}
#endif
#endif /*DIRENT_H*/
#endif /*DIRENT_H*/
Loading

0 comments on commit 3639c24

Please sign in to comment.