diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-03-08 15:37:28 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-03-08 19:18:58 +0100 |
commit | 330f7fec6858de97fe762c272ca499764bc6b02b (patch) | |
tree | 60d1a07314d2ac5cfe315b22f402f6aff0d8a472 /main.c | |
parent | 565e05204abf0706adafba68a49f5496d67d081e (diff) |
main: expose global prototype as `global` property on root scope
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -96,7 +96,7 @@ static int parse(uc_parse_config *config, uc_source *src, bool skip_shebang, json_object *env, json_object *modules) { - uc_prototype *globals = uc_prototype_new(NULL); + uc_prototype *globals = uc_prototype_new(NULL), *rootscope = NULL; uc_function *entry; uc_vm vm = {}; char c, c2, *err; @@ -143,7 +143,13 @@ parse(uc_parse_config *config, uc_source *src, /* load std functions into global scope */ uc_lib_init(globals); - rc = uc_vm_execute(&vm, entry, globals, modules); + /* create instance of global scope, set "global" property on it */ + rootscope = uc_protoref_new(xjs_new_object(), globals); + + json_object_object_add(rootscope->header.jso, "global", + uc_value_get(globals->header.jso)); + + rc = uc_vm_execute(&vm, entry, rootscope, modules); if (rc) { rc = 1; @@ -154,6 +160,9 @@ out: uc_vm_free(&vm); uc_value_put(globals->header.jso); + if (rootscope) + uc_value_put(rootscope->header.jso); + return rc; } |