Skip to content

Commit

Permalink
Merge branch 'main' into fix_dry_run_triple_slash_directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored May 28, 2024
2 parents c06962a + 328bd8a commit 84689bf
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 35 deletions.
7 changes: 7 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,6 +1754,13 @@ impl CliOptions {
.unwrap_or_default();

from_config_file.extend_from_slice(&self.flags.unstable_config.features);

if *DENO_FUTURE {
from_config_file.extend_from_slice(&[
deno_runtime::deno_fs::UNSTABLE_FEATURE_NAME.to_string(),
]);
}

from_config_file
}

Expand Down
1 change: 1 addition & 0 deletions ext/fs/30_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ async function writeFile(
append: options.append ?? false,
create: options.create ?? true,
createNew: options.createNew ?? false,
truncate: !(options.append ?? false),
write: true,
});
await data.pipeTo(file.writable, {
Expand Down
53 changes: 30 additions & 23 deletions ext/web/06_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -5088,28 +5088,32 @@ function initializeCountSizeFunction(globalObject) {
WeakMapPrototypeSet(countSizeFunctionWeakMap, globalObject, size);
}

async function* createAsyncFromSyncIterator(syncIterator) {
// deno-lint-ignore prefer-primordials
yield* syncIterator;
}

// Ref: https://tc39.es/ecma262/#sec-getiterator
function getIterator(obj, async = false) {
if (async) {
if (obj[SymbolAsyncIterator] == null) {
if (obj[SymbolIterator] == null) {
throw new TypeError("No iterator found");
}
return createAsyncFromSyncIterator(obj[SymbolIterator]());
} else {
return obj[SymbolAsyncIterator]();
function getAsyncOrSyncIterator(obj) {
let iterator;
if (obj[SymbolAsyncIterator] != null) {
iterator = obj[SymbolAsyncIterator]();
if (!isObject(iterator)) {
throw new TypeError(
"[Symbol.asyncIterator] returned a non-object value",
);
}
} else {
if (obj[SymbolIterator] == null) {
throw new TypeError("No iterator found");
} else if (obj[SymbolIterator] != null) {
iterator = obj[SymbolIterator]();
if (!isObject(iterator)) {
throw new TypeError("[Symbol.iterator] returned a non-object value");
}
return obj[SymbolIterator]();
} else {
throw new TypeError("No iterator found");
}
if (typeof iterator.next !== "function") {
throw new TypeError("iterator.next is not a function");
}
return iterator;
}

function isObject(x) {
return (typeof x === "object" && x != null) || typeof x === "function";
}

const _resourceBacking = Symbol("[[resourceBacking]]");
Expand Down Expand Up @@ -5204,26 +5208,29 @@ class ReadableStream {
);
asyncIterable = webidl.converters.any(asyncIterable);

const iterator = getIterator(asyncIterable, true);
const iterator = getAsyncOrSyncIterator(asyncIterable);

const stream = createReadableStream(noop, async () => {
// deno-lint-ignore prefer-primordials
const res = await iterator.next();
if (typeof res !== "object") {
if (!isObject(res)) {
throw new TypeError("iterator.next value is not an object");
}
if (res.done) {
readableStreamDefaultControllerClose(stream[_controller]);
} else {
readableStreamDefaultControllerEnqueue(stream[_controller], res.value);
readableStreamDefaultControllerEnqueue(
stream[_controller],
await res.value,
);
}
}, async (reason) => {
if (typeof iterator.return === "undefined") {
if (iterator.return == null) {
return undefined;
} else {
// deno-lint-ignore prefer-primordials
const res = await iterator.return(reason);
if (typeof res !== "object") {
if (!isObject(res)) {
throw new TypeError("iterator.return value is not an object");
} else {
return undefined;
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/future/unstable_flags/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"steps": [
{
// Notice `--unstable-*` flags are not needed anymore
"args": "run -A main.js",
"output": "main.out",
"envs": {
"DENO_FUTURE": "1"
}
},
{
// Notice `--unstable-*` flags are not needed anymore
"args": "run -A worker.js",
"output": "main.out",
"envs": {
"DENO_FUTURE": "1"
}
}
]
}
4 changes: 4 additions & 0 deletions tests/specs/future/unstable_flags/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log(
// Undefined without `--unstable-fs`
Deno.build.os === "windows" ? true : typeof Deno.umask === "function",
);
1 change: 1 addition & 0 deletions tests/specs/future/unstable_flags/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
5 changes: 5 additions & 0 deletions tests/specs/future/unstable_flags/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { delay } from "../../../util/std/async/delay.ts";

const worker = new Worker(import.meta.resolve("./main.js"), { type: "module" });
await delay(1_000);
worker.terminate();
18 changes: 18 additions & 0 deletions tests/unit/write_file_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,3 +425,21 @@ Deno.test(
assertEquals(Deno.readFileSync(filename), new Uint8Array([1, 2]));
},
);

Deno.test(
{ permissions: { read: true, write: true } },
async function overwriteFileWithStream() {
const filename = Deno.makeTempDirSync() + "/test.txt";
await Deno.writeFile(filename, new Uint8Array([1, 2, 3, 4]));

const stream = new ReadableStream({
pull(controller) {
controller.enqueue(new Uint8Array([1]));
controller.enqueue(new Uint8Array([2]));
controller.close();
},
});
await Deno.writeFile(filename, stream);
assertEquals(Deno.readFileSync(filename), new Uint8Array([1, 2]));
},
);
13 changes: 2 additions & 11 deletions tests/wpt/runner/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3170,14 +3170,8 @@
"owning-type-message-port.any.worker.html": false,
"owning-type.any.html": false,
"owning-type.any.worker.html": false,
"from.any.html": [
"ReadableStream.from accepts a sync iterable of values",
"ReadableStream.from accepts a sync iterable of promises"
],
"from.any.worker.html": [
"ReadableStream.from accepts a sync iterable of values",
"ReadableStream.from accepts a sync iterable of promises"
]
"from.any.html": true,
"from.any.worker.html": true
},
"transform-streams": {
"backpressure.any.html": true,
Expand Down Expand Up @@ -7162,9 +7156,6 @@
"response-blob-realm.any.html": [
"realm of the Uint8Array from Response bytes()"
],
"response-blob-realm.any.worker.html": [
"realm of the Uint8Array from Response bytes()"
],
"response-init-001.any.html": true,
"response-init-001.any.worker.html": true,
"response-init-002.any.html": true,
Expand Down
2 changes: 1 addition & 1 deletion tests/wpt/suite
Submodule suite updated 172 files

0 comments on commit 84689bf

Please sign in to comment.