summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index e515081df..cb2fb01a0 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -17,6 +17,10 @@ pub fn init(i: &mut Isolate, s: &ThreadSafeState) {
"fetch_source_files",
s.core_op(json_op(s.stateful_op(op_fetch_source_files))),
);
+ i.register_op(
+ "fetch_asset",
+ s.core_op(json_op(s.stateful_op(op_fetch_asset))),
+ );
}
#[derive(Deserialize)]
@@ -145,3 +149,21 @@ fn op_fetch_source_files(
Ok(JsonOp::Async(future))
}
+
+#[derive(Deserialize)]
+struct FetchAssetArgs {
+ name: String,
+}
+
+fn op_fetch_asset(
+ _state: &ThreadSafeState,
+ args: Value,
+ _zero_copy: Option<PinnedBuf>,
+) -> Result<JsonOp, ErrBox> {
+ let args: FetchAssetArgs = serde_json::from_value(args)?;
+ if let Some(source_code) = crate::js::get_asset(&args.name) {
+ Ok(JsonOp::Sync(json!(source_code)))
+ } else {
+ panic!("op_fetch_asset bad asset {}", args.name)
+ }
+}