mirror of
https://github.com/denoland/deno.git
synced 2024-12-01 16:51:13 -05:00
Merge branch 'main' into support_create_connection
Signed-off-by: Yoshiya Hinosawa <stibium121@gmail.com>
This commit is contained in:
commit
d6af2c918c
8 changed files with 301 additions and 437 deletions
|
@ -264,6 +264,16 @@ fn napi_define_class<'s>(
|
|||
Err(status) => return status,
|
||||
};
|
||||
|
||||
let mut accessor_property = v8::PropertyAttribute::NONE;
|
||||
|
||||
if p.attributes & napi_enumerable == 0 {
|
||||
accessor_property = accessor_property | v8::PropertyAttribute::DONT_ENUM;
|
||||
}
|
||||
if p.attributes & napi_configurable == 0 {
|
||||
accessor_property =
|
||||
accessor_property | v8::PropertyAttribute::DONT_DELETE;
|
||||
}
|
||||
|
||||
if p.getter.is_some() || p.setter.is_some() {
|
||||
let getter = p.getter.map(|g| {
|
||||
create_function_template(&mut env.scope(), env_ptr, None, g, p.data)
|
||||
|
@ -271,8 +281,6 @@ fn napi_define_class<'s>(
|
|||
let setter = p.setter.map(|s| {
|
||||
create_function_template(&mut env.scope(), env_ptr, None, s, p.data)
|
||||
});
|
||||
|
||||
let mut accessor_property = v8::PropertyAttribute::NONE;
|
||||
if getter.is_some()
|
||||
&& setter.is_some()
|
||||
&& (p.attributes & napi_writable) == 0
|
||||
|
@ -280,15 +288,6 @@ fn napi_define_class<'s>(
|
|||
accessor_property =
|
||||
accessor_property | v8::PropertyAttribute::READ_ONLY;
|
||||
}
|
||||
if p.attributes & napi_enumerable == 0 {
|
||||
accessor_property =
|
||||
accessor_property | v8::PropertyAttribute::DONT_ENUM;
|
||||
}
|
||||
if p.attributes & napi_configurable == 0 {
|
||||
accessor_property =
|
||||
accessor_property | v8::PropertyAttribute::DONT_DELETE;
|
||||
}
|
||||
|
||||
let proto = tpl.prototype_template(&mut env.scope());
|
||||
proto.set_accessor_property(name, getter, setter, accessor_property);
|
||||
} else if let Some(method) = p.method {
|
||||
|
@ -300,10 +299,14 @@ fn napi_define_class<'s>(
|
|||
p.data,
|
||||
);
|
||||
let proto = tpl.prototype_template(&mut env.scope());
|
||||
proto.set(name, function.into());
|
||||
proto.set_with_attr(name, function.into(), accessor_property);
|
||||
} else {
|
||||
let proto = tpl.prototype_template(&mut env.scope());
|
||||
proto.set(name, p.value.unwrap().into());
|
||||
if (p.attributes & napi_writable) == 0 {
|
||||
accessor_property =
|
||||
accessor_property | v8::PropertyAttribute::READ_ONLY;
|
||||
}
|
||||
proto.set_with_attr(name, p.value.unwrap().into(), accessor_property);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,11 @@ import {
|
|||
ReadableStreamPrototype,
|
||||
resourceForReadableStream,
|
||||
} from "ext:deno_web/06_streams.js";
|
||||
import { listen, listenOptionApiName, TcpConn } from "ext:deno_net/01_net.js";
|
||||
import {
|
||||
listen,
|
||||
listenOptionApiName,
|
||||
UpgradedConn,
|
||||
} from "ext:deno_net/01_net.js";
|
||||
import { hasTlsKeyPairOptions, listenTls } from "ext:deno_net/02_tls.js";
|
||||
import { SymbolAsyncDispose } from "ext:deno_web/00_infra.js";
|
||||
|
||||
|
@ -189,7 +193,7 @@ class InnerRequest {
|
|||
|
||||
const upgradeRid = op_http_upgrade_raw(external);
|
||||
|
||||
const conn = new TcpConn(
|
||||
const conn = new UpgradedConn(
|
||||
upgradeRid,
|
||||
underlyingConn?.remoteAddr,
|
||||
underlyingConn?.localAddr,
|
||||
|
|
|
@ -194,6 +194,20 @@ class Conn {
|
|||
}
|
||||
}
|
||||
|
||||
class UpgradedConn extends Conn {
|
||||
#rid = 0;
|
||||
|
||||
constructor(rid, remoteAddr, localAddr) {
|
||||
super(rid, remoteAddr, localAddr);
|
||||
ObjectDefineProperty(this, internalRidSymbol, {
|
||||
__proto__: null,
|
||||
enumerable: false,
|
||||
value: rid,
|
||||
});
|
||||
this.#rid = rid;
|
||||
}
|
||||
}
|
||||
|
||||
class TcpConn extends Conn {
|
||||
#rid = 0;
|
||||
|
||||
|
@ -601,5 +615,6 @@ export {
|
|||
resolveDns,
|
||||
TcpConn,
|
||||
UnixConn,
|
||||
UpgradedConn,
|
||||
validatePort,
|
||||
};
|
||||
|
|
|
@ -66,7 +66,7 @@ import { getTimerDuration } from "ext:deno_node/internal/timers.mjs";
|
|||
import { serve, upgradeHttpRaw } from "ext:deno_http/00_serve.ts";
|
||||
import { headersEntries } from "ext:deno_fetch/20_headers.js";
|
||||
import { resourceForReadableStream } from "ext:deno_web/06_streams.js";
|
||||
import { TcpConn } from "ext:deno_net/01_net.js";
|
||||
import { UpgradedConn } from "ext:deno_net/01_net.js";
|
||||
import { STATUS_CODES } from "node:_http_server";
|
||||
import { methods as METHODS } from "node:_http_common";
|
||||
|
||||
|
@ -513,7 +513,7 @@ class ClientRequest extends OutgoingMessage {
|
|||
const upgradeRid = await op_node_http_fetch_response_upgrade(
|
||||
res.responseRid,
|
||||
);
|
||||
const conn = new TcpConn(
|
||||
const conn = new UpgradedConn(
|
||||
upgradeRid,
|
||||
{
|
||||
transport: "tcp",
|
||||
|
|
|
@ -304,7 +304,9 @@ export class TCP extends ConnectionWrap {
|
|||
* @return An error status code.
|
||||
*/
|
||||
setNoDelay(noDelay: boolean): number {
|
||||
this[kStreamBaseField].setNoDelay(noDelay);
|
||||
if ("setNoDelay" in this[kStreamBaseField]) {
|
||||
this[kStreamBaseField].setNoDelay(noDelay);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -147,438 +147,226 @@ impl Resource for SignalStreamResource {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGHUP" => Ok(1),
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGQUIT" => Ok(3),
|
||||
"SIGILL" => Ok(4),
|
||||
"SIGTRAP" => Ok(5),
|
||||
"SIGIOT" => Ok(6),
|
||||
"SIGABRT" => Ok(6),
|
||||
"SIGEMT" => Ok(7),
|
||||
"SIGFPE" => Ok(8),
|
||||
"SIGKILL" => Ok(9),
|
||||
"SIGBUS" => Ok(10),
|
||||
"SIGSEGV" => Ok(11),
|
||||
"SIGSYS" => Ok(12),
|
||||
"SIGPIPE" => Ok(13),
|
||||
"SIGALRM" => Ok(14),
|
||||
"SIGTERM" => Ok(15),
|
||||
"SIGURG" => Ok(16),
|
||||
"SIGSTOP" => Ok(17),
|
||||
"SIGTSTP" => Ok(18),
|
||||
"SIGCONT" => Ok(19),
|
||||
"SIGCHLD" => Ok(20),
|
||||
"SIGTTIN" => Ok(21),
|
||||
"SIGTTOU" => Ok(22),
|
||||
"SIGIO" => Ok(23),
|
||||
"SIGXCPU" => Ok(24),
|
||||
"SIGXFSZ" => Ok(25),
|
||||
"SIGVTALRM" => Ok(26),
|
||||
"SIGPROF" => Ok(27),
|
||||
"SIGWINCH" => Ok(28),
|
||||
"SIGINFO" => Ok(29),
|
||||
"SIGUSR1" => Ok(30),
|
||||
"SIGUSR2" => Ok(31),
|
||||
"SIGTHR" => Ok(32),
|
||||
"SIGLIBRT" => Ok(33),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
macro_rules! first_literal {
|
||||
($head:literal $(, $tail:literal)*) => {
|
||||
$head
|
||||
};
|
||||
}
|
||||
macro_rules! signal_dict {
|
||||
($error_msg:expr, $(($number:literal, $($name:literal)|+)),*) => {
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
$($($name)|* => Ok($number),)*
|
||||
_ => Err(type_error($error_msg(s))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
$($number => Ok(first_literal!($($name),+)),)*
|
||||
_ => Err(type_error($error_msg(s))),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "freebsd")]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
1 => Ok("SIGHUP"),
|
||||
2 => Ok("SIGINT"),
|
||||
3 => Ok("SIGQUIT"),
|
||||
4 => Ok("SIGILL"),
|
||||
5 => Ok("SIGTRAP"),
|
||||
6 => Ok("SIGABRT"),
|
||||
7 => Ok("SIGEMT"),
|
||||
8 => Ok("SIGFPE"),
|
||||
9 => Ok("SIGKILL"),
|
||||
10 => Ok("SIGBUS"),
|
||||
11 => Ok("SIGSEGV"),
|
||||
12 => Ok("SIGSYS"),
|
||||
13 => Ok("SIGPIPE"),
|
||||
14 => Ok("SIGALRM"),
|
||||
15 => Ok("SIGTERM"),
|
||||
16 => Ok("SIGURG"),
|
||||
17 => Ok("SIGSTOP"),
|
||||
18 => Ok("SIGTSTP"),
|
||||
19 => Ok("SIGCONT"),
|
||||
20 => Ok("SIGCHLD"),
|
||||
21 => Ok("SIGTTIN"),
|
||||
22 => Ok("SIGTTOU"),
|
||||
23 => Ok("SIGIO"),
|
||||
24 => Ok("SIGXCPU"),
|
||||
25 => Ok("SIGXFSZ"),
|
||||
26 => Ok("SIGVTALRM"),
|
||||
27 => Ok("SIGPROF"),
|
||||
28 => Ok("SIGWINCH"),
|
||||
29 => Ok("SIGINFO"),
|
||||
30 => Ok("SIGUSR1"),
|
||||
31 => Ok("SIGUSR2"),
|
||||
32 => Ok("SIGTHR"),
|
||||
33 => Ok("SIGLIBRT"),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|s| { format!("Invalid signal : {}", s) },
|
||||
(1, "SIGHUP"),
|
||||
(2, "SIGINT"),
|
||||
(3, "SIGQUIT"),
|
||||
(4, "SIGILL"),
|
||||
(5, "SIGTRAP"),
|
||||
(6, "SIGABRT" | "SIGIOT"),
|
||||
(7, "SIGEMT"),
|
||||
(8, "SIGFPE"),
|
||||
(9, "SIGKILL"),
|
||||
(10, "SIGBUS"),
|
||||
(11, "SIGSEGV"),
|
||||
(12, "SIGSYS"),
|
||||
(13, "SIGPIPE"),
|
||||
(14, "SIGALRM"),
|
||||
(15, "SIGTERM"),
|
||||
(16, "SIGURG"),
|
||||
(17, "SIGSTOP"),
|
||||
(18, "SIGTSTP"),
|
||||
(19, "SIGCONT"),
|
||||
(20, "SIGCHLD"),
|
||||
(21, "SIGTTIN"),
|
||||
(22, "SIGTTOU"),
|
||||
(23, "SIGIO"),
|
||||
(24, "SIGXCPU"),
|
||||
(25, "SIGXFSZ"),
|
||||
(26, "SIGVTALRM"),
|
||||
(27, "SIGPROF"),
|
||||
(28, "SIGWINCH"),
|
||||
(29, "SIGINFO"),
|
||||
(30, "SIGUSR1"),
|
||||
(31, "SIGUSR2"),
|
||||
(32, "SIGTHR"),
|
||||
(33, "SIGLIBRT")
|
||||
);
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGHUP" => Ok(1),
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGQUIT" => Ok(3),
|
||||
"SIGILL" => Ok(4),
|
||||
"SIGTRAP" => Ok(5),
|
||||
"SIGIOT" => Ok(6),
|
||||
"SIGABRT" => Ok(6),
|
||||
"SIGEMT" => Ok(7),
|
||||
"SIGFPE" => Ok(8),
|
||||
"SIGKILL" => Ok(9),
|
||||
"SIGBUS" => Ok(10),
|
||||
"SIGSEGV" => Ok(11),
|
||||
"SIGSYS" => Ok(12),
|
||||
"SIGPIPE" => Ok(13),
|
||||
"SIGALRM" => Ok(14),
|
||||
"SIGTERM" => Ok(15),
|
||||
"SIGURG" => Ok(16),
|
||||
"SIGSTOP" => Ok(17),
|
||||
"SIGTSTP" => Ok(18),
|
||||
"SIGCONT" => Ok(19),
|
||||
"SIGCHLD" => Ok(20),
|
||||
"SIGTTIN" => Ok(21),
|
||||
"SIGTTOU" => Ok(22),
|
||||
"SIGIO" => Ok(23),
|
||||
"SIGXCPU" => Ok(24),
|
||||
"SIGXFSZ" => Ok(25),
|
||||
"SIGVTALRM" => Ok(26),
|
||||
"SIGPROF" => Ok(27),
|
||||
"SIGWINCH" => Ok(28),
|
||||
"SIGINFO" => Ok(29),
|
||||
"SIGUSR1" => Ok(30),
|
||||
"SIGUSR2" => Ok(31),
|
||||
"SIGTHR" => Ok(32),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
1 => Ok("SIGHUP"),
|
||||
2 => Ok("SIGINT"),
|
||||
3 => Ok("SIGQUIT"),
|
||||
4 => Ok("SIGILL"),
|
||||
5 => Ok("SIGTRAP"),
|
||||
6 => Ok("SIGABRT"),
|
||||
7 => Ok("SIGEMT"),
|
||||
8 => Ok("SIGFPE"),
|
||||
9 => Ok("SIGKILL"),
|
||||
10 => Ok("SIGBUS"),
|
||||
11 => Ok("SIGSEGV"),
|
||||
12 => Ok("SIGSYS"),
|
||||
13 => Ok("SIGPIPE"),
|
||||
14 => Ok("SIGALRM"),
|
||||
15 => Ok("SIGTERM"),
|
||||
16 => Ok("SIGURG"),
|
||||
17 => Ok("SIGSTOP"),
|
||||
18 => Ok("SIGTSTP"),
|
||||
19 => Ok("SIGCONT"),
|
||||
20 => Ok("SIGCHLD"),
|
||||
21 => Ok("SIGTTIN"),
|
||||
22 => Ok("SIGTTOU"),
|
||||
23 => Ok("SIGIO"),
|
||||
24 => Ok("SIGXCPU"),
|
||||
25 => Ok("SIGXFSZ"),
|
||||
26 => Ok("SIGVTALRM"),
|
||||
27 => Ok("SIGPROF"),
|
||||
28 => Ok("SIGWINCH"),
|
||||
29 => Ok("SIGINFO"),
|
||||
30 => Ok("SIGUSR1"),
|
||||
31 => Ok("SIGUSR2"),
|
||||
32 => Ok("SIGTHR"),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|s| { format!("Invalid signal : {}", s) },
|
||||
(1, "SIGHUP"),
|
||||
(2, "SIGINT"),
|
||||
(3, "SIGQUIT"),
|
||||
(4, "SIGILL"),
|
||||
(5, "SIGTRAP"),
|
||||
(6, "SIGABRT" | "SIGIOT"),
|
||||
(7, "SIGEMT"),
|
||||
(8, "SIGKILL"),
|
||||
(10, "SIGBUS"),
|
||||
(11, "SIGSEGV"),
|
||||
(12, "SIGSYS"),
|
||||
(13, "SIGPIPE"),
|
||||
(14, "SIGALRM"),
|
||||
(15, "SIGTERM"),
|
||||
(16, "SIGURG"),
|
||||
(17, "SIGSTOP"),
|
||||
(18, "SIGTSTP"),
|
||||
(19, "SIGCONT"),
|
||||
(20, "SIGCHLD"),
|
||||
(21, "SIGTTIN"),
|
||||
(22, "SIGTTOU"),
|
||||
(23, "SIGIO"),
|
||||
(24, "SIGXCPU"),
|
||||
(25, "SIGXFSZ"),
|
||||
(26, "SIGVTALRM"),
|
||||
(27, "SIGPROF"),
|
||||
(28, "SIGWINCH"),
|
||||
(29, "SIGINFO"),
|
||||
(30, "SIGUSR1"),
|
||||
(31, "SIGUSR2"),
|
||||
(32, "SIGTHR")
|
||||
);
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGHUP" => Ok(1),
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGQUIT" => Ok(3),
|
||||
"SIGILL" => Ok(4),
|
||||
"SIGTRAP" => Ok(5),
|
||||
"SIGIOT" => Ok(6),
|
||||
"SIGABRT" => Ok(6),
|
||||
"SIGBUS" => Ok(7),
|
||||
"SIGFPE" => Ok(8),
|
||||
"SIGKILL" => Ok(9),
|
||||
"SIGUSR1" => Ok(10),
|
||||
"SIGSEGV" => Ok(11),
|
||||
"SIGUSR2" => Ok(12),
|
||||
"SIGPIPE" => Ok(13),
|
||||
"SIGALRM" => Ok(14),
|
||||
"SIGTERM" => Ok(15),
|
||||
"SIGSTKFLT" => Ok(16),
|
||||
"SIGCHLD" => Ok(17),
|
||||
"SIGCONT" => Ok(18),
|
||||
"SIGSTOP" => Ok(19),
|
||||
"SIGTSTP" => Ok(20),
|
||||
"SIGTTIN" => Ok(21),
|
||||
"SIGTTOU" => Ok(22),
|
||||
"SIGURG" => Ok(23),
|
||||
"SIGXCPU" => Ok(24),
|
||||
"SIGXFSZ" => Ok(25),
|
||||
"SIGVTALRM" => Ok(26),
|
||||
"SIGPROF" => Ok(27),
|
||||
"SIGWINCH" => Ok(28),
|
||||
"SIGIO" | "SIGPOLL" => Ok(29),
|
||||
"SIGPWR" => Ok(30),
|
||||
"SIGSYS" | "SIGUNUSED" => Ok(31),
|
||||
_ => Err(type_error(format!("Invalid signal : {s}"))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "linux"))]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
1 => Ok("SIGHUP"),
|
||||
2 => Ok("SIGINT"),
|
||||
3 => Ok("SIGQUIT"),
|
||||
4 => Ok("SIGILL"),
|
||||
5 => Ok("SIGTRAP"),
|
||||
6 => Ok("SIGABRT"),
|
||||
7 => Ok("SIGBUS"),
|
||||
8 => Ok("SIGFPE"),
|
||||
9 => Ok("SIGKILL"),
|
||||
10 => Ok("SIGUSR1"),
|
||||
11 => Ok("SIGSEGV"),
|
||||
12 => Ok("SIGUSR2"),
|
||||
13 => Ok("SIGPIPE"),
|
||||
14 => Ok("SIGALRM"),
|
||||
15 => Ok("SIGTERM"),
|
||||
16 => Ok("SIGSTKFLT"),
|
||||
17 => Ok("SIGCHLD"),
|
||||
18 => Ok("SIGCONT"),
|
||||
19 => Ok("SIGSTOP"),
|
||||
20 => Ok("SIGTSTP"),
|
||||
21 => Ok("SIGTTIN"),
|
||||
22 => Ok("SIGTTOU"),
|
||||
23 => Ok("SIGURG"),
|
||||
24 => Ok("SIGXCPU"),
|
||||
25 => Ok("SIGXFSZ"),
|
||||
26 => Ok("SIGVTALRM"),
|
||||
27 => Ok("SIGPROF"),
|
||||
28 => Ok("SIGWINCH"),
|
||||
29 => Ok("SIGIO"),
|
||||
30 => Ok("SIGPWR"),
|
||||
31 => Ok("SIGSYS"),
|
||||
_ => Err(type_error(format!("Invalid signal : {s}"))),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|s| { format!("Invalid signal : {s}") },
|
||||
(1, "SIGHUP"),
|
||||
(2, "SIGINT"),
|
||||
(3, "SIGQUIT"),
|
||||
(4, "SIGILL"),
|
||||
(5, "SIGTRAP"),
|
||||
(6, "SIGABRT" | "SIGIOT"),
|
||||
(7, "SIGBUS"),
|
||||
(8, "SIGFPE"),
|
||||
(9, "SIGKILL"),
|
||||
(10, "SIGUSR1"),
|
||||
(11, "SIGSEGV"),
|
||||
(12, "SIGUSR2"),
|
||||
(13, "SIGPIPE"),
|
||||
(14, "SIGALRM"),
|
||||
(15, "SIGTERM"),
|
||||
(16, "SIGSTKFLT"),
|
||||
(17, "SIGCHLD"),
|
||||
(18, "SIGCONT"),
|
||||
(19, "SIGSTOP"),
|
||||
(20, "SIGTSTP"),
|
||||
(21, "SIGTTIN"),
|
||||
(22, "SIGTTOU"),
|
||||
(23, "SIGURG"),
|
||||
(24, "SIGXCPU"),
|
||||
(25, "SIGXFSZ"),
|
||||
(26, "SIGVTALRM"),
|
||||
(27, "SIGPROF"),
|
||||
(28, "SIGWINCH"),
|
||||
(29, "SIGIO" | "SIGPOLL"),
|
||||
(30, "SIGPWR"),
|
||||
(31, "SIGSYS" | "SIGUNUSED")
|
||||
);
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGHUP" => Ok(1),
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGQUIT" => Ok(3),
|
||||
"SIGILL" => Ok(4),
|
||||
"SIGTRAP" => Ok(5),
|
||||
"SIGIOT" => Ok(6),
|
||||
"SIGABRT" => Ok(6),
|
||||
"SIGEMT" => Ok(7),
|
||||
"SIGFPE" => Ok(8),
|
||||
"SIGKILL" => Ok(9),
|
||||
"SIGBUS" => Ok(10),
|
||||
"SIGSEGV" => Ok(11),
|
||||
"SIGSYS" => Ok(12),
|
||||
"SIGPIPE" => Ok(13),
|
||||
"SIGALRM" => Ok(14),
|
||||
"SIGTERM" => Ok(15),
|
||||
"SIGURG" => Ok(16),
|
||||
"SIGSTOP" => Ok(17),
|
||||
"SIGTSTP" => Ok(18),
|
||||
"SIGCONT" => Ok(19),
|
||||
"SIGCHLD" => Ok(20),
|
||||
"SIGTTIN" => Ok(21),
|
||||
"SIGTTOU" => Ok(22),
|
||||
"SIGIO" => Ok(23),
|
||||
"SIGXCPU" => Ok(24),
|
||||
"SIGXFSZ" => Ok(25),
|
||||
"SIGVTALRM" => Ok(26),
|
||||
"SIGPROF" => Ok(27),
|
||||
"SIGWINCH" => Ok(28),
|
||||
"SIGINFO" => Ok(29),
|
||||
"SIGUSR1" => Ok(30),
|
||||
"SIGUSR2" => Ok(31),
|
||||
_ => Err(type_error(format!("Invalid signal: {s}"))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
1 => Ok("SIGHUP"),
|
||||
2 => Ok("SIGINT"),
|
||||
3 => Ok("SIGQUIT"),
|
||||
4 => Ok("SIGILL"),
|
||||
5 => Ok("SIGTRAP"),
|
||||
6 => Ok("SIGABRT"),
|
||||
7 => Ok("SIGEMT"),
|
||||
8 => Ok("SIGFPE"),
|
||||
9 => Ok("SIGKILL"),
|
||||
10 => Ok("SIGBUS"),
|
||||
11 => Ok("SIGSEGV"),
|
||||
12 => Ok("SIGSYS"),
|
||||
13 => Ok("SIGPIPE"),
|
||||
14 => Ok("SIGALRM"),
|
||||
15 => Ok("SIGTERM"),
|
||||
16 => Ok("SIGURG"),
|
||||
17 => Ok("SIGSTOP"),
|
||||
18 => Ok("SIGTSTP"),
|
||||
19 => Ok("SIGCONT"),
|
||||
20 => Ok("SIGCHLD"),
|
||||
21 => Ok("SIGTTIN"),
|
||||
22 => Ok("SIGTTOU"),
|
||||
23 => Ok("SIGIO"),
|
||||
24 => Ok("SIGXCPU"),
|
||||
25 => Ok("SIGXFSZ"),
|
||||
26 => Ok("SIGVTALRM"),
|
||||
27 => Ok("SIGPROF"),
|
||||
28 => Ok("SIGWINCH"),
|
||||
29 => Ok("SIGINFO"),
|
||||
30 => Ok("SIGUSR1"),
|
||||
31 => Ok("SIGUSR2"),
|
||||
_ => Err(type_error(format!("Invalid signal: {s}"))),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|s| { format!("Invalid signal : {s}") },
|
||||
(1, "SIGHUP"),
|
||||
(2, "SIGINT"),
|
||||
(3, "SIGQUIT"),
|
||||
(4, "SIGILL"),
|
||||
(5, "SIGTRAP"),
|
||||
(6, "SIGABRT" | "SIGIOT"),
|
||||
(7, "SIGEMT"),
|
||||
(8, "SIGFPE"),
|
||||
(9, "SIGKILL"),
|
||||
(10, "SIGBUS"),
|
||||
(11, "SIGSEGV"),
|
||||
(12, "SIGSYS"),
|
||||
(13, "SIGPIPE"),
|
||||
(14, "SIGALRM"),
|
||||
(15, "SIGTERM"),
|
||||
(16, "SIGURG"),
|
||||
(17, "SIGSTOP"),
|
||||
(18, "SIGTSTP"),
|
||||
(19, "SIGCONT"),
|
||||
(20, "SIGCHLD"),
|
||||
(21, "SIGTTIN"),
|
||||
(22, "SIGTTOU"),
|
||||
(23, "SIGIO"),
|
||||
(24, "SIGXCPU"),
|
||||
(25, "SIGXFSZ"),
|
||||
(26, "SIGVTALRM"),
|
||||
(27, "SIGPROF"),
|
||||
(28, "SIGWINCH"),
|
||||
(29, "SIGINFO"),
|
||||
(30, "SIGUSR1"),
|
||||
(31, "SIGUSR2")
|
||||
);
|
||||
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGHUP" => Ok(1),
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGQUIT" => Ok(3),
|
||||
"SIGILL" => Ok(4),
|
||||
"SIGTRAP" => Ok(5),
|
||||
"SIGIOT" => Ok(6),
|
||||
"SIGABRT" => Ok(6),
|
||||
"SIGEMT" => Ok(7),
|
||||
"SIGFPE" => Ok(8),
|
||||
"SIGKILL" => Ok(9),
|
||||
"SIGBUS" => Ok(10),
|
||||
"SIGSEGV" => Ok(11),
|
||||
"SIGSYS" => Ok(12),
|
||||
"SIGPIPE" => Ok(13),
|
||||
"SIGALRM" => Ok(14),
|
||||
"SIGTERM" => Ok(15),
|
||||
"SIGUSR1" => Ok(16),
|
||||
"SIGUSR2" => Ok(17),
|
||||
"SIGCLD" => Ok(18),
|
||||
"SIGCHLD" => Ok(18),
|
||||
"SIGPWR" => Ok(19),
|
||||
"SIGWINCH" => Ok(20),
|
||||
"SIGURG" => Ok(21),
|
||||
"SIGPOLL" => Ok(22),
|
||||
"SIGIO" => Ok(22),
|
||||
"SIGSTOP" => Ok(23),
|
||||
"SIGTSTP" => Ok(24),
|
||||
"SIGCONT" => Ok(25),
|
||||
"SIGTTIN" => Ok(26),
|
||||
"SIGTTOU" => Ok(27),
|
||||
"SIGVTALRM" => Ok(28),
|
||||
"SIGPROF" => Ok(29),
|
||||
"SIGXCPU" => Ok(30),
|
||||
"SIGXFSZ" => Ok(31),
|
||||
"SIGWAITING" => Ok(32),
|
||||
"SIGLWP" => Ok(33),
|
||||
"SIGFREEZE" => Ok(34),
|
||||
"SIGTHAW" => Ok(35),
|
||||
"SIGCANCEL" => Ok(36),
|
||||
"SIGLOST" => Ok(37),
|
||||
"SIGXRES" => Ok(38),
|
||||
"SIGJVM1" => Ok(39),
|
||||
"SIGJVM2" => Ok(40),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "solaris", target_os = "illumos"))]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
1 => Ok("SIGHUP"),
|
||||
2 => Ok("SIGINT"),
|
||||
3 => Ok("SIGQUIT"),
|
||||
4 => Ok("SIGILL"),
|
||||
5 => Ok("SIGTRAP"),
|
||||
6 => Ok("SIGABRT"),
|
||||
7 => Ok("SIGEMT"),
|
||||
8 => Ok("SIGFPE"),
|
||||
9 => Ok("SIGKILL"),
|
||||
10 => Ok("SIGBUS"),
|
||||
11 => Ok("SIGSEGV"),
|
||||
12 => Ok("SIGSYS"),
|
||||
13 => Ok("SIGPIPE"),
|
||||
14 => Ok("SIGALRM"),
|
||||
15 => Ok("SIGTERM"),
|
||||
16 => Ok("SIGUSR1"),
|
||||
17 => Ok("SIGUSR2"),
|
||||
18 => Ok("SIGCHLD"),
|
||||
19 => Ok("SIGPWR"),
|
||||
20 => Ok("SIGWINCH"),
|
||||
21 => Ok("SIGURG"),
|
||||
22 => Ok("SIGPOLL"),
|
||||
23 => Ok("SIGSTOP"),
|
||||
24 => Ok("SIGTSTP"),
|
||||
25 => Ok("SIGCONT"),
|
||||
26 => Ok("SIGTTIN"),
|
||||
27 => Ok("SIGTTOU"),
|
||||
28 => Ok("SIGVTALRM"),
|
||||
29 => Ok("SIGPROF"),
|
||||
30 => Ok("SIGXCPU"),
|
||||
31 => Ok("SIGXFSZ"),
|
||||
32 => Ok("SIGWAITING"),
|
||||
33 => Ok("SIGLWP"),
|
||||
34 => Ok("SIGFREEZE"),
|
||||
35 => Ok("SIGTHAW"),
|
||||
36 => Ok("SIGCANCEL"),
|
||||
37 => Ok("SIGLOST"),
|
||||
38 => Ok("SIGXRES"),
|
||||
39 => Ok("SIGJVM1"),
|
||||
40 => Ok("SIGJVM2"),
|
||||
_ => Err(type_error(format!("Invalid signal : {}", s))),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|s| { format!("Invalid signal : {s}") },
|
||||
(1, "SIGHUP"),
|
||||
(2, "SIGINT"),
|
||||
(3, "SIGQUIT"),
|
||||
(4, "SIGILL"),
|
||||
(5, "SIGTRAP"),
|
||||
(6, "SIGABRT" | "SIGIOT"),
|
||||
(7, "SIGEMT"),
|
||||
(8, "SIGFPE"),
|
||||
(9, "SIGKILL"),
|
||||
(10, "SIGBUS"),
|
||||
(11, "SIGSEGV"),
|
||||
(12, "SIGSYS"),
|
||||
(13, "SIGPIPE"),
|
||||
(14, "SIGALRM"),
|
||||
(15, "SIGTERM"),
|
||||
(16, "SIGUSR1"),
|
||||
(17, "SIGUSR2"),
|
||||
(18, "SIGCHLD"),
|
||||
(19, "SIGPWR"),
|
||||
(20, "SIGWINCH"),
|
||||
(21, "SIGURG"),
|
||||
(22, "SIGPOLL"),
|
||||
(23, "SIGSTOP"),
|
||||
(24, "SIGTSTP"),
|
||||
(25, "SIGCONT"),
|
||||
(26, "SIGTTIN"),
|
||||
(27, "SIGTTOU"),
|
||||
(28, "SIGVTALRM"),
|
||||
(29, "SIGPROF"),
|
||||
(30, "SIGXCPU"),
|
||||
(31, "SIGXFSZ"),
|
||||
(32, "SIGWAITING"),
|
||||
(33, "SIGLWP"),
|
||||
(34, "SIGFREEZE"),
|
||||
(35, "SIGTHAW"),
|
||||
(36, "SIGCANCEL"),
|
||||
(37, "SIGLOST"),
|
||||
(38, "SIGXRES"),
|
||||
(39, "SIGJVM1"),
|
||||
(40, "SIGJVM2")
|
||||
);
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> {
|
||||
match s {
|
||||
"SIGINT" => Ok(2),
|
||||
"SIGBREAK" => Ok(21),
|
||||
_ => Err(type_error(
|
||||
"Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
||||
match s {
|
||||
2 => Ok("SIGINT"),
|
||||
21 => Ok("SIGBREAK"),
|
||||
_ => Err(type_error(
|
||||
"Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK).",
|
||||
)),
|
||||
}
|
||||
}
|
||||
signal_dict!(
|
||||
|_| { "Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK)." },
|
||||
(2, "SIGINT"),
|
||||
(21, "SIGBREAK")
|
||||
);
|
||||
|
||||
#[cfg(unix)]
|
||||
#[op2(fast)]
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
import { assert, assertEquals, loadTestLibrary } from "./common.js";
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertThrows,
|
||||
loadTestLibrary,
|
||||
} from "./common.js";
|
||||
|
||||
const object = loadTestLibrary();
|
||||
|
||||
|
@ -12,4 +17,22 @@ Deno.test("napi object", function () {
|
|||
|
||||
const r1 = object.test_object_get(r);
|
||||
assert(r === r1);
|
||||
|
||||
const r2 = object.test_object_attr_property(r);
|
||||
assert(r === r2);
|
||||
assertThrows(
|
||||
() => {
|
||||
r2.self = "2";
|
||||
},
|
||||
Error,
|
||||
"Cannot assign to read only property 'self' of object '#<Object>'",
|
||||
);
|
||||
|
||||
assertThrows(
|
||||
() => {
|
||||
r2.method = () => {};
|
||||
},
|
||||
Error,
|
||||
"Cannot assign to read only property 'method' of object '#<Object>'",
|
||||
);
|
||||
});
|
||||
|
|
|
@ -40,10 +40,39 @@ extern "C" fn test_object_get(
|
|||
obj
|
||||
}
|
||||
|
||||
extern "C" fn test_object_attr_property(
|
||||
env: napi_env,
|
||||
info: napi_callback_info,
|
||||
) -> napi_value {
|
||||
let (args, argc, _) = napi_get_callback_info!(env, info, 1);
|
||||
assert_eq!(argc, 1);
|
||||
|
||||
let obj = args[0];
|
||||
let mut property = napi_new_property!(env, "self", test_object_new);
|
||||
property.attributes = PropertyAttributes::enumerable;
|
||||
property.method = None;
|
||||
property.value = obj;
|
||||
let mut method_property = napi_new_property!(env, "method", test_object_new);
|
||||
method_property.attributes = PropertyAttributes::enumerable;
|
||||
let properties = &[property, method_property];
|
||||
assert_napi_ok!(napi_define_properties(
|
||||
env,
|
||||
obj,
|
||||
properties.len(),
|
||||
properties.as_ptr()
|
||||
));
|
||||
obj
|
||||
}
|
||||
|
||||
pub fn init(env: napi_env, exports: napi_value) {
|
||||
let properties = &[
|
||||
napi_new_property!(env, "test_object_new", test_object_new),
|
||||
napi_new_property!(env, "test_object_get", test_object_get),
|
||||
napi_new_property!(
|
||||
env,
|
||||
"test_object_attr_property",
|
||||
test_object_attr_property
|
||||
),
|
||||
];
|
||||
|
||||
assert_napi_ok!(napi_define_properties(
|
||||
|
|
Loading…
Reference in a new issue