Compare commits
9 Commits
8cf98d8a9e
...
024d796ca4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
024d796ca4 | ||
|
|
ea185dbffd | ||
|
|
6571262af0 | ||
|
|
77ae133747 | ||
|
|
142a2d518b | ||
|
|
5b65c64fe5 | ||
|
|
e985fa5fe1 | ||
|
|
160ade2410 | ||
|
|
e2bc5948c1 |
@@ -574,7 +574,21 @@ int cell_init(int argc, char **argv)
|
||||
if (JS_IsException(result)) {
|
||||
JSValue exc = JS_GetException(ctx);
|
||||
const char *str = JS_ToCString(ctx, exc);
|
||||
if (str) { printf("Exception: %s\n", str); JS_FreeCString(ctx, str); }
|
||||
if (str) { printf("Error: %s\n", str); JS_FreeCString(ctx, str); }
|
||||
cJSON *stack = JS_GetStack(ctx);
|
||||
if (stack) {
|
||||
int n = cJSON_GetArraySize(stack);
|
||||
for (int i = 0; i < n; i++) {
|
||||
cJSON *fr = cJSON_GetArrayItem(stack, i);
|
||||
const char *fn = cJSON_GetStringValue(cJSON_GetObjectItem(fr, "function"));
|
||||
const char *file = cJSON_GetStringValue(cJSON_GetObjectItem(fr, "file"));
|
||||
int line = (int)cJSON_GetNumberValue(cJSON_GetObjectItem(fr, "line"));
|
||||
int col = (int)cJSON_GetNumberValue(cJSON_GetObjectItem(fr, "column"));
|
||||
printf(" at %s (%s:%d:%d)\n", fn ? fn : "<anonymous>", file ? file : "<unknown>", line, col);
|
||||
}
|
||||
cJSON_Delete(stack);
|
||||
}
|
||||
JS_FreeValue(ctx, exc);
|
||||
} else if (!JS_IsNull(result)) {
|
||||
const char *str = JS_ToCString(ctx, result);
|
||||
if (str) { printf("%s\n", str); JS_FreeCString(ctx, str); }
|
||||
@@ -716,6 +730,20 @@ int cell_init(int argc, char **argv)
|
||||
printf("Error: %s\n", err_str);
|
||||
JS_FreeCString(ctx, err_str);
|
||||
}
|
||||
cJSON *stack = JS_GetStack(ctx);
|
||||
if (stack) {
|
||||
int n = cJSON_GetArraySize(stack);
|
||||
for (int i = 0; i < n; i++) {
|
||||
cJSON *fr = cJSON_GetArrayItem(stack, i);
|
||||
const char *fn = cJSON_GetStringValue(cJSON_GetObjectItem(fr, "function"));
|
||||
const char *file = cJSON_GetStringValue(cJSON_GetObjectItem(fr, "file"));
|
||||
int line = (int)cJSON_GetNumberValue(cJSON_GetObjectItem(fr, "line"));
|
||||
int col = (int)cJSON_GetNumberValue(cJSON_GetObjectItem(fr, "column"));
|
||||
printf(" at %s (%s:%d:%d)\n", fn ? fn : "<anonymous>", file ? file : "<unknown>", line, col);
|
||||
}
|
||||
cJSON_Delete(stack);
|
||||
}
|
||||
JS_FreeValue(ctx, exc);
|
||||
exit_code = 1;
|
||||
} else if (!JS_IsNull(result)) {
|
||||
const char *str = JS_ToCString(ctx, result);
|
||||
|
||||
995
source/quickjs.c
995
source/quickjs.c
File diff suppressed because it is too large
Load Diff
@@ -1260,6 +1260,11 @@ char *JS_Mcode (const char *ast_json);
|
||||
Returns result of execution, or JS_EXCEPTION on error. */
|
||||
JSValue JS_CallMcode (JSContext *ctx, const char *mcode_json);
|
||||
|
||||
/* Get stack trace as cJSON array of frame objects.
|
||||
Returns NULL if no register VM frame is active.
|
||||
Caller must call cJSON_Delete() on the result. */
|
||||
struct cJSON *JS_GetStack (JSContext *ctx);
|
||||
|
||||
/* Integrate a CellModule with an environment and execute.
|
||||
Returns callable function value, or JS_EXCEPTION on error. */
|
||||
JSValue cell_module_integrate (JSContext *ctx, CellModule *mod, JSValue env);
|
||||
|
||||
39
tests/demo.ce
Normal file
39
tests/demo.ce
Normal file
@@ -0,0 +1,39 @@
|
||||
function safe_add(a, b) {
|
||||
return a + b
|
||||
} disruption {
|
||||
print("disruption caught in safe_add")
|
||||
}
|
||||
|
||||
function inner() {
|
||||
disrupt
|
||||
}
|
||||
|
||||
function outer() {
|
||||
inner()
|
||||
} disruption {
|
||||
print("disruption caught in outer — from inner()")
|
||||
}
|
||||
|
||||
// Test 1: explicit disrupt with handler
|
||||
function test_explicit() {
|
||||
disrupt
|
||||
} disruption {
|
||||
print("test 1: explicit disrupt handled")
|
||||
}
|
||||
test_explicit()
|
||||
|
||||
// Test 2: type error disrupt (number + function)
|
||||
safe_add(1, print)
|
||||
|
||||
// Test 3: unwinding — inner disrupts, outer catches
|
||||
outer()
|
||||
|
||||
// Test 4: disrupt from inside disruption clause
|
||||
function test_nested() {
|
||||
disrupt
|
||||
} disruption {
|
||||
print("test 4: first disruption")
|
||||
}
|
||||
test_nested()
|
||||
|
||||
print("done")
|
||||
@@ -252,29 +252,21 @@ loop: for (var m = 0; m < 3; m++) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- try/catch/finally ---
|
||||
var tc
|
||||
try {
|
||||
throw "error"
|
||||
} catch (e) {
|
||||
tc = e
|
||||
// --- disrupt and disruption ---
|
||||
function disrupt_test() {
|
||||
disrupt
|
||||
}
|
||||
|
||||
var tcf = 0
|
||||
try {
|
||||
throw "err"
|
||||
} catch (e) {
|
||||
tcf = 1
|
||||
} finally {
|
||||
tcf += 10
|
||||
function disruption_test() {
|
||||
var x = 1
|
||||
} disruption {
|
||||
var y = 2
|
||||
}
|
||||
|
||||
// --- try/finally (no catch) ---
|
||||
var tf = 0
|
||||
try {
|
||||
tf = 1
|
||||
} finally {
|
||||
tf += 1
|
||||
function disrupt_with_disruption() {
|
||||
disrupt
|
||||
} disruption {
|
||||
var handled = true
|
||||
}
|
||||
|
||||
// --- delete operator ---
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
try { 1 } catch(e) { 2 }
|
||||
@@ -1 +0,0 @@
|
||||
var x = 1; try { throw 0 } catch(e) { x = 2 } finally { x = x + 1 }; x
|
||||
@@ -1 +0,0 @@
|
||||
var x = 1; try { x = 2 } finally { x = 3 }; x
|
||||
@@ -1 +0,0 @@
|
||||
try { throw "err" } catch(e) { e }
|
||||
Reference in New Issue
Block a user