summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/examples/hello_runtime.rs2
-rw-r--r--runtime/ops/file.rs31
-rw-r--r--runtime/ops/mod.rs1
-rw-r--r--runtime/permissions.rs1
-rw-r--r--runtime/web_worker.rs10
-rw-r--r--runtime/worker.rs8
6 files changed, 52 insertions, 1 deletions
diff --git a/runtime/examples/hello_runtime.rs b/runtime/examples/hello_runtime.rs
index e8bf9841e..9c3cbd67e 100644
--- a/runtime/examples/hello_runtime.rs
+++ b/runtime/examples/hello_runtime.rs
@@ -2,6 +2,7 @@
use deno_core::error::AnyError;
use deno_core::FsModuleLoader;
+use deno_runtime::deno_file::BlobUrlStore;
use deno_runtime::permissions::Permissions;
use deno_runtime::worker::MainWorker;
use deno_runtime::worker::WorkerOptions;
@@ -39,6 +40,7 @@ async fn main() -> Result<(), AnyError> {
no_color: false,
get_error_class_fn: Some(&get_error_class_name),
location: None,
+ blob_url_store: BlobUrlStore::default(),
};
let js_path =
diff --git a/runtime/ops/file.rs b/runtime/ops/file.rs
new file mode 100644
index 000000000..e7f68b207
--- /dev/null
+++ b/runtime/ops/file.rs
@@ -0,0 +1,31 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+use deno_core::url::Url;
+use deno_file::op_file_create_object_url;
+use deno_file::op_file_revoke_object_url;
+use deno_file::BlobUrlStore;
+use deno_file::Location;
+
+pub fn init(
+ rt: &mut deno_core::JsRuntime,
+ blob_url_store: BlobUrlStore,
+ maybe_location: Option<Url>,
+) {
+ {
+ let op_state = rt.op_state();
+ let mut op_state = op_state.borrow_mut();
+ op_state.put(blob_url_store);
+ if let Some(location) = maybe_location {
+ op_state.put(Location(location));
+ }
+ }
+ super::reg_json_sync(
+ rt,
+ "op_file_create_object_url",
+ op_file_create_object_url,
+ );
+ super::reg_json_sync(
+ rt,
+ "op_file_revoke_object_url",
+ op_file_revoke_object_url,
+ );
+}
diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs
index 6574546b1..67eae27b2 100644
--- a/runtime/ops/mod.rs
+++ b/runtime/ops/mod.rs
@@ -2,6 +2,7 @@
pub mod crypto;
pub mod fetch;
+pub mod file;
pub mod fs;
pub mod fs_events;
pub mod io;
diff --git a/runtime/permissions.rs b/runtime/permissions.rs
index 6e9000e16..45b7c0bf1 100644
--- a/runtime/permissions.rs
+++ b/runtime/permissions.rs
@@ -587,6 +587,7 @@ impl Permissions {
))),
},
"data" => Ok(()),
+ "blob" => Ok(()),
_ => self.net.check_url(specifier),
}
}
diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs
index f5c81e6d4..c30b715e4 100644
--- a/runtime/web_worker.rs
+++ b/runtime/web_worker.rs
@@ -23,6 +23,7 @@ use deno_core::JsRuntime;
use deno_core::ModuleLoader;
use deno_core::ModuleSpecifier;
use deno_core::RuntimeOptions;
+use deno_file::BlobUrlStore;
use log::debug;
use std::env;
use std::rc::Rc;
@@ -155,6 +156,7 @@ pub struct WebWorkerOptions {
/// Sets `Deno.noColor` in JS runtime.
pub no_color: bool,
pub get_error_class_fn: Option<GetErrorClassFn>,
+ pub blob_url_store: BlobUrlStore,
}
impl WebWorker {
@@ -217,7 +219,7 @@ impl WebWorker {
}
ops::web_worker::init(js_runtime, sender.clone(), handle);
- ops::runtime::init(js_runtime, main_module);
+ ops::runtime::init(js_runtime, main_module.clone());
ops::fetch::init(
js_runtime,
options.user_agent.clone(),
@@ -232,6 +234,11 @@ impl WebWorker {
ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close);
ops::reg_json_sync(js_runtime, "op_resources", deno_core::op_resources);
ops::url::init(js_runtime);
+ ops::file::init(
+ js_runtime,
+ options.blob_url_store.clone(),
+ Some(main_module),
+ );
ops::io::init(js_runtime);
ops::webgpu::init(js_runtime);
ops::websocket::init(
@@ -518,6 +525,7 @@ mod tests {
ts_version: "x".to_string(),
no_color: true,
get_error_class_fn: None,
+ blob_url_store: BlobUrlStore::default(),
};
let mut worker = WebWorker::from_options(
diff --git a/runtime/worker.rs b/runtime/worker.rs
index 00434b313..982198d65 100644
--- a/runtime/worker.rs
+++ b/runtime/worker.rs
@@ -21,6 +21,7 @@ use deno_core::ModuleId;
use deno_core::ModuleLoader;
use deno_core::ModuleSpecifier;
use deno_core::RuntimeOptions;
+use deno_file::BlobUrlStore;
use log::debug;
use std::env;
use std::rc::Rc;
@@ -66,6 +67,7 @@ pub struct WorkerOptions {
pub no_color: bool,
pub get_error_class_fn: Option<GetErrorClassFn>,
pub location: Option<Url>,
+ pub blob_url_store: BlobUrlStore,
}
impl MainWorker {
@@ -129,6 +131,11 @@ impl MainWorker {
ops::reg_json_sync(js_runtime, "op_close", deno_core::op_close);
ops::reg_json_sync(js_runtime, "op_resources", deno_core::op_resources);
ops::url::init(js_runtime);
+ ops::file::init(
+ js_runtime,
+ options.blob_url_store.clone(),
+ options.location.clone(),
+ );
ops::fs_events::init(js_runtime);
ops::fs::init(js_runtime);
ops::io::init(js_runtime);
@@ -298,6 +305,7 @@ mod tests {
no_color: true,
get_error_class_fn: None,
location: None,
+ blob_url_store: BlobUrlStore::default(),
};
MainWorker::from_options(main_module, permissions, &options)