diff --git a/internal/engine.cm b/internal/engine.cm index 4d4fec46..efb901f2 100644 --- a/internal/engine.cm +++ b/internal/engine.cm @@ -312,9 +312,6 @@ var actor_mod = use_core('actor') var wota = use_core('wota') var nota = use_core('nota') -function is_actor(value) { - return is_object(value) && value[ACTORDATA] -} var ENETSERVICE = 0.1 var REPLYTIMEOUT = 60 // seconds before replies are ignored @@ -439,7 +436,6 @@ var race = pronto.race var sequence = pronto.sequence runtime_env.actor = actor -runtime_env.is_actor = is_actor runtime_env.log = log runtime_env.send = send runtime_env.fallback = fallback diff --git a/source/cell.c b/source/cell.c index ad91899a..a0145e34 100644 --- a/source/cell.c +++ b/source/cell.c @@ -345,7 +345,8 @@ void script_startup(cell_rt *prt) tmp = js_core_json_use(js); JS_SetPropertyStr(js, env_ref.val, "json", tmp); - crt->actor_sym_ref.val = JS_NewString(js, "__ACTOR__"); + crt->actor_sym_ref.val = JS_NewObject(js); + JS_CellStone(js, crt->actor_sym_ref.val); JS_SetActorSym(js, JS_DupValue(js, crt->actor_sym_ref.val)); JS_SetPropertyStr(js, env_ref.val, "actorsym", JS_DupValue(js, crt->actor_sym_ref.val)); @@ -565,7 +566,8 @@ int cell_init(int argc, char **argv) cli_rt->on_exception_ref.val = JS_NULL; cli_rt->message_handle_ref.val = JS_NULL; cli_rt->unneeded_ref.val = JS_NULL; - cli_rt->actor_sym_ref.val = JS_NewString(ctx, "__ACTOR__"); + cli_rt->actor_sym_ref.val = JS_NewObject(ctx); + JS_CellStone(ctx, cli_rt->actor_sym_ref.val); JS_SetActorSym(ctx, JS_DupValue(ctx, cli_rt->actor_sym_ref.val)); root_cell = cli_rt; diff --git a/source/runtime.c b/source/runtime.c index e5a67b75..824b3489 100644 --- a/source/runtime.c +++ b/source/runtime.c @@ -11159,6 +11159,16 @@ static JSValue js_cell_is_object (JSContext *ctx, JSValue this_val, int argc, JS return JS_NewBool (ctx, mist_is_record (argv[0])); } +/* is_actor(val) - true for actor objects (have actor_sym property) */ +static JSValue js_cell_is_actor (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { + if (argc < 1) return JS_FALSE; + JSValue val = argv[0]; + if (!mist_is_record (val)) return JS_FALSE; + if (JS_IsNull (ctx->actor_sym)) return JS_FALSE; + int has = JS_HasPropertyKey (ctx, val, ctx->actor_sym); + return JS_NewBool (ctx, has > 0); +} + /* is_stone(val) - check if value is immutable */ static JSValue js_cell_is_stone (JSContext *ctx, JSValue this_val, int argc, JSValue *argv) { (void)this_val; @@ -11344,6 +11354,7 @@ static void JS_AddIntrinsicBaseObjects (JSContext *ctx) { js_set_global_cfunc(ctx, "is_null", js_cell_is_null, 1); js_set_global_cfunc(ctx, "is_number", js_cell_is_number, 1); js_set_global_cfunc(ctx, "is_object", js_cell_is_object, 1); + js_set_global_cfunc(ctx, "is_actor", js_cell_is_actor, 1); js_set_global_cfunc(ctx, "is_stone", js_cell_is_stone, 1); js_set_global_cfunc(ctx, "is_text", js_cell_is_text, 1); js_set_global_cfunc(ctx, "is_proto", js_cell_is_proto, 2);