module misty

This commit is contained in:
2025-01-19 14:28:09 -06:00
parent b4d1277a9d
commit 8e95fd2355
7 changed files with 41 additions and 72 deletions

View File

@@ -7359,12 +7359,14 @@ JSC_CCALL(rtree_insert,
JSValue v = argv[0];
rect r;
JS_GETATOM(js,r,v,rect_atom,rect)
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
JSValue *ins = malloc(sizeof(*ins));
*ins = JS_DupValue(js,v);
if (!rtree_insert(tree, min, max, ins)) {
@@ -7387,12 +7389,14 @@ JSC_CCALL(rtree_remove,
JSValue v = argv[0];
rect r;
JS_GETATOM(js,r,v,rect_atom,rect)
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
if (!rtree_delete_with_comparator(tree, min, max, &v, rtree_cmp, js))
return JS_ThrowOutOfMemory(js);
@@ -7421,12 +7425,14 @@ bool rtree_array_iter(const NUMTYPE *min, const NUMTYPE *max, const JSValue *dat
JSC_CCALL(rtree_query,
rtree *tree = js2rtree(js,self);
rect r = js2rect(js,argv[0]);
NUMTYPE min[2];
NUMTYPE max[2];
NUMTYPE min[3];
NUMTYPE max[3];
min[0] = r.x;
min[1] = r.y;
min[2] = 0;
max[0] = r.x+r.w;
max[1] = r.y+r.h;
max[2] = 0;
struct rtree_iter_data data = {0};
data.js = js;

View File

@@ -17,7 +17,6 @@ JSContext *global_js = NULL;
JSValue on_exception = JS_UNDEFINED;
#ifndef NDEBUG
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT
#else
@@ -82,7 +81,7 @@ void script_startup() {
char *eng = read_file("core/scripts/engine.js");
JSValue v = script_eval(js, "core/scripts/engine.js", eng);
JS_FreeValue(js, v);
uncaught_exception(js,v);
free(eng);
}
@@ -97,11 +96,20 @@ void script_stop()
void uncaught_exception(JSContext *js, JSValue v)
{
if (!JS_IsUndefined(on_exception) && JS_IsException(v)) {
if (!JS_IsException(v)) return;
if (!JS_IsUndefined(on_exception)) {
JSValue ex = JS_GetException(js);
JSValue ret = JS_Call(js, on_exception, JS_UNDEFINED, 1, &ex);
JS_FreeValue(js,ret);
JS_FreeValue(js,ex);
} else {
JSValue ex = JS_GetException(js);
JSValue stack = JS_GetPropertyStr(js,ex,"stack");
const char *st = JS_ToCString(js,stack);
printf("Unhandled exception:\n%s\n", st);
JS_FreeValue(js,stack);
JS_FreeValue(js,ex);
}
JS_FreeValue(js,v);