Skip to content

Instantly share code, notes, and snippets.

View domenic's full-sized avatar
📵
Away from the internet through 2024-06-16

Domenic Denicola domenic

📵
Away from the internet through 2024-06-16
View GitHub Profile
@domenic
domenic / should-all-be-global.md
Created August 19, 2024 03:06
Suggested Window ∩ Worker ∩ Worklet list
@domenic
domenic / generate-urltestdata.js
Created December 30, 2022 09:53
urltestdata.json generator using jsdom/whatwg-url
"use strict";
const { URL } = require(".");
const inputs = [
"https://\u0000y",
"https://x/\u0000y",
"https://x/?\u0000y",
"https://x/?#\u0000y"
];
@domenic
domenic / README.md
Last active February 1, 2023 17:17
Generic zero-copy ArrayBuffer

Generic zero-copy ArrayBuffer usage

Most APIs which accept binary data need to ensure that the data is not modified while they read from it. (Without loss of generality, let's only analyze ArrayBuffer instances for now.) Modifications can come about due to the API processing the data asynchronously, or due to the API processing the data on some other thread which runs in parallel to the main thread. (E.g., an OS API which reads from the provided ArrayBuffer and writes it to a file.)

On the web platform, APIs generally solve this by immediately making a copy of the incoming data. The code is essentially:

function someAPI(arrayBuffer) {
  arrayBuffer = arrayBuffer.slice(); // make a copy
@domenic
domenic / same-site.md
Created September 28, 2020 15:40
Alternate same-site algorithms

Two origins, A and B, are said to be same site if the following returns true:

  1. Let siteA be the result of obtaining a site from A.
  2. Let siteB be the result of obtaining a site from B.
  3. Return true if siteA equals siteB.

Two origins, A and B, are said to be schemelessly-same site if the following returns true:

  1. Let siteA be the result of obtaining a site from A.
  2. Let siteB be the result of obtaining a site from B.
@domenic
domenic / library-consumer.mjs
Created July 11, 2019 15:32
Readonly Sets attempt
import { languagesSet } from "./some-library.mjs";
// Allowed
languagesSet.keys();
languagesSet.entries();
languagesSet.forEach(l => console.log);
languagesSet.size;
languagesSet.values();
// Will throw TypeError
@domenic
domenic / engine-ua-sniffer.js
Last active September 6, 2019 16:40
Rendering engine UA sniffer
// This is a minimal UA sniffer, that only cares about the rendering/JS engine
// name and version, which should be enough to do feature discrimination and
// differential code loading.
//
// This is distinct from things like https://www.npmjs.com/package/ua-parser-js
// which distinguish between different branded browsers that use the same rendering
// engine. That sort of distinction is maybe useful for analytics purposes, but
// for differential code loading it is overcomplicated.
//
// This is meant to demonstrate that UA sniffing is not really that hard if you're
@domenic
domenic / tostring-in-js.md
Last active July 9, 2019 21:21
ToString() in JavaScript

ToString() in JavaScript

I am posting this as a gist because I am too lazy to figure out my blog. TODO: move it to https://domenic.me/ one day.

A lot of specifications use the ToString() abstract operation. (What's an abstract operation?) For example, any web specification which uses Web IDL's DOMString type (i.e., its basic string type) will convert incoming values using ToString(). Similarly, various parts of the JS specification itself perform ToString(). One example is the Error constructor, which we will refer to going forward.

If you are trying to implement or polyfill such a specification in JavaScript, how do you do it? For example, given

function ErrorConstructorPolyfill(message) {
@domenic
domenic / after-markdown-conversion.html
Created April 26, 2019 21:39
Working mode before and after
<!DOCTYPE HTML>
<html lang="en">
<meta charset="utf-8">
<title>Working Mode — WHATWG</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#3A7908">
<link rel="icon" href="https://resources.whatwg.org/logo.svg">
<link rel="stylesheet" href="/style/shared.css">
<link rel="stylesheet" href="/style/subpages.css">
@domenic
domenic / difference.md
Last active January 16, 2019 20:19
Set.prototype.difference, simplified

Context: tc39/proposal-set-methods#50

Proposed spec texts

Set.prototype.difference(arg), minimalist

  1. If Type(this) is not Object, or this does not have a [[SetData]] internal slot, throw a new TypeError exception.
  2. If Type(arg) is not Object, or arg does not have a [[SetData]] internal slot, throw a new TypeError exception.
  3. Let diffList be a List containing all elements that are in this.[[SetData]] but are not in arg.[[SetData]], using SameValueZero to determine identity. (Optional: formalize this with a loop that operates on the Lists.)
  4. Let newSet be ? OrdinaryCreateFromConstructor(%Set%, "%SetPrototype%", « [[SetData]] »).
@domenic
domenic / link-stuff.md
Last active December 22, 2018 17:42
Revamping link fetching and stuff