Draft#1510
Closed
qr243vbi wants to merge 107 commits into
Closed
Conversation
Store the original file path in module_loader_opaque, let normalize function read from that and store a normalized filepath in context opaque, and make module loader read from the filepath from that. Make it possible to preserve the custom script name while resolving from another path.
添加位置变动(操作变动)回调接口,为外部实现调试功能实现可能
Introduces JS_SetOPChangedHandler to allow setting a callback for operation changes in the JSContext. Also adds calls to emit_source_loc in various statement parsing locations to improve source location tracking during parsing.
假如没有,位置跟踪会发生异常。
解决在函数内出现静态错误时,返回的堆栈信息中的列号错误的bug。
Introduces functions to get stack depth and retrieve local variables at a specific stack frame level, along with a struct for local variable info and a function to free the allocated array. Also updates the JSOPChangedHandler signature to include JSContext for improved debugging capabilities.
I wanted only library for djgpp.
Compiler installed from rpm packages.
Here is the build script:
// mes.sh
rm -rf /tmp/builddir_qjs
PREFIX=/opt/qjs
DESTDIR=$HOME/qjs
LIBRARY_PATH="$PREFIX/lib" \
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" \
C_INCLUDE_PATH="$PREFIX/include" \
CFLAGS="-O2 -I$PREFIX/include" \
CXXFLAGS="-O2 -I$PREFIX/include" \
LDFLAGS="-L$PREFIX/lib" \
meson setup /tmp/builddir_qjs --cross-file cross/linux-djgpp.ini \
-Dprefix=$PREFIX \
-Dexamples=disabled \
-Dlibc=false \
-Dtests=disabled \
-Dlibonly=true || exit 1
meson compile -C /tmp/builddir_qjs || exit 2
mkdir -p $DESTDIR
meson install -C /tmp/builddir_qjs --destdir $DESTDIR || exit 3
// linux-djgpp.ini
[binaries]
c = ['/usr/bin/i586-pc-msdosdjgpp-gcc', '-Wno-incompatible-pointer-types']
cpp = '/usr/bin/i586-pc-msdosdjgpp-g++'
objc = '/usr/bin/i586-pc-msdosdjgpp-gcc'
ar = '/usr/bin/i586-pc-msdosdjgpp-ar'
pkg-config = '/usr/bin/pkg-config'
strip = '/usr/bin/i586-pc-msdosdjgpp-strip'
exe_wrapper = '/bin/true'
ld = '/usr/bin/i586-pc-msdosdjgpp-ld'
cmake = '/usr/bin/cmake'
[properties]
root = '/usr/i586-pc-msdosdjgpp'
need_exe_wrapper = false
[host_machine]
system = 'dos'
cpu_family = 'x86'
cpu = 'i586'
endian = 'little'
[cmake]
CMAKE_BUILD_WITH_INSTALL_RPATH = 'ON'
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM = 'NEVER'
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY = 'ONLY'
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE = 'ONLY'
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE = 'ONLY'
-pthread cause errors
假如采用旧的代码,会发生下面的错误:
function add(a, b){
return a + b;
var b // OP_return会出现在这里
while(1){}
}
add(1, 2)
Rename the old operation_changed/JSOPChangedHandler to bytecode_trace/JSBytecodeTraceFunc and replace JS_SetOPChangedHandler with JS_SetBytecodeTraceHandler. Add conditional compilation guards so debugger-related code is compiled only when QJS_ENABLE_DEBUGGER is set (including stack depth, local-variable APIs, and freeing logic). Introduce emit_source_loc_debug no-op macro when debugger is disabled and make JS_GetStackDepth return -1 without the debugger. Update public header comments to reflect the new API and behavior.
The C API took a size_t len but passed it to js_alloc_string, whose length parameter is int. With len > INT_MAX (e.g. INT_MAX + 1), the cast truncated the value, producing either a tiny or negative-sized allocation while the subsequent memcpy(str16(str), buf, len * 2) wrote the full size_t length — heap overflow on misuse from C. Reject len > JS_STRING_LEN_MAX before allocating, matching the existing guard in JS_NewStringLen. Test: api-test now calls JS_NewStringUTF16(ctx, NULL, INT_MAX + 1) and asserts JS_IsException + the "invalid string length" error. Before the fix, the same call segfaults (or is caught by ASan as a heap-buffer-overflow).
api-test.c: - Align debug_trace_cb argument indentation with the opening parenthesis. - Update JS_GetLocalVariablesAtLevel call sites to the new signature (returns int, takes JSDebugLocalVar **pvars out parameter). - Add an out-of-callback test: calling JS_GetLocalVariablesAtLevel when no frame is active must succeed and set pvars=NULL, count=0. - Drop comments that merely restate what the code already says. quickjs-opcode.h: - Drop trailing inline comment on DEF(debug, ...). quickjs.c: - Move the JS_AtomGetStr forward declaration to the main forward- declaration block instead of placing it next to its first use. - Remove comments above js_get_stack_frame_at_level and JS_GetStackDepth that add no information beyond the function names. - Change JS_GetLocalVariablesAtLevel to return int (0 = ok, -1 = exception) and add a JSDebugLocalVar **pvars out parameter so callers can distinguish "no variables / no active frame" (returns 0, NULL) from a real OOM error (returns -1, exception pending). The OOM path no longer clears the pending exception so the caller can inspect it. - Pass true/false instead of 1/0 for the is_arg argument of APPEND_VAR. - Free the vars allocation when all entries were filtered out (idx==0) so the array is never returned with a zero count. - Extract emit_debug() from emit_source_loc_debug(). At the throw statement and the default expression-statement path, where emit_source_loc() is already called unconditionally, use emit_source_loc() + emit_debug() instead of emit_source_loc_debug() to avoid emitting a duplicate OP_source_loc opcode. quickjs.h: - Change JSDebugLocalVar::is_arg from int to bool. - Remove field comments that just restate the field names. - Update JS_GetLocalVariablesAtLevel declaration and its doc comment to match the new int-return / out-parameter contract.
Mochaa qjsc resolve
Feat/text encoder decoder
Fix/find var htab scope level
…-error fix(cutils): handle vsnprintf encoding error in dbuf_printf
…mcpy fix(libc): avoid undefined memcpy in js_worker_postMessage with len==0
…6-length fix(string): reject oversized len in JS_NewStringUTF16
fix(libc): correct privilege drop order and sentinel in js_os_exec
Fix column reporting for invalid number literals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some draft changes