-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: change impl for Deno.exit #11
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements a new approach for Deno.exit() functionality that provides controlled script termination instead of dangerous process exit. The change replaces the previous implementation that used std::process::exit() with a V8 isolate termination mechanism that stops JavaScript execution immediately while keeping the runtime alive.
- Replaces dangerous
std::process::exit()with controlled V8 isolate termination - Adds comprehensive exit request handling and runtime state management
- Introduces extensive test coverage for various exit scenarios including infinite loops
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/op_whitelist.js | Updates operation name from op_rustyscript_exit to op_script_exit |
| src/inner_runtime.rs | Adds V8 isolate handle storage and script exit handling logic throughout runtime operations |
| src/ext/os/mod.rs | Replaces process exit with V8 termination mechanism using OpState for exit requests |
| src/ext/os/init_os.js | Updates JavaScript implementation to use new operation and adds unload event dispatch |
| src/ext/os/test.rs | Adds comprehensive tests for script termination scenarios |
| src/error.rs | Introduces new ScriptExit error variant with helper methods |
| examples/os_exit.rs | Expands example with extensive testing of exit scenarios and zero-tolerance validation |
Comments suppressed due to low confidence (2)
src/ext/os/test.rs:21
- The parameter validation test has been weakened significantly. The new test only checks function.length instead of actually validating that invalid parameters are rejected, which reduces test coverage for error handling.
// Test parameter validation by checking function signature
src/ext/os/test.rs:28
- This test accepts both 0 and 1 parameters as valid, but doesn't verify the actual parameter validation logic in the implementation. Consider testing the actual validation behavior in a controlled way.
param_validation = Deno.exit.length === 1 || Deno.exit.length === 0;
e7791b6 to
69c623d
Compare
| } | ||
|
|
||
| println!("Success! The os_exit feature is working correctly."); | ||
| println!("JavaScript code now has access to Deno.exit() for script termination."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ランタイム自体が Deno と互換性がある状態なので Node 互換の os.exit ではなく Deno.exit と命名しています
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
質問です。Deno.exit という名前は露出はしないという認識ですがあっていますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ドキュメント上では露出しませんが、呼び出し自体は可能です。
スクリプトを終了させるだけなので、仮に呼び出し可能とわかってもセキュリティ的に問題はない認識です。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Deno" という固有名詞が入っても問題ないかどうか気になったのでした。
仮にランタイムがNode.jsになった場合 "Node.exit" にする必要がでそうだと思ったのですが合っていますか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deno_core に依存しているので && Node 互換の JS ランタイム ラッパーが rust に存在いないので、今後ランタイムが Node 互換になることはないです。
| pub struct V8IsolateHandle(pub Rc<deno_core::v8::IsolateHandle>); | ||
|
|
||
| /// Request script termination with the given exit code (replaces dangerous std::process::exit) | ||
| /// This terminates V8 execution immediately for zero-tolerance termination |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここがメインです
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::process::exit(code); の利用から変更した。なるほど!
k1LoW
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
| pub struct V8IsolateHandle(pub Rc<deno_core::v8::IsolateHandle>); | ||
|
|
||
| /// Request script termination with the given exit code (replaces dangerous std::process::exit) | ||
| /// This terminates V8 execution immediately for zero-tolerance termination |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::process::exit(code); の利用から変更した。なるほど!
remiposo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Q]
-
Sorry for the basic question, but what was the reason we can't use deno_os's exit implementation?
https://github.com/denoland/deno/blob/5612d2edc7262d7bfb3bcfb0f18649b01ec94b53/ext/os/30_os.js#L77-L99 -
The
reasonparameter doesn't seem to be used - is it necessary?
こちら最終的には std::process::exit(code); を呼んでいて OS プロセス自体を終了させてしまうため、今回の用途( Rust 側にコントロールを返す)には適していませんでした。
これはデバッグ時の消し忘れですね! |
|
お二方レビューありがとうございました! |
No description provided.