From 245f69256b9e22f7759b887e82138ad3844a8cf4 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Mon, 31 Jan 2022 14:16:39 +0900 Subject: [PATCH] feat(runtime): stabilize addSignalListener API (#13438) --- cli/dts/lib.deno.ns.d.ts | 30 ++++++++++++++++++++++++++++++ cli/dts/lib.deno.unstable.d.ts | 34 ---------------------------------- runtime/js/90_deno_ns.js | 4 ++-- runtime/ops/signal.rs | 4 ---- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/cli/dts/lib.deno.ns.d.ts b/cli/dts/lib.deno.ns.d.ts index 3ff78106ea..f24e2fecac 100644 --- a/cli/dts/lib.deno.ns.d.ts +++ b/cli/dts/lib.deno.ns.d.ts @@ -2298,6 +2298,36 @@ declare namespace Deno { | "SIGXCPU" | "SIGXFSZ"; + /** Registers the given function as a listener of the given signal event. + * + * ```ts + * Deno.addSignalListener("SIGTERM", () => { + * console.log("SIGTERM!") + * }); + * ``` + * + * NOTE: This functionality is not yet implemented on Windows. + */ + export function addSignalListener(signal: Signal, handler: () => void): void; + + /** Removes the given signal listener that has been registered with + * Deno.addSignalListener. + * + * ```ts + * const listener = () => { + * console.log("SIGTERM!") + * }; + * Deno.addSignalListener("SIGTERM", listener); + * Deno.removeSignalListener("SIGTERM", listener); + * ``` + * + * NOTE: This functionality is not yet implemented on Windows. + */ + export function removeSignalListener( + signal: Signal, + handler: () => void, + ): void; + export type ProcessStatus = | { success: true; diff --git a/cli/dts/lib.deno.unstable.d.ts b/cli/dts/lib.deno.unstable.d.ts index c5a51ae36b..bc87ec02a2 100644 --- a/cli/dts/lib.deno.unstable.d.ts +++ b/cli/dts/lib.deno.unstable.d.ts @@ -741,40 +741,6 @@ declare namespace Deno { */ export function applySourceMap(location: Location): Location; - /** **UNSTABLE**: new API, yet to be vetted. - * - * Registers the given function as a listener of the given signal event. - * - * ```ts - * Deno.addSignalListener("SIGTERM", () => { - * console.log("SIGTERM!") - * }); - * ``` - * - * NOTE: This functionality is not yet implemented on Windows. - */ - export function addSignalListener(signal: Signal, handler: () => void): void; - - /** **UNSTABLE**: new API, yet to be vetted. - * - * Removes the given signal listener that has been registered with - * Deno.addSignalListener. - * - * ```ts - * const listener = () => { - * console.log("SIGTERM!") - * }; - * Deno.addSignalListener("SIGTERM", listener); - * Deno.removeSignalListener("SIGTERM", listener); - * ``` - * - * NOTE: This functionality is not yet implemented on Windows. - */ - export function removeSignalListener( - signal: Signal, - handler: () => void, - ): void; - export type SetRawOptions = { cbreak: boolean; }; diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 93e46b61e7..55cd349147 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -108,11 +108,11 @@ resolveDns: __bootstrap.net.resolveDns, upgradeWebSocket: __bootstrap.http.upgradeWebSocket, kill: __bootstrap.process.kill, + addSignalListener: __bootstrap.signals.addSignalListener, + removeSignalListener: __bootstrap.signals.removeSignalListener, }; __bootstrap.denoNsUnstable = { - addSignalListener: __bootstrap.signals.addSignalListener, - removeSignalListener: __bootstrap.signals.removeSignalListener, emit: __bootstrap.compilerApi.emit, setRaw: __bootstrap.tty.setRaw, consoleSize: __bootstrap.tty.consoleSize, diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 0fa5ba3e42..9511b83e23 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -179,7 +179,6 @@ fn op_signal_bind( sig: String, _: (), ) -> Result { - super::check_unstable(state, "Deno.signal"); let signo = signal_str_to_int(&sig)?; if signal_hook_registry::FORBIDDEN.contains(&signo) { return Err(type_error(format!( @@ -201,8 +200,6 @@ async fn op_signal_poll( rid: ResourceId, _: (), ) -> Result { - super::check_unstable2(&state, "Deno.signal"); - let resource = state .borrow_mut() .resource_table @@ -222,7 +219,6 @@ pub fn op_signal_unbind( rid: ResourceId, _: (), ) -> Result<(), AnyError> { - super::check_unstable(state, "Deno.signal"); state.resource_table.close(rid)?; Ok(()) }