summaryrefslogtreecommitdiff
path: root/ext/web/14_compression.js
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-02-07 20:22:46 +0100
committerGitHub <noreply@github.com>2023-02-07 20:22:46 +0100
commitb4aa1530970f7b9cc4e6f2f27e077852c4e178d3 (patch)
tree3d008912affe8550692183bd2697a386db5e3c79 /ext/web/14_compression.js
parent65500f36e870b4ada3996b06aa287e30177d21a3 (diff)
refactor: Use ES modules for internal runtime code (#17648)
This PR refactors all internal js files (except core) to be written as ES modules. `__bootstrap`has been mostly replaced with static imports in form in `internal:[path to file from repo root]`. To specify if files are ESM, an `esm` method has been added to `Extension`, similar to the `js` method. A new ModuleLoader called `InternalModuleLoader` has been added to enable the loading of internal specifiers, which is used in all situations except when a snapshot is only loaded, and not a new one is created from it. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/web/14_compression.js')
-rw-r--r--ext/web/14_compression.js227
1 files changed, 110 insertions, 117 deletions
diff --git a/ext/web/14_compression.js b/ext/web/14_compression.js
index 338f8c803..680da757e 100644
--- a/ext/web/14_compression.js
+++ b/ext/web/14_compression.js
@@ -5,127 +5,120 @@
/// <reference path="./internal.d.ts" />
/// <reference path="./lib.deno_web.d.ts" />
-"use strict";
-
-((window) => {
- const core = window.Deno.core;
- const ops = core.ops;
- const webidl = window.__bootstrap.webidl;
- const { TransformStream } = window.__bootstrap.streams;
-
- webidl.converters.CompressionFormat = webidl.createEnumConverter(
- "CompressionFormat",
- [
- "deflate",
- "deflate-raw",
- "gzip",
- ],
- );
-
- class CompressionStream {
- #transform;
-
- constructor(format) {
- const prefix = "Failed to construct 'CompressionStream'";
- webidl.requiredArguments(arguments.length, 1, { prefix });
- format = webidl.converters.CompressionFormat(format, {
- prefix,
- context: "Argument 1",
- });
-
- const rid = ops.op_compression_new(format, false);
-
- this.#transform = new TransformStream({
- transform(chunk, controller) {
- chunk = webidl.converters.BufferSource(chunk, {
- prefix,
- context: "chunk",
- });
- const output = ops.op_compression_write(
- rid,
- chunk,
- );
- maybeEnqueue(controller, output);
- },
- flush(controller) {
- const output = ops.op_compression_finish(rid);
- maybeEnqueue(controller, output);
- },
- });
-
- this[webidl.brand] = webidl.brand;
- }
-
- get readable() {
- webidl.assertBranded(this, CompressionStreamPrototype);
- return this.#transform.readable;
- }
-
- get writable() {
- webidl.assertBranded(this, CompressionStreamPrototype);
- return this.#transform.writable;
- }
+const core = globalThis.Deno.core;
+const ops = core.ops;
+import * as webidl from "internal:ext/webidl/00_webidl.js";
+import { TransformStream } from "internal:ext/web/06_streams.js";
+
+webidl.converters.CompressionFormat = webidl.createEnumConverter(
+ "CompressionFormat",
+ [
+ "deflate",
+ "deflate-raw",
+ "gzip",
+ ],
+);
+
+class CompressionStream {
+ #transform;
+
+ constructor(format) {
+ const prefix = "Failed to construct 'CompressionStream'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ format = webidl.converters.CompressionFormat(format, {
+ prefix,
+ context: "Argument 1",
+ });
+
+ const rid = ops.op_compression_new(format, false);
+
+ this.#transform = new TransformStream({
+ transform(chunk, controller) {
+ chunk = webidl.converters.BufferSource(chunk, {
+ prefix,
+ context: "chunk",
+ });
+ const output = ops.op_compression_write(
+ rid,
+ chunk,
+ );
+ maybeEnqueue(controller, output);
+ },
+ flush(controller) {
+ const output = ops.op_compression_finish(rid);
+ maybeEnqueue(controller, output);
+ },
+ });
+
+ this[webidl.brand] = webidl.brand;
}
- webidl.configurePrototype(CompressionStream);
- const CompressionStreamPrototype = CompressionStream.prototype;
-
- class DecompressionStream {
- #transform;
-
- constructor(format) {
- const prefix = "Failed to construct 'DecompressionStream'";
- webidl.requiredArguments(arguments.length, 1, { prefix });
- format = webidl.converters.CompressionFormat(format, {
- prefix,
- context: "Argument 1",
- });
-
- const rid = ops.op_compression_new(format, true);
-
- this.#transform = new TransformStream({
- transform(chunk, controller) {
- chunk = webidl.converters.BufferSource(chunk, {
- prefix,
- context: "chunk",
- });
- const output = ops.op_compression_write(
- rid,
- chunk,
- );
- maybeEnqueue(controller, output);
- },
- flush(controller) {
- const output = ops.op_compression_finish(rid);
- maybeEnqueue(controller, output);
- },
- });
-
- this[webidl.brand] = webidl.brand;
- }
-
- get readable() {
- webidl.assertBranded(this, DecompressionStreamPrototype);
- return this.#transform.readable;
- }
-
- get writable() {
- webidl.assertBranded(this, DecompressionStreamPrototype);
- return this.#transform.writable;
- }
+ get readable() {
+ webidl.assertBranded(this, CompressionStreamPrototype);
+ return this.#transform.readable;
}
- function maybeEnqueue(controller, output) {
- if (output && output.byteLength > 0) {
- controller.enqueue(output);
- }
+ get writable() {
+ webidl.assertBranded(this, CompressionStreamPrototype);
+ return this.#transform.writable;
}
+}
+
+webidl.configurePrototype(CompressionStream);
+const CompressionStreamPrototype = CompressionStream.prototype;
+
+class DecompressionStream {
+ #transform;
+
+ constructor(format) {
+ const prefix = "Failed to construct 'DecompressionStream'";
+ webidl.requiredArguments(arguments.length, 1, { prefix });
+ format = webidl.converters.CompressionFormat(format, {
+ prefix,
+ context: "Argument 1",
+ });
+
+ const rid = ops.op_compression_new(format, true);
+
+ this.#transform = new TransformStream({
+ transform(chunk, controller) {
+ chunk = webidl.converters.BufferSource(chunk, {
+ prefix,
+ context: "chunk",
+ });
+ const output = ops.op_compression_write(
+ rid,
+ chunk,
+ );
+ maybeEnqueue(controller, output);
+ },
+ flush(controller) {
+ const output = ops.op_compression_finish(rid);
+ maybeEnqueue(controller, output);
+ },
+ });
+
+ this[webidl.brand] = webidl.brand;
+ }
+
+ get readable() {
+ webidl.assertBranded(this, DecompressionStreamPrototype);
+ return this.#transform.readable;
+ }
+
+ get writable() {
+ webidl.assertBranded(this, DecompressionStreamPrototype);
+ return this.#transform.writable;
+ }
+}
+
+function maybeEnqueue(controller, output) {
+ if (output && output.byteLength > 0) {
+ controller.enqueue(output);
+ }
+}
- webidl.configurePrototype(DecompressionStream);
- const DecompressionStreamPrototype = DecompressionStream.prototype;
+webidl.configurePrototype(DecompressionStream);
+const DecompressionStreamPrototype = DecompressionStream.prototype;
- window.__bootstrap.compression = {
- CompressionStream,
- DecompressionStream,
- };
-})(globalThis);
+export { CompressionStream, DecompressionStream };