Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5398b54
Update quickjs.c
G-Yong Dec 12, 2025
c1f2e00
Add operation changed handler and emit source locations
G-Yong Dec 12, 2025
9ed51a9
格式对其
G-Yong Dec 13, 2025
c0141e7
Fix comment formatting in quickjs.c
G-Yong Dec 13, 2025
acd4535
Fix comment formatting in quickjs.h
G-Yong Dec 13, 2025
39b5ce8
add `emit_source_loc(s) ` for `for` and `if`
G-Yong Dec 14, 2025
442ab63
remove `emit_source_loc` from `case` `default`; add it for `break`
G-Yong Dec 14, 2025
22d98ce
remove file's UTF8-BOM
G-Yong Dec 14, 2025
e449357
增加try catch finally 语句的位置跟踪语句
G-Yong Dec 15, 2025
942e9dd
Fix number literal parsing error handling (#1)
G-Yong Jan 27, 2026
2fd8274
Merge remote-tracking branch 'upstream/master'
G-Yong Jan 27, 2026
b644d17
Add debug API for stack frames and local variables
G-Yong Jan 31, 2026
564675e
Merge remote-tracking branch 'upstream/master'
G-Yong Jan 31, 2026
9948ffc
Merge branch 'quickjs-ng:master' into master
G-Yong Feb 2, 2026
c185571
fix TailCall's line and column number error.
G-Yong Feb 4, 2026
a009be9
Merge branch 'quickjs-ng:master' into master
G-Yong Feb 10, 2026
eb8981e
Merge branch 'quickjs-ng:master' into master
G-Yong Feb 12, 2026
b2531c8
Merge branch 'quickjs-ng:master' into master
G-Yong Feb 24, 2026
2227626
解决函数return语句后假如跟着while会导致得到错误的return行号的问题
G-Yong Mar 3, 2026
5faa3aa
Merge remote-tracking branch 'upstream/master'
G-Yong Mar 3, 2026
afc287f
Merge branch 'quickjs-ng:master' into master
G-Yong Mar 26, 2026
76aec02
Added a compile-time macro QJS_ENABLE_DEBUGGER to gate all the debug…
G-Yong Mar 28, 2026
fc71cbd
Merge remote-tracking branch 'upstream/master'
G-Yong Mar 28, 2026
6d4c96b
Refactor bytecode trace API and debug guards
G-Yong Mar 30, 2026
e1fc1be
Merge branch 'quickjs-ng:master' into master
G-Yong Mar 30, 2026
d98951d
Restore unexpected changes
G-Yong Mar 30, 2026
59e0422
Merge branch 'master' of https://github.com/G-Yong/quickjs
G-Yong Mar 30, 2026
9894306
Remove unnecessary macro definitions
G-Yong Mar 30, 2026
1e05bd7
Add per-context debugger with OP_debug
G-Yong Apr 1, 2026
abdf36c
Merge branch 'quickjs-ng:master' into master
G-Yong Apr 1, 2026
793ced2
Move DEF(debug) to end of opcode list to preserve opcode numbering (#2)
Copilot Apr 1, 2026
765fbf3
Use JS_AtomGetStr for debug break
G-Yong Apr 1, 2026
71b7ddf
Remove some modifications that are unnecessary under the current arch…
G-Yong Apr 1, 2026
6190ff1
Restore the things that were accidentally deleted earlier.
G-Yong Apr 1, 2026
9985cf7
Remove commented-out debug_break code
G-Yong Apr 1, 2026
219046a
Use unlikely() for debug_break check
G-Yong Apr 2, 2026
7e0a42d
Add JS_SetDebugBreakHandler and emit OP_debug
G-Yong Apr 2, 2026
4d34848
fix: do not update last_opcode_pos when emitting OP_debug (#3)
G-Yong Apr 2, 2026
16bb4d7
Rename debug break API to trace and bump BC
G-Yong Apr 2, 2026
87c3115
Merge branch 'quickjs-ng:master' into master
G-Yong Apr 2, 2026
c5a673a
Update api-test.c
G-Yong Apr 2, 2026
5d32778
Regenerate pre-compiled bytecode files (make codegen) to fix version …
Copilot Apr 3, 2026
b23207e
Merge branch 'quickjs-ng:master' into master
G-Yong Apr 3, 2026
1110f2c
Update quickjs-opcode.h
G-Yong Apr 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 125 additions & 0 deletions api-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,130 @@ static void get_uint8array(void)
JS_FreeRuntime(rt);
}

static struct {
int call_count;
int last_line;
int last_col;
char last_filename[256];
char last_funcname[256];
int stack_depth;
int max_local_count;
int abort_at; /* abort (return -1) on this call, 0 = never */
} trace_state;

static int debug_trace_cb(JSContext *ctx,
const char *filename,
const char *funcname,
int line,
int col)
{
trace_state.call_count++;
trace_state.last_line = line;
trace_state.last_col = col;
snprintf(trace_state.last_filename, sizeof(trace_state.last_filename),
"%s", filename);
snprintf(trace_state.last_funcname, sizeof(trace_state.last_funcname),
"%s", funcname);
trace_state.stack_depth = JS_GetStackDepth(ctx);
int count = 0;
JSDebugLocalVar *vars = JS_GetLocalVariablesAtLevel(ctx, 0, &count);
if (count > trace_state.max_local_count)
trace_state.max_local_count = count;
if (vars)
JS_FreeLocalVariables(ctx, vars, count);
if (trace_state.abort_at > 0 &&
trace_state.call_count >= trace_state.abort_at)
return -1;
return 0;
}

static void debug_trace(void)
{
JSRuntime *rt = JS_NewRuntime();
JSContext *ctx = JS_NewContext(rt);

/* no handler set: eval should work and call_count stays 0 */
memset(&trace_state, 0, sizeof(trace_state));
{
JSValue ret = eval(ctx, "1+2");
assert(!JS_IsException(ret));
JS_FreeValue(ctx, ret);
assert(trace_state.call_count == 0);
}

/* set handler: callback fires for each statement */
JS_SetDebugTraceHandler(ctx, debug_trace_cb);
memset(&trace_state, 0, sizeof(trace_state));
{
JSValue ret = eval(ctx, "var x = 1; x + 2");
assert(!JS_IsException(ret));
JS_FreeValue(ctx, ret);
assert(trace_state.call_count > 0);
assert(!strcmp(trace_state.last_filename, "<input>"));
}

/* stack depth inside a nested call */
memset(&trace_state, 0, sizeof(trace_state));
{
static const char code[] =
"function outer() {\n"
" function inner() {\n"
" return 42;\n"
" }\n"
" return inner();\n"
"}\n"
"outer();\n";
JSValue ret = eval(ctx, code);
assert(!JS_IsException(ret));
JS_FreeValue(ctx, ret);
assert(trace_state.call_count > 0);
/* the deepest invocation should have a stack depth > 1 */
/* (just verify we got a sane value; exact depth depends on internals) */
assert(trace_state.stack_depth >= 1);
}

/* local variables are visible inside the callback */
memset(&trace_state, 0, sizeof(trace_state));
{
static const char code[] =
"function f(a, b) {\n"
" var c = a + b;\n"
" return c;\n"
"}\n"
"f(10, 20);\n";
JSValue ret = eval(ctx, code);
assert(!JS_IsException(ret));
JS_FreeValue(ctx, ret);
assert(trace_state.call_count > 0);
/* inside f() we should see locals (a, b, c) at some point */
assert(trace_state.max_local_count >= 2);
}

/* returning non-zero aborts execution */
memset(&trace_state, 0, sizeof(trace_state));
trace_state.abort_at = 1; /* abort on first callback */
{
JSValue ret = eval(ctx, "1+2; 3+4");
assert(JS_IsException(ret));
JS_FreeValue(ctx, ret);
JSValue exc = JS_GetException(ctx);
JS_FreeValue(ctx, exc);
}

/* clear handler: callbacks no longer fire */
JS_SetDebugTraceHandler(ctx, NULL);
memset(&trace_state, 0, sizeof(trace_state));
{
JSValue ret = eval(ctx, "1+2");
assert(!JS_IsException(ret));
JS_FreeValue(ctx, ret);
assert(trace_state.call_count == 0);
}

JS_FreeContext(ctx);
JS_FreeRuntime(rt);
}

int main(void)
{
cfunctions();
Expand All @@ -981,5 +1105,6 @@ int main(void)
slice_string_tocstring();
immutable_array_buffer();
get_uint8array();
debug_trace();
return 0;
}
129 changes: 68 additions & 61 deletions builtin-array-fromasync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#include <inttypes.h>

const uint32_t qjsc_builtin_array_fromasync_size = 875;
const uint32_t qjsc_builtin_array_fromasync_size = 936;

const uint8_t qjsc_builtin_array_fromasync[875] = {
0x19, 0x26, 0x96, 0xb9, 0xe5, 0x0e, 0x01, 0x28,
const uint8_t qjsc_builtin_array_fromasync[936] = {
0x1a, 0xba, 0xbf, 0x06, 0x16, 0x0e, 0x01, 0x28,
0x53, 0x79, 0x6d, 0x62, 0x6f, 0x6c, 0xb7, 0x61,
0x73, 0x79, 0x6e, 0x63, 0x49, 0x74, 0x65, 0x72,
0x61, 0x74, 0x6f, 0x72, 0x01, 0x2a, 0x4f, 0x62,
Expand All @@ -27,15 +27,15 @@ const uint8_t qjsc_builtin_array_fromasync[875] = {
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x01, 0x08, 0x63,
0x61, 0x6c, 0x6c, 0x0c, 0x00, 0x02, 0x00, 0xa2,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01,
0x04, 0x01, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x0c,
0x06, 0x01, 0xa4, 0x01, 0x00, 0x00, 0x00, 0x0c,
0x43, 0x02, 0x01, 0x00, 0x05, 0x00, 0x05, 0x01,
0x05, 0x00, 0x01, 0x03, 0x05, 0xb0, 0x02, 0x00,
0x05, 0x00, 0x01, 0x06, 0x05, 0xb0, 0x02, 0x00,
0x01, 0x40, 0x03, 0xa6, 0x03, 0x00, 0x01, 0x40,
0x00, 0xcc, 0x03, 0x00, 0x01, 0x40, 0x01, 0xce,
0x03, 0x00, 0x01, 0x40, 0x04, 0xd0, 0x03, 0x00,
0x01, 0x40, 0x02, 0x0c, 0x60, 0x02, 0x01, 0xfa,
0x01, 0x03, 0x0e, 0x01, 0x06, 0x00, 0x05, 0x00,
0x86, 0x04, 0x11, 0xd2, 0x03, 0x00, 0x01, 0x00,
0xbe, 0x04, 0x11, 0xd2, 0x03, 0x00, 0x01, 0x00,
0xd4, 0x03, 0x00, 0x01, 0x00, 0xd6, 0x03, 0x00,
0x01, 0x00, 0xd2, 0x03, 0x01, 0xff, 0xff, 0xff,
0xff, 0x0f, 0x20, 0xd4, 0x03, 0x01, 0x01, 0x20,
Expand All @@ -55,65 +55,72 @@ const uint8_t qjsc_builtin_array_fromasync[875] = {
0xca, 0xd3, 0x11, 0xf2, 0xea, 0x08, 0x0e, 0x38,
0x46, 0x00, 0x00, 0x00, 0xdb, 0xcb, 0x60, 0x07,
0x00, 0x60, 0x06, 0x00, 0x60, 0x05, 0x00, 0x60,
0x04, 0x00, 0x60, 0x03, 0x00, 0xd2, 0x38, 0x46,
0x00, 0x00, 0x00, 0xae, 0xea, 0x16, 0xd2, 0x96,
0x04, 0x1b, 0x00, 0x00, 0x00, 0xae, 0xea, 0x0c,
0xdd, 0x11, 0x04, 0xf2, 0x00, 0x00, 0x00, 0x21,
0x01, 0x00, 0x30, 0x06, 0xcc, 0xb4, 0xc2, 0x04,
0xc1, 0x0d, 0xf5, 0xc2, 0x05, 0x09, 0xc2, 0x06,
0xd1, 0xde, 0x46, 0xc2, 0x07, 0x61, 0x07, 0x00,
0x07, 0xab, 0xea, 0x0f, 0x0a, 0x11, 0x62, 0x06,
0x00, 0x0e, 0xd1, 0xdf, 0x46, 0x11, 0x62, 0x07,
0x00, 0x0e, 0x61, 0x07, 0x00, 0x07, 0xab, 0x68,
0xa6, 0x00, 0x00, 0x00, 0x60, 0x08, 0x00, 0x06,
0x04, 0x00, 0x60, 0x03, 0x00, 0xf6, 0xd2, 0xf6,
0x38, 0x46, 0x00, 0x00, 0x00, 0xae, 0xea, 0x19,
0xd2, 0x96, 0xf6, 0x04, 0x1b, 0x00, 0x00, 0x00,
0xae, 0xea, 0x0e, 0xf6, 0xf6, 0xdd, 0x11, 0x04,
0xf2, 0x00, 0x00, 0x00, 0x21, 0x01, 0x00, 0x30,
0xf6, 0xf6, 0x06, 0xcc, 0xb4, 0xc2, 0x04, 0xc1,
0x0d, 0xf5, 0xc2, 0x05, 0xf6, 0xf6, 0x09, 0xc2,
0x06, 0xd1, 0xde, 0x46, 0xc2, 0x07, 0xf6, 0x61,
0x07, 0x00, 0xf6, 0x07, 0xab, 0xea, 0x10, 0xf6,
0x0a, 0x11, 0x62, 0x06, 0x00, 0x0e, 0xd1, 0xdf,
0x46, 0x11, 0x62, 0x07, 0x00, 0x0e, 0xf6, 0x61,
0x07, 0x00, 0xf6, 0x07, 0xab, 0x68, 0xb6, 0x00,
0x00, 0x00, 0x60, 0x08, 0x00, 0xf6, 0xf6, 0x06,
0x11, 0xf2, 0xeb, 0x0c, 0x6f, 0x41, 0x32, 0x00,
0x00, 0x00, 0xc2, 0x08, 0x0e, 0xec, 0x05, 0x0e,
0xd1, 0xec, 0xf2, 0x61, 0x08, 0x00, 0x8c, 0x11,
0xeb, 0x03, 0x0e, 0xb4, 0x11, 0x62, 0x08, 0x00,
0x0e, 0x61, 0x05, 0x00, 0xea, 0x0c, 0xc1, 0x0d,
0x11, 0x61, 0x08, 0x00, 0x21, 0x01, 0x00, 0xec,
0x06, 0xe0, 0x61, 0x08, 0x00, 0xef, 0x11, 0x62,
0x03, 0x00, 0x0e, 0x61, 0x04, 0x00, 0x61, 0x08,
0x00, 0xa5, 0x68, 0x2a, 0x01, 0x00, 0x00, 0x60,
0x09, 0x00, 0xd1, 0x61, 0x04, 0x00, 0x46, 0xc2,
0x09, 0x61, 0x06, 0x00, 0xea, 0x0a, 0x61, 0x09,
0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e, 0xd2,
0xea, 0x17, 0xd2, 0x41, 0xf3, 0x00, 0x00, 0x00,
0xd3, 0x61, 0x09, 0x00, 0x61, 0x04, 0x00, 0x24,
0x03, 0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e,
0x5d, 0x04, 0x00, 0x61, 0x03, 0x00, 0x61, 0x04,
0x00, 0x90, 0x62, 0x04, 0x00, 0x0b, 0x61, 0x09,
0x00, 0x4b, 0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x3e, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x3f, 0x00,
0x00, 0x00, 0xf1, 0x0e, 0xec, 0x9e, 0x60, 0x0a,
0x00, 0x61, 0x07, 0x00, 0x41, 0xf3, 0x00, 0x00,
0x00, 0xd1, 0x24, 0x01, 0x00, 0xc2, 0x0a, 0x61,
0x05, 0x00, 0xea, 0x09, 0xc1, 0x0d, 0x11, 0x21,
0x00, 0x00, 0xec, 0x03, 0xe0, 0xee, 0x11, 0x62,
0x03, 0x00, 0x0e, 0x6b, 0x8c, 0x00, 0x00, 0x00,
0x60, 0x0c, 0x00, 0x60, 0x0b, 0x00, 0x06, 0x11,
0xf2, 0xeb, 0x13, 0x6f, 0x41, 0x41, 0x00, 0x00,
0x00, 0xc2, 0x0b, 0x41, 0x6a, 0x00, 0x00, 0x00,
0xc2, 0x0c, 0x0e, 0xec, 0x10, 0x0e, 0x61, 0x0a,
0x00, 0x41, 0x6b, 0x00, 0x00, 0x00, 0x24, 0x00,
0x00, 0x8a, 0xec, 0xe0, 0x61, 0x0c, 0x00, 0xeb,
0x4e, 0x61, 0x06, 0x00, 0xea, 0x0a, 0x61, 0x0b,
0x00, 0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e, 0xd2,
0xea, 0x17, 0xd2, 0x41, 0xf3, 0x00, 0x00, 0x00,
0xd3, 0x61, 0x0b, 0x00, 0x61, 0x04, 0x00, 0x24,
0x03, 0x00, 0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e,
0x5d, 0x04, 0x00, 0x61, 0x03, 0x00, 0x61, 0x04,
0xd1, 0xec, 0xf2, 0xf6, 0x61, 0x08, 0x00, 0x8c,
0x11, 0xeb, 0x03, 0x0e, 0xb4, 0x11, 0x62, 0x08,
0x00, 0x0e, 0xf6, 0x61, 0x05, 0x00, 0xea, 0x0d,
0xf6, 0xc1, 0x0d, 0x11, 0x61, 0x08, 0x00, 0x21,
0x01, 0x00, 0xec, 0x07, 0xe0, 0xf6, 0x61, 0x08,
0x00, 0xef, 0x11, 0x62, 0x03, 0x00, 0x0e, 0x61,
0x04, 0x00, 0xf6, 0x61, 0x08, 0x00, 0xa5, 0x68,
0x4a, 0x01, 0x00, 0x00, 0x60, 0x09, 0x00, 0xf6,
0xf6, 0xd1, 0x61, 0x04, 0x00, 0x46, 0xc2, 0x09,
0xf6, 0x61, 0x06, 0x00, 0xea, 0x0b, 0xf6, 0x61,
0x09, 0x00, 0x8a, 0x11, 0x62, 0x09, 0x00, 0x0e,
0xf6, 0xd2, 0xea, 0x19, 0xf6, 0xd2, 0x41, 0xf3,
0x00, 0x00, 0x00, 0xf6, 0xd3, 0x61, 0x09, 0x00,
0x61, 0x04, 0x00, 0x24, 0x03, 0x00, 0x8a, 0x11,
0x62, 0x09, 0x00, 0x0e, 0xf6, 0x5d, 0x04, 0x00,
0xf6, 0x61, 0x03, 0x00, 0x61, 0x04, 0x00, 0x90,
0x62, 0x04, 0x00, 0x0b, 0x61, 0x09, 0x00, 0x4b,
0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x3e, 0x00,
0x00, 0x00, 0x0a, 0x4b, 0x3f, 0x00, 0x00, 0x00,
0xf1, 0x0e, 0xec, 0x94, 0x60, 0x0a, 0x00, 0xf6,
0xf6, 0x61, 0x07, 0x00, 0x41, 0xf3, 0x00, 0x00,
0x00, 0xf6, 0xd1, 0x24, 0x01, 0x00, 0xc2, 0x0a,
0xf6, 0x61, 0x05, 0x00, 0xea, 0x0a, 0xf6, 0xc1,
0x0d, 0x11, 0x21, 0x00, 0x00, 0xec, 0x04, 0xe0,
0xf6, 0xee, 0x11, 0x62, 0x03, 0x00, 0x0e, 0x6b,
0x99, 0x00, 0x00, 0x00, 0xf6, 0x60, 0x0c, 0x00,
0x60, 0x0b, 0x00, 0xf6, 0xf6, 0x06, 0x11, 0xf2,
0xeb, 0x13, 0x6f, 0x41, 0x41, 0x00, 0x00, 0x00,
0xc2, 0x0b, 0x41, 0x6a, 0x00, 0x00, 0x00, 0xc2,
0x0c, 0x0e, 0xec, 0x11, 0x0e, 0x61, 0x0a, 0x00,
0x41, 0x6b, 0x00, 0x00, 0x00, 0xf6, 0x24, 0x00,
0x00, 0x8a, 0xec, 0xdf, 0xf6, 0x61, 0x0c, 0x00,
0xeb, 0x56, 0xf6, 0x61, 0x06, 0x00, 0xea, 0x0b,
0xf6, 0x61, 0x0b, 0x00, 0x8a, 0x11, 0x62, 0x0b,
0x00, 0x0e, 0xf6, 0xd2, 0xea, 0x19, 0xf6, 0xd2,
0x41, 0xf3, 0x00, 0x00, 0x00, 0xf6, 0xd3, 0x61,
0x0b, 0x00, 0x61, 0x04, 0x00, 0x24, 0x03, 0x00,
0x8a, 0x11, 0x62, 0x0b, 0x00, 0x0e, 0xf6, 0x5d,
0x04, 0x00, 0xf6, 0x61, 0x03, 0x00, 0x61, 0x04,
0x00, 0x90, 0x62, 0x04, 0x00, 0x0b, 0x61, 0x0b,
0x00, 0x4b, 0x41, 0x00, 0x00, 0x00, 0x0a, 0x4b,
0x3e, 0x00, 0x00, 0x00, 0x0a, 0x4b, 0x3f, 0x00,
0x00, 0x00, 0xf1, 0x0e, 0xec, 0x83, 0x0e, 0x06,
0x6c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0xec, 0x1e,
0x6c, 0x05, 0x00, 0x00, 0x00, 0x30, 0x61, 0x0a,
0x00, 0x40, 0x06, 0x00, 0x00, 0x00, 0xea, 0x0d,
0x61, 0x0a, 0x00, 0x41, 0x06, 0x00, 0x00, 0x00,
0x24, 0x00, 0x00, 0x0e, 0x6d, 0x61, 0x03, 0x00,
0x61, 0x04, 0x00, 0x42, 0x32, 0x00, 0x00, 0x00,
0x61, 0x03, 0x00, 0x2f, 0xbf, 0x00, 0x28, 0xbf,
0x00, 0xcd, 0x28,
0x00, 0x00, 0xf1, 0x0e, 0xed, 0x78, 0xff, 0x0e,
0x06, 0x6c, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0xec,
0x22, 0x6c, 0x05, 0x00, 0x00, 0x00, 0x30, 0xf6,
0x61, 0x0a, 0x00, 0x40, 0x06, 0x00, 0x00, 0x00,
0xea, 0x0f, 0xf6, 0x61, 0x0a, 0x00, 0x41, 0x06,
0x00, 0x00, 0x00, 0xf6, 0x24, 0x00, 0x00, 0x0e,
0xf6, 0x6d, 0xf6, 0x61, 0x03, 0x00, 0x61, 0x04,
0x00, 0x42, 0x32, 0x00, 0x00, 0x00, 0xf6, 0x61,
0x03, 0x00, 0xf6, 0x2f, 0xf6, 0xf6, 0xbf, 0x00,
0xf6, 0x28, 0xf6, 0xbf, 0x00, 0xcd, 0xf6, 0x28,
};

Loading
Loading