@ai-ecoverse/slicc-kernel 1.47.1 → 1.47.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8889,6 +8889,58 @@ function rewrite(hop, status2, location) {
8889
8889
  body: toGet ? void 0 : hop.body
8890
8890
  };
8891
8891
  }
8892
+ function isHex(byte) {
8893
+ return byte !== void 0 && /^[0-9A-Fa-f]$/.test(String.fromCharCode(byte));
8894
+ }
8895
+ function percentDecode(input) {
8896
+ const bytes = new TextEncoder().encode(input);
8897
+ const out = new Uint8Array(bytes.length);
8898
+ let at = 0;
8899
+ for (let i = 0; i < bytes.length; i++) {
8900
+ const byte = bytes[i];
8901
+ if (byte === 37 && isHex(bytes[i + 1]) && isHex(bytes[i + 2])) {
8902
+ out[at++] = Number.parseInt(
8903
+ String.fromCharCode(bytes[i + 1], bytes[i + 2]),
8904
+ 16
8905
+ );
8906
+ i += 2;
8907
+ } else out[at++] = byte;
8908
+ }
8909
+ return out.subarray(0, at);
8910
+ }
8911
+ function latin1(bytes) {
8912
+ let text = "";
8913
+ for (let at = 0; at < bytes.length; at += SLICE) {
8914
+ text += String.fromCharCode(...bytes.subarray(at, at + SLICE));
8915
+ }
8916
+ return text;
8917
+ }
8918
+ function dataResponse(request) {
8919
+ const url = withoutFragment(new URL(request.url));
8920
+ const rest2 = url.slice("data:".length);
8921
+ const comma = rest2.indexOf(",");
8922
+ if (comma < 0) throw failed2(new JsCallError("EINVAL", "a data: URL without a comma"));
8923
+ let type = rest2.slice(0, comma).replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, "");
8924
+ let body = percentDecode(rest2.slice(comma + 1));
8925
+ const base642 = BASE64.exec(type);
8926
+ if (base642) {
8927
+ type = type.slice(0, base642.index).replace(/[\t\n\f\r ]+$/, "");
8928
+ let binary;
8929
+ try {
8930
+ binary = atob(latin1(body));
8931
+ } catch {
8932
+ throw failed2(new JsCallError("EINVAL", "a data: URL whose base64 does not decode"));
8933
+ }
8934
+ body = Uint8Array.from(binary, (c) => c.charCodeAt(0));
8935
+ }
8936
+ if (type.startsWith(";")) type = `text/plain${type}`;
8937
+ if (!MIME.test(type)) type = "text/plain;charset=US-ASCII";
8938
+ const response = new Response(body, {
8939
+ status: 200,
8940
+ headers: { "content-type": type }
8941
+ });
8942
+ return withMeta(response, url, false);
8943
+ }
8892
8944
  function withMeta(response, url, redirected) {
8893
8945
  const clone = response.clone.bind(response);
8894
8946
  Object.defineProperty(response, "url", { value: url });
@@ -9037,6 +9089,11 @@ function fetchOp(kernel) {
9037
9089
  const request = new Request(input, init);
9038
9090
  const { signal } = request;
9039
9091
  signal.throwIfAborted();
9092
+ const { protocol } = new URL(request.url);
9093
+ if (protocol === "data:") return dataResponse(request);
9094
+ if (protocol !== "http:" && protocol !== "https:") {
9095
+ throw failed2(new JsCallError("EPROTONOSUPPORT", protocol));
9096
+ }
9040
9097
  const known = await traitsOf().catch((err) => {
9041
9098
  throw failed2(err);
9042
9099
  });
@@ -9069,7 +9126,7 @@ function fetchOp(kernel) {
9069
9126
  }
9070
9127
  };
9071
9128
  }
9072
- var CHUNK, MAX_REDIRECTS, NULL_BODY, REDIRECTS, BODY_HEADERS, DECODED, CREDENTIALS, OVER;
9129
+ var CHUNK, MAX_REDIRECTS, NULL_BODY, REDIRECTS, BODY_HEADERS, DECODED, CREDENTIALS, OVER, MIME, BASE64, SLICE;
9073
9130
  var init_js_fetch = __esm({
9074
9131
  "src/process/js/js-fetch.ts"() {
9075
9132
  "use strict";
@@ -9088,6 +9145,9 @@ var init_js_fetch = __esm({
9088
9145
  DECODED = /* @__PURE__ */ new Set(["gzip", "x-gzip", "deflate"]);
9089
9146
  CREDENTIALS = /* @__PURE__ */ new Set(["authorization", "proxy-authorization", "cookie", "cookie2"]);
9090
9147
  OVER = /* @__PURE__ */ Symbol("over");
9148
+ MIME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+(?:[\t ]*;.*)?$/s;
9149
+ BASE64 = /; *base64$/i;
9150
+ SLICE = 32768;
9091
9151
  }
9092
9152
  });
9093
9153
 
@@ -9590,7 +9650,7 @@ function ttyOps(kernel) {
9590
9650
  }
9591
9651
  };
9592
9652
  const restore = async () => {
9593
- for (const [fd, original] of [...saved]) {
9653
+ for (const [fd, original] of [...saved].reverse()) {
9594
9654
  saved.delete(fd);
9595
9655
  await setAttr(fd, original).catch(() => void 0);
9596
9656
  }