remove dupavlue and freevalue
This commit is contained in:
@@ -324,7 +324,6 @@ void script_startup(JSContext *js)
|
||||
js->actor_label = js->name; /* may be NULL; updated when name is set */
|
||||
JS_SetHeapMemoryLimit(js, ACTOR_MEMORY_LIMIT);
|
||||
|
||||
JS_FreeValue(js, js_core_blob_use(js));
|
||||
|
||||
// Try engine fast-path: load engine.cm from source-hash cache
|
||||
size_t bin_size;
|
||||
@@ -390,8 +389,8 @@ void script_startup(JSContext *js)
|
||||
|
||||
js->actor_sym_ref.val = JS_NewObject(js);
|
||||
JS_CellStone(js, js->actor_sym_ref.val);
|
||||
JS_SetActorSym(js, JS_DupValue(js, js->actor_sym_ref.val));
|
||||
JS_SetPropertyStr(js, env_ref.val, "actorsym", JS_DupValue(js, js->actor_sym_ref.val));
|
||||
JS_SetActorSym(js, js->actor_sym_ref.val);
|
||||
JS_SetPropertyStr(js, env_ref.val, "actorsym", js->actor_sym_ref.val);
|
||||
|
||||
// Always set init (even if null)
|
||||
if (js->init_wota) {
|
||||
@@ -621,11 +620,10 @@ int cell_init(int argc, char **argv)
|
||||
|
||||
ctx->actor_sym_ref.val = JS_NewObject(ctx);
|
||||
JS_CellStone(ctx, ctx->actor_sym_ref.val);
|
||||
JS_SetActorSym(ctx, JS_DupValue(ctx, ctx->actor_sym_ref.val));
|
||||
JS_SetActorSym(ctx, ctx->actor_sym_ref.val);
|
||||
|
||||
root_ctx = ctx;
|
||||
|
||||
JS_FreeValue(ctx, js_core_blob_use(ctx));
|
||||
|
||||
int exit_code = 0;
|
||||
int use_native_engine = 0;
|
||||
@@ -670,7 +668,7 @@ int cell_init(int argc, char **argv)
|
||||
JS_SetPropertyStr(ctx, boot_env_ref.val, "core_path", btmp);
|
||||
btmp = shop_path ? JS_NewString(ctx, shop_path) : JS_NULL;
|
||||
JS_SetPropertyStr(ctx, boot_env_ref.val, "shop_path", btmp);
|
||||
JS_SetPropertyStr(ctx, boot_env_ref.val, "actorsym", JS_DupValue(ctx, ctx->actor_sym_ref.val));
|
||||
JS_SetPropertyStr(ctx, boot_env_ref.val, "actorsym", ctx->actor_sym_ref.val);
|
||||
btmp = js_core_json_use(ctx);
|
||||
JS_SetPropertyStr(ctx, boot_env_ref.val, "json", btmp);
|
||||
if (native_mode)
|
||||
@@ -734,7 +732,7 @@ int cell_init(int argc, char **argv)
|
||||
JS_SetPropertyStr(ctx, env_ref.val, "core_path", tmp);
|
||||
tmp = shop_path ? JS_NewString(ctx, shop_path) : JS_NULL;
|
||||
JS_SetPropertyStr(ctx, env_ref.val, "shop_path", tmp);
|
||||
JS_SetPropertyStr(ctx, env_ref.val, "actorsym", JS_DupValue(ctx, ctx->actor_sym_ref.val));
|
||||
JS_SetPropertyStr(ctx, env_ref.val, "actorsym", ctx->actor_sym_ref.val);
|
||||
tmp = js_core_json_use(ctx);
|
||||
JS_SetPropertyStr(ctx, env_ref.val, "json", tmp);
|
||||
if (native_mode || !warn_mode || eval_script) {
|
||||
|
||||
@@ -280,14 +280,6 @@ static inline JS_BOOL JS_IsTrue(JSValue v) { return v == JS_TRUE; }
|
||||
static inline JS_BOOL JS_IsFalse(JSValue v) { return v == JS_FALSE; }
|
||||
JS_BOOL JS_IsActor(JSContext *ctx, JSValue val);
|
||||
|
||||
/* ============================================================
|
||||
GC References — no-ops with copying GC
|
||||
============================================================ */
|
||||
#define JS_DupValue(ctx, v) (v)
|
||||
#define JS_FreeValue(ctx, v) ((void)0)
|
||||
#define JS_DupValueRT(rt, v) (v)
|
||||
#define JS_FreeValueRT(rt, v) ((void)0)
|
||||
|
||||
/* ============================================================
|
||||
C Function Typedefs
|
||||
============================================================ */
|
||||
@@ -1102,19 +1094,16 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
||||
// Safe integer property extraction (null → 0)
|
||||
#define JS_GETINT(JS, TARGET, VALUE, PROP) { \
|
||||
JSValue __##PROP##__v = JS_GetPropertyStr(JS, VALUE, #PROP); \
|
||||
TARGET = JS_IsNull(__##PROP##__v) ? 0 : (int)js2number(JS, __##PROP##__v); \
|
||||
JS_FreeValue(JS, __##PROP##__v); }
|
||||
TARGET = JS_IsNull(__##PROP##__v) ? 0 : (int)js2number(JS, __##PROP##__v); }
|
||||
|
||||
// Common macros for property access
|
||||
#define JS_GETPROP(JS, TARGET, VALUE, PROP, TYPE) {\
|
||||
JSValue __##PROP##__v = JS_GetPropertyStr(JS,VALUE,#PROP); \
|
||||
TARGET = js2##TYPE(JS, __##PROP##__v); \
|
||||
JS_FreeValue(JS,__##PROP##__v); }\
|
||||
TARGET = js2##TYPE(JS, __##PROP##__v); }\
|
||||
|
||||
#define JS_GETATOM(JS, TARGET, VALUE, ATOM, TYPE) {\
|
||||
JSValue __##PROP##__v = JS_GetPropertyStr(JS,VALUE,#ATOM); \
|
||||
TARGET = js2##TYPE(JS, __##PROP##__v); \
|
||||
JS_FreeValue(JS,__##PROP##__v); }\
|
||||
TARGET = js2##TYPE(JS, __##PROP##__v); }\
|
||||
|
||||
/* ============================================================
|
||||
Enum Mapping System
|
||||
|
||||
@@ -307,7 +307,6 @@ void *timer_thread_func(void *arg) {
|
||||
JSValue cb = t.actor->timers[idx].value;
|
||||
hmdel(t.actor->timers, t.timer_id);
|
||||
actor_clock(t.actor, cb);
|
||||
JS_FreeValue(t.actor, cb);
|
||||
}
|
||||
pthread_mutex_unlock(t.actor->msg_mutex);
|
||||
}
|
||||
@@ -471,7 +470,6 @@ void actor_free(JSContext *actor)
|
||||
pthread_mutex_lock(actor->mutex);
|
||||
|
||||
for (int i = 0; i < hmlen(actor->timers); i++) {
|
||||
JS_FreeValue(actor, actor->timers[i].value);
|
||||
}
|
||||
|
||||
hmfree(actor->timers);
|
||||
@@ -481,7 +479,6 @@ void actor_free(JSContext *actor)
|
||||
if (actor->letters[i].type == LETTER_BLOB) {
|
||||
blob_destroy(actor->letters[i].blob_data);
|
||||
} else if (actor->letters[i].type == LETTER_CALLBACK) {
|
||||
JS_FreeValue(actor, actor->letters[i].callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -912,23 +909,19 @@ void actor_turn(JSContext *actor)
|
||||
if (JS_IsSuspended(result)) {
|
||||
actor->vm_suspended = 1;
|
||||
actor->state = ACTOR_SLOW;
|
||||
JS_FreeValue(actor, arg);
|
||||
goto ENDTURN_SLOW;
|
||||
}
|
||||
if (!uncaught_exception(actor, result))
|
||||
actor->disrupt = 1;
|
||||
JS_FreeValue(actor, arg);
|
||||
} else if (l.type == LETTER_CALLBACK) {
|
||||
result = JS_Call(actor, l.callback, JS_NULL, 0, NULL);
|
||||
if (JS_IsSuspended(result)) {
|
||||
actor->vm_suspended = 1;
|
||||
actor->state = ACTOR_SLOW;
|
||||
JS_FreeValue(actor, l.callback);
|
||||
goto ENDTURN_SLOW;
|
||||
}
|
||||
if (!uncaught_exception(actor, result))
|
||||
actor->disrupt = 1;
|
||||
JS_FreeValue(actor, l.callback);
|
||||
}
|
||||
|
||||
if (actor->disrupt) goto ENDTURN;
|
||||
@@ -1017,7 +1010,7 @@ void actor_clock(JSContext *actor, JSValue fn)
|
||||
{
|
||||
letter l;
|
||||
l.type = LETTER_CALLBACK;
|
||||
l.callback = JS_DupValue(actor, fn);
|
||||
l.callback = fn;
|
||||
pthread_mutex_lock(actor->msg_mutex);
|
||||
arrput(actor->letters, l);
|
||||
pthread_mutex_unlock(actor->msg_mutex);
|
||||
@@ -1031,7 +1024,7 @@ uint32_t actor_delay(JSContext *actor, JSValue fn, double seconds)
|
||||
static uint32_t global_timer_id = 1;
|
||||
uint32_t id = global_timer_id++;
|
||||
|
||||
JSValue cb = JS_DupValue(actor, fn);
|
||||
JSValue cb = fn;
|
||||
hmput(actor->timers, id, cb);
|
||||
|
||||
uint64_t now = cell_ns();
|
||||
|
||||
@@ -117,7 +117,6 @@ void actor_free(JSContext *actor)
|
||||
}
|
||||
|
||||
for (int i = 0; i < hmlen(actor->timers); i++) {
|
||||
JS_FreeValue(actor, actor->timers[i].value);
|
||||
}
|
||||
|
||||
hmfree(actor->timers);
|
||||
@@ -127,7 +126,6 @@ void actor_free(JSContext *actor)
|
||||
if (actor->letters[i].type == LETTER_BLOB) {
|
||||
blob_destroy(actor->letters[i].blob_data);
|
||||
} else if (actor->letters[i].type == LETTER_CALLBACK) {
|
||||
JS_FreeValue(actor, actor->letters[i].callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,7 +287,6 @@ void actor_loop()
|
||||
JSValue cb = t.actor->timers[idx].value;
|
||||
hmdel(t.actor->timers, t.timer_id);
|
||||
actor_clock(t.actor, cb);
|
||||
JS_FreeValue(t.actor, cb);
|
||||
}
|
||||
}
|
||||
continue; // Loop again
|
||||
@@ -385,11 +382,9 @@ void actor_turn(JSContext *actor)
|
||||
blob_destroy(l.blob_data);
|
||||
result = JS_Call(actor, actor->message_handle_ref.val, JS_NULL, 1, &arg);
|
||||
uncaught_exception(actor, result);
|
||||
JS_FreeValue(actor, arg);
|
||||
} else if (l.type == LETTER_CALLBACK) {
|
||||
result = JS_Call(actor, l.callback, JS_NULL, 0, NULL);
|
||||
uncaught_exception(actor, result);
|
||||
JS_FreeValue(actor, l.callback);
|
||||
}
|
||||
|
||||
if (actor->disrupt) goto ENDTURN;
|
||||
@@ -405,7 +400,7 @@ void actor_clock(JSContext *actor, JSValue fn)
|
||||
{
|
||||
letter l;
|
||||
l.type = LETTER_CALLBACK;
|
||||
l.callback = JS_DupValue(actor, fn);
|
||||
l.callback = fn;
|
||||
arrput(actor->letters, l);
|
||||
set_actor_state(actor);
|
||||
}
|
||||
@@ -415,7 +410,7 @@ uint32_t actor_delay(JSContext *actor, JSValue fn, double seconds)
|
||||
static uint32_t global_timer_id = 1;
|
||||
uint32_t id = global_timer_id++;
|
||||
|
||||
JSValue cb = JS_DupValue(actor, fn);
|
||||
JSValue cb = fn;
|
||||
hmput(actor->timers, id, cb);
|
||||
|
||||
uint64_t now = cell_ns();
|
||||
|
||||
Reference in New Issue
Block a user