summaryrefslogtreecommitdiff
path: root/cli/ops/compiler.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-08-24 13:20:48 -0700
committerGitHub <noreply@github.com>2019-08-24 13:20:48 -0700
commit2235dd795d3cc6c24ff1bdd1bbdcd110b4b0bdfc (patch)
treea5811adc062cbb1c66f05c863c9be245cf4fd2d2 /cli/ops/compiler.rs
parentbdc0a13261deaa3748f51d9948b4e7b92864c324 (diff)
Revert json ops (#2814)
* Revert "port more ops to JSON (#2809)" This reverts commit 137f33733d365026903d40e7cde6e34ac6c36dcf. * Revert "port ops to JSON: compiler, errors, fetch, files (#2804)" This reverts commit 79f82cf10ed1dbf91346994250d7311a4d74377a. * Revert "Port rest of os ops to JSON (#2802)" This reverts commit 5b2baa5c990fbeae747e952c5dcd7a5369e950b1.
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r--cli/ops/compiler.rs90
1 files changed, 54 insertions, 36 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 39d3a6d7f..efdcd2c9b 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -1,68 +1,86 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-use super::dispatch_json::{Deserialize, JsonOp, Value};
+use super::dispatch_flatbuffers::serialize_response;
+use super::utils::*;
+use crate::deno_error;
+use crate::msg;
use crate::state::ThreadSafeState;
use crate::tokio_util;
use deno::*;
-
-#[derive(Deserialize)]
-#[serde(rename_all = "camelCase")]
-struct CacheArgs {
- module_id: String,
- contents: String,
- extension: String,
-}
+use flatbuffers::FlatBufferBuilder;
+use futures::Future;
pub fn op_cache(
state: &ThreadSafeState,
- args: Value,
- _zero_copy: Option<PinnedBuf>,
-) -> Result<JsonOp, ErrBox> {
- let args: CacheArgs = serde_json::from_value(args)?;
+ base: &msg::Base<'_>,
+ data: Option<PinnedBuf>,
+) -> CliOpResult {
+ assert!(data.is_none());
+ let inner = base.inner_as_cache().unwrap();
+ let extension = inner.extension().unwrap();
+ // TODO: rename to something with 'url'
+ let module_id = inner.module_id().unwrap();
+ let contents = inner.contents().unwrap();
- let module_specifier = ModuleSpecifier::resolve_url(&args.module_id)
+ let module_specifier = ModuleSpecifier::resolve_url(module_id)
.expect("Should be valid module specifier");
state.ts_compiler.cache_compiler_output(
&module_specifier,
- &args.extension,
- &args.contents,
+ extension,
+ contents,
)?;
- Ok(JsonOp::Sync(json!({})))
-}
-
-#[derive(Deserialize)]
-struct FetchSourceFileArgs {
- specifier: String,
- referrer: String,
+ ok_buf(empty_buf())
}
pub fn op_fetch_source_file(
state: &ThreadSafeState,
- args: Value,
- _zero_copy: Option<PinnedBuf>,
-) -> Result<JsonOp, ErrBox> {
- let args: FetchSourceFileArgs = serde_json::from_value(args)?;
+ base: &msg::Base<'_>,
+ data: Option<PinnedBuf>,
+) -> CliOpResult {
+ if !base.sync() {
+ return Err(deno_error::no_async_support());
+ }
+ assert!(data.is_none());
+ let inner = base.inner_as_fetch_source_file().unwrap();
+ let cmd_id = base.cmd_id();
+ let specifier = inner.specifier().unwrap();
+ let referrer = inner.referrer().unwrap();
// TODO(ry) Maybe a security hole. Only the compiler worker should have access
// to this. Need a test to demonstrate the hole.
let is_dyn_import = false;
let resolved_specifier =
- state.resolve(&args.specifier, &args.referrer, false, is_dyn_import)?;
+ state.resolve(specifier, referrer, false, is_dyn_import)?;
let fut = state
.file_fetcher
- .fetch_source_file_async(&resolved_specifier);
+ .fetch_source_file_async(&resolved_specifier)
+ .and_then(move |out| {
+ let builder = &mut FlatBufferBuilder::new();
+ let data_off = builder.create_vector(out.source_code.as_slice());
+ let msg_args = msg::FetchSourceFileResArgs {
+ module_name: Some(builder.create_string(&out.url.to_string())),
+ filename: Some(builder.create_string(&out.filename.to_str().unwrap())),
+ media_type: out.media_type,
+ data: Some(data_off),
+ };
+ let inner = msg::FetchSourceFileRes::create(builder, &msg_args);
+ Ok(serialize_response(
+ cmd_id,
+ builder,
+ msg::BaseArgs {
+ inner: Some(inner.as_union_value()),
+ inner_type: msg::Any::FetchSourceFileRes,
+ ..Default::default()
+ },
+ ))
+ });
// WARNING: Here we use tokio_util::block_on() which starts a new Tokio
// runtime for executing the future. This is so we don't inadvernently run
// out of threads in the main runtime.
- let out = tokio_util::block_on(fut)?;
- Ok(JsonOp::Sync(json!({
- "moduleName": out.url.to_string(),
- "filename": out.filename.to_str().unwrap(),
- "mediaType": out.media_type as i32,
- "sourceCode": String::from_utf8(out.source_code).unwrap(),
- })))
+ let result_buf = tokio_util::block_on(fut)?;
+ Ok(Op::Sync(result_buf))
}