summaryrefslogtreecommitdiff
path: root/cli/js/web
diff options
context:
space:
mode:
Diffstat (limited to 'cli/js/web')
-rw-r--r--cli/js/web/blob.ts20
-rw-r--r--cli/js/web/dom_file.ts6
-rw-r--r--cli/js/web/dom_types.ts6
-rw-r--r--cli/js/web/text_encoding.ts9
4 files changed, 19 insertions, 22 deletions
diff --git a/cli/js/web/blob.ts b/cli/js/web/blob.ts
index 896337b10..1309ddff0 100644
--- a/cli/js/web/blob.ts
+++ b/cli/js/web/blob.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import * as domTypes from "./dom_types.ts";
-import { hasOwnProperty } from "../util.ts";
import { TextEncoder } from "./text_encoding.ts";
import { build } from "../build.ts";
@@ -144,34 +143,29 @@ export class DenoBlob implements domTypes.Blob {
return;
}
- options = options || {};
- // Set ending property's default value to "transparent".
- if (!hasOwnProperty(options, "ending")) {
- options.ending = "transparent";
- }
-
- if (options.type && !containsOnlyASCII(options.type)) {
+ const { ending = "transparent", type = "" } = options ?? {};
+ if (!containsOnlyASCII(type)) {
const errMsg = "The 'type' property must consist of ASCII characters.";
throw new SyntaxError(errMsg);
}
- const bytes = processBlobParts(blobParts!, options);
+ const bytes = processBlobParts(blobParts!, { ending, type });
// Normalize options.type.
- let type = options.type ? options.type : "";
+ let normalizedType = type;
if (type.length) {
for (let i = 0; i < type.length; ++i) {
const char = type[i];
if (char < "\u0020" || char > "\u007E") {
- type = "";
+ normalizedType = "";
break;
}
}
- type = type.toLowerCase();
+ normalizedType = type.toLowerCase();
}
// Set Blob object's properties.
this[bytesSymbol] = bytes;
this.size = bytes.byteLength;
- this.type = type;
+ this.type = normalizedType;
// Register bytes for internal private use.
blobBytesWeakMap.set(this, bytes);
diff --git a/cli/js/web/dom_file.ts b/cli/js/web/dom_file.ts
index 2b9dbff24..cf2a40398 100644
--- a/cli/js/web/dom_file.ts
+++ b/cli/js/web/dom_file.ts
@@ -11,14 +11,14 @@ export class DomFileImpl extends blob.DenoBlob implements domTypes.DomFile {
fileName: string,
options?: domTypes.FilePropertyBag
) {
- options = options || {};
- super(fileBits, options);
+ const { lastModified = Date.now(), ...blobPropertyBag } = options ?? {};
+ super(fileBits, blobPropertyBag);
// 4.1.2.1 Replace any "/" character (U+002F SOLIDUS)
// with a ":" (U + 003A COLON)
this.name = String(fileName).replace(/\u002F/g, "\u003A");
// 4.1.3.3 If lastModified is not provided, set lastModified to the current
// date and time represented in number of milliseconds since the Unix Epoch.
- this.lastModified = options.lastModified || Date.now();
+ this.lastModified = lastModified;
}
}
diff --git a/cli/js/web/dom_types.ts b/cli/js/web/dom_types.ts
index cdd681615..23347ce66 100644
--- a/cli/js/web/dom_types.ts
+++ b/cli/js/web/dom_types.ts
@@ -258,12 +258,12 @@ interface ProgressEvent extends Event {
}
export interface EventListenerOptions {
- capture: boolean;
+ capture?: boolean;
}
export interface AddEventListenerOptions extends EventListenerOptions {
- once: boolean;
- passive: boolean;
+ once?: boolean;
+ passive?: boolean;
}
export interface AbortSignal extends EventTarget {
diff --git a/cli/js/web/text_encoding.ts b/cli/js/web/text_encoding.ts
index 0709e7123..928cbe7e1 100644
--- a/cli/js/web/text_encoding.ts
+++ b/cli/js/web/text_encoding.ts
@@ -154,11 +154,14 @@ class SingleByteDecoder implements Decoder {
private _index: number[];
private _fatal: boolean;
- constructor(index: number[], options: DecoderOptions) {
- if (options.ignoreBOM) {
+ constructor(
+ index: number[],
+ { ignoreBOM = false, fatal = false }: DecoderOptions = {}
+ ) {
+ if (ignoreBOM) {
throw new TypeError("Ignoring the BOM is available only with utf-8.");
}
- this._fatal = options.fatal || false;
+ this._fatal = fatal;
this._index = index;
}
handler(stream: Stream, byte: number): number {