fix(path/string): path.format/relative arg validation + String.includes position#3498
Merged
Conversation
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.
Closes #2992
Closes #2995
Closes #2812
Implementation
#2992 — path.format argument validation + field coercion
js_path_format/js_path_win32_format(crates/perry-runtime/src/path.rs) now reimplement Node's_formatexactly via a sharedformat_descriptor(obj_f64, sep)helper:pathObjectis validated: a non-object (null,undefined, number, string, ...) throwsTypeError [ERR_INVALID_ARG_TYPE]with the"pathObject" argument must be of type objectmessage.dir,root,base,name,ext) are read with Node's||semantics: truthy values are ToString-coerced (js_jsvalue_to_string), falsy values (0,false,null,"") contribute nothing. Fixes the bug where a numericdirwas dropped ({dir:1, base:"b"}returned"b"instead of"1/b").dir = pathObject.dir || pathObject.root; the separator is omitted only whendir === pathObject.root. Removes the old dedup hacks that diverged from Node.The top-level object handle already reached the runtime as a NaN-boxed
f64, so no codegen change was needed forformat.#2995 — path.relative argument validation on the compiled path
Added validating entry points
js_path_relative_checked(from_f64, to_f64)/js_path_win32_relative_checkedthat receive the NaN-boxed operands, validate each is a string (throwingTypeError [ERR_INVALID_ARG_TYPE]namingfrom/to), then forward to the existing string-only helpers. The compiled lowerings (Expr::PathRelativeinarrays_finds.rs/instance_misc1.rs, andPathWin32Method::Relativesplit out of its shared arm) now pass the doubles to these checked wrappers instead of silently unboxing invalid pointers to"".#2812 — honor position in String.prototype.includes
The typed
includeslowering (crates/perry-codegen/src/lower_string_method.rs) now routes the optional second argument through the newjs_string_position_to_indexruntime helper (JS ToIntegerOrInfinity + clamp:NaN/-Infinity-> 0,+Infinity->i32::MAX, otherwise truncate/saturate) and callsjs_string_index_of_frominstead ofjs_string_index_of. This avoids LLVMfptosi's undefined result on non-finite inputs and matches Node ("ababa".includes("a", Infinity) === false). The second argument is still evaluated for side effects.New codegen-emitted
#[no_mangle]fns (js_path_relative_checked,js_path_win32_relative_checked,js_string_position_to_index) have#[used]keepalive anchors +runtime_declsdeclarations so the auto-optimize whole-program bitcode pass does not dead-strip them.No new HIR variant added.
Validation
test-files/test_gap_path_includes_2992_2995_2812.tsis byte-identical tonode --experimental-strip-typesunder the DEFAULT auto-optimize compile (covers all issue repro cases incl. err.name/message/code for throws).#[used]anchors verified present in the freshly-rebuiltlibperry_runtime.a(each symbol count == 1)../scripts/check_file_size.sh-> OK.cargo fmt --all -- --check-> clean.cargo test --release -p perry-runtime(path/string modules) andcargo test --release -p perry-hir-> green.