Skip to content

Instantly share code, notes, and snippets.

@domenic
domenic / 1MyDOMPoint.js
Last active August 29, 2015 14:02
Subclassing DOM objects via @@create
// Using ES5 syntax to avoid any confusion.
function makeSlots(obj, slotNames) { /* native code */ }
function setSlot(obj, name, value) { /* native code */ }
function getSlot(obj, name) { /* native code */ }
function ensureBranded(obj) {
if (getSlot(obj, 'domPointer') !== 'DOM_POINTER_FOR_MY_DOM_POINT') {
throw new TypeError('Incompatible method or accessor call: ' +
'the this value is not a MyDOMPoint');
@domenic
domenic / node-default-headers.js
Last active August 29, 2015 14:03
Node's default HTTP request headers
"use strict";
var http = require("http");
http.createServer(function (req) {
console.log(req.headers);
})
.listen(1337);
http.get('http://localhost:1337');
@domenic
domenic / 1-geometry.md
Last active August 29, 2015 14:03
One way of doing DOMRect + DOMQuadBounds

DOMRectUtils

[NoInterfaceObject]
interface DOMRectUtils {
  readonly attribute unrestricted double top;
  readonly attribute unrestricted double right;
  readonly attribute unrestricted double bottom;
  readonly attribute unrestricted double left;
}
@domenic
domenic / 1-geometry.md
Last active August 29, 2015 14:03
Another take on geometry

DOMRectReadOnly

[Constructor(DOMQuadInit quad)]
[Constructor(unrestricted optional double x = 0, unrestricted optional double y = 0,
             unrestricted optional double width = 0, unrestricted optional double height = 0)]
interface DOMRectReadOnly {
  readonly attribute unrestricted double x;
  readonly attribute unrestricted double y;
  readonly attribute unrestricted double width;
@domenic
domenic / proxy.js
Last active August 29, 2015 14:03
ServiceWorker server vs. client request
self.onfetch = ev => {
var serverReq = ev.request;
var clientReq = new Request(serverReq.url, {
method: serverReq.method,
headers: serverReq.headers,
mode: serverReq.mode,
credentials: serverReq.credentials
});
serverReq.body.pipeTo(clientReq.body);
@domenic
domenic / event-emitter.js
Created July 21, 2014 19:08
Trying and failing to emulate EventTarget error handling with JS
function EventEmitter() {
this._eventsMap = Object.create(null);
}
EventEmitter.prototype.on = function (eventName, handler) {
if (!this._eventsMap[eventName]) {
this._eventsMap[eventName] = [];
}
this._eventsMap[eventName].push(handler);
@domenic
domenic / params.js
Last active August 29, 2015 14:05 — forked from herzi/params.js
/**
* Turns: {
* keyOne: promiseOne,
* keyTwo: promiseTwo
* } into {
* keyOne: resolutionOne,
* keyTwo: resolutionTwo
* }
*
* (To avoid messing around with unclear array indices when calling different
@domenic
domenic / streams-simplifications.md
Last active August 29, 2015 14:05
Streams API Potential Simplifications: Investigative Report

Streams API Potential Simplifications: Investigative Report

Part 1: Conslidated Write

This proposed change is semantic.

Background

Right now, we have two asynchronous signals given off by our WritableStreams:

@domenic
domenic / aria-summary.md
Last active August 29, 2015 14:05
ARIA summary

This document contains my personal summary of how ARIA and HTML interact. It might be useful background reading.

Internal State vs. Attributes

ARIA lets you set three things on an element: roles, states, or properties. States and properties are only conceptually different so we can discuss them together as stoperties for conciseness. (ARIA uses the term "attributes" but there are already several uses of that word floating around so we don't continue that practice in this document.) An element's role is a string and an element's stoperties are given by a string-to-string map.

Like many features of elements, elements maintain their "true" role and stoperties as internal state. There are also HTML attributes which can affect these. For example, <hr> will have role separator, even though it has no role="" attribute.

What Does the HTML Spec Say

@domenic
domenic / aria-illustrations.md
Last active August 29, 2015 14:05
ARIA illustrations

Illustrative ARIA Scenarios

In what follows, let el.[[role]] and el.[[aria-expanded]] and the like be a fictional syntax for getting the true, screen-reader exposed ARIA values for an element. Let "no role" manifest as null in JavaScript.

These code samples are meant to show how ARIA roles manifest themselves, both in an author-exposed way via attributes, and to screen-readers via the .[[true-values]]. Seeing how these two interact is fairly enlightening.

Roles

HTMLHRElement