Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 13, 2019
1 parent 0d64eef commit 7f680d0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 88 deletions.
75 changes: 0 additions & 75 deletions cli/dyn_import.rs

This file was deleted.

1 change: 0 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod deno_error;
pub mod diagnostics;
mod disk_cache;
mod dispatch_minimal;
mod dyn_import;
mod file_fetcher;
pub mod flags;
pub mod fmt_errors;
Expand Down
27 changes: 25 additions & 2 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::compilers::JsCompiler;
use crate::compilers::JsonCompiler;
use crate::compilers::TsCompiler;
use crate::deno_dir;
use crate::dyn_import;
use crate::file_fetcher::SourceFileFetcher;
use crate::flags;
use crate::global_timer::GlobalTimer;
Expand Down Expand Up @@ -134,7 +133,7 @@ impl Loader for ThreadSafeState {
ModuleSpecifier::resolve_import(specifier, referrer)?;

if is_dyn_import {
dyn_import::check_permissions(self.clone(), &module_specifier)?;
self.check_dyn_import(&module_specifier)?;
}

Ok(module_specifier)
Expand Down Expand Up @@ -311,6 +310,30 @@ impl ThreadSafeState {
self.permissions.check_run()
}

pub fn check_dyn_import(
self: &Self,
module_specifier: &ModuleSpecifier,
) -> Result<(), ErrBox> {
let u = module_specifier.as_url();
match u.scheme() {
"http" | "https" => {
self.check_net_url(u)?;
}
"file" => {
let filename = u
.to_file_path()
.unwrap()
.into_os_string()
.into_string()
.unwrap();
self.check_read(&filename)?;
}
// TODO(ry) Handle error without gracefully.
_ => panic!("Unsupported scheme for dynamic import"),
}
Ok(())
}

#[cfg(test)]
pub fn mock(argv: Vec<String>) -> ThreadSafeState {
ThreadSafeState::new(
Expand Down
15 changes: 6 additions & 9 deletions cli/worker.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::dyn_import;
use crate::fmt_errors::JSError;
use crate::state::ThreadSafeState;
use crate::tokio_util;
Expand Down Expand Up @@ -40,14 +39,12 @@ impl Worker {

let state_ = state.clone();
i.set_dyn_import(move |id, specifier, referrer| {
Box::new(dyn_import::DynamicRecursiveLoad(
RecursiveLoad::dynamic_import(
id,
specifier,
referrer,
state_.clone(),
state_.modules.clone(),
),
Box::new(RecursiveLoad::dynamic_import(
id,
specifier,
referrer,
state_.clone(),
state_.modules.clone(),
))
});

Expand Down
2 changes: 1 addition & 1 deletion tests/error_015_dynamic_import_permissions.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[WILDCARD]error: Uncaught TypeError: permission denied
error: Uncaught TypeError: permission denied

0 comments on commit 7f680d0

Please sign in to comment.