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

[WIP]: Feat: add BigInt support #440

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
endif()

list(APPEND QUICK_JS_SOURCE
# third_party/quickjs/src/libbf.c
third_party/quickjs/src/libbf.c
third_party/quickjs/src/cutils.c
third_party/quickjs/src/libregexp.c
third_party/quickjs/src/libunicode.c
Expand Down Expand Up @@ -211,7 +211,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
if(WIN32)
target_link_libraries(quickjs pthreadVC2)
target_include_directories(quickjs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third_party/quickjs/compat/win32/atomic)
target_compile_definitions(quickjs PUBLIC HAVE_STRUCT_TIMESPEC=1 _HAS_EXCEPTIONS=1)
target_compile_definitions(quickjs PUBLIC HAVE_STRUCT_TIMESPEC=1 _HAS_EXCEPTIONS=1 -DCONFIG_BIGNUM=1)
else()
target_link_libraries(quickjs Threads::Threads)
endif()
Expand Down Expand Up @@ -552,7 +552,7 @@ if ($ENV{WEBF_JS_ENGINE} MATCHES "quickjs")
# https://stackoverflow.com/questions/14735010/how-do-you-get-gccs-builtin-frame-address-to-work-with-o2
add_compile_options(-fno-optimize-sibling-calls -fno-omit-frame-pointer)
endif()
target_compile_options(quickjs PUBLIC -DCONFIG_VERSION=${\"QUICKJS_VERSION\"})
target_compile_options(quickjs PUBLIC -DCONFIG_VERSION=${\"QUICKJS_VERSION\"} -DCONFIG_BIGNUM=1)

endif ()

Expand Down
42 changes: 42 additions & 0 deletions bridge/bindings/qjs/qjs_engine_patch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <Windows.h>
#endif

#ifdef CONFIG_BIGNUM
#include <quickjs/libbf.h>
#endif

typedef struct JSProxyData {
JSValue target;
JSValue handler;
Expand All @@ -28,6 +32,44 @@ typedef enum {
JS_GC_OBJ_TYPE_JS_CONTEXT,
} JSGCObjectTypeEnum;

#ifdef CONFIG_BIGNUM

enum OPCodeEnum {
#define FMT(f)
#define DEF(id, size, n_pop, n_push, f) OP_##id,
#define def(id, size, n_pop, n_push, f)
#include "quickjs/quickjs-opcode.h"
#undef def
#undef DEF
#undef FMT
OP_COUNT, /* excluding temporary opcodes */
/* temporary opcodes : overlap with the short opcodes */
OP_TEMP_START = OP_nop + 1,
OP___dummy = OP_TEMP_START - 1,
#define FMT(f)
#define DEF(id, size, n_pop, n_push, f)
#define def(id, size, n_pop, n_push, f) OP_##id,
#include "quickjs/quickjs-opcode.h"
#undef def
#undef DEF
#undef FMT
OP_TEMP_END,
};

/* function pointers are used for numeric operations so that it is
possible to remove some numeric types */
typedef struct {
JSValue (*to_string)(JSContext* ctx, JSValueConst val);
JSValue (*from_string)(JSContext* ctx, const char* buf, int radix, int flags, slimb_t* pexponent);
int (*unary_arith)(JSContext* ctx, JSValue* pres, OPCodeEnum op, JSValue op1);
int (*binary_arith)(JSContext* ctx, OPCodeEnum op, JSValue* pres, JSValue op1, JSValue op2);
int (*compare)(JSContext* ctx, OPCodeEnum op, JSValue op1, JSValue op2);
/* only for bigfloat: */
JSValue (*mul_pow10_to_float64)(JSContext* ctx, const bf_t* a, int64_t exponent);
int (*mul_pow10)(JSContext* ctx, JSValue* sp);
} JSNumericOperations;
#endif

struct JSGCObjectHeader {
int ref_count; /* must come first, 32-bit */
JSGCObjectTypeEnum gc_obj_type : 4;
Expand Down
2 changes: 1 addition & 1 deletion bridge/polyfill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"es6-promise": "^4.2.8",
"event-emitter": "^0.3.5",
"expect": "^25.1.0",
"qjsc": "^0.2.11",
"qjsc": "^0.3.0",
"ts-jest": "^24.3.0",
"tslib": "^1.11.2"
},
Expand Down
Loading
Loading