aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/javascript/jsc/api/FFI.h18
-rw-r--r--src/javascript/jsc/api/bun.zig2
-rw-r--r--src/javascript/jsc/api/ffi.zig2
-rw-r--r--src/javascript/jsc/bindings/JSFFIFunction.h5
4 files changed, 15 insertions, 12 deletions
diff --git a/src/javascript/jsc/api/FFI.h b/src/javascript/jsc/api/FFI.h
index 096abcfd9..42bc03fc8 100644
--- a/src/javascript/jsc/api/FFI.h
+++ b/src/javascript/jsc/api/FFI.h
@@ -99,6 +99,7 @@ typedef union EncodedJSValue {
#endif
void* asPtr;
+ double asDouble;
} EncodedJSValue;
EncodedJSValue ValueUndefined = { TagValueUndefined };
@@ -115,6 +116,7 @@ JSContext cachedJSContext;
void* cachedCallbackFunction;
#endif
+
static EncodedJSValue INT32_TO_JSVALUE(int32_t val) __attribute__((__always_inline__));
static EncodedJSValue DOUBLE_TO_JSVALUE(double val) __attribute__((__always_inline__));
static EncodedJSValue FLOAT_TO_JSVALUE(float val) __attribute__((__always_inline__));
@@ -148,19 +150,16 @@ static EncodedJSValue INT32_TO_JSVALUE(int32_t val) {
return res;
}
+
static EncodedJSValue DOUBLE_TO_JSVALUE(double val) {
- EncodedJSValue res;
-#ifdef USES_FLOAT
- res.asInt64 = trunc(val) == val ? val : val - DoubleEncodeOffset;
-#else
-// should never get here
- res.asInt64 = 0xa;
-#endif
+ EncodedJSValue res;
+ res.asDouble = val;
+ res.asInt64 += DoubleEncodeOffset;
return res;
}
static EncodedJSValue FLOAT_TO_JSVALUE(float val) {
- return DOUBLE_TO_JSVALUE(val);
+ return DOUBLE_TO_JSVALUE((double)val);
}
static EncodedJSValue BOOLEAN_TO_JSVALUE(bool val) {
@@ -171,7 +170,8 @@ static EncodedJSValue BOOLEAN_TO_JSVALUE(bool val) {
static double JSVALUE_TO_DOUBLE(EncodedJSValue val) {
- return val.asInt64 + DoubleEncodeOffset;
+ val.asInt64 -= DoubleEncodeOffset;
+ return val.asDouble;
}
static float JSVALUE_TO_FLOAT(EncodedJSValue val) {
diff --git a/src/javascript/jsc/api/bun.zig b/src/javascript/jsc/api/bun.zig
index 79a0ae12f..632d85500 100644
--- a/src/javascript/jsc/api/bun.zig
+++ b/src/javascript/jsc/api/bun.zig
@@ -1477,7 +1477,7 @@ pub fn nanoseconds(
_: JSC.C.ExceptionRef,
) JSC.C.JSValueRef {
const ns = JSC.VirtualMachine.vm.origin_timer.read();
- JSC.JSValue.jsNumberFromUint64(ns).asObjectRef();
+ return JSC.JSValue.jsNumberFromUint64(ns).asObjectRef();
}
pub fn serve(
diff --git a/src/javascript/jsc/api/ffi.zig b/src/javascript/jsc/api/ffi.zig
index 7ae3b60dc..b3be0062f 100644
--- a/src/javascript/jsc/api/ffi.zig
+++ b/src/javascript/jsc/api/ffi.zig
@@ -740,7 +740,6 @@ pub const FFI = struct {
}
_ = TCC.tcc_set_output_type(state, TCC.TCC_OUTPUT_MEMORY);
- CompilerRT.inject(state);
const compilation_result = TCC.tcc_compile_string(
state,
@@ -763,6 +762,7 @@ pub const FFI = struct {
_ = TCC.tcc_add_symbol(state, "bun_call", JSC.C.JSObjectCallAsFunction);
_ = TCC.tcc_add_symbol(state, "cachedJSContext", js_context);
_ = TCC.tcc_add_symbol(state, "cachedCallbackFunction", js_function);
+ CompilerRT.inject(state);
var relocation_size = TCC.tcc_relocate(state, null);
if (relocation_size == 0) return;
diff --git a/src/javascript/jsc/bindings/JSFFIFunction.h b/src/javascript/jsc/bindings/JSFFIFunction.h
index 8f65bf632..421adc3ff 100644
--- a/src/javascript/jsc/bindings/JSFFIFunction.h
+++ b/src/javascript/jsc/bindings/JSFFIFunction.h
@@ -34,7 +34,10 @@ using FFIFunction = JSC::EncodedJSValue (*)(JSC::JSGlobalObject* globalObject, J
*
* It was about 20% faster than using the JavaScriptCore C API for functions with 1 argument
*
- * Note: there is no wrapper function here
+ * There is no wrapper function. It does zero bounds checking on the arguments.
+ * It does not check for exceptions. It does not check for return value.
+ * It is the caller's responsibility to not buffer overflow the arguments
+ * For all those reasons, this shouldn't be used directly.
*/
class JSFFIFunction final : public JSC::JSFunction {
public: