fix(function): preserve source text for toString#375
Conversation
|
Warning Review limit reached
More reviews will be available in 57 minutes and 49 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (29)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e3785541a9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let parser = Parser::new(tokens) | ||
| pub fn parse_tokens( | ||
| tokens : Array[@token.Token], | ||
| source? : String = "", |
There was a problem hiding this comment.
Do not slice an empty source in parse_tokens
parse_tokens still defaults source to "", but the new function/class AST paths call consume_source_text, which slices self.source using token offsets. Existing callers that only pass tokens, including the benchmark parse paths that call @parser.parse_tokens(tokens), will hit this for any tokenized program containing functions/classes and either abort on the out-of-range substring or attach bogus source text. Please require/provide the original source or make source capture optional when no source was supplied.
Useful? React with 👍 / 👎.
Benchmark ResultsRun: https://github.com/dowdiness/js_engine/actions/runs/27741321336
Stage summary
Focused bytecode base-vs-head comparison
Base-vs-head comparison
Mean-time chart (log scale)
Closure-conversion comparison
|
e378554 to
58fc5de
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c2731f8f0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e63a87e872
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| compile_ternary(cond, then_expr, else_expr) | ||
| FuncExpr(name, params, body, _) => compile_func_expr(name, params, body) | ||
| FuncExprExt(name, params, rest_param, body, _) => | ||
| FuncExpr(name, params, body, _, _) => compile_func_expr(name, params, body) |
There was a problem hiding this comment.
Preserve source text in compiled functions
When code runs through the public run_compiled / --closure-conversion path, the parser has already attached the new source_text field, but this branch discards it before building the compiled function. The compiled function is later represented as an InterpreterCallableWithContext with no [[SourceText]], so inputs like run_compiled("console.log((function f(){}).toString())") still print a [native code] fallback instead of the parsed source, unlike the normal interpreter path. Thread the source text through the compiled function/arrow/declaration helpers so the two execution modes stay aligned.
Useful? React with 👍 / 👎.
Summary
Function.prototype.toStringfor parsed user functions/classes where available, while keeping native fallback handling.) {.parse_tokens, hoisted generator/async declaration source-text threading, and source-derived token end offsets for regex/template/escaped identifier captures.Refs #310.
Validation
moon checkmoon test— 2106 passed, 0 failedmoon fmt && moon checkmoon infomoon test parser --filter '*parse_tokens*'moon test interpreter --filter '*Function.prototype.toString*'NEW_MOON_MOD=0 make test262-filter FILTER=Function/prototype/toStringNotes
This reduces the Function/prototype/toString filter from the previous 108 aggregate failures to 22 aggregate failures. Remaining failures are mostly NativeFunction matcher/native formatting gaps for bound/proxy/symbol-named builtins.