summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-12-19 02:44:42 +0530
committerGitHub <noreply@github.com>2021-12-18 16:14:42 -0500
commit6de53b631fcdb96d72639b6d2db3592d5fa8498d (patch)
tree9a93d868f5f434a4898f212cb6bd53e65ca49ce0 /runtime
parent3db18bf9e6466c74efd9052df4d372ea0b581154 (diff)
refactor: use `once_cell` instead of `lazy_static` (#13135)
Diffstat (limited to 'runtime')
-rw-r--r--runtime/Cargo.toml2
-rw-r--r--runtime/colors.rs6
-rw-r--r--runtime/ops/io.rs54
-rw-r--r--runtime/permissions.rs12
4 files changed, 39 insertions, 35 deletions
diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml
index d26836bd6..33d72e706 100644
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -68,10 +68,10 @@ filetime = "0.2.15"
fs3 = "0.5.0"
http = "0.2.4"
hyper = { version = "0.14.12", features = ["server", "stream", "http1", "http2", "runtime"] }
-lazy_static = "1.4.0"
libc = "0.2.106"
log = "0.4.14"
notify = "=5.0.0-pre.12"
+once_cell = "=1.9.0"
regex = "1.5.4"
ring = "0.16.20"
serde = { version = "1.0.129", features = ["derive"] }
diff --git a/runtime/colors.rs b/runtime/colors.rs
index 00241b4e0..c66f528db 100644
--- a/runtime/colors.rs
+++ b/runtime/colors.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+use once_cell::sync::Lazy;
use std::fmt;
use std::io::Write;
use termcolor::Color::{Ansi256, Black, Blue, Cyan, Green, Red, White, Yellow};
@@ -8,9 +9,8 @@ use termcolor::{Ansi, ColorSpec, WriteColor};
#[cfg(windows)]
use termcolor::{BufferWriter, ColorChoice};
-lazy_static::lazy_static! {
- static ref NO_COLOR: bool = std::env::var_os("NO_COLOR").is_some();
-}
+static NO_COLOR: Lazy<bool> =
+ Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
pub fn use_color() -> bool {
!(*NO_COLOR)
diff --git a/runtime/ops/io.rs b/runtime/ops/io.rs
index e1128e833..89da5f508 100644
--- a/runtime/ops/io.rs
+++ b/runtime/ops/io.rs
@@ -15,6 +15,7 @@ use deno_core::RcRef;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
+use once_cell::sync::Lazy;
use std::borrow::Cow;
use std::fs::File as StdFile;
use std::io::Read;
@@ -36,32 +37,35 @@ use {
};
#[cfg(unix)]
-lazy_static::lazy_static! {
- static ref STDIN_HANDLE: StdFile = unsafe { StdFile::from_raw_fd(0) };
- static ref STDOUT_HANDLE: StdFile = unsafe { StdFile::from_raw_fd(1) };
- static ref STDERR_HANDLE: StdFile = unsafe { StdFile::from_raw_fd(2) };
-}
-
+static STDIN_HANDLE: Lazy<StdFile> =
+ Lazy::new(|| unsafe { StdFile::from_raw_fd(0) });
+#[cfg(unix)]
+static STDOUT_HANDLE: Lazy<StdFile> =
+ Lazy::new(|| unsafe { StdFile::from_raw_fd(1) });
+#[cfg(unix)]
+static STDERR_HANDLE: Lazy<StdFile> =
+ Lazy::new(|| unsafe { StdFile::from_raw_fd(2) });
+
+/// Due to portability issues on Windows handle to stdout is created from raw
+/// file descriptor. The caveat of that approach is fact that when this
+/// handle is dropped underlying file descriptor is closed - that is highly
+/// not desirable in case of stdout. That's why we store this global handle
+/// that is then cloned when obtaining stdio for process. In turn when
+/// resource table is dropped storing reference to that handle, the handle
+/// itself won't be closed (so Deno.core.print) will still work.
+// TODO(ry) It should be possible to close stdout.
#[cfg(windows)]
-lazy_static::lazy_static! {
- /// Due to portability issues on Windows handle to stdout is created from raw
- /// file descriptor. The caveat of that approach is fact that when this
- /// handle is dropped underlying file descriptor is closed - that is highly
- /// not desirable in case of stdout. That's why we store this global handle
- /// that is then cloned when obtaining stdio for process. In turn when
- /// resource table is dropped storing reference to that handle, the handle
- /// itself won't be closed (so Deno.core.print) will still work.
- // TODO(ry) It should be possible to close stdout.
- static ref STDIN_HANDLE: StdFile = unsafe {
- StdFile::from_raw_handle(GetStdHandle(winbase::STD_INPUT_HANDLE))
- };
- static ref STDOUT_HANDLE: StdFile = unsafe {
- StdFile::from_raw_handle(GetStdHandle(winbase::STD_OUTPUT_HANDLE))
- };
- static ref STDERR_HANDLE: StdFile = unsafe {
- StdFile::from_raw_handle(GetStdHandle(winbase::STD_ERROR_HANDLE))
- };
-}
+static STDIN_HANDLE: Lazy<StdFile> = Lazy::new(|| unsafe {
+ StdFile::from_raw_handle(GetStdHandle(winbase::STD_INPUT_HANDLE))
+});
+#[cfg(windows)]
+static STDOUT_HANDLE: Lazy<StdFile> = Lazy::new(|| unsafe {
+ StdFile::from_raw_handle(GetStdHandle(winbase::STD_OUTPUT_HANDLE))
+});
+#[cfg(windows)]
+static STDERR_HANDLE: Lazy<StdFile> = Lazy::new(|| unsafe {
+ StdFile::from_raw_handle(GetStdHandle(winbase::STD_ERROR_HANDLE))
+});
pub fn init() -> Extension {
Extension::builder()
diff --git a/runtime/permissions.rs b/runtime/permissions.rs
index 50c126f3f..1b0d8b914 100644
--- a/runtime/permissions.rs
+++ b/runtime/permissions.rs
@@ -16,6 +16,7 @@ use deno_core::url;
use deno_core::ModuleSpecifier;
use deno_core::OpState;
use log;
+use once_cell::sync::Lazy;
use std::collections::HashSet;
use std::fmt;
use std::hash::Hash;
@@ -29,9 +30,8 @@ use std::sync::atomic::Ordering;
const PERMISSION_EMOJI: &str = "⚠️";
-lazy_static::lazy_static! {
- static ref DEBUG_LOG_ENABLED: bool = log::log_enabled!(log::Level::Debug);
-}
+static DEBUG_LOG_ENABLED: Lazy<bool> =
+ Lazy::new(|| log::log_enabled!(log::Level::Debug));
/// Tri-state value for storing permission state
#[derive(PartialEq, Debug, Clone, Copy, Deserialize, PartialOrd)]
@@ -2017,9 +2017,9 @@ fn permission_prompt(_message: &str) -> bool {
static STUB_PROMPT_VALUE: AtomicBool = AtomicBool::new(true);
#[cfg(test)]
-lazy_static::lazy_static! {
- static ref PERMISSION_PROMPT_STUB_VALUE_SETTER: Mutex<PermissionPromptStubValueSetter> = Mutex::new(PermissionPromptStubValueSetter);
-}
+static PERMISSION_PROMPT_STUB_VALUE_SETTER: Lazy<
+ Mutex<PermissionPromptStubValueSetter>,
+> = Lazy::new(|| Mutex::new(PermissionPromptStubValueSetter));
#[cfg(test)]
struct PermissionPromptStubValueSetter;