Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ QUICKJS_DEFINES:=-D_GNU_SOURCE -DCONFIG_VERSION=\"$(QUICKJS_CONFIG_VERSION)\"
EMCC_EXPORTED_FUNCS+=-s EXPORTED_FUNCTIONS=$(shell cat $(BUILD_WRAPPER)/symbols.json)

CFLAGS_EMCC+=-s WASM=1
CFLAGS_EMCC+=-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap", "addFunction", "removeFunction", "_malloc", "_free"]'
CFLAGS_EMCC+=-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap", "addFunction", "removeFunction", "stringToUTF8", "lengthBytesUTF8", "_malloc", "_free"]'
CFLAGS_EMCC+=-s NODEJS_CATCH_EXIT=0
CFLAGS_EMCC+=-s MODULARIZE=1
CFLAGS_EMCC+=-s EXPORT_NAME=QuickJSRaw
Expand Down
15 changes: 13 additions & 2 deletions c/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
#define QTS_DUMP(value) ;
#endif

/**
* Signal to our FFI code generator that this string argument should be passed as a pointer
* allocated by the caller on the heap, not a JS string on the stack.
* https://github.com/emscripten-core/emscripten/issues/6860#issuecomment-405818401
*/
#define HeapChar const char

void qts_log(char* msg) {
fputs(PKG, stderr);
fputs(msg, stderr);
Expand Down Expand Up @@ -291,7 +298,7 @@ double QTS_GetFloat64(JSContext *ctx, JSValueConst *value) {
return result;
}

JSValue *QTS_NewString(JSContext *ctx, const char* string) {
JSValue *QTS_NewString(JSContext *ctx, HeapChar *string) {
return jsvalue_to_heap(JS_NewString(ctx, string));
}

Expand Down Expand Up @@ -434,7 +441,7 @@ char *QTS_Dump(JSContext *ctx, JSValueConst *obj) {
return QTS_GetString(ctx, obj);
}

JSValue *QTS_Eval(JSContext *ctx, const char* js_code) {
JSValue *QTS_Eval(JSContext *ctx, HeapChar *js_code) {
return jsvalue_to_heap(JS_Eval(ctx, js_code, strlen(js_code), "eval.js", JS_EVAL_TYPE_GLOBAL));
}

Expand Down Expand Up @@ -470,3 +477,7 @@ JSValue *QTS_NewPromiseCapability(JSContext *ctx, JSValue **resolve_funcs_out) {
resolve_funcs_out[1] = jsvalue_to_heap(resolve_funcs[1]);
return jsvalue_to_heap(promise);
}

void QTS_TestStringArg(const char *string) {
// pass
}
Loading