mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
FUTURE(ext/fs): make Deno.FsFile
constructor illegal (#23235)
I'm unsure whether we're planning to make the `Deno.FsFile` constructor illegal or remove `FsFile` from the `Deno.*` namspace in Deno 2. Either way, this PR works towards the former. I'll create a superceding PR if the latter is planned instead. Towards #23089
This commit is contained in:
parent
b74a4f29f2
commit
d3f3e0d717
4 changed files with 29 additions and 0 deletions
|
@ -90,6 +90,7 @@ const {
|
||||||
SymbolAsyncIterator,
|
SymbolAsyncIterator,
|
||||||
SymbolIterator,
|
SymbolIterator,
|
||||||
SymbolFor,
|
SymbolFor,
|
||||||
|
TypeError,
|
||||||
Uint32Array,
|
Uint32Array,
|
||||||
} = primordials;
|
} = primordials;
|
||||||
|
|
||||||
|
@ -673,6 +674,11 @@ class FsFile {
|
||||||
new Error().stack,
|
new Error().stack,
|
||||||
"Use `Deno.open` or `Deno.openSync` instead.",
|
"Use `Deno.open` or `Deno.openSync` instead.",
|
||||||
);
|
);
|
||||||
|
if (internals.future) {
|
||||||
|
throw new TypeError(
|
||||||
|
"`Deno.FsFile` cannot be constructed, use `Deno.open()` or `Deno.openSync()` instead.",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -678,6 +678,11 @@ function bootstrapMainRuntime(runtimeOptions, warmup = false) {
|
||||||
9: future,
|
9: future,
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
|
// TODO(iuioiua): remove in Deno v2. This allows us to dynamically delete
|
||||||
|
// class properties within constructors for classes that are not defined
|
||||||
|
// within the Deno namespace.
|
||||||
|
internals.future = future;
|
||||||
|
|
||||||
removeImportedOps();
|
removeImportedOps();
|
||||||
|
|
||||||
deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning;
|
deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning;
|
||||||
|
@ -840,6 +845,11 @@ function bootstrapWorkerRuntime(
|
||||||
9: future,
|
9: future,
|
||||||
} = runtimeOptions;
|
} = runtimeOptions;
|
||||||
|
|
||||||
|
// TODO(iuioiua): remove in Deno v2. This allows us to dynamically delete
|
||||||
|
// class properties within constructors for classes that are not defined
|
||||||
|
// within the Deno namespace.
|
||||||
|
internals.future = future;
|
||||||
|
|
||||||
deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning;
|
deprecatedApiWarningDisabled = shouldDisableDeprecatedApiWarning;
|
||||||
verboseDeprecatedApiWarning = shouldUseVerboseDeprecatedApiWarning;
|
verboseDeprecatedApiWarning = shouldUseVerboseDeprecatedApiWarning;
|
||||||
performance.setTimeOrigin(DateNow());
|
performance.setTimeOrigin(DateNow());
|
||||||
|
|
|
@ -31,4 +31,16 @@ console.log("Deno.writeAllSync is", Deno.writeAllSync);
|
||||||
console.log("Deno.write is", Deno.write);
|
console.log("Deno.write is", Deno.write);
|
||||||
console.log("Deno.writeSync is", Deno.writeSync);
|
console.log("Deno.writeSync is", Deno.writeSync);
|
||||||
|
|
||||||
|
try {
|
||||||
|
new Deno.FsFile(0);
|
||||||
|
} catch (error) {
|
||||||
|
if (
|
||||||
|
error instanceof TypeError &&
|
||||||
|
error.message ===
|
||||||
|
"`Deno.FsFile` cannot be constructed, use `Deno.open()` or `Deno.openSync()` instead."
|
||||||
|
) {
|
||||||
|
console.log("Deno.FsFile constructor is illegal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.close();
|
self.close();
|
||||||
|
|
|
@ -27,3 +27,4 @@ Deno.writeAll is undefined
|
||||||
Deno.writeAllSync is undefined
|
Deno.writeAllSync is undefined
|
||||||
Deno.write is undefined
|
Deno.write is undefined
|
||||||
Deno.writeSync is undefined
|
Deno.writeSync is undefined
|
||||||
|
Deno.FsFile constructor is illegal
|
||||||
|
|
Loading…
Add table
Reference in a new issue