Merge branch 'fix_gc' into pitweb
This commit is contained in:
@@ -154,6 +154,43 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
||||
|
||||
#define countof(x) (sizeof(x)/sizeof((x)[0]))
|
||||
|
||||
/* GC safety macros for C functions that allocate multiple heap objects.
|
||||
Any allocation call (JS_NewObject, JS_SetPropertyStr, etc.) can trigger GC.
|
||||
JS_ROOT style: explicit, use .val to access the rooted value.
|
||||
JS_LOCAL style: transparent, GC updates the C local through a pointer. */
|
||||
|
||||
#define JS_FRAME(ctx) \
|
||||
JSContext *_js_ctx = (ctx); \
|
||||
JSGCRef *_js_gc_frame = JS_GetGCFrame(_js_ctx); \
|
||||
JSLocalRef *_js_local_frame = JS_GetLocalFrame(_js_ctx)
|
||||
|
||||
#define JS_ROOT(name, init) \
|
||||
JSGCRef name; \
|
||||
JS_PushGCRef(_js_ctx, &name); \
|
||||
name.val = (init)
|
||||
|
||||
#define JS_LOCAL(name, init) \
|
||||
JSValue name = (init); \
|
||||
JSLocalRef name##__lr; \
|
||||
name##__lr.ptr = &name; \
|
||||
JS_PushLocalRef(_js_ctx, &name##__lr)
|
||||
|
||||
#define JS_RETURN(val) do { \
|
||||
JSValue _js_ret = (val); \
|
||||
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); \
|
||||
return _js_ret; \
|
||||
} while (0)
|
||||
|
||||
#define JS_RETURN_NULL() do { \
|
||||
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); \
|
||||
return JS_NULL; \
|
||||
} while (0)
|
||||
|
||||
#define JS_RETURN_EX() do { \
|
||||
JS_RestoreFrame(_js_ctx, _js_gc_frame, _js_local_frame); \
|
||||
return JS_EXCEPTION; \
|
||||
} while (0)
|
||||
|
||||
// Common macros for property access
|
||||
#define JS_GETPROP(JS, TARGET, VALUE, PROP, TYPE) {\
|
||||
JSValue __##PROP##__v = JS_GetPropertyStr(JS,VALUE,#PROP); \
|
||||
|
||||
Reference in New Issue
Block a user