diff --git a/quickjs.c b/quickjs.c index 6774f84..14fbb6e 100644 --- a/quickjs.c +++ b/quickjs.c @@ -364,6 +364,10 @@ typedef struct JSVarRef { JSValue value; /* used when the variable is no longer on the stack */ } JSVarRef; +typedef struct JSRefCountHeader { + int ref_count; +} JSRefCountHeader; + /* the same structure is used for big integers. Big integers are never infinite or NaNs */ typedef struct JSBigInt { @@ -1362,6 +1366,16 @@ static JSValue js_dup(JSValue v) return v; } +JSValue JS_DupValue(JSContext *ctx, JSValue v) +{ + return js_dup(v); +} + +JSValue JS_DupValueRT(JSRuntime *rt, JSValue v) +{ + return js_dup(v); +} + static void js_trigger_gc(JSRuntime *rt, size_t size) { BOOL force_gc; @@ -5523,7 +5537,7 @@ static void free_zero_refcount(JSRuntime *rt) } /* called with the ref_count of 'v' reaches zero. */ -void __JS_FreeValueRT(JSRuntime *rt, JSValue v) +static void js_free_value_rt(JSRuntime *rt, JSValue v) { uint32_t tag = JS_VALUE_GET_TAG(v); @@ -5587,14 +5601,24 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v) } break; default: - printf("__JS_FreeValue: unknown tag=%d\n", tag); + printf("js_free_value_rt: unknown tag=%d\n", tag); abort(); } } -void __JS_FreeValue(JSContext *ctx, JSValue v) +void JS_FreeValueRT(JSRuntime *rt, JSValue v) { - __JS_FreeValueRT(ctx->rt, v); + if (JS_VALUE_HAS_REF_COUNT(v)) { + JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); + if (--p->ref_count <= 0) { + js_free_value_rt(rt, v); + } + } +} + +void JS_FreeValue(JSContext *ctx, JSValue v) +{ + JS_FreeValueRT(ctx->rt, v); } /* garbage collection */ @@ -20177,7 +20201,7 @@ static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end) - Skip comments - Expect 'import' keyword not followed by '(' or '.' - Expect 'export' keyword - - Expect 'await' keyword + - Expect 'await' keyword */ /* input is pure ASCII or UTF-8 encoded source code */ BOOL JS_DetectModule(const char *input, size_t input_len) diff --git a/quickjs.h b/quickjs.h index d449205..f48d360 100644 --- a/quickjs.h +++ b/quickjs.h @@ -87,10 +87,6 @@ enum { /* any larger tag is FLOAT64 if JS_NAN_BOXING */ }; -typedef struct JSRefCountHeader { - int ref_count; -} JSRefCountHeader; - #define JS_FLOAT64_NAN NAN #define JSValueConst JSValue /* For backwards compatibility. */ @@ -589,46 +585,10 @@ JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowReferenceError(JSContext *ctx, JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowRangeError(JSContext *ctx, const char *fmt, ...); JS_EXTERN JSValue __js_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...); JS_EXTERN JSValue JS_ThrowOutOfMemory(JSContext *ctx); - -JS_EXTERN void __JS_FreeValue(JSContext *ctx, JSValue v); -static inline void JS_FreeValue(JSContext *ctx, JSValue v) -{ - if (JS_VALUE_HAS_REF_COUNT(v)) { - JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); - if (--p->ref_count <= 0) { - __JS_FreeValue(ctx, v); - } - } -} -JS_EXTERN void __JS_FreeValueRT(JSRuntime *rt, JSValue v); -static inline void JS_FreeValueRT(JSRuntime *rt, JSValue v) -{ - if (JS_VALUE_HAS_REF_COUNT(v)) { - JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); - if (--p->ref_count <= 0) { - __JS_FreeValueRT(rt, v); - } - } -} - -static inline JSValue JS_DupValue(JSContext *ctx, JSValue v) -{ - if (JS_VALUE_HAS_REF_COUNT(v)) { - JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); - p->ref_count++; - } - return v; -} - -static inline JSValue JS_DupValueRT(JSRuntime *rt, JSValue v) -{ - if (JS_VALUE_HAS_REF_COUNT(v)) { - JSRefCountHeader *p = (JSRefCountHeader *)JS_VALUE_GET_PTR(v); - p->ref_count++; - } - return v; -} - +JS_EXTERN void JS_FreeValue(JSContext *ctx, JSValue v); +JS_EXTERN void JS_FreeValueRT(JSRuntime *rt, JSValue v); +JS_EXTERN JSValue JS_DupValue(JSContext *ctx, JSValue v); +JS_EXTERN JSValue JS_DupValueRT(JSRuntime *rt, JSValue v); JS_EXTERN int JS_ToBool(JSContext *ctx, JSValue val); /* return -1 for JS_EXCEPTION */ JS_EXTERN int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValue val); static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val)