Skip to content

Commit 23944d1

Browse files
Merge branch 'main' into fix_watchfs_remove_event
2 parents 02123d5 + 12b3772 commit 23944d1

File tree

35 files changed

+242
-39
lines changed

35 files changed

+242
-39
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ repository = "https://github.com/denoland/deno"
4646

4747
[workspace.dependencies]
4848
deno_ast = { version = "=0.43.3", features = ["transpiling"] }
49-
deno_core = { version = "0.321.0" }
49+
deno_core = { version = "0.322.0" }
5050

5151
deno_bench_util = { version = "0.173.0", path = "./bench_util" }
5252
deno_config = { version = "=0.39.2", features = ["workspace", "sync"] }

cli/args/flags.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3083,7 +3083,7 @@ Evaluate a task from string
30833083
Arg::new("eval")
30843084
.long("eval")
30853085
.help(
3086-
"Evaluate the passed value as if, it was a task in a configuration file",
3086+
"Evaluate the passed value as if it was a task in a configuration file",
30873087
).action(ArgAction::SetTrue)
30883088
)
30893089
.arg(node_modules_dir_arg())

cli/lsp/tsc.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4454,11 +4454,7 @@ fn op_load<'s>(
44544454
== NodeModuleKind::Cjs,
44554455
})
44564456
};
4457-
4458-
lsp_warn!("op_load {} {}", &specifier, maybe_load_response.is_some());
4459-
44604457
let serialized = serde_v8::to_v8(scope, maybe_load_response)?;
4461-
44624458
state.performance.measure(mark);
44634459
Ok(serialized)
44644460
}

cli/standalone/code_cache.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ impl DenoCompileCodeCache {
4242
// attempt to deserialize the cache data
4343
match deserialize(&file_path, cache_key) {
4444
Ok(data) => {
45-
log::debug!("Loaded {} code cache entries", data.len());
45+
log::debug!(
46+
"Loaded {} code cache entries from {}",
47+
data.len(),
48+
file_path.display()
49+
);
4650
Self {
4751
strategy: CodeCacheStrategy::SubsequentRun(
4852
SubsequentRunCodeCacheStrategy {
@@ -53,7 +57,11 @@ impl DenoCompileCodeCache {
5357
}
5458
}
5559
Err(err) => {
56-
log::debug!("Failed to deserialize code cache: {:#}", err);
60+
log::debug!(
61+
"Failed to deserialize code cache from {}: {:#}",
62+
file_path.display(),
63+
err
64+
);
5765
Self {
5866
strategy: CodeCacheStrategy::FirstRun(FirstRunCodeCacheStrategy {
5967
cache_key,
@@ -186,6 +194,7 @@ impl FirstRunCodeCacheStrategy {
186194
Ok(()) => {
187195
if let Err(err) = std::fs::rename(&temp_file, &self.file_path) {
188196
log::debug!("Failed to rename code cache: {}", err);
197+
let _ = std::fs::remove_file(&temp_file);
189198
} else {
190199
log::debug!("Serialized {} code cache entries", count);
191200
}

cli/standalone/virtual_fs.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl FileBackedVfsFile {
634634
}
635635

636636
fn read_to_buf(&self, buf: &mut [u8]) -> FsResult<usize> {
637-
let pos = {
637+
let read_pos = {
638638
let mut pos = self.pos.lock();
639639
let read_pos = *pos;
640640
// advance the position due to the read
@@ -643,12 +643,12 @@ impl FileBackedVfsFile {
643643
};
644644
self
645645
.vfs
646-
.read_file(&self.file, pos, buf)
646+
.read_file(&self.file, read_pos, buf)
647647
.map_err(|err| err.into())
648648
}
649649

650650
fn read_to_end(&self) -> FsResult<Vec<u8>> {
651-
let pos = {
651+
let read_pos = {
652652
let mut pos = self.pos.lock();
653653
let read_pos = *pos;
654654
// todo(dsherret): should this always set it to the end of the file?
@@ -658,12 +658,12 @@ impl FileBackedVfsFile {
658658
}
659659
read_pos
660660
};
661-
if pos > self.file.len {
661+
if read_pos > self.file.len {
662662
return Ok(Vec::new());
663663
}
664-
let size = (self.file.len - pos) as usize;
664+
let size = (self.file.len - read_pos) as usize;
665665
let mut buf = vec![0; size];
666-
self.vfs.read_file(&self.file, pos, &mut buf)?;
666+
self.vfs.read_file(&self.file, read_pos, &mut buf)?;
667667
Ok(buf)
668668
}
669669
}
@@ -893,8 +893,9 @@ impl FileBackedVfs {
893893
buf: &mut [u8],
894894
) -> std::io::Result<usize> {
895895
let read_range = self.get_read_range(file, pos, buf.len() as u64)?;
896-
buf.copy_from_slice(&self.vfs_data[read_range]);
897-
Ok(buf.len())
896+
let read_len = read_range.len();
897+
buf[..read_len].copy_from_slice(&self.vfs_data[read_range]);
898+
Ok(read_len)
898899
}
899900

900901
fn get_read_range(
@@ -903,15 +904,15 @@ impl FileBackedVfs {
903904
pos: u64,
904905
len: u64,
905906
) -> std::io::Result<Range<usize>> {
906-
let data = &self.vfs_data;
907-
let start = self.fs_root.start_file_offset + file.offset + pos;
908-
let end = start + len;
909-
if end > data.len() as u64 {
907+
if pos > file.len {
910908
return Err(std::io::Error::new(
911909
std::io::ErrorKind::UnexpectedEof,
912910
"unexpected EOF",
913911
));
914912
}
913+
let file_offset = self.fs_root.start_file_offset + file.offset;
914+
let start = file_offset + pos;
915+
let end = file_offset + std::cmp::min(pos + len, file.len);
915916
Ok(start as usize..end as usize)
916917
}
917918

cli/tools/fmt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ pub fn format_sql(
549549
// Add single new line to the end of file.
550550
formatted_str.push('\n');
551551

552-
Ok(Some(formatted_str))
552+
Ok(if formatted_str == file_text {
553+
None
554+
} else {
555+
Some(formatted_str)
556+
})
553557
}
554558

555559
/// Formats a single TS, TSX, JS, JSX, JSONC, JSON, MD, IPYNB or SQL file.

cli/util/path.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ pub fn is_importable_ext(path: &Path) -> bool {
2727
if let Some(ext) = get_extension(path) {
2828
matches!(
2929
ext.as_str(),
30-
"ts" | "tsx" | "js" | "jsx" | "mjs" | "mts" | "cjs" | "cts" | "json"
30+
"ts"
31+
| "tsx"
32+
| "js"
33+
| "jsx"
34+
| "mjs"
35+
| "mts"
36+
| "cjs"
37+
| "cts"
38+
| "json"
39+
| "wasm"
3140
)
3241
} else {
3342
false
@@ -222,6 +231,7 @@ mod test {
222231
assert!(is_script_ext(Path::new("foo.cjs")));
223232
assert!(is_script_ext(Path::new("foo.cts")));
224233
assert!(!is_script_ext(Path::new("foo.json")));
234+
assert!(!is_script_ext(Path::new("foo.wasm")));
225235
assert!(!is_script_ext(Path::new("foo.mjsx")));
226236
}
227237

@@ -243,6 +253,7 @@ mod test {
243253
assert!(is_importable_ext(Path::new("foo.cjs")));
244254
assert!(is_importable_ext(Path::new("foo.cts")));
245255
assert!(is_importable_ext(Path::new("foo.json")));
256+
assert!(is_importable_ext(Path::new("foo.wasm")));
246257
assert!(!is_importable_ext(Path::new("foo.mjsx")));
247258
}
248259

ext/node/polyfills/_fs/_fs_readFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export function readFile(
8888
}
8989
const buffer = maybeDecode(data, encoding);
9090
(cb as BinaryCallback)(null, buffer);
91-
}, (err) => cb && cb(denoErrorToNodeError(err)));
91+
}, (err) => cb && cb(denoErrorToNodeError(err, { path, syscall: "open" })));
9292
}
9393
}
9494

@@ -122,7 +122,7 @@ export function readFileSync(
122122
try {
123123
data = Deno.readFileSync(path);
124124
} catch (err) {
125-
throw denoErrorToNodeError(err);
125+
throw denoErrorToNodeError(err, { path, syscall: "open" });
126126
}
127127
const encoding = getEncoding(opt);
128128
if (encoding && encoding !== "binary") {

ext/websocket/01_websocket.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,14 @@ class WebSocket extends EventTarget {
330330
webidl.requiredArguments(arguments.length, 1, prefix);
331331
data = webidl.converters.WebSocketSend(data, prefix, "Argument 1");
332332

333-
if (this[_readyState] !== OPEN) {
333+
if (this[_readyState] === CONNECTING) {
334334
throw new DOMException("'readyState' not OPEN", "InvalidStateError");
335335
}
336336

337+
if (this[_readyState] !== OPEN) {
338+
return;
339+
}
340+
337341
if (this[_sendQueue].length === 0) {
338342
// Fast path if the send queue is empty, for example when only synchronous
339343
// data is being sent.

tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ deno_semver.workspace = true
4545
deno_terminal.workspace = true
4646
deno_tls.workspace = true
4747
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
48-
file_test_runner = "0.7.2"
48+
file_test_runner = "0.7.3"
4949
flaky_test = "=0.2.2"
5050
hickory-client = "=0.24"
5151
hickory-server = "=0.24"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"tempDir": true,
3+
"steps": [{
4+
"args": "run -A setup.js",
5+
"output": "[WILDCARD]"
6+
}, {
7+
"if": "unix",
8+
"args": "compile --allow-read=data --include data --output main main.ts",
9+
"output": "[WILDCARD]"
10+
}, {
11+
"if": "unix",
12+
"commandName": "./main",
13+
"args": [],
14+
"output": "[WILDCARD]",
15+
"exitCode": 0
16+
}, {
17+
"if": "windows",
18+
"args": "compile --allow-read=data --include data --output main.exe main.ts",
19+
"output": "[WILDCARD]"
20+
}, {
21+
"if": "windows",
22+
"commandName": "./main.exe",
23+
"args": [],
24+
"output": "[WILDCARD]",
25+
"exitCode": 0
26+
}]
27+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// buffer larger than file
2+
{
3+
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
4+
const data = new Uint8Array(13);
5+
const len = file.readSync(data);
6+
if (len !== 13) {
7+
throw new Error("Unexpected read length");
8+
}
9+
if (file.readSync(new Uint8Array(1024)) !== null) {
10+
throw new Error("Unexpected.");
11+
}
12+
const textData = new TextDecoder().decode(data);
13+
if (textData !== "Hello, world!") {
14+
throw new Error("Unexpected file data (1): " + textData);
15+
}
16+
}
17+
18+
// buffer smaller than file
19+
{
20+
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
21+
const finalData = new Uint8Array(13);
22+
const data = new Uint8Array(2);
23+
let pos = 0;
24+
while (true) {
25+
const len = file.readSync(data);
26+
if (len === 0 || len == null) {
27+
break;
28+
}
29+
finalData.set(data.subarray(0, len), pos);
30+
pos += len;
31+
}
32+
const textData = new TextDecoder().decode(finalData);
33+
if (textData !== "Hello, world!") {
34+
throw new Error("Unexpected file data (2): " + textData);
35+
}
36+
}
37+
38+
// large amount of data, small reads
39+
{
40+
const bytes = new Uint8Array((1024 ** 2) * 20);
41+
using file = Deno.openSync(import.meta.dirname + "/data/2.dat");
42+
const buffer = new Uint8Array(2);
43+
let pos = 0;
44+
while (true) {
45+
const len = file.readSync(buffer);
46+
if (len === 0 || len == null) {
47+
break;
48+
}
49+
bytes.set(buffer.subarray(0, len), pos);
50+
pos += len;
51+
}
52+
for (let i = 0; i < bytes.length; i++) {
53+
if (bytes[i] !== i % 256) {
54+
throw new Error("Unexpected data.");
55+
}
56+
}
57+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deno.mkdirSync("data");
2+
Deno.writeTextFileSync("data/1.txt", "Hello, world!");
3+
const bytes = new Uint8Array((1024 ** 2) * 20);
4+
for (let i = 0; i < bytes.length; i++) {
5+
bytes[i] = i % 256;
6+
}
7+
Deno.writeFileSync("data/2.dat", bytes);

tests/specs/fmt/sql/__test__.jsonc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"flag": {
99
"args": "fmt --unstable-sql",
10-
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
10+
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
1111
},
1212
"config_file": {
1313
"steps": [{
@@ -18,8 +18,12 @@
1818
"output": "[WILDCARD]"
1919
}, {
2020
"args": "fmt",
21-
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
21+
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
2222
}]
23+
},
24+
"well_formatted_check": {
25+
"args": "fmt --unstable-sql --check well_formatted.sql",
26+
"output": "Checked 1 file\n"
2327
}
2428
}
2529
}

0 commit comments

Comments
 (0)