mirror of
https://github.com/DoneJS-Runtime/quickjs-done-nextgen.git
synced 2025-01-09 17:43:15 +00:00
Move JS_{Dup,Free}Value and the RT variants from header, reduced duplication
This commit is contained in:
parent
1eb9608d64
commit
5590756b93
2 changed files with 33 additions and 49 deletions
34
quickjs.c
34
quickjs.c
|
@ -364,6 +364,10 @@ typedef struct JSVarRef {
|
||||||
JSValue value; /* used when the variable is no longer on the stack */
|
JSValue value; /* used when the variable is no longer on the stack */
|
||||||
} JSVarRef;
|
} JSVarRef;
|
||||||
|
|
||||||
|
typedef struct JSRefCountHeader {
|
||||||
|
int ref_count;
|
||||||
|
} JSRefCountHeader;
|
||||||
|
|
||||||
/* the same structure is used for big integers.
|
/* the same structure is used for big integers.
|
||||||
Big integers are never infinite or NaNs */
|
Big integers are never infinite or NaNs */
|
||||||
typedef struct JSBigInt {
|
typedef struct JSBigInt {
|
||||||
|
@ -1362,6 +1366,16 @@ static JSValue js_dup(JSValue v)
|
||||||
return 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)
|
static void js_trigger_gc(JSRuntime *rt, size_t size)
|
||||||
{
|
{
|
||||||
BOOL force_gc;
|
BOOL force_gc;
|
||||||
|
@ -5523,7 +5537,7 @@ static void free_zero_refcount(JSRuntime *rt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called with the ref_count of 'v' reaches zero. */
|
/* 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);
|
uint32_t tag = JS_VALUE_GET_TAG(v);
|
||||||
|
|
||||||
|
@ -5587,14 +5601,24 @@ void __JS_FreeValueRT(JSRuntime *rt, JSValue v)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("__JS_FreeValue: unknown tag=%d\n", tag);
|
printf("js_free_value_rt: unknown tag=%d\n", tag);
|
||||||
abort();
|
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 */
|
/* garbage collection */
|
||||||
|
@ -20177,7 +20201,7 @@ static void skip_shebang(const uint8_t **pp, const uint8_t *buf_end)
|
||||||
- Skip comments
|
- Skip comments
|
||||||
- Expect 'import' keyword not followed by '(' or '.'
|
- Expect 'import' keyword not followed by '(' or '.'
|
||||||
- Expect 'export' keyword
|
- Expect 'export' keyword
|
||||||
- Expect 'await' keyword
|
- Expect 'await' keyword
|
||||||
*/
|
*/
|
||||||
/* input is pure ASCII or UTF-8 encoded source code */
|
/* input is pure ASCII or UTF-8 encoded source code */
|
||||||
BOOL JS_DetectModule(const char *input, size_t input_len)
|
BOOL JS_DetectModule(const char *input, size_t input_len)
|
||||||
|
|
48
quickjs.h
48
quickjs.h
|
@ -87,10 +87,6 @@ enum {
|
||||||
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
|
/* any larger tag is FLOAT64 if JS_NAN_BOXING */
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct JSRefCountHeader {
|
|
||||||
int ref_count;
|
|
||||||
} JSRefCountHeader;
|
|
||||||
|
|
||||||
#define JS_FLOAT64_NAN NAN
|
#define JS_FLOAT64_NAN NAN
|
||||||
#define JSValueConst JSValue /* For backwards compatibility. */
|
#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_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_printf_like(2, 3) JS_ThrowInternalError(JSContext *ctx, const char *fmt, ...);
|
||||||
JS_EXTERN JSValue JS_ThrowOutOfMemory(JSContext *ctx);
|
JS_EXTERN JSValue JS_ThrowOutOfMemory(JSContext *ctx);
|
||||||
|
JS_EXTERN void JS_FreeValue(JSContext *ctx, JSValue v);
|
||||||
JS_EXTERN void __JS_FreeValue(JSContext *ctx, JSValue v);
|
JS_EXTERN void JS_FreeValueRT(JSRuntime *rt, JSValue v);
|
||||||
static inline void JS_FreeValue(JSContext *ctx, JSValue v)
|
JS_EXTERN JSValue JS_DupValue(JSContext *ctx, JSValue v);
|
||||||
{
|
JS_EXTERN JSValue JS_DupValueRT(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_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 int JS_ToBool(JSContext *ctx, JSValue val); /* return -1 for JS_EXCEPTION */
|
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);
|
JS_EXTERN int JS_ToInt32(JSContext *ctx, int32_t *pres, JSValue val);
|
||||||
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val)
|
static inline int JS_ToUint32(JSContext *ctx, uint32_t *pres, JSValue val)
|
||||||
|
|
Loading…
Reference in a new issue