Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stdout and stderr encoding on Windows #14559

Merged
merged 8 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cli/tests/integration/repl_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ fn pty_assign_global_this() {
});
}

#[test]
fn pty_emoji() {
// windows was having issues displaying this
util::with_pty(&["repl"], |mut console| {
console.write_line("console.log('🦕');");
console.write_line("close();");

let output = console.read_all_output();
// one for input, one for output
let emoji_count = output.chars().filter(|c| *c == '🦕').count();
assert_eq!(emoji_count, 2);
});
Comment on lines +211 to +220
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

}

#[test]
fn console_log() {
let (out, err) = util::run_and_collect_output(
Expand Down
94 changes: 38 additions & 56 deletions runtime/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,8 @@ fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> {
#[op]
fn op_seek_sync(state: &mut OpState, args: SeekArgs) -> Result<u64, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
let pos = StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.seek(seek_from).map_err(AnyError::from),
Err(_) => Err(type_error(
"cannot seek on this type of resource".to_string(),
)),
let pos = StdFileResource::with_file(state, rid, |std_file| {
std_file.seek(seek_from).map_err(AnyError::from)
})?;
Ok(pos)
}
Expand All @@ -343,10 +340,10 @@ async fn op_seek_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || {
let mut std_file = std_file.lock().unwrap();
let mut std_file = std_file.lock();
std_file.seek(seek_from)
})
.await?
Expand All @@ -358,9 +355,8 @@ fn op_fdatasync_sync(
state: &mut OpState,
rid: ResourceId,
) -> Result<(), AnyError> {
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_data().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
StdFileResource::with_file(state, rid, |std_file| {
std_file.sync_data().map_err(AnyError::from)
})?;
Ok(())
}
Expand All @@ -375,10 +371,10 @@ async fn op_fdatasync_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
std_file.sync_data()
})
.await?
Expand All @@ -387,9 +383,8 @@ async fn op_fdatasync_async(

#[op]
fn op_fsync_sync(state: &mut OpState, rid: ResourceId) -> Result<(), AnyError> {
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.sync_all().map_err(AnyError::from),
Err(_) => Err(type_error("cannot sync this type of resource".to_string())),
StdFileResource::with_file(state, rid, |std_file| {
std_file.sync_all().map_err(AnyError::from)
})?;
Ok(())
}
Expand All @@ -404,10 +399,10 @@ async fn op_fsync_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
std_file.sync_all()
})
.await?
Expand All @@ -419,9 +414,8 @@ fn op_fstat_sync(
state: &mut OpState,
rid: ResourceId,
) -> Result<FsStat, AnyError> {
let metadata = StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.metadata().map_err(AnyError::from),
Err(_) => Err(type_error("cannot stat this type of resource".to_string())),
let metadata = StdFileResource::with_file(state, rid, |std_file| {
std_file.metadata().map_err(AnyError::from)
})?;
Ok(get_stat(metadata))
}
Expand All @@ -436,10 +430,10 @@ async fn op_fstat_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

let metadata = tokio::task::spawn_blocking(move || {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
std_file.metadata()
})
.await?
Expand All @@ -456,16 +450,13 @@ fn op_flock_sync(
use fs3::FileExt;
super::check_unstable(state, "Deno.flockSync");

StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => {
if exclusive {
std_file.lock_exclusive()?;
} else {
std_file.lock_shared()?;
}
Ok(())
StdFileResource::with_file(state, rid, |std_file| {
if exclusive {
std_file.lock_exclusive()?;
} else {
std_file.lock_shared()?;
}
Err(_) => Err(type_error("cannot lock this type of resource".to_string())),
Ok(())
})
}

Expand All @@ -483,10 +474,10 @@ async fn op_flock_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || -> Result<(), AnyError> {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
if exclusive {
std_file.lock_exclusive()?;
} else {
Expand All @@ -505,12 +496,9 @@ fn op_funlock_sync(
use fs3::FileExt;
super::check_unstable(state, "Deno.funlockSync");

StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => {
std_file.unlock()?;
Ok(())
}
Err(_) => Err(type_error("cannot lock this type of resource".to_string())),
StdFileResource::with_file(state, rid, |std_file| {
std_file.unlock()?;
Ok(())
})
}

Expand All @@ -527,10 +515,10 @@ async fn op_funlock_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || -> Result<(), AnyError> {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
std_file.unlock()?;
Ok(())
})
Expand Down Expand Up @@ -1590,9 +1578,8 @@ fn op_ftruncate_sync(
) -> Result<(), AnyError> {
let rid = args.rid;
let len = args.len as u64;
StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => std_file.set_len(len).map_err(AnyError::from),
Err(_) => Err(type_error("cannot truncate this type of resource")),
StdFileResource::with_file(state, rid, |std_file| {
std_file.set_len(len).map_err(AnyError::from)
})?;
Ok(())
}
Expand All @@ -1610,10 +1597,10 @@ async fn op_ftruncate_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();

tokio::task::spawn_blocking(move || {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
std_file.set_len(len)
})
.await?
Expand Down Expand Up @@ -1879,14 +1866,9 @@ fn op_futime_sync(
let atime = filetime::FileTime::from_unix_time(args.atime.0, args.atime.1);
let mtime = filetime::FileTime::from_unix_time(args.mtime.0, args.mtime.1);

StdFileResource::with(state, rid, |r| match r {
Ok(std_file) => {
filetime::set_file_handle_times(std_file, Some(atime), Some(mtime))
.map_err(AnyError::from)
}
Err(_) => Err(type_error(
"cannot futime on this type of resource".to_string(),
)),
StdFileResource::with_file(state, rid, |std_file| {
filetime::set_file_handle_times(std_file, Some(atime), Some(mtime))
.map_err(AnyError::from)
})?;

Ok(())
Expand All @@ -1907,9 +1889,9 @@ async fn op_futime_async(
.resource_table
.get::<StdFileResource>(rid)?;

let std_file = resource.std_file()?;
let std_file = resource.std_file();
tokio::task::spawn_blocking(move || {
let std_file = std_file.lock().unwrap();
let std_file = std_file.lock();
filetime::set_file_handle_times(&std_file, Some(atime), Some(mtime))?;
Ok(())
})
Expand Down
Loading