1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

Clippy fixes (#2009)

This commit is contained in:
Bert Belder 2019-03-28 08:09:19 -04:00 committed by Ryan Dahl
parent 1fec34b463
commit da1b98b690
5 changed files with 23 additions and 29 deletions

View file

@ -186,12 +186,8 @@ mod tests {
maybe_source_map: None,
};
out = compile_sync(
Arc::new(IsolateState::mock()),
specifier,
&referrer,
&mut out,
);
out =
compile_sync(Arc::new(IsolateState::mock()), specifier, &referrer, &out);
assert!(
out
.maybe_output_code

View file

@ -692,7 +692,7 @@ mod tests {
fn test_cache_path() {
let (temp_dir, deno_dir) = test_setup(false, false);
let filename = "hello.js";
let source_code = "1+2".as_bytes();
let source_code = b"1+2";
let hash = source_code_hash(filename, source_code, version::DENO);
assert_eq!(
(
@ -708,9 +708,9 @@ mod tests {
let (_temp_dir, deno_dir) = test_setup(false, false);
let filename = "hello.js";
let source_code = "1+2".as_bytes();
let output_code = "1+2 // output code".as_bytes();
let source_map = "{}".as_bytes();
let source_code = b"1+2";
let output_code = b"1+2 // output code";
let source_map = b"{}";
let hash = source_code_hash(filename, source_code, version::DENO);
let (cache_path, source_map_path) =
deno_dir.cache_path(filename, source_code);
@ -719,41 +719,41 @@ mod tests {
let out = ModuleMetaData {
filename: filename.to_owned(),
source_code: source_code.to_owned(),
source_code: source_code[..].to_owned(),
module_name: "hello.js".to_owned(),
media_type: msg::MediaType::TypeScript,
maybe_output_code: Some(output_code.to_owned()),
maybe_output_code: Some(output_code[..].to_owned()),
maybe_output_code_filename: None,
maybe_source_map: Some(source_map.to_owned()),
maybe_source_map: Some(source_map[..].to_owned()),
maybe_source_map_filename: None,
};
let r = deno_dir.code_cache(&out);
r.expect("code_cache error");
assert!(cache_path.exists());
assert_eq!(output_code.to_owned(), fs::read(&cache_path).unwrap());
assert_eq!(output_code[..].to_owned(), fs::read(&cache_path).unwrap());
}
#[test]
fn test_source_code_hash() {
assert_eq!(
"7e44de2ed9e0065da09d835b76b8d70be503d276",
source_code_hash("hello.ts", "1+2".as_bytes(), "0.2.11")
source_code_hash("hello.ts", b"1+2", "0.2.11")
);
// Different source_code should result in different hash.
assert_eq!(
"57033366cf9db1ef93deca258cdbcd9ef5f4bde1",
source_code_hash("hello.ts", "1".as_bytes(), "0.2.11")
source_code_hash("hello.ts", b"1", "0.2.11")
);
// Different filename should result in different hash.
assert_eq!(
"19657f90b5b0540f87679e2fb362e7bd62b644b0",
source_code_hash("hi.ts", "1+2".as_bytes(), "0.2.11")
source_code_hash("hi.ts", b"1+2", "0.2.11")
);
// Different version should result in different hash.
assert_eq!(
"e2b4b7162975a02bf2770f16836eb21d5bcb8be1",
source_code_hash("hi.ts", "1+2".as_bytes(), "0.2.0")
source_code_hash("hi.ts", b"1+2", "0.2.0")
);
}
@ -1456,7 +1456,7 @@ mod tests {
#[test]
fn test_filter_shebang() {
assert_eq!(filter_shebang("#!".as_bytes().to_owned()), "".as_bytes());
assert_eq!(filter_shebang(b"#!"[..].to_owned()), b"");
assert_eq!(
filter_shebang("#!\n\n".as_bytes().to_owned()),
"\n\n".as_bytes()

View file

@ -209,7 +209,7 @@ pub fn apply_source_map(
// The bundle does not get built for 'cargo check', so we don't embed the
// bundle source map.
#[cfg(feature = "check-only")]
fn builtin_source_map(script_name: &str) -> Option<Vec<u8>> {
fn builtin_source_map(_: &str) -> Option<Vec<u8>> {
None
}

View file

@ -13,7 +13,7 @@ pub fn deno_isolate_init() -> StartupData {
StartupData::Script(Script {
filename: "gen/bundle/main.js".to_string(),
source: std::str::from_utf8(source_bytes).unwrap().to_string(),
source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");
@ -40,7 +40,7 @@ pub fn compiler_isolate_init() -> StartupData {
StartupData::Script(Script {
filename: "gen/bundle/compiler.js".to_string(),
source: std::str::from_utf8(source_bytes).unwrap().to_string(),
source: std::str::from_utf8(&source_bytes[..]).unwrap().to_string(),
})
} else {
debug!("Deno isolate init with snapshots.");

View file

@ -140,11 +140,10 @@ impl<B: Behavior> Isolate<B> {
};
// If we want to use execute this has to happen here sadly.
match startup_script {
Some(s) => core_isolate
if let Some(s) = startup_script {
core_isolate
.execute(s.filename.as_str(), s.source.as_str())
.unwrap(),
None => {}
.unwrap()
};
core_isolate
@ -510,9 +509,8 @@ impl IsolateHandle {
/// the isolate.
pub fn terminate_execution(&self) {
unsafe {
match *self.shared_libdeno_isolate.lock().unwrap() {
Some(isolate) => libdeno::deno_terminate_execution(isolate),
None => (),
if let Some(isolate) = *self.shared_libdeno_isolate.lock().unwrap() {
libdeno::deno_terminate_execution(isolate)
}
}
}