1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

perf: remove current_dir() call in Deno.mainModule (#17883)

This commit is contained in:
David Sherret 2023-02-22 18:22:24 -05:00 committed by GitHub
parent 1c14127c4f
commit a31d8869ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {