This repository was archived by the owner on Dec 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
chore: change impl for Deno.exit #11
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac9e2da
chore: change impl for Deno.exit
mocchira 860e532
fix: github workflows
mocchira dd46d46
fix: handle os_exit feature properly
mocchira 69c623d
refactor: retrieve js_error.message once
mocchira ae00526
refactor: remove unnecessary code block
mocchira bb8ed35
chore: add ci
mocchira b739dc3
refactor: remove redundant tests
mocchira 3f0e451
refactor: remove unused reason field
mocchira File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,39 @@ | ||
| use super::ExtensionTrait; | ||
| use deno_core::{extension, op2, Extension}; | ||
| use deno_core::{extension, op2, Extension, OpState}; | ||
| use std::rc::Rc; | ||
|
|
||
| /// Exit the process with the given exit code | ||
| /// A structure to store exit code in OpState when script exit is requested | ||
| #[derive(Clone, Debug)] | ||
| pub struct ScriptExitRequest { | ||
| pub code: i32, | ||
| } | ||
|
|
||
| /// Wrapper for V8 isolate handle that can be stored in OpState | ||
| #[derive(Clone)] | ||
| 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| #[op2(fast)] | ||
| fn op_rustyscript_exit(#[smi] code: i32) { | ||
| std::process::exit(code); | ||
| fn op_script_exit(state: &mut OpState, #[smi] code: i32) -> Result<(), crate::Error> { | ||
| // Store the exit request in OpState for retrieval after termination | ||
| let exit_request = ScriptExitRequest { code }; | ||
| state.put(exit_request); | ||
|
|
||
| // IMMEDIATE TERMINATION: Terminate V8 execution immediately | ||
| // This will stop ANY JavaScript execution, including infinite loops | ||
| if let Some(isolate_handle) = state.try_borrow::<V8IsolateHandle>() { | ||
| isolate_handle.0.terminate_execution(); | ||
| } | ||
|
|
||
| // Return Ok - the V8 termination will handle immediate stopping | ||
| Ok(()) | ||
| } | ||
|
|
||
| extension!( | ||
| init_os, | ||
| deps = [rustyscript], | ||
| ops = [op_rustyscript_exit], | ||
| ops = [op_script_exit], | ||
| esm_entry_point = "ext:init_os/init_os.js", | ||
| esm = [ dir "src/ext/os", "init_os.js" ], | ||
| ); | ||
|
|
||
Oops, something went wrong.
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.
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 と命名しています
Uh oh!
There was an error while loading. Please reload this page.
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 互換になることはないです。