mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
perf: remove current_dir()
call in Deno.mainModule
(#17883)
This commit is contained in:
parent
1c14127c4f
commit
a31d8869ea
1 changed files with 4 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::permissions::PermissionsContainer;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::op;
|
||||
use deno_core::Extension;
|
||||
|
@ -20,17 +19,15 @@ pub fn init(main_module: ModuleSpecifier) -> Extension {
|
|||
|
||||
#[op]
|
||||
fn op_main_module(state: &mut OpState) -> Result<String, AnyError> {
|
||||
let main = state.borrow::<ModuleSpecifier>().to_string();
|
||||
let main_url = deno_core::resolve_url_or_path(&main)?;
|
||||
let main_url = state.borrow::<ModuleSpecifier>();
|
||||
let main_path = main_url.to_string();
|
||||
if main_url.scheme() == "file" {
|
||||
let main_path = std::env::current_dir()
|
||||
.context("Failed to get current working directory")?
|
||||
.join(main_url.to_string());
|
||||
let main_path = main_url.to_file_path().unwrap();
|
||||
state
|
||||
.borrow_mut::<PermissionsContainer>()
|
||||
.check_read_blind(&main_path, "main_module", "Deno.mainModule")?;
|
||||
}
|
||||
Ok(main)
|
||||
Ok(main_path)
|
||||
}
|
||||
|
||||
pub fn ppid() -> i64 {
|
||||
|
|
Loading…
Reference in a new issue