summaryrefslogtreecommitdiff
path: root/op_crates/web/00_infra.js
diff options
context:
space:
mode:
authorLuca Casonato <lucacasonato@yahoo.com>2021-04-08 15:05:08 +0200
committerGitHub <noreply@github.com>2021-04-08 15:05:08 +0200
commitc867c1aa476b3f00933be08cbc5f528973e37857 (patch)
tree4966a8a2e853db1c552ec39821a65bc13f927d5a /op_crates/web/00_infra.js
parentd2e500e1cf7d27132fee92cc09238e1bc98897c6 (diff)
fix: enable FileReader wpt and align to spec (#10063)
This adds some algorithms from the whatwg mimesniff, whatwg infra, and whatwg encoding specs that FileReader needs to use internally.
Diffstat (limited to 'op_crates/web/00_infra.js')
-rw-r--r--op_crates/web/00_infra.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/op_crates/web/00_infra.js b/op_crates/web/00_infra.js
new file mode 100644
index 000000000..0590ffd03
--- /dev/null
+++ b/op_crates/web/00_infra.js
@@ -0,0 +1,31 @@
+// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
+
+// @ts-check
+/// <reference path="../../core/lib.deno_core.d.ts" />
+/// <reference path="../web/internal.d.ts" />
+/// <reference path="../web/lib.deno_web.d.ts" />
+
+"use strict";
+
+((window) => {
+ /**
+ * https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points
+ * @param {string} input
+ * @param {number} position
+ * @param {(char: string) => boolean} condition
+ * @returns {{result: string, position: number}}
+ */
+ function collectSequenceOfCodepoints(input, position, condition) {
+ const start = position;
+ for (
+ let c = input.charAt(position);
+ position < input.length && condition(c);
+ c = input.charAt(++position)
+ );
+ return { result: input.slice(start, position), position };
+ }
+
+ window.__bootstrap.infra = {
+ collectSequenceOfCodepoints,
+ };
+})(globalThis);