mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 16:49:18 -05:00
feat(ops): reland fast zero copy string arguments (#17996)
Reland https://github.com/denoland/deno/pull/16777 The codegen is disabled in async ops and when fallback to slow call is possible (return type is a Result) to avoid hitting this V8 bug: https://github.com/denoland/deno/issues/17159
This commit is contained in:
parent
64503fabd8
commit
38555a6a0f
36 changed files with 778 additions and 94 deletions
|
@ -1,8 +1,3 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
const count = 100000;
|
||||
|
||||
const start = Date.now();
|
||||
for (let i = 0; i < count; i++) console.log("Hello World");
|
||||
const elapsed = Date.now() - start;
|
||||
const rate = Math.floor(count / (elapsed / 1000));
|
||||
console.log(`time ${elapsed} ms rate ${rate}`);
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
const queueMicrotask = globalThis.queueMicrotask || process.nextTick;
|
||||
let [total, count] = typeof Deno !== "undefined"
|
||||
? Deno.args
|
||||
: [process.argv[2], process.argv[3]];
|
||||
|
||||
total = total ? parseInt(total, 0) : 50;
|
||||
count = count ? parseInt(count, 10) : 1000000;
|
||||
count = count ? parseInt(count, 10) : 10000000;
|
||||
|
||||
function bench(fun) {
|
||||
const start = Date.now();
|
||||
|
@ -13,7 +12,7 @@ function bench(fun) {
|
|||
const elapsed = Date.now() - start;
|
||||
const rate = Math.floor(count / (elapsed / 1000));
|
||||
console.log(`time ${elapsed} ms rate ${rate}`);
|
||||
if (--total) queueMicrotask(() => bench(fun));
|
||||
if (--total) bench(fun);
|
||||
}
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
|
21
cli/bench/webstorage.js
Normal file
21
cli/bench/webstorage.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
// Note: when benchmarking across different Deno version, make sure to clear
|
||||
// the DENO_DIR cache.
|
||||
let [total, count] = typeof Deno !== "undefined" ? Deno.args : [];
|
||||
|
||||
total = total ? parseInt(total, 0) : 50;
|
||||
count = count ? parseInt(count, 10) : 1000000;
|
||||
|
||||
function bench(fun) {
|
||||
const start = Date.now();
|
||||
for (let i = 0; i < count; i++) fun(i);
|
||||
const elapsed = Date.now() - start;
|
||||
const rate = Math.floor(count / (elapsed / 1000));
|
||||
console.log(`time ${elapsed} ms rate ${rate}`);
|
||||
if (--total) queueMicrotask(() => bench(fun));
|
||||
}
|
||||
|
||||
localStorage.clear();
|
||||
localStorage.setItem("foo", "bar");
|
||||
bench(() => localStorage.getItem("foo"));
|
|
@ -800,9 +800,9 @@ pub fn resolve_npm_package_reference_types(
|
|||
}
|
||||
|
||||
#[op]
|
||||
fn op_is_node_file(state: &mut OpState, path: String) -> bool {
|
||||
fn op_is_node_file(state: &mut OpState, path: &str) -> bool {
|
||||
let state = state.borrow::<State>();
|
||||
match ModuleSpecifier::parse(&path) {
|
||||
match ModuleSpecifier::parse(path) {
|
||||
Ok(specifier) => state
|
||||
.maybe_npm_resolver
|
||||
.as_ref()
|
||||
|
|
|
@ -108,7 +108,7 @@ pub fn op_metrics(state: &mut OpState) -> (OpMetrics, Vec<OpMetrics>) {
|
|||
|
||||
/// Builtin utility to print to stdout/stderr
|
||||
#[op]
|
||||
pub fn op_print(msg: String, is_err: bool) -> Result<(), Error> {
|
||||
pub fn op_print(msg: &str, is_err: bool) -> Result<(), Error> {
|
||||
if is_err {
|
||||
stderr().write_all(msg.as_bytes())?;
|
||||
stderr().flush().unwrap();
|
||||
|
@ -153,12 +153,12 @@ pub fn op_wasm_streaming_feed(
|
|||
pub fn op_wasm_streaming_set_url(
|
||||
state: &mut OpState,
|
||||
rid: ResourceId,
|
||||
url: String,
|
||||
url: &str,
|
||||
) -> Result<(), Error> {
|
||||
let wasm_streaming =
|
||||
state.resource_table.get::<WasmStreamingResource>(rid)?;
|
||||
|
||||
wasm_streaming.0.borrow_mut().set_url(&url);
|
||||
wasm_streaming.0.borrow_mut().set_url(url);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ function opUrlReparse(href, setter, value) {
|
|||
href,
|
||||
setter,
|
||||
value,
|
||||
componentsBuf.buffer,
|
||||
componentsBuf,
|
||||
);
|
||||
return getSerialization(status, href);
|
||||
}
|
||||
|
@ -54,12 +54,12 @@ function opUrlReparse(href, setter, value) {
|
|||
function opUrlParse(href, maybeBase) {
|
||||
let status;
|
||||
if (maybeBase === undefined) {
|
||||
status = ops.op_url_parse(href, componentsBuf.buffer);
|
||||
status = ops.op_url_parse(href, componentsBuf);
|
||||
} else {
|
||||
status = ops.op_url_parse_with_base(
|
||||
href,
|
||||
maybeBase,
|
||||
componentsBuf.buffer,
|
||||
componentsBuf,
|
||||
);
|
||||
}
|
||||
return getSerialization(status, href, maybeBase);
|
||||
|
|
|
@ -38,11 +38,11 @@ pub fn init() -> Extension {
|
|||
#[op]
|
||||
pub fn op_url_parse_with_base(
|
||||
state: &mut OpState,
|
||||
href: String,
|
||||
base_href: String,
|
||||
buf: &mut [u8],
|
||||
href: &str,
|
||||
base_href: &str,
|
||||
buf: &mut [u32],
|
||||
) -> u32 {
|
||||
let base_url = match Url::parse(&base_href) {
|
||||
let base_url = match Url::parse(base_href) {
|
||||
Ok(url) => url,
|
||||
Err(_) => return ParseStatus::Err as u32,
|
||||
};
|
||||
|
@ -64,8 +64,8 @@ pub fn op_url_get_serialization(state: &mut OpState) -> String {
|
|||
}
|
||||
|
||||
/// Parse `href` without a `base_url`. Fills the out `buf` with URL components.
|
||||
#[op]
|
||||
pub fn op_url_parse(state: &mut OpState, href: String, buf: &mut [u8]) -> u32 {
|
||||
#[op(fast)]
|
||||
pub fn op_url_parse(state: &mut OpState, href: &str, buf: &mut [u32]) -> u32 {
|
||||
parse_url(state, href, None, buf)
|
||||
}
|
||||
|
||||
|
@ -96,15 +96,14 @@ pub fn op_url_parse(state: &mut OpState, href: String, buf: &mut [u8]) -> u32 {
|
|||
#[inline]
|
||||
fn parse_url(
|
||||
state: &mut OpState,
|
||||
href: String,
|
||||
href: &str,
|
||||
base_href: Option<&Url>,
|
||||
buf: &mut [u8],
|
||||
buf: &mut [u32],
|
||||
) -> u32 {
|
||||
match Url::options().base_url(base_href).parse(&href) {
|
||||
match Url::options().base_url(base_href).parse(href) {
|
||||
Ok(url) => {
|
||||
let inner_url = quirks::internal_components(&url);
|
||||
|
||||
let buf: &mut [u32] = as_u32_slice(buf);
|
||||
buf[0] = inner_url.scheme_end;
|
||||
buf[1] = inner_url.username_end;
|
||||
buf[2] = inner_url.host_start;
|
||||
|
|
|
@ -248,10 +248,10 @@ pub fn op_blob_create_object_url(
|
|||
|
||||
#[op]
|
||||
pub fn op_blob_revoke_object_url(
|
||||
state: &mut OpState,
|
||||
url: String,
|
||||
state: &mut deno_core::OpState,
|
||||
url: &str,
|
||||
) -> Result<(), AnyError> {
|
||||
let url = Url::parse(&url)?;
|
||||
let url = Url::parse(url)?;
|
||||
let blob_store = state.borrow::<BlobStore>();
|
||||
blob_store.remove_object_url(&url);
|
||||
Ok(())
|
||||
|
|
|
@ -41,11 +41,11 @@ impl Resource for CompressionResource {
|
|||
#[op]
|
||||
pub fn op_compression_new(
|
||||
state: &mut OpState,
|
||||
format: String,
|
||||
format: &str,
|
||||
is_decoder: bool,
|
||||
) -> ResourceId {
|
||||
let w = Vec::new();
|
||||
let inner = match (format.as_str(), is_decoder) {
|
||||
let inner = match (format, is_decoder) {
|
||||
("deflate", true) => Inner::DeflateDecoder(ZlibDecoder::new(w)),
|
||||
("deflate", false) => {
|
||||
Inner::DeflateEncoder(ZlibEncoder::new(w, Compression::default()))
|
||||
|
|
|
@ -269,7 +269,7 @@ fn op_encoding_decode_single(
|
|||
#[op]
|
||||
fn op_encoding_new_decoder(
|
||||
state: &mut OpState,
|
||||
label: String,
|
||||
label: &str,
|
||||
fatal: bool,
|
||||
ignore_bom: bool,
|
||||
) -> Result<ResourceId, AnyError> {
|
||||
|
@ -350,25 +350,43 @@ impl Resource for TextDecoderResource {
|
|||
}
|
||||
}
|
||||
|
||||
#[op(v8)]
|
||||
#[op]
|
||||
fn op_encoding_encode_into(
|
||||
scope: &mut v8::HandleScope,
|
||||
input: serde_v8::Value,
|
||||
input: Cow<'_, str>,
|
||||
buffer: &mut [u8],
|
||||
out_buf: &mut [u32],
|
||||
) -> Result<(), AnyError> {
|
||||
let s = v8::Local::<v8::String>::try_from(input.v8_value)?;
|
||||
) {
|
||||
// Since `input` is already UTF-8, we can simply find the last UTF-8 code
|
||||
// point boundary from input that fits in `buffer`, and copy the bytes up to
|
||||
// that point.
|
||||
let boundary = if buffer.len() >= input.len() {
|
||||
input.len()
|
||||
} else {
|
||||
let mut boundary = buffer.len();
|
||||
|
||||
let mut nchars = 0;
|
||||
out_buf[1] = s.write_utf8(
|
||||
scope,
|
||||
buffer,
|
||||
Some(&mut nchars),
|
||||
v8::WriteOptions::NO_NULL_TERMINATION
|
||||
| v8::WriteOptions::REPLACE_INVALID_UTF8,
|
||||
) as u32;
|
||||
out_buf[0] = nchars as u32;
|
||||
Ok(())
|
||||
// The maximum length of a UTF-8 code point is 4 bytes.
|
||||
for _ in 0..4 {
|
||||
if input.is_char_boundary(boundary) {
|
||||
break;
|
||||
}
|
||||
debug_assert!(boundary > 0);
|
||||
boundary -= 1;
|
||||
}
|
||||
|
||||
debug_assert!(input.is_char_boundary(boundary));
|
||||
boundary
|
||||
};
|
||||
|
||||
buffer[..boundary].copy_from_slice(input[..boundary].as_bytes());
|
||||
|
||||
// The `read` output parameter is measured in UTF-16 code units.
|
||||
out_buf[0] = match input {
|
||||
// Borrowed Cow strings are zero-copy views into the V8 heap.
|
||||
// Thus, they are guarantee to be SeqOneByteString.
|
||||
Cow::Borrowed(v) => v[..boundary].len() as u32,
|
||||
Cow::Owned(v) => v[..boundary].encode_utf16().count() as u32,
|
||||
};
|
||||
out_buf[1] = boundary as u32;
|
||||
}
|
||||
|
||||
#[op(v8)]
|
||||
|
|
|
@ -138,8 +138,8 @@ pub fn op_webstorage_key(
|
|||
#[op]
|
||||
pub fn op_webstorage_set(
|
||||
state: &mut OpState,
|
||||
key: String,
|
||||
value: String,
|
||||
key: &str,
|
||||
value: &str,
|
||||
persistent: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
|
@ -183,7 +183,7 @@ pub fn op_webstorage_get(
|
|||
#[op]
|
||||
pub fn op_webstorage_remove(
|
||||
state: &mut OpState,
|
||||
key_name: String,
|
||||
key_name: &str,
|
||||
persistent: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let conn = get_webstorage(state, persistent)?;
|
||||
|
|
|
@ -430,7 +430,8 @@ fn q_fast_ty(v: &FastValue) -> Quote {
|
|||
FastValue::V8Value => q!({ v8::Local<v8::Value> }),
|
||||
FastValue::Uint8Array
|
||||
| FastValue::Uint32Array
|
||||
| FastValue::Float64Array => unreachable!(),
|
||||
| FastValue::Float64Array
|
||||
| FastValue::SeqOneByteString => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,6 +451,7 @@ fn q_fast_ty_variant(v: &FastValue) -> Quote {
|
|||
FastValue::Uint8Array => q!({ TypedArray(CType::Uint8) }),
|
||||
FastValue::Uint32Array => q!({ TypedArray(CType::Uint32) }),
|
||||
FastValue::Float64Array => q!({ TypedArray(CType::Float64) }),
|
||||
FastValue::SeqOneByteString => q!({ SeqOneByteString }),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
34
ops/lib.rs
34
ops/lib.rs
|
@ -423,7 +423,12 @@ fn codegen_arg(
|
|||
return quote! { let #ident = (); };
|
||||
}
|
||||
// Fast path for `String`
|
||||
if is_string(&**ty) {
|
||||
if let Some(is_ref) = is_string(&**ty) {
|
||||
let ref_block = if is_ref {
|
||||
quote! { let #ident = #ident.as_ref(); }
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
return quote! {
|
||||
let #ident = match #core::v8::Local::<#core::v8::String>::try_from(args.get(#idx as i32)) {
|
||||
Ok(v8_string) => #core::serde_v8::to_utf8(v8_string, scope),
|
||||
|
@ -431,6 +436,18 @@ fn codegen_arg(
|
|||
return #core::_ops::throw_type_error(scope, format!("Expected string at position {}", #idx));
|
||||
}
|
||||
};
|
||||
#ref_block
|
||||
};
|
||||
}
|
||||
// Fast path for `Cow<'_, str>`
|
||||
if is_cow_str(&**ty) {
|
||||
return quote! {
|
||||
let #ident = match #core::v8::Local::<#core::v8::String>::try_from(args.get(#idx as i32)) {
|
||||
Ok(v8_string) => ::std::borrow::Cow::Owned(#core::serde_v8::to_utf8(v8_string, scope)),
|
||||
Err(_) => {
|
||||
return #core::_ops::throw_type_error(scope, format!("Expected string at position {}", #idx));
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
// Fast path for `Option<String>`
|
||||
|
@ -701,14 +718,25 @@ fn is_result(ty: impl ToTokens) -> bool {
|
|||
}
|
||||
}
|
||||
|
||||
fn is_string(ty: impl ToTokens) -> bool {
|
||||
tokens(ty) == "String"
|
||||
fn is_string(ty: impl ToTokens) -> Option<bool> {
|
||||
let toks = tokens(ty);
|
||||
if toks == "String" {
|
||||
return Some(false);
|
||||
}
|
||||
if toks == "& str" {
|
||||
return Some(true);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn is_option_string(ty: impl ToTokens) -> bool {
|
||||
tokens(ty) == "Option < String >"
|
||||
}
|
||||
|
||||
fn is_cow_str(ty: impl ToTokens) -> bool {
|
||||
tokens(&ty).starts_with("Cow <") && tokens(&ty).ends_with("str >")
|
||||
}
|
||||
|
||||
enum SliceType {
|
||||
U8,
|
||||
U8Mut,
|
||||
|
|
|
@ -37,6 +37,13 @@ pub(crate) enum BailoutReason {
|
|||
FastUnsupportedParamType,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum StringType {
|
||||
Cow,
|
||||
Ref,
|
||||
Owned,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum TransformKind {
|
||||
// serde_v8::Value
|
||||
|
@ -44,6 +51,7 @@ enum TransformKind {
|
|||
SliceU32(bool),
|
||||
SliceU8(bool),
|
||||
SliceF64(bool),
|
||||
SeqOneByteString(StringType),
|
||||
PtrU8,
|
||||
PtrVoid,
|
||||
WasmMemory,
|
||||
|
@ -78,6 +86,13 @@ impl Transform {
|
|||
}
|
||||
}
|
||||
|
||||
fn seq_one_byte_string(index: usize, is_ref: StringType) -> Self {
|
||||
Transform {
|
||||
kind: TransformKind::SeqOneByteString(is_ref),
|
||||
index,
|
||||
}
|
||||
}
|
||||
|
||||
fn wasm_memory(index: usize) -> Self {
|
||||
Transform {
|
||||
kind: TransformKind::WasmMemory,
|
||||
|
@ -180,6 +195,21 @@ impl Transform {
|
|||
};
|
||||
})
|
||||
}
|
||||
// &str
|
||||
TransformKind::SeqOneByteString(str_ty) => {
|
||||
*ty = parse_quote! { *const #core::v8::fast_api::FastApiOneByteString };
|
||||
match str_ty {
|
||||
StringType::Ref => q!(Vars { var: &ident }, {
|
||||
let var = unsafe { &*var }.as_str();
|
||||
}),
|
||||
StringType::Cow => q!(Vars { var: &ident }, {
|
||||
let var = ::std::borrow::Cow::Borrowed(unsafe { &*var }.as_str());
|
||||
}),
|
||||
StringType::Owned => q!(Vars { var: &ident }, {
|
||||
let var = unsafe { &*var }.as_str().to_owned();
|
||||
}),
|
||||
}
|
||||
}
|
||||
TransformKind::WasmMemory => {
|
||||
// Note: `ty` is correctly set to __opts by the fast call tier.
|
||||
// U8 slice is always byte-aligned.
|
||||
|
@ -252,6 +282,7 @@ pub(crate) enum FastValue {
|
|||
Uint8Array,
|
||||
Uint32Array,
|
||||
Float64Array,
|
||||
SeqOneByteString,
|
||||
}
|
||||
|
||||
impl FastValue {
|
||||
|
@ -388,6 +419,13 @@ impl Optimizer {
|
|||
self.analyze_param_type(index, param)?;
|
||||
}
|
||||
|
||||
// TODO(@littledivy): https://github.com/denoland/deno/issues/17159
|
||||
if self.returns_result
|
||||
&& self.fast_parameters.contains(&FastValue::SeqOneByteString)
|
||||
{
|
||||
self.fast_compatible = false;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -661,10 +699,58 @@ impl Optimizer {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Cow<'_, str>
|
||||
PathSegment {
|
||||
ident, arguments, ..
|
||||
} if ident == "Cow" => {
|
||||
if let PathArguments::AngleBracketed(
|
||||
AngleBracketedGenericArguments { args, .. },
|
||||
) = arguments
|
||||
{
|
||||
assert_eq!(args.len(), 2);
|
||||
|
||||
let ty = &args[1];
|
||||
match ty {
|
||||
GenericArgument::Type(Type::Path(TypePath {
|
||||
path: Path { segments, .. },
|
||||
..
|
||||
})) => {
|
||||
let segment = single_segment(segments)?;
|
||||
match segment {
|
||||
PathSegment { ident, .. } if ident == "str" => {
|
||||
self.fast_parameters.push(FastValue::SeqOneByteString);
|
||||
assert!(self
|
||||
.transforms
|
||||
.insert(
|
||||
index,
|
||||
Transform::seq_one_byte_string(
|
||||
index,
|
||||
StringType::Cow
|
||||
)
|
||||
)
|
||||
.is_none());
|
||||
}
|
||||
_ => return Err(BailoutReason::FastUnsupportedParamType),
|
||||
}
|
||||
}
|
||||
_ => return Err(BailoutReason::FastUnsupportedParamType),
|
||||
}
|
||||
}
|
||||
}
|
||||
// Is `T` a fast scalar?
|
||||
PathSegment { ident, .. } => {
|
||||
if let Some(val) = get_fast_scalar(ident.to_string().as_str()) {
|
||||
self.fast_parameters.push(val);
|
||||
} else if ident == "String" {
|
||||
// Is `T` an owned String?
|
||||
self.fast_parameters.push(FastValue::SeqOneByteString);
|
||||
assert!(self
|
||||
.transforms
|
||||
.insert(
|
||||
index,
|
||||
Transform::seq_one_byte_string(index, StringType::Owned)
|
||||
)
|
||||
.is_none());
|
||||
} else {
|
||||
return Err(BailoutReason::FastUnsupportedParamType);
|
||||
}
|
||||
|
@ -687,6 +773,17 @@ impl Optimizer {
|
|||
{
|
||||
self.has_ref_opstate = true;
|
||||
}
|
||||
// Is `T` a str?
|
||||
PathSegment { ident, .. } if ident == "str" => {
|
||||
self.fast_parameters.push(FastValue::SeqOneByteString);
|
||||
assert!(self
|
||||
.transforms
|
||||
.insert(
|
||||
index,
|
||||
Transform::seq_one_byte_string(index, StringType::Ref)
|
||||
)
|
||||
.is_none());
|
||||
}
|
||||
_ => return Err(BailoutReason::FastUnsupportedParamType),
|
||||
}
|
||||
}
|
||||
|
|
11
ops/optimizer_tests/cow_str.expected
Normal file
11
ops/optimizer_tests/cow_str.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
=== Optimizer Dump ===
|
||||
returns_result: false
|
||||
has_ref_opstate: false
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(Void)
|
||||
fast_parameters: [V8Value, SeqOneByteString]
|
||||
transforms: {0: Transform { kind: SeqOneByteString(Cow), index: 0 }}
|
||||
is_async: false
|
||||
fast_compatible: true
|
87
ops/optimizer_tests/cow_str.out
Normal file
87
ops/optimizer_tests/cow_str.out
Normal file
|
@ -0,0 +1,87 @@
|
|||
#[allow(non_camel_case_types)]
|
||||
///Auto-generated by `deno_ops`, i.e: `#[op]`
|
||||
///
|
||||
///Use `op_cow_str::decl()` to get an op-declaration
|
||||
///you can include in a `deno_core::Extension`.
|
||||
pub struct op_cow_str;
|
||||
#[doc(hidden)]
|
||||
impl op_cow_str {
|
||||
pub fn name() -> &'static str {
|
||||
stringify!(op_cow_str)
|
||||
}
|
||||
pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
|
||||
use deno_core::v8::MapFnTo;
|
||||
Self::v8_func.map_fn_to()
|
||||
}
|
||||
pub fn decl<'scope>() -> deno_core::OpDecl {
|
||||
deno_core::OpDecl {
|
||||
name: Self::name(),
|
||||
v8_fn_ptr: Self::v8_fn_ptr(),
|
||||
enabled: true,
|
||||
fast_fn: Some(
|
||||
Box::new(op_cow_str_fast {
|
||||
_phantom: ::std::marker::PhantomData,
|
||||
}),
|
||||
),
|
||||
is_async: false,
|
||||
is_unstable: false,
|
||||
is_v8: false,
|
||||
argc: 1usize,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn call(c: Cow<'_, str>) {}
|
||||
pub fn v8_func<'scope>(
|
||||
scope: &mut deno_core::v8::HandleScope<'scope>,
|
||||
args: deno_core::v8::FunctionCallbackArguments,
|
||||
mut rv: deno_core::v8::ReturnValue,
|
||||
) {
|
||||
let ctx = unsafe {
|
||||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
|
||||
as *const deno_core::_ops::OpCtx)
|
||||
};
|
||||
let arg_0 = match deno_core::v8::Local::<
|
||||
deno_core::v8::String,
|
||||
>::try_from(args.get(0usize as i32)) {
|
||||
Ok(v8_string) => {
|
||||
::std::borrow::Cow::Owned(deno_core::serde_v8::to_utf8(v8_string, scope))
|
||||
}
|
||||
Err(_) => {
|
||||
return deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!("Expected string at position {}", 0usize),
|
||||
);
|
||||
}
|
||||
};
|
||||
let result = Self::call(arg_0);
|
||||
let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
|
||||
op_state.tracker.track_sync(ctx.id);
|
||||
}
|
||||
}
|
||||
struct op_cow_str_fast {
|
||||
_phantom: ::std::marker::PhantomData<()>,
|
||||
}
|
||||
impl<'scope> deno_core::v8::fast_api::FastFunction for op_cow_str_fast {
|
||||
fn function(&self) -> *const ::std::ffi::c_void {
|
||||
op_cow_str_fast_fn as *const ::std::ffi::c_void
|
||||
}
|
||||
fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
|
||||
use deno_core::v8::fast_api::Type::*;
|
||||
use deno_core::v8::fast_api::CType;
|
||||
&[V8Value, SeqOneByteString]
|
||||
}
|
||||
fn return_type(&self) -> deno_core::v8::fast_api::CType {
|
||||
deno_core::v8::fast_api::CType::Void
|
||||
}
|
||||
}
|
||||
fn op_cow_str_fast_fn<'scope>(
|
||||
_: deno_core::v8::Local<deno_core::v8::Object>,
|
||||
c: *const deno_core::v8::fast_api::FastApiOneByteString,
|
||||
) -> () {
|
||||
use deno_core::v8;
|
||||
use deno_core::_ops;
|
||||
let c = ::std::borrow::Cow::Borrowed(unsafe { &*c }.as_str());
|
||||
let result = op_cow_str::call(c);
|
||||
result
|
||||
}
|
3
ops/optimizer_tests/cow_str.rs
Normal file
3
ops/optimizer_tests/cow_str.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn op_cow_str(c: Cow<'_, str>) {
|
||||
// ...
|
||||
}
|
|
@ -1 +1,11 @@
|
|||
MustBeSingleSegment
|
||||
=== Optimizer Dump ===
|
||||
returns_result: true
|
||||
has_ref_opstate: true
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(Void)
|
||||
fast_parameters: [V8Value, SeqOneByteString]
|
||||
transforms: {1: Transform { kind: SeqOneByteString(Owned), index: 1 }}
|
||||
is_async: false
|
||||
fast_compatible: false
|
||||
|
|
|
@ -27,7 +27,7 @@ impl op_blob_revoke_object_url {
|
|||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn call(state: &mut deno_core::OpState, url: String) -> Result<(), AnyError> {
|
||||
pub fn call(state: &mut OpState, url: String) -> Result<(), AnyError> {
|
||||
let url = Url::parse(&url)?;
|
||||
let blob_store = state.borrow::<BlobStore>();
|
||||
blob_store.remove_object_url(&url);
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
pub fn op_blob_revoke_object_url(
|
||||
state: &mut deno_core::OpState,
|
||||
state: &mut OpState,
|
||||
url: String,
|
||||
) -> Result<(), AnyError> {
|
||||
// TODO(@littledivy): fast compatible https://github.com/denoland/deno/issues/17159
|
||||
let url = Url::parse(&url)?;
|
||||
let blob_store = state.borrow::<BlobStore>();
|
||||
blob_store.remove_object_url(&url);
|
||||
|
|
11
ops/optimizer_tests/op_print.expected
Normal file
11
ops/optimizer_tests/op_print.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
=== Optimizer Dump ===
|
||||
returns_result: true
|
||||
has_ref_opstate: true
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(Void)
|
||||
fast_parameters: [V8Value, SeqOneByteString, Bool]
|
||||
transforms: {1: Transform { kind: SeqOneByteString(Ref), index: 1 }}
|
||||
is_async: false
|
||||
fast_compatible: false
|
82
ops/optimizer_tests/op_print.out
Normal file
82
ops/optimizer_tests/op_print.out
Normal file
|
@ -0,0 +1,82 @@
|
|||
#[allow(non_camel_case_types)]
|
||||
///Auto-generated by `deno_ops`, i.e: `#[op]`
|
||||
///
|
||||
///Use `op_print::decl()` to get an op-declaration
|
||||
///you can include in a `deno_core::Extension`.
|
||||
pub struct op_print;
|
||||
#[doc(hidden)]
|
||||
impl op_print {
|
||||
pub fn name() -> &'static str {
|
||||
stringify!(op_print)
|
||||
}
|
||||
pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
|
||||
use deno_core::v8::MapFnTo;
|
||||
Self::v8_func.map_fn_to()
|
||||
}
|
||||
pub fn decl<'scope>() -> deno_core::OpDecl {
|
||||
deno_core::OpDecl {
|
||||
name: Self::name(),
|
||||
v8_fn_ptr: Self::v8_fn_ptr(),
|
||||
enabled: true,
|
||||
fast_fn: None,
|
||||
is_async: false,
|
||||
is_unstable: false,
|
||||
is_v8: false,
|
||||
argc: 2usize,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn call(state: &mut OpState, msg: &str, is_err: bool) -> Result<(), AnyError> {}
|
||||
pub fn v8_func<'scope>(
|
||||
scope: &mut deno_core::v8::HandleScope<'scope>,
|
||||
args: deno_core::v8::FunctionCallbackArguments,
|
||||
mut rv: deno_core::v8::ReturnValue,
|
||||
) {
|
||||
let ctx = unsafe {
|
||||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
|
||||
as *const deno_core::_ops::OpCtx)
|
||||
};
|
||||
let arg_0 = match deno_core::v8::Local::<
|
||||
deno_core::v8::String,
|
||||
>::try_from(args.get(0usize as i32)) {
|
||||
Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
|
||||
Err(_) => {
|
||||
return deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!("Expected string at position {}", 0usize),
|
||||
);
|
||||
}
|
||||
};
|
||||
let arg_0 = arg_0.as_ref();
|
||||
let arg_1 = args.get(1usize as i32);
|
||||
let arg_1 = match deno_core::serde_v8::from_v8(scope, arg_1) {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
let msg = format!(
|
||||
"Error parsing args at position {}: {}", 1usize,
|
||||
deno_core::anyhow::Error::from(err)
|
||||
);
|
||||
return deno_core::_ops::throw_type_error(scope, msg);
|
||||
}
|
||||
};
|
||||
let result = Self::call(
|
||||
&mut std::cell::RefCell::borrow_mut(&ctx.state),
|
||||
arg_0,
|
||||
arg_1,
|
||||
);
|
||||
let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
|
||||
op_state.tracker.track_sync(ctx.id);
|
||||
match result {
|
||||
Ok(result) => {}
|
||||
Err(err) => {
|
||||
let exception = deno_core::error::to_v8_error(
|
||||
scope,
|
||||
op_state.get_error_class_fn,
|
||||
&err,
|
||||
);
|
||||
scope.throw_exception(exception);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
7
ops/optimizer_tests/op_print.rs
Normal file
7
ops/optimizer_tests/op_print.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
fn op_print(
|
||||
state: &mut OpState,
|
||||
msg: &str,
|
||||
is_err: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
// TODO(@littledivy): fast compatible https://github.com/denoland/deno/issues/17159
|
||||
}
|
11
ops/optimizer_tests/owned_string.expected
Normal file
11
ops/optimizer_tests/owned_string.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
=== Optimizer Dump ===
|
||||
returns_result: false
|
||||
has_ref_opstate: false
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(U32)
|
||||
fast_parameters: [V8Value, SeqOneByteString]
|
||||
transforms: {0: Transform { kind: SeqOneByteString(Owned), index: 0 }}
|
||||
is_async: false
|
||||
fast_compatible: true
|
99
ops/optimizer_tests/owned_string.out
Normal file
99
ops/optimizer_tests/owned_string.out
Normal file
|
@ -0,0 +1,99 @@
|
|||
#[allow(non_camel_case_types)]
|
||||
///Auto-generated by `deno_ops`, i.e: `#[op]`
|
||||
///
|
||||
///Use `op_string_length::decl()` to get an op-declaration
|
||||
///you can include in a `deno_core::Extension`.
|
||||
pub struct op_string_length;
|
||||
#[doc(hidden)]
|
||||
impl op_string_length {
|
||||
pub fn name() -> &'static str {
|
||||
stringify!(op_string_length)
|
||||
}
|
||||
pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
|
||||
use deno_core::v8::MapFnTo;
|
||||
Self::v8_func.map_fn_to()
|
||||
}
|
||||
pub fn decl<'scope>() -> deno_core::OpDecl {
|
||||
deno_core::OpDecl {
|
||||
name: Self::name(),
|
||||
v8_fn_ptr: Self::v8_fn_ptr(),
|
||||
enabled: true,
|
||||
fast_fn: Some(
|
||||
Box::new(op_string_length_fast {
|
||||
_phantom: ::std::marker::PhantomData,
|
||||
}),
|
||||
),
|
||||
is_async: false,
|
||||
is_unstable: false,
|
||||
is_v8: false,
|
||||
argc: 1usize,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn call(string: String) -> u32 {
|
||||
string.len() as u32
|
||||
}
|
||||
pub fn v8_func<'scope>(
|
||||
scope: &mut deno_core::v8::HandleScope<'scope>,
|
||||
args: deno_core::v8::FunctionCallbackArguments,
|
||||
mut rv: deno_core::v8::ReturnValue,
|
||||
) {
|
||||
let ctx = unsafe {
|
||||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
|
||||
as *const deno_core::_ops::OpCtx)
|
||||
};
|
||||
let arg_0 = match deno_core::v8::Local::<
|
||||
deno_core::v8::String,
|
||||
>::try_from(args.get(0usize as i32)) {
|
||||
Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
|
||||
Err(_) => {
|
||||
return deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!("Expected string at position {}", 0usize),
|
||||
);
|
||||
}
|
||||
};
|
||||
let result = Self::call(arg_0);
|
||||
let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
|
||||
op_state.tracker.track_sync(ctx.id);
|
||||
match deno_core::serde_v8::to_v8(scope, result) {
|
||||
Ok(ret) => rv.set(ret),
|
||||
Err(err) => {
|
||||
deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!(
|
||||
"Error serializing return: {}",
|
||||
deno_core::anyhow::Error::from(err)
|
||||
),
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
struct op_string_length_fast {
|
||||
_phantom: ::std::marker::PhantomData<()>,
|
||||
}
|
||||
impl<'scope> deno_core::v8::fast_api::FastFunction for op_string_length_fast {
|
||||
fn function(&self) -> *const ::std::ffi::c_void {
|
||||
op_string_length_fast_fn as *const ::std::ffi::c_void
|
||||
}
|
||||
fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
|
||||
use deno_core::v8::fast_api::Type::*;
|
||||
use deno_core::v8::fast_api::CType;
|
||||
&[V8Value, SeqOneByteString]
|
||||
}
|
||||
fn return_type(&self) -> deno_core::v8::fast_api::CType {
|
||||
deno_core::v8::fast_api::CType::Uint32
|
||||
}
|
||||
}
|
||||
fn op_string_length_fast_fn<'scope>(
|
||||
_: deno_core::v8::Local<deno_core::v8::Object>,
|
||||
string: *const deno_core::v8::fast_api::FastApiOneByteString,
|
||||
) -> u32 {
|
||||
use deno_core::v8;
|
||||
use deno_core::_ops;
|
||||
let string = unsafe { &*string }.as_str().to_owned();
|
||||
let result = op_string_length::call(string);
|
||||
result
|
||||
}
|
3
ops/optimizer_tests/owned_string.rs
Normal file
3
ops/optimizer_tests/owned_string.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn op_string_length(string: String) -> u32 {
|
||||
string.len() as u32
|
||||
}
|
11
ops/optimizer_tests/strings.expected
Normal file
11
ops/optimizer_tests/strings.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
=== Optimizer Dump ===
|
||||
returns_result: false
|
||||
has_ref_opstate: false
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(U32)
|
||||
fast_parameters: [V8Value, SeqOneByteString]
|
||||
transforms: {0: Transform { kind: SeqOneByteString(Ref), index: 0 }}
|
||||
is_async: false
|
||||
fast_compatible: true
|
100
ops/optimizer_tests/strings.out
Normal file
100
ops/optimizer_tests/strings.out
Normal file
|
@ -0,0 +1,100 @@
|
|||
#[allow(non_camel_case_types)]
|
||||
///Auto-generated by `deno_ops`, i.e: `#[op]`
|
||||
///
|
||||
///Use `op_string_length::decl()` to get an op-declaration
|
||||
///you can include in a `deno_core::Extension`.
|
||||
pub struct op_string_length;
|
||||
#[doc(hidden)]
|
||||
impl op_string_length {
|
||||
pub fn name() -> &'static str {
|
||||
stringify!(op_string_length)
|
||||
}
|
||||
pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
|
||||
use deno_core::v8::MapFnTo;
|
||||
Self::v8_func.map_fn_to()
|
||||
}
|
||||
pub fn decl<'scope>() -> deno_core::OpDecl {
|
||||
deno_core::OpDecl {
|
||||
name: Self::name(),
|
||||
v8_fn_ptr: Self::v8_fn_ptr(),
|
||||
enabled: true,
|
||||
fast_fn: Some(
|
||||
Box::new(op_string_length_fast {
|
||||
_phantom: ::std::marker::PhantomData,
|
||||
}),
|
||||
),
|
||||
is_async: false,
|
||||
is_unstable: false,
|
||||
is_v8: false,
|
||||
argc: 1usize,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn call(string: &str) -> u32 {
|
||||
string.len() as u32
|
||||
}
|
||||
pub fn v8_func<'scope>(
|
||||
scope: &mut deno_core::v8::HandleScope<'scope>,
|
||||
args: deno_core::v8::FunctionCallbackArguments,
|
||||
mut rv: deno_core::v8::ReturnValue,
|
||||
) {
|
||||
let ctx = unsafe {
|
||||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
|
||||
as *const deno_core::_ops::OpCtx)
|
||||
};
|
||||
let arg_0 = match deno_core::v8::Local::<
|
||||
deno_core::v8::String,
|
||||
>::try_from(args.get(0usize as i32)) {
|
||||
Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
|
||||
Err(_) => {
|
||||
return deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!("Expected string at position {}", 0usize),
|
||||
);
|
||||
}
|
||||
};
|
||||
let arg_0 = arg_0.as_ref();
|
||||
let result = Self::call(arg_0);
|
||||
let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
|
||||
op_state.tracker.track_sync(ctx.id);
|
||||
match deno_core::serde_v8::to_v8(scope, result) {
|
||||
Ok(ret) => rv.set(ret),
|
||||
Err(err) => {
|
||||
deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!(
|
||||
"Error serializing return: {}",
|
||||
deno_core::anyhow::Error::from(err)
|
||||
),
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
struct op_string_length_fast {
|
||||
_phantom: ::std::marker::PhantomData<()>,
|
||||
}
|
||||
impl<'scope> deno_core::v8::fast_api::FastFunction for op_string_length_fast {
|
||||
fn function(&self) -> *const ::std::ffi::c_void {
|
||||
op_string_length_fast_fn as *const ::std::ffi::c_void
|
||||
}
|
||||
fn args(&self) -> &'static [deno_core::v8::fast_api::Type] {
|
||||
use deno_core::v8::fast_api::Type::*;
|
||||
use deno_core::v8::fast_api::CType;
|
||||
&[V8Value, SeqOneByteString]
|
||||
}
|
||||
fn return_type(&self) -> deno_core::v8::fast_api::CType {
|
||||
deno_core::v8::fast_api::CType::Uint32
|
||||
}
|
||||
}
|
||||
fn op_string_length_fast_fn<'scope>(
|
||||
_: deno_core::v8::Local<deno_core::v8::Object>,
|
||||
string: *const deno_core::v8::fast_api::FastApiOneByteString,
|
||||
) -> u32 {
|
||||
use deno_core::v8;
|
||||
use deno_core::_ops;
|
||||
let string = unsafe { &*string }.as_str();
|
||||
let result = op_string_length::call(string);
|
||||
result
|
||||
}
|
3
ops/optimizer_tests/strings.rs
Normal file
3
ops/optimizer_tests/strings.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
fn op_string_length(string: &str) -> u32 {
|
||||
string.len() as u32
|
||||
}
|
11
ops/optimizer_tests/strings_result.expected
Normal file
11
ops/optimizer_tests/strings_result.expected
Normal file
|
@ -0,0 +1,11 @@
|
|||
=== Optimizer Dump ===
|
||||
returns_result: true
|
||||
has_ref_opstate: false
|
||||
has_rc_opstate: false
|
||||
has_fast_callback_option: false
|
||||
needs_fast_callback_option: false
|
||||
fast_result: Some(U32)
|
||||
fast_parameters: [V8Value, SeqOneByteString]
|
||||
transforms: {0: Transform { kind: SeqOneByteString(Ref), index: 0 }}
|
||||
is_async: false
|
||||
fast_compatible: false
|
71
ops/optimizer_tests/strings_result.out
Normal file
71
ops/optimizer_tests/strings_result.out
Normal file
|
@ -0,0 +1,71 @@
|
|||
#[allow(non_camel_case_types)]
|
||||
///Auto-generated by `deno_ops`, i.e: `#[op]`
|
||||
///
|
||||
///Use `op_string_length::decl()` to get an op-declaration
|
||||
///you can include in a `deno_core::Extension`.
|
||||
pub struct op_string_length;
|
||||
#[doc(hidden)]
|
||||
impl op_string_length {
|
||||
pub fn name() -> &'static str {
|
||||
stringify!(op_string_length)
|
||||
}
|
||||
pub fn v8_fn_ptr<'scope>() -> deno_core::v8::FunctionCallback {
|
||||
use deno_core::v8::MapFnTo;
|
||||
Self::v8_func.map_fn_to()
|
||||
}
|
||||
pub fn decl<'scope>() -> deno_core::OpDecl {
|
||||
deno_core::OpDecl {
|
||||
name: Self::name(),
|
||||
v8_fn_ptr: Self::v8_fn_ptr(),
|
||||
enabled: true,
|
||||
fast_fn: None,
|
||||
is_async: false,
|
||||
is_unstable: false,
|
||||
is_v8: false,
|
||||
argc: 1usize,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn call(string: &str) -> Result<u32, AnyError> {
|
||||
Ok(string.len() as u32)
|
||||
}
|
||||
pub fn v8_func<'scope>(
|
||||
scope: &mut deno_core::v8::HandleScope<'scope>,
|
||||
args: deno_core::v8::FunctionCallbackArguments,
|
||||
mut rv: deno_core::v8::ReturnValue,
|
||||
) {
|
||||
let ctx = unsafe {
|
||||
&*(deno_core::v8::Local::<deno_core::v8::External>::cast(args.data()).value()
|
||||
as *const deno_core::_ops::OpCtx)
|
||||
};
|
||||
let arg_0 = match deno_core::v8::Local::<
|
||||
deno_core::v8::String,
|
||||
>::try_from(args.get(0usize as i32)) {
|
||||
Ok(v8_string) => deno_core::serde_v8::to_utf8(v8_string, scope),
|
||||
Err(_) => {
|
||||
return deno_core::_ops::throw_type_error(
|
||||
scope,
|
||||
format!("Expected string at position {}", 0usize),
|
||||
);
|
||||
}
|
||||
};
|
||||
let arg_0 = arg_0.as_ref();
|
||||
let result = Self::call(arg_0);
|
||||
let op_state = ::std::cell::RefCell::borrow(&*ctx.state);
|
||||
op_state.tracker.track_sync(ctx.id);
|
||||
match result {
|
||||
Ok(result) => {
|
||||
rv.set_uint32(result as u32);
|
||||
}
|
||||
Err(err) => {
|
||||
let exception = deno_core::error::to_v8_error(
|
||||
scope,
|
||||
op_state.get_error_class_fn,
|
||||
&err,
|
||||
);
|
||||
scope.throw_exception(exception);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
4
ops/optimizer_tests/strings_result.rs
Normal file
4
ops/optimizer_tests/strings_result.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
// https://github.com/denoland/deno/issues/16979
|
||||
fn op_string_length(string: &str) -> Result<u32, AnyError> {
|
||||
Ok(string.len() as u32)
|
||||
}
|
|
@ -545,7 +545,7 @@ fn op_umask(state: &mut OpState, mask: Option<u32>) -> Result<u32, AnyError> {
|
|||
}
|
||||
|
||||
#[op]
|
||||
fn op_chdir(state: &mut OpState, directory: String) -> Result<(), AnyError> {
|
||||
fn op_chdir(state: &mut OpState, directory: &str) -> Result<(), AnyError> {
|
||||
let d = PathBuf::from(&directory);
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
|
@ -620,10 +620,10 @@ async fn op_mkdir_async(
|
|||
#[op]
|
||||
fn op_chmod_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
mode: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
let path = Path::new(&path);
|
||||
let path = Path::new(path);
|
||||
let mode = mode & 0o777;
|
||||
|
||||
state
|
||||
|
@ -675,11 +675,11 @@ fn raw_chmod(path: &Path, _raw_mode: u32) -> Result<(), AnyError> {
|
|||
#[op]
|
||||
fn op_chown_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
#[cfg_attr(windows, allow(unused_variables))] uid: Option<u32>,
|
||||
#[cfg_attr(windows, allow(unused_variables))] gid: Option<u32>,
|
||||
) -> Result<(), AnyError> {
|
||||
let path = Path::new(&path).to_path_buf();
|
||||
let path = Path::new(path).to_path_buf();
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
.check_write(&path, "Deno.chownSync()")?;
|
||||
|
@ -750,10 +750,10 @@ async fn op_chown_async(
|
|||
#[op]
|
||||
fn op_remove_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
recursive: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let path = PathBuf::from(&path);
|
||||
let path = PathBuf::from(path);
|
||||
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
|
@ -847,11 +847,11 @@ async fn op_remove_async(
|
|||
#[op]
|
||||
fn op_copy_file_sync(
|
||||
state: &mut OpState,
|
||||
from: String,
|
||||
to: String,
|
||||
from: &str,
|
||||
to: &str,
|
||||
) -> Result<(), AnyError> {
|
||||
let from_path = PathBuf::from(&from);
|
||||
let to_path = PathBuf::from(&to);
|
||||
let from_path = PathBuf::from(from);
|
||||
let to_path = PathBuf::from(to);
|
||||
|
||||
let permissions = state.borrow_mut::<PermissionsContainer>();
|
||||
permissions.check_read(&from_path, "Deno.copyFileSync()")?;
|
||||
|
@ -1115,11 +1115,11 @@ pub struct StatArgs {
|
|||
#[op]
|
||||
fn op_stat_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
lstat: bool,
|
||||
out_buf: &mut [u32],
|
||||
) -> Result<(), AnyError> {
|
||||
let path = PathBuf::from(&path);
|
||||
let path = PathBuf::from(path);
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
.check_read(&path, "Deno.statSync()")?;
|
||||
|
@ -1325,11 +1325,11 @@ async fn op_read_dir_async(
|
|||
#[op]
|
||||
fn op_rename_sync(
|
||||
state: &mut OpState,
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
oldpath: &str,
|
||||
newpath: &str,
|
||||
) -> Result<(), AnyError> {
|
||||
let oldpath = PathBuf::from(&oldpath);
|
||||
let newpath = PathBuf::from(&newpath);
|
||||
let oldpath = PathBuf::from(oldpath);
|
||||
let newpath = PathBuf::from(newpath);
|
||||
|
||||
let permissions = state.borrow_mut::<PermissionsContainer>();
|
||||
permissions.check_read(&oldpath, "Deno.renameSync()")?;
|
||||
|
@ -1377,11 +1377,11 @@ async fn op_rename_async(
|
|||
#[op]
|
||||
fn op_link_sync(
|
||||
state: &mut OpState,
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
oldpath: &str,
|
||||
newpath: &str,
|
||||
) -> Result<(), AnyError> {
|
||||
let oldpath = PathBuf::from(&oldpath);
|
||||
let newpath = PathBuf::from(&newpath);
|
||||
let oldpath = PathBuf::from(oldpath);
|
||||
let newpath = PathBuf::from(newpath);
|
||||
|
||||
let permissions = state.borrow_mut::<PermissionsContainer>();
|
||||
permissions.check_read(&oldpath, "Deno.linkSync()")?;
|
||||
|
@ -1433,12 +1433,12 @@ async fn op_link_async(
|
|||
#[op]
|
||||
fn op_symlink_sync(
|
||||
state: &mut OpState,
|
||||
oldpath: String,
|
||||
newpath: String,
|
||||
oldpath: &str,
|
||||
newpath: &str,
|
||||
_type: Option<String>,
|
||||
) -> Result<(), AnyError> {
|
||||
let oldpath = PathBuf::from(&oldpath);
|
||||
let newpath = PathBuf::from(&newpath);
|
||||
let oldpath = PathBuf::from(oldpath);
|
||||
let newpath = PathBuf::from(newpath);
|
||||
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
|
@ -1631,10 +1631,10 @@ async fn op_ftruncate_async(
|
|||
#[op]
|
||||
fn op_truncate_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
len: u64,
|
||||
) -> Result<(), AnyError> {
|
||||
let path = PathBuf::from(&path);
|
||||
let path = PathBuf::from(path);
|
||||
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
|
@ -1901,13 +1901,13 @@ async fn op_futime_async(
|
|||
#[op]
|
||||
fn op_utime_sync(
|
||||
state: &mut OpState,
|
||||
path: String,
|
||||
path: &str,
|
||||
atime_secs: i64,
|
||||
atime_nanos: u32,
|
||||
mtime_secs: i64,
|
||||
mtime_nanos: u32,
|
||||
) -> Result<(), AnyError> {
|
||||
let path = PathBuf::from(&path);
|
||||
let path = PathBuf::from(path);
|
||||
let atime = filetime::FileTime::from_unix_time(atime_secs, atime_nanos);
|
||||
let mtime = filetime::FileTime::from_unix_time(mtime_secs, mtime_nanos);
|
||||
|
||||
|
|
|
@ -671,7 +671,7 @@ impl Resource for StdFileResource {
|
|||
#[op]
|
||||
pub fn op_print(
|
||||
state: &mut OpState,
|
||||
msg: String,
|
||||
msg: &str,
|
||||
is_err: bool,
|
||||
) -> Result<(), AnyError> {
|
||||
let rid = if is_err { 2 } else { 1 };
|
||||
|
|
|
@ -83,10 +83,10 @@ fn op_exec_path(state: &mut OpState) -> Result<String, AnyError> {
|
|||
#[op]
|
||||
fn op_set_env(
|
||||
state: &mut OpState,
|
||||
key: String,
|
||||
value: String,
|
||||
key: &str,
|
||||
value: &str,
|
||||
) -> Result<(), AnyError> {
|
||||
state.borrow_mut::<PermissionsContainer>().check_env(&key)?;
|
||||
state.borrow_mut::<PermissionsContainer>().check_env(key)?;
|
||||
if key.is_empty() {
|
||||
return Err(type_error("Key is an empty string."));
|
||||
}
|
||||
|
|
|
@ -463,9 +463,9 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> {
|
|||
#[op]
|
||||
fn op_signal_bind(
|
||||
state: &mut OpState,
|
||||
sig: String,
|
||||
sig: &str,
|
||||
) -> Result<ResourceId, AnyError> {
|
||||
let signo = signal_str_to_int(&sig)?;
|
||||
let signo = signal_str_to_int(sig)?;
|
||||
if signal_hook_registry::FORBIDDEN.contains(&signo) {
|
||||
return Err(type_error(format!(
|
||||
"Binding to signal '{sig}' is not allowed",
|
||||
|
@ -483,9 +483,9 @@ fn op_signal_bind(
|
|||
#[op]
|
||||
fn op_signal_bind(
|
||||
state: &mut OpState,
|
||||
sig: String,
|
||||
sig: &str,
|
||||
) -> Result<ResourceId, AnyError> {
|
||||
let signo = signal_str_to_int(&sig)?;
|
||||
let signo = signal_str_to_int(sig)?;
|
||||
let resource = SignalStreamResource {
|
||||
signal: AsyncRefCell::new(match signo {
|
||||
// SIGINT
|
||||
|
|
Loading…
Reference in a new issue