Skip to content

fix: guard against proxy traps raising exceptions in REPL tokenizer #4457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 2, 2025

Conversation

Snehil-Shah
Copy link
Member

@Snehil-Shah Snehil-Shah commented Jan 2, 2025

Description

What is the purpose of this pull request?

This pull request:

  • Here's the updated behavior:
In [1]: var z = ndarray2fancy(ndempty([2,2]))
Out[1]: "ndarray( 'float64', new Float64Array( [ 0, 0, 0, 0 ] ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' )"

In [2]: z[':']
Error: invalid operation. Number of slice dimensions does not match the number of array dimensions. Array shape: (2,2). Slice dimensions: 1.

Typing z[':'] doesn't crash anything anymore as previously we were eagerly trying to evaluate the member expression, which ends up triggering proxy traps, crashing the REPL. Everything works as expected now, and you gracefully see the error after you press ENTER and actually run the statement.

Related Issues

Does this pull request have any related issues?

This pull request:

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

No.

Checklist

Please ensure the following tasks are completed before submitting this pull request.


@stdlib-js/reviewers

Signed-off-by: Snehil Shah <[email protected]>

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

Signed-off-by: Snehil Shah <[email protected]>

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@stdlib-bot stdlib-bot added REPL Issue or pull request specific to the project REPL. Needs Review A pull request which needs code review. labels Jan 2, 2025
@stdlib-bot
Copy link
Contributor

stdlib-bot commented Jan 2, 2025

Coverage Report

Package Statements Branches Functions Lines
repl $\color{red}11603/14393$
$\color{green}+80.62\%$
$\color{red}665/900$
$\color{green}+73.89\%$
$\color{red}153/266$
$\color{green}+57.52\%$
$\color{red}11603/14393$
$\color{green}+80.62\%$

The above coverage report was generated for the changes in this PR.

Signed-off-by: Snehil Shah <[email protected]>

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: passed
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
@Snehil-Shah
Copy link
Member Author

Snehil-Shah commented Jan 2, 2025

I'm not entirely sure if this is the best way to handle this..

Should I list object keys of the context and check if the prop exists in that, instead of checking if the property exists directly using the has method.

@Snehil-Shah Snehil-Shah marked this pull request as draft January 2, 2025 16:39
@stdlib-bot stdlib-bot removed the Needs Review A pull request which needs code review. label Jan 2, 2025
@Snehil-Shah Snehil-Shah marked this pull request as ready for review January 2, 2025 18:32
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label Jan 2, 2025
Copy link
Member

@kgryte kgryte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for submitting this patch, @Snehil-Shah!

@kgryte kgryte removed the Needs Review A pull request which needs code review. label Jan 2, 2025
@kgryte kgryte changed the title fix(repl): avoid falling into proxy traps in tokenizer fix: guard against proxy traps raising exceptions in REPL tokenizer Jan 2, 2025
@kgryte kgryte merged commit 2de9ed7 into stdlib-js:develop Jan 2, 2025
30 checks passed
Neerajpathak07 pushed a commit to Neerajpathak07/stdlib that referenced this pull request Jan 3, 2025
0PrashantYadav0 pushed a commit to 0PrashantYadav0/stdlib that referenced this pull request Jan 9, 2025
@Snehil-Shah Snehil-Shah deleted the dont-crash-tokenizer branch January 19, 2025 19:11
Neerajpathak07 pushed a commit to Neerajpathak07/stdlib that referenced this pull request Jan 23, 2025
Neerajpathak07 pushed a commit to Neerajpathak07/stdlib that referenced this pull request Feb 23, 2025
ShabiShett07 pushed a commit to ShabiShett07/stdlib that referenced this pull request Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Issue or pull request specific to the project REPL.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants