diff --git a/cli/bench/console.js b/cli/bench/console.js index 1e0ebb37a6..b1873953c3 100644 --- a/cli/bench/console.js +++ b/cli/bench/console.js @@ -1,3 +1,8 @@ // Copyright 2018-2022 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}`); diff --git a/cli/bench/encode_into.js b/cli/bench/encode_into.js index 458a88b84c..aaee234348 100644 --- a/cli/bench/encode_into.js +++ b/cli/bench/encode_into.js @@ -1,10 +1,11 @@ // Copyright 2018-2022 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) : 10000000; +count = count ? parseInt(count, 10) : 1000000; function bench(fun) { const start = Date.now(); @@ -12,7 +13,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) bench(fun); + if (--total) queueMicrotask(() => bench(fun)); } const encoder = new TextEncoder(); diff --git a/cli/bench/webstorage.js b/cli/bench/webstorage.js deleted file mode 100644 index bdb10e5681..0000000000 --- a/cli/bench/webstorage.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2018-2022 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")); diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index a587de3761..3751712f08 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -710,9 +710,9 @@ pub fn resolve_npm_package_reference_types( } #[op] -fn op_is_node_file(state: &mut OpState, path: &str) -> bool { +fn op_is_node_file(state: &mut OpState, path: String) -> bool { let state = state.borrow::(); - match ModuleSpecifier::parse(path) { + match ModuleSpecifier::parse(&path) { Ok(specifier) => state .maybe_npm_resolver .as_ref() diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 858ce97bd8..6374e9951e 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -107,7 +107,7 @@ pub fn op_metrics(state: &mut OpState) -> (OpMetrics, Vec) { /// Builtin utility to print to stdout/stderr #[op] -pub fn op_print(msg: &str, is_err: bool) -> Result<(), Error> { +pub fn op_print(msg: String, is_err: bool) -> Result<(), Error> { if is_err { stderr().write_all(msg.as_bytes())?; stderr().flush().unwrap(); @@ -152,12 +152,12 @@ pub fn op_wasm_streaming_feed( pub fn op_wasm_streaming_set_url( state: &mut OpState, rid: ResourceId, - url: &str, + url: String, ) -> Result<(), Error> { let wasm_streaming = state.resource_table.get::(rid)?; - wasm_streaming.0.borrow_mut().set_url(url); + wasm_streaming.0.borrow_mut().set_url(&url); Ok(()) } diff --git a/ext/node/lib.rs b/ext/node/lib.rs index 5282c0660b..b2443db0bb 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -262,7 +262,7 @@ fn op_require_proxy_path(filename: String) -> String { } #[op] -fn op_require_is_request_relative(request: &str) -> bool { +fn op_require_is_request_relative(request: String) -> bool { if request.starts_with("./") || request.starts_with("../") || request == ".." { return true; diff --git a/ext/url/00_url.js b/ext/url/00_url.js index 754c647b12..5479cb59ce 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -56,12 +56,12 @@ function opUrlParse(href, maybeBase) { let status; if (maybeBase === undefined) { - status = ops.op_url_parse(href, componentsBuf); + status = ops.op_url_parse(href, componentsBuf.buffer); } else { - status = ops.op_url_parse_with_base( + status = core.ops.op_url_parse_with_base( href, maybeBase, - componentsBuf, + componentsBuf.buffer, ); } return getSerialization(status, href); @@ -71,7 +71,7 @@ if (status === 0) { return href; } else if (status === 1) { - return ops.op_url_get_serialization(); + return core.ops.op_url_get_serialization(); } else { throw new TypeError("Invalid URL"); } diff --git a/ext/url/lib.rs b/ext/url/lib.rs index 01014ccd34..ac668207fd 100644 --- a/ext/url/lib.rs +++ b/ext/url/lib.rs @@ -41,11 +41,11 @@ pub fn init() -> Extension { #[op] pub fn op_url_parse_with_base( state: &mut OpState, - href: &str, - base_href: &str, - buf: &mut [u32], + href: String, + base_href: String, + buf: &mut [u8], ) -> 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, }; @@ -67,8 +67,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(fast)] -pub fn op_url_parse(state: &mut OpState, href: &str, buf: &mut [u32]) -> u32 { +#[op] +pub fn op_url_parse(state: &mut OpState, href: String, buf: &mut [u8]) -> u32 { parse_url(state, href, None, buf) } @@ -99,14 +99,15 @@ pub fn op_url_parse(state: &mut OpState, href: &str, buf: &mut [u32]) -> u32 { #[inline] fn parse_url( state: &mut OpState, - href: &str, + href: String, base_href: Option<&Url>, - buf: &mut [u32], + buf: &mut [u8], ) -> 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; diff --git a/ext/web/blob.rs b/ext/web/blob.rs index 5f19368609..7da42e178c 100644 --- a/ext/web/blob.rs +++ b/ext/web/blob.rs @@ -252,9 +252,9 @@ pub fn op_blob_create_object_url( #[op] pub fn op_blob_revoke_object_url( state: &mut deno_core::OpState, - url: &str, + url: String, ) -> Result<(), AnyError> { - let url = Url::parse(url)?; + let url = Url::parse(&url)?; let blob_store = state.borrow::(); blob_store.remove_object_url(&url); Ok(()) diff --git a/ext/web/compression.rs b/ext/web/compression.rs index 05dcf02b19..d2647e4988 100644 --- a/ext/web/compression.rs +++ b/ext/web/compression.rs @@ -41,11 +41,11 @@ impl Resource for CompressionResource { #[op] pub fn op_compression_new( state: &mut OpState, - format: &str, + format: String, is_decoder: bool, ) -> ResourceId { let w = Vec::new(); - let inner = match (format, is_decoder) { + let inner = match (format.as_str(), is_decoder) { ("deflate", true) => Inner::DeflateDecoder(ZlibDecoder::new(w)), ("deflate", false) => { Inner::DeflateEncoder(ZlibEncoder::new(w, Compression::default())) diff --git a/ext/web/lib.rs b/ext/web/lib.rs index 7c75a9a288..cfbcee6e3d 100644 --- a/ext/web/lib.rs +++ b/ext/web/lib.rs @@ -270,7 +270,7 @@ fn op_encoding_decode_single( #[op] fn op_encoding_new_decoder( state: &mut OpState, - label: &str, + label: String, fatal: bool, ignore_bom: bool, ) -> Result { @@ -352,43 +352,25 @@ impl Resource for TextDecoderResource { } } -#[op] +#[op(v8)] fn op_encoding_encode_into( - input: Cow<'_, str>, + scope: &mut v8::HandleScope, + input: serde_v8::Value, buffer: &mut [u8], out_buf: &mut [u32], -) { - // 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(); +) -> Result<(), AnyError> { + let s = v8::Local::::try_from(input.v8_value)?; - // 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; + 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(()) } #[op(v8)] diff --git a/ext/webstorage/lib.rs b/ext/webstorage/lib.rs index 58b7c07e43..6284a59bc6 100644 --- a/ext/webstorage/lib.rs +++ b/ext/webstorage/lib.rs @@ -139,8 +139,8 @@ pub fn op_webstorage_key( #[op] pub fn op_webstorage_set( state: &mut OpState, - key: &str, - value: &str, + key: String, + value: String, persistent: bool, ) -> Result<(), AnyError> { let conn = get_webstorage(state, persistent)?; @@ -184,7 +184,7 @@ pub fn op_webstorage_get( #[op] pub fn op_webstorage_remove( state: &mut OpState, - key_name: &str, + key_name: String, persistent: bool, ) -> Result<(), AnyError> { let conn = get_webstorage(state, persistent)?; diff --git a/ops/fast_call.rs b/ops/fast_call.rs index 1d6bfa1fa2..f2ed8cb2d7 100644 --- a/ops/fast_call.rs +++ b/ops/fast_call.rs @@ -403,9 +403,7 @@ fn q_fast_ty(v: &FastValue) -> Quote { FastValue::F64 => q!({ f64 }), FastValue::Bool => q!({ bool }), FastValue::V8Value => q!({ v8::Local }), - FastValue::Uint8Array - | FastValue::Uint32Array - | FastValue::SeqOneByteString => unreachable!(), + FastValue::Uint8Array | FastValue::Uint32Array => unreachable!(), } } @@ -423,7 +421,6 @@ fn q_fast_ty_variant(v: &FastValue) -> Quote { FastValue::V8Value => q!({ V8Value }), FastValue::Uint8Array => q!({ TypedArray(CType::Uint8) }), FastValue::Uint32Array => q!({ TypedArray(CType::Uint32) }), - FastValue::SeqOneByteString => q!({ SeqOneByteString }), } } diff --git a/ops/lib.rs b/ops/lib.rs index 7fa800b14c..b4bef1d138 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -411,12 +411,7 @@ fn codegen_arg( return quote! { let #ident = (); }; } // Fast path for `String` - if let Some(is_ref) = is_string(&**ty) { - let ref_block = if is_ref { - quote! { let #ident = #ident.as_ref(); } - } else { - quote! {} - }; + if is_string(&**ty) { 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), @@ -424,18 +419,6 @@ 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` @@ -646,25 +629,14 @@ fn is_result(ty: impl ToTokens) -> bool { } } -fn is_string(ty: impl ToTokens) -> Option { - let toks = tokens(ty); - if toks == "String" { - return Some(false); - } - if toks == "& str" { - return Some(true); - } - None +fn is_string(ty: impl ToTokens) -> bool { + tokens(ty) == "String" } 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, diff --git a/ops/optimizer.rs b/ops/optimizer.rs index 99de4b4240..2d68a296fd 100644 --- a/ops/optimizer.rs +++ b/ops/optimizer.rs @@ -19,20 +19,12 @@ pub(crate) enum BailoutReason { FastUnsupportedParamType, } -#[derive(Debug, PartialEq)] -enum StringType { - Cow, - Ref, - Owned, -} - #[derive(Debug, PartialEq)] enum TransformKind { // serde_v8::Value V8Value, SliceU32(bool), SliceU8(bool), - SeqOneByteString(StringType), PtrU8, WasmMemory, } @@ -59,13 +51,6 @@ 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, @@ -147,21 +132,6 @@ 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. q!(Vars { var: &ident, core }, { @@ -228,7 +198,6 @@ pub(crate) enum FastValue { V8Value, Uint8Array, Uint32Array, - SeqOneByteString, } impl Default for FastValue { @@ -581,58 +550,10 @@ 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); } @@ -655,17 +576,6 @@ 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), } } diff --git a/ops/optimizer_tests/cow_str.expected b/ops/optimizer_tests/cow_str.expected deleted file mode 100644 index 8b28965bad..0000000000 --- a/ops/optimizer_tests/cow_str.expected +++ /dev/null @@ -1,11 +0,0 @@ -=== 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 diff --git a/ops/optimizer_tests/cow_str.out b/ops/optimizer_tests/cow_str.out deleted file mode 100644 index da405f451d..0000000000 --- a/ops/optimizer_tests/cow_str.out +++ /dev/null @@ -1,87 +0,0 @@ -#[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::::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, - 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 -} diff --git a/ops/optimizer_tests/cow_str.rs b/ops/optimizer_tests/cow_str.rs deleted file mode 100644 index b7214bdc7e..0000000000 --- a/ops/optimizer_tests/cow_str.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn op_cow_str(c: Cow<'_, str>) { - // ... -} diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.expected b/ops/optimizer_tests/op_blob_revoke_object_url.expected index 5b3e43edc3..0fae25e860 100644 --- a/ops/optimizer_tests/op_blob_revoke_object_url.expected +++ b/ops/optimizer_tests/op_blob_revoke_object_url.expected @@ -1,11 +1 @@ -=== 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: true +MustBeSingleSegment \ No newline at end of file diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.out b/ops/optimizer_tests/op_blob_revoke_object_url.out index 28fe17acb8..72bc75e059 100644 --- a/ops/optimizer_tests/op_blob_revoke_object_url.out +++ b/ops/optimizer_tests/op_blob_revoke_object_url.out @@ -18,11 +18,7 @@ impl op_blob_revoke_object_url { name: Self::name(), v8_fn_ptr: Self::v8_fn_ptr(), enabled: true, - fast_fn: Some( - Box::new(op_blob_revoke_object_url_fast { - _phantom: ::std::marker::PhantomData, - }), - ), + fast_fn: None, is_async: false, is_unstable: false, is_v8: false, @@ -31,7 +27,7 @@ impl op_blob_revoke_object_url { } #[inline] #[allow(clippy::too_many_arguments)] - pub fn call(state: &mut OpState, url: String) -> Result<(), AnyError> { + pub fn call(state: &mut deno_core::OpState, url: String) -> Result<(), AnyError> { let url = Url::parse(&url)?; let blob_store = state.borrow::(); blob_store.remove_object_url(&url); @@ -46,18 +42,6 @@ impl op_blob_revoke_object_url { &*(deno_core::v8::Local::::cast(args.data()).value() as *const deno_core::_ops::OpCtx) }; - { - let op_state = &mut std::cell::RefCell::borrow_mut(&ctx.state); - if let Some(err) = op_state.last_fast_op_error.take() { - let exception = deno_core::error::to_v8_error( - scope, - op_state.get_error_class_fn, - &err, - ); - scope.throw_exception(exception); - return; - } - } let arg_0 = match deno_core::v8::Local::< deno_core::v8::String, >::try_from(args.get(0usize as i32)) { @@ -85,45 +69,3 @@ impl op_blob_revoke_object_url { }; } } -struct op_blob_revoke_object_url_fast { - _phantom: ::std::marker::PhantomData<()>, -} -impl<'scope> deno_core::v8::fast_api::FastFunction for op_blob_revoke_object_url_fast { - fn function(&self) -> *const ::std::ffi::c_void { - op_blob_revoke_object_url_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, CallbackOptions] - } - fn return_type(&self) -> deno_core::v8::fast_api::CType { - deno_core::v8::fast_api::CType::Void - } -} -fn op_blob_revoke_object_url_fast_fn<'scope>( - _: deno_core::v8::Local, - url: *const deno_core::v8::fast_api::FastApiOneByteString, - fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, -) -> () { - use deno_core::v8; - use deno_core::_ops; - let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { - &mut *fast_api_callback_options - }; - let __ctx = unsafe { - &*(v8::Local::::cast(unsafe { __opts.data.data }).value() - as *const _ops::OpCtx) - }; - let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); - let url = unsafe { &*url }.as_str().to_owned(); - let result = op_blob_revoke_object_url::call(state, url); - match result { - Ok(result) => result, - Err(err) => { - state.last_fast_op_error.replace(err); - __opts.fallback = true; - Default::default() - } - } -} diff --git a/ops/optimizer_tests/op_blob_revoke_object_url.rs b/ops/optimizer_tests/op_blob_revoke_object_url.rs index b51a2ed7f5..8e139da06d 100644 --- a/ops/optimizer_tests/op_blob_revoke_object_url.rs +++ b/ops/optimizer_tests/op_blob_revoke_object_url.rs @@ -1,5 +1,5 @@ pub fn op_blob_revoke_object_url( - state: &mut OpState, + state: &mut deno_core::OpState, url: String, ) -> Result<(), AnyError> { let url = Url::parse(&url)?; diff --git a/ops/optimizer_tests/op_print.expected b/ops/optimizer_tests/op_print.expected deleted file mode 100644 index fb52693aa2..0000000000 --- a/ops/optimizer_tests/op_print.expected +++ /dev/null @@ -1,11 +0,0 @@ -=== 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: true diff --git a/ops/optimizer_tests/op_print.out b/ops/optimizer_tests/op_print.out deleted file mode 100644 index 5d0062a01a..0000000000 --- a/ops/optimizer_tests/op_print.out +++ /dev/null @@ -1,141 +0,0 @@ -#[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: Some( - Box::new(op_print_fast { - _phantom: ::std::marker::PhantomData, - }), - ), - 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::::cast(args.data()).value() - as *const deno_core::_ops::OpCtx) - }; - { - let op_state = &mut std::cell::RefCell::borrow_mut(&ctx.state); - if let Some(err) = op_state.last_fast_op_error.take() { - let exception = deno_core::error::to_v8_error( - scope, - op_state.get_error_class_fn, - &err, - ); - scope.throw_exception(exception); - return; - } - } - 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); - } - }; - } -} -struct op_print_fast { - _phantom: ::std::marker::PhantomData<()>, -} -impl<'scope> deno_core::v8::fast_api::FastFunction for op_print_fast { - fn function(&self) -> *const ::std::ffi::c_void { - op_print_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, Bool, CallbackOptions] - } - fn return_type(&self) -> deno_core::v8::fast_api::CType { - deno_core::v8::fast_api::CType::Void - } -} -fn op_print_fast_fn<'scope>( - _: deno_core::v8::Local, - msg: *const deno_core::v8::fast_api::FastApiOneByteString, - is_err: bool, - fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, -) -> () { - use deno_core::v8; - use deno_core::_ops; - let __opts: &mut v8::fast_api::FastApiCallbackOptions = unsafe { - &mut *fast_api_callback_options - }; - let __ctx = unsafe { - &*(v8::Local::::cast(unsafe { __opts.data.data }).value() - as *const _ops::OpCtx) - }; - let state = &mut ::std::cell::RefCell::borrow_mut(&__ctx.state); - let msg = unsafe { &*msg }.as_str(); - let result = op_print::call(state, msg, is_err); - match result { - Ok(result) => result, - Err(err) => { - state.last_fast_op_error.replace(err); - __opts.fallback = true; - Default::default() - } - } -} diff --git a/ops/optimizer_tests/op_print.rs b/ops/optimizer_tests/op_print.rs deleted file mode 100644 index 516521a0e9..0000000000 --- a/ops/optimizer_tests/op_print.rs +++ /dev/null @@ -1,6 +0,0 @@ -fn op_print( - state: &mut OpState, - msg: &str, - is_err: bool, -) -> Result<(), AnyError> { -} diff --git a/ops/optimizer_tests/owned_string.expected b/ops/optimizer_tests/owned_string.expected deleted file mode 100644 index a152754129..0000000000 --- a/ops/optimizer_tests/owned_string.expected +++ /dev/null @@ -1,11 +0,0 @@ -=== 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 diff --git a/ops/optimizer_tests/owned_string.out b/ops/optimizer_tests/owned_string.out deleted file mode 100644 index 4892221f81..0000000000 --- a/ops/optimizer_tests/owned_string.out +++ /dev/null @@ -1,99 +0,0 @@ -#[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::::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, - 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 -} diff --git a/ops/optimizer_tests/owned_string.rs b/ops/optimizer_tests/owned_string.rs deleted file mode 100644 index 102cf00fb9..0000000000 --- a/ops/optimizer_tests/owned_string.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn op_string_length(string: String) -> u32 { - string.len() as u32 -} diff --git a/ops/optimizer_tests/strings.expected b/ops/optimizer_tests/strings.expected deleted file mode 100644 index ead741054a..0000000000 --- a/ops/optimizer_tests/strings.expected +++ /dev/null @@ -1,11 +0,0 @@ -=== 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 diff --git a/ops/optimizer_tests/strings.out b/ops/optimizer_tests/strings.out deleted file mode 100644 index 41f09c4f8d..0000000000 --- a/ops/optimizer_tests/strings.out +++ /dev/null @@ -1,100 +0,0 @@ -#[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::::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, - 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 -} diff --git a/ops/optimizer_tests/strings.rs b/ops/optimizer_tests/strings.rs deleted file mode 100644 index 860f1e8ec9..0000000000 --- a/ops/optimizer_tests/strings.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn op_string_length(string: &str) -> u32 { - string.len() as u32 -} diff --git a/runtime/ops/fs.rs b/runtime/ops/fs.rs index b661c6ea80..ec60eed62c 100644 --- a/runtime/ops/fs.rs +++ b/runtime/ops/fs.rs @@ -530,13 +530,13 @@ fn op_umask(state: &mut OpState, mask: Option) -> Result { } #[op] -fn op_chdir(state: &mut OpState, directory: &str) -> Result<(), AnyError> { +fn op_chdir(state: &mut OpState, directory: String) -> Result<(), AnyError> { let d = PathBuf::from(&directory); state .borrow_mut::() .read .check(&d, Some("Deno.chdir()"))?; - set_current_dir(d).map_err(|err| { + set_current_dir(&d).map_err(|err| { Error::new(err.kind(), format!("{}, chdir '{}'", err, directory)) })?; Ok(()) @@ -609,10 +609,10 @@ async fn op_mkdir_async( #[op] fn op_chmod_sync( state: &mut OpState, - path: &str, + path: String, mode: u32, ) -> Result<(), AnyError> { - let path = Path::new(path); + let path = Path::new(&path); let mode = mode & 0o777; state @@ -667,11 +667,11 @@ fn raw_chmod(path: &Path, _raw_mode: u32) -> Result<(), AnyError> { #[op] fn op_chown_sync( state: &mut OpState, - path: &str, + path: String, #[cfg_attr(windows, allow(unused_variables))] uid: Option, #[cfg_attr(windows, allow(unused_variables))] gid: Option, ) -> Result<(), AnyError> { - let path = Path::new(path).to_path_buf(); + let path = Path::new(&path).to_path_buf(); state .borrow_mut::() .write @@ -740,10 +740,10 @@ async fn op_chown_async( #[op] fn op_remove_sync( state: &mut OpState, - path: &str, + path: String, recursive: bool, ) -> Result<(), AnyError> { - let path = PathBuf::from(path); + let path = PathBuf::from(&path); state .borrow_mut::() @@ -841,11 +841,11 @@ async fn op_remove_async( #[op] fn op_copy_file_sync( state: &mut OpState, - from: &str, - to: &str, + from: String, + to: String, ) -> 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::(); permissions @@ -1103,11 +1103,11 @@ pub struct StatArgs { #[op] fn op_stat_sync( state: &mut OpState, - path: &str, + path: String, lstat: bool, out_buf: &mut [u32], ) -> Result<(), AnyError> { - let path = PathBuf::from(path); + let path = PathBuf::from(&path); state .borrow_mut::() .read @@ -1319,11 +1319,11 @@ async fn op_read_dir_async( #[op] fn op_rename_sync( state: &mut OpState, - oldpath: &str, - newpath: &str, + oldpath: String, + newpath: String, ) -> 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::(); permissions @@ -1388,11 +1388,11 @@ async fn op_rename_async( #[op] fn op_link_sync( state: &mut OpState, - oldpath: &str, - newpath: &str, + oldpath: String, + newpath: String, ) -> 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::(); permissions.read.check(&oldpath, Some("Deno.linkSync()"))?; @@ -1455,12 +1455,12 @@ async fn op_link_async( #[op] fn op_symlink_sync( state: &mut OpState, - oldpath: &str, - newpath: &str, + oldpath: String, + newpath: String, _type: Option, ) -> 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::() @@ -1675,10 +1675,10 @@ async fn op_ftruncate_async( #[op] fn op_truncate_sync( state: &mut OpState, - path: &str, + path: String, len: u64, ) -> Result<(), AnyError> { - let path = PathBuf::from(path); + let path = PathBuf::from(&path); state .borrow_mut::() @@ -1955,13 +1955,13 @@ async fn op_futime_async( #[op] fn op_utime_sync( state: &mut OpState, - path: &str, + path: String, 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); diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs index d8a1af69e0..646a540bc4 100644 --- a/runtime/ops/io.rs +++ b/runtime/ops/io.rs @@ -670,7 +670,7 @@ impl Resource for StdFileResource { #[op] pub fn op_print( state: &mut OpState, - msg: &str, + msg: String, is_err: bool, ) -> Result<(), AnyError> { let rid = if is_err { 2 } else { 1 }; diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 844fbaecc0..b93935955b 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -78,10 +78,10 @@ fn op_exec_path(state: &mut OpState) -> Result { #[op] fn op_set_env( state: &mut OpState, - key: &str, - value: &str, + key: String, + value: String, ) -> Result<(), AnyError> { - state.borrow_mut::().env.check(key)?; + state.borrow_mut::().env.check(&key)?; if key.is_empty() { return Err(type_error("Key is an empty string.")); } diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 66530a8384..95c166787c 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -453,9 +453,9 @@ pub fn signal_int_to_str(s: libc::c_int) -> Result<&'static str, AnyError> { #[op] fn op_signal_bind( state: &mut OpState, - sig: &str, + sig: String, ) -> Result { - 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 '{}' is not allowed", @@ -474,9 +474,9 @@ fn op_signal_bind( #[op] fn op_signal_bind( state: &mut OpState, - sig: &str, + sig: String, ) -> Result { - let signo = signal_str_to_int(sig)?; + let signo = signal_str_to_int(&sig)?; let resource = SignalStreamResource { signal: AsyncRefCell::new(match signo { // SIGINT