closes #18: actor data now behind private symbol
This commit is contained in:
@@ -38,10 +38,9 @@ $_.delay($_.stop, 3)
|
|||||||
|
|
||||||
var os = use('os')
|
var os = use('os')
|
||||||
var actor = use('actor')
|
var actor = use('actor')
|
||||||
var ioguy = {
|
var ioguy = {}
|
||||||
__ACTORDATA__: {
|
ioguy[cell.actor_sym] = {
|
||||||
id: actor.ioactor()
|
id: actor.ioactor()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send(ioguy, {
|
send(ioguy, {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
(function engine() {
|
(function engine() {
|
||||||
globalThis.cell = prosperon
|
globalThis.cell = prosperon
|
||||||
cell.DOC = Symbol()
|
cell.DOC = Symbol()
|
||||||
var ACTORDATA = cell.hidden.ACTORSYM
|
var ACTORDATA = cell.hidden.actorsym
|
||||||
ACTORDATA = '__ACTORDATA__' // TODO: implement the actual actorsym
|
|
||||||
var SYSYM = '__SYSTEM__'
|
var SYSYM = '__SYSTEM__'
|
||||||
|
|
||||||
var ENETSERVICE = 0.1
|
var ENETSERVICE = 0.1
|
||||||
@@ -112,7 +111,6 @@ function disrupt(err)
|
|||||||
actor_mod.on_exception(disrupt)
|
actor_mod.on_exception(disrupt)
|
||||||
|
|
||||||
var js = use_embed('js')
|
var js = use_embed('js')
|
||||||
|
|
||||||
var io = use_embed('io')
|
var io = use_embed('io')
|
||||||
|
|
||||||
if (!io.exists('.cell')) {
|
if (!io.exists('.cell')) {
|
||||||
@@ -596,7 +594,7 @@ function actor_send(actor, message) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.system(`Unable to send message to actor ${json.encode(actor)}`)
|
log.system(`Unable to send message to actor ${json.encode(actor[ACTORDATA])}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Holds all messages queued during the current turn.
|
// Holds all messages queued during the current turn.
|
||||||
|
|||||||
@@ -341,6 +341,7 @@ cell_rt *create_actor(void *wota)
|
|||||||
actor->message_handle = JS_UNDEFINED;
|
actor->message_handle = JS_UNDEFINED;
|
||||||
actor->unneeded = JS_UNDEFINED;
|
actor->unneeded = JS_UNDEFINED;
|
||||||
actor->on_exception = JS_UNDEFINED;
|
actor->on_exception = JS_UNDEFINED;
|
||||||
|
actor->actor_sym = JS_ATOM_NULL;
|
||||||
|
|
||||||
arrsetcap(actor->letters, 5);
|
arrsetcap(actor->letters, 5);
|
||||||
|
|
||||||
@@ -672,7 +673,7 @@ void script_startup(cell_rt *prt)
|
|||||||
JS_SetContextOpaque(js, prt);
|
JS_SetContextOpaque(js, prt);
|
||||||
prt->context = js;
|
prt->context = js;
|
||||||
ffi_load(js);
|
ffi_load(js);
|
||||||
|
|
||||||
PHYSFS_File *eng = PHYSFS_openRead(ENGINE);
|
PHYSFS_File *eng = PHYSFS_openRead(ENGINE);
|
||||||
if (!eng) {
|
if (!eng) {
|
||||||
printf("ERROR: Could not open file %s! %s\n", ENGINE, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
printf("ERROR: Could not open file %s! %s\n", ENGINE, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()));
|
||||||
|
|||||||
@@ -1613,6 +1613,14 @@ void ffi_load(JSContext *js)
|
|||||||
JS_SetPropertyStr(js, hidden_fn, "use_dyn", JS_NewCFunction(js, js_os_use_dyn, "use_dyn", 1));
|
JS_SetPropertyStr(js, hidden_fn, "use_dyn", JS_NewCFunction(js, js_os_use_dyn, "use_dyn", 1));
|
||||||
JS_SetPropertyStr(js, hidden_fn, "use_embed", JS_NewCFunction(js, js_os_use_embed, "use_embed", 1));
|
JS_SetPropertyStr(js, hidden_fn, "use_embed", JS_NewCFunction(js, js_os_use_embed, "use_embed", 1));
|
||||||
|
|
||||||
|
const char actorsym_script[] = "var sym = Symbol(`actordata`); sym;";
|
||||||
|
|
||||||
|
JSValue actorsym = JS_Eval(js, actorsym_script, sizeof(actorsym_script)-1, "internal", JS_EVAL_FLAG_STRICT);
|
||||||
|
|
||||||
|
JS_SetPropertyStr(js, hidden_fn, "actorsym", actorsym);
|
||||||
|
|
||||||
|
rt->actor_sym = JS_ValueToAtom(js, actorsym);
|
||||||
|
|
||||||
if (rt->init_wota) {
|
if (rt->init_wota) {
|
||||||
JS_SetPropertyStr(js, hidden_fn, "init", wota2value(js, rt->init_wota));
|
JS_SetPropertyStr(js, hidden_fn, "init", wota2value(js, rt->init_wota));
|
||||||
// init wota can now be freed
|
// init wota can now be freed
|
||||||
@@ -1620,11 +1628,6 @@ void ffi_load(JSContext *js)
|
|||||||
rt->init_wota = NULL;
|
rt->init_wota = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// cell_rt *actor = JS_GetContextOpaque(js);
|
|
||||||
// JSValue actorsym = js_newsymbol(js, "actor symbol", 0);
|
|
||||||
// actor->actor_sym = JS_ValueToAtom(js, actorsym);
|
|
||||||
// JS_SetPropertyStr(js, hidden_fn, "ACTORDATA", JS_DupValue(js,actorsym));
|
|
||||||
// JS_FreeValue(js, actorsym);
|
|
||||||
JS_SetPropertyStr(js, prosp, "hidden", hidden_fn);
|
JS_SetPropertyStr(js, prosp, "hidden", hidden_fn);
|
||||||
|
|
||||||
JS_FreeValue(js,globalThis);
|
JS_FreeValue(js,globalThis);
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ cell_rt *js2actor(JSContext *js, JSValue v)
|
|||||||
if (!JS_IsObject(v))
|
if (!JS_IsObject(v))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
cell_rt *crt = JS_GetContextOpaque(js);
|
cell_rt *crt = JS_GetContextOpaque(js);
|
||||||
JSValue actor_data = JS_GetPropertyStr(js, v, "__ACTORDATA__");
|
JSValue actor_data = JS_GetProperty(js, v, crt->actor_sym);
|
||||||
|
|
||||||
if (JS_IsUndefined(actor_data)) {
|
if (JS_IsUndefined(actor_data)) {
|
||||||
JS_FreeValue(js, actor_data);
|
JS_FreeValue(js, actor_data);
|
||||||
@@ -68,7 +68,7 @@ JSValue actor2js(JSContext *js, cell_rt *actor)
|
|||||||
|
|
||||||
cell_rt *crt = JS_GetContextOpaque(js);
|
cell_rt *crt = JS_GetContextOpaque(js);
|
||||||
|
|
||||||
JS_SetPropertyStr(js, actor_obj, "__ACTORDATA__", actor_data);
|
JS_SetProperty(js, actor_obj, crt->actor_sym, actor_data);
|
||||||
|
|
||||||
return actor_obj;
|
return actor_obj;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,5 +6,6 @@
|
|||||||
JSValue js_actor_use(JSContext *js);
|
JSValue js_actor_use(JSContext *js);
|
||||||
cell_rt *js2actor(JSContext *js, JSValue v);
|
cell_rt *js2actor(JSContext *js, JSValue v);
|
||||||
JSValue actor2js(JSContext *js, cell_rt *actor);
|
JSValue actor2js(JSContext *js, cell_rt *actor);
|
||||||
|
JSValue js_actor_set_symbol(JSContext *js, JSValue self, int argc, JSValue *argv);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -102,10 +102,20 @@ char *js_do_nota_decode(JSContext *js, JSValue *tmp, char *nota, JSValue holder,
|
|||||||
break;
|
break;
|
||||||
case NOTA_SYM:
|
case NOTA_SYM:
|
||||||
nota = nota_read_sym(&b, nota);
|
nota = nota_read_sym(&b, nota);
|
||||||
switch(b) {
|
if (b == NOTA_PRIVATE) {
|
||||||
case NOTA_NULL: *tmp = JS_UNDEFINED; break;
|
JSValue inner;
|
||||||
case NOTA_FALSE: *tmp = JS_NewBool(js, 0); break;
|
nota = js_do_nota_decode(js, &inner, nota, holder, JS_UNDEFINED, reviver);
|
||||||
case NOTA_TRUE: *tmp = JS_NewBool(js, 1); break;
|
JSValue obj = JS_NewObject(js);
|
||||||
|
cell_rt *crt = JS_GetContextOpaque(js);
|
||||||
|
JS_SetProperty(js, obj, crt->actor_sym, inner);
|
||||||
|
*tmp = obj;
|
||||||
|
} else {
|
||||||
|
switch(b) {
|
||||||
|
case NOTA_NULL: *tmp = JS_UNDEFINED; break;
|
||||||
|
case NOTA_FALSE: *tmp = JS_NewBool(js, 0); break;
|
||||||
|
case NOTA_TRUE: *tmp = JS_NewBool(js, 1); break;
|
||||||
|
default: *tmp = JS_UNDEFINED; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -191,6 +201,15 @@ static void nota_encode_value(NotaEncodeContext *enc, JSValueConst val, JSValueC
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cell_rt *crt = JS_GetContextOpaque(ctx);
|
||||||
|
JSValue adata = JS_GetProperty(ctx, replaced, crt->actor_sym);
|
||||||
|
if (!JS_IsUndefined(adata)) {
|
||||||
|
nota_write_sym(&enc->nb, NOTA_PRIVATE);
|
||||||
|
nota_encode_value(enc, adata, replaced, JS_UNDEFINED);
|
||||||
|
JS_FreeValue(ctx, adata);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
JS_FreeValue(ctx, adata);
|
||||||
if (nota_stack_has(enc, replaced)) {
|
if (nota_stack_has(enc, replaced)) {
|
||||||
enc->cycle = 1;
|
enc->cycle = 1;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -152,6 +152,15 @@ static void wota_encode_value(WotaEncodeContext *enc, JSValueConst val, JSValueC
|
|||||||
wota_stack_pop(enc);
|
wota_stack_pop(enc);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
cell_rt *crt = JS_GetContextOpaque(ctx);
|
||||||
|
JSValue adata = JS_GetProperty(ctx, replaced, crt->actor_sym);
|
||||||
|
if (!JS_IsUndefined(adata)) {
|
||||||
|
wota_write_sym(&enc->wb, WOTA_PRIVATE);
|
||||||
|
wota_encode_value(enc, adata, replaced, JS_UNDEFINED);
|
||||||
|
JS_FreeValue(ctx, adata);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
JS_FreeValue(ctx, adata);
|
||||||
if (wota_stack_has(enc, replaced)) {
|
if (wota_stack_has(enc, replaced)) {
|
||||||
enc->cycle = 1;
|
enc->cycle = 1;
|
||||||
break;
|
break;
|
||||||
@@ -201,7 +210,14 @@ static char *decode_wota_value(JSContext *ctx, char *data_ptr, JSValue *out_val,
|
|||||||
case WOTA_SYM: {
|
case WOTA_SYM: {
|
||||||
int scode;
|
int scode;
|
||||||
data_ptr = wota_read_sym(&scode, data_ptr);
|
data_ptr = wota_read_sym(&scode, data_ptr);
|
||||||
if (scode == WOTA_NULL) *out_val = JS_UNDEFINED;
|
if (scode == WOTA_PRIVATE) {
|
||||||
|
JSValue inner = JS_UNDEFINED;
|
||||||
|
data_ptr = decode_wota_value(ctx, data_ptr, &inner, holder, JS_UNDEFINED, reviver);
|
||||||
|
JSValue obj = JS_NewObject(ctx);
|
||||||
|
cell_rt *crt = JS_GetContextOpaque(ctx);
|
||||||
|
JS_SetProperty(ctx, obj, crt->actor_sym, inner);
|
||||||
|
*out_val = obj;
|
||||||
|
} else if (scode == WOTA_NULL) *out_val = JS_UNDEFINED;
|
||||||
else if (scode == WOTA_FALSE) *out_val = JS_NewBool(ctx, 0);
|
else if (scode == WOTA_FALSE) *out_val = JS_NewBool(ctx, 0);
|
||||||
else if (scode == WOTA_TRUE) *out_val = JS_NewBool(ctx, 1);
|
else if (scode == WOTA_TRUE) *out_val = JS_NewBool(ctx, 1);
|
||||||
else *out_val = JS_UNDEFINED;
|
else *out_val = JS_UNDEFINED;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
$_.start(e => {
|
$_.start(e => {
|
||||||
|
log.console("SENDING!")
|
||||||
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
send(e.actor, { message: "Hello! Good to go?" }, msg => {
|
||||||
log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
log.console(`Original sender got message back: ${json.encode(msg)}. Stopping!`)
|
||||||
$_.stop()
|
$_.stop()
|
||||||
|
|||||||
Reference in New Issue
Block a user