Skip to content

Commit

Permalink
Rewrite to use Web IDL, and generally modernize
Browse files Browse the repository at this point in the history
Closes whatwg#963.

Normative changes to widely-implemented features, roughly in order of most disruptive to least-disruptive:

* For the queuing strategy classes, their size and highWaterMark properties are now getters on the prototype, instead of data properties on the prototype and instance (respectively). Closes whatwg#1005. In particular this means that attempts to set either of them post-creation will throw a TypeError. Chromium already ships these semantics.

* Functions which take a dictionary no longer accept non-objects.

* For the queuing strategy classes, their highWaterMark property will no longer return a non-number from their highWaterMark properties, if one was passed to the constructor. Instead, NaN will be returned.

* All methods and accessors are now enumerable, per Web IDL defaults, instead of non-enumerable, per ECMAScript defaults.

* All classes are now exposed globally. Formerly, ReadableStreamDefaultReader, ReadableStreamBYOBReader, ReadableStreamDefaultController, ReadableByteStreamController, WritableStreamDefaultWriter, WritableStreamDefaultController, and TransformStreamDefaultController were not exposed. Closes whatwg#586.

* All classes now have [Symbol.toStringTag] properties. Closes whatwg#952.

* Some functions have changed their length property value.

* Some exceptions are thrown earlier, at argument-conversion time.

* Property lookup in options arguments now happens earlier, at argument-conversion time, and in alphabetical order, per dictionary rules.

Normative changes to unimplemented features:

* ReadableStream's getIterator() method has been renamed to values() as part of adopting Web IDL's infrastructure for async iterators.

* The byobRequest property on ReadableByteStreamController now returns null when there is no BYOB request, instead of returning undefined.

* The view property on ReadableStreamBYOBRequest now returns null when the view cannot be written into, instead of returning undefined.

* Various byte-stream-related APIs that used to specifically prohibit detached buffers now check for zero-length views or buffers, which is a more general category.

* The async iterator's next() and return() methods now behave more like async generators, e.g. returning promises fulfilled with { value: undefined, done: true } after return()ing the iterator, instead of returning a rejected promise.

Editorial changes:

* All APIs are specified to using Web IDL now, instead of using a modified version of the ECMAScript specification conventions. We continue using abstract operations and completion records for now, and we have to drop down to the ECMAScript level in a couple places (notably for dealing with %ObjectPrototype% vs. null-prototype iteration result objects, and transferring array buffers). But overall this removes a lot of type-checking and conversion boilerplate from the specification. Closes whatwg#963. Closes whatwg#1017. See whatwg#1036 for further followup on the iteration result objects.

* Individual abstract operations, constructors, methods, and properties no longer have their own heading. They are instead lumped together in sections. Closes whatwg#885.

* The constructors, methods, and properties are now documented in a per-class block, using the usual WHATWG "domintro" style. Closes whatwg#907.

* Abstract operations are now consistently alphabetized within their section. Closes whatwg#684.

* By using Bikeshed's <div algorithm> feature, we now get automatic identifier highlighting. Closes whatwg#687.

* Switched to 100-character line limits, 1-space indents, and omitting end tags, per WHATWG conventions.

* Removed usage of emu-algify in favor of using some more of Bikeshed's built-in features, plus manually annotating a few things.

* Switched to concise Bikeshed linking syntax, e.g. [=term=] and [$AbstractOp$].

* Eliminated a number of utility abstract operations, especially around calling functions, by better using Web IDL.

Other bug fixes:

* Web IDL makes constructor behavior clear, so this closes whatwg#965.
  • Loading branch information
domenic authored and yutakahirano committed Jun 3, 2021
1 parent 32ac410 commit 7dbcfed
Show file tree
Hide file tree
Showing 61 changed files with 7,419 additions and 7,697 deletions.
18 changes: 11 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ charset = utf-8
indent_size = 2
indent_style = space
trim_trailing_whitespace = true
max_line_length = 100

[*.{js,bs}]
[Makefile]
indent_style = tab

[*.bs]
indent_size = 1

[*.py]
indent_size = 4

[*.js]
max_line_length = 120

[.gitmodules]
indent_style = tab

[Makefile]
indent_style = tab

[.travis.yml]
indent_size = 2
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
/deploy_key.pub
/index.html
/review.sh
/index.html.*
/node_modules/
/npm-debug.log
20 changes: 7 additions & 13 deletions .pr-preview.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
{
"src_file": "index.bs",
"type": "bikeshed",
"params": {
"force": 1,
"md-status": "LS-PR",
"md-Text-Macro": "PR-NUMBER {{ pull_request.number }}"
},
"post_processing": {
"name": "emu-algify",
"options": {
"throwingIndicators": true
}
}
"src_file": "index.bs",
"type": "bikeshed",
"params": {
"force": 1,
"md-status": "LS-PR",
"md-Text-Macro": "PR-NUMBER {{ pull_request.number }}"
}
}
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js: stable
sudo: false

env:
global:
Expand All @@ -12,7 +11,6 @@ before_install:
script:
- npm test
- cd ..
- npm install
- make deploy

branches:
Expand Down
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ SHELL=/bin/bash -o pipefail
.PHONY: local remote deploy review

remote: index.bs
curl https://api.csswg.org/bikeshed/ -f -F [email protected] > index.html.postbs -F md-Text-Macro="SNAPSHOT-LINK LOCAL COPY"
node_modules/.bin/emu-algify --throwing-indicators < index.html.postbs > index.html
@ (HTTP_STATUS=$$(curl https://api.csswg.org/bikeshed/ \
--output index.html \
--write-out "%{http_code}" \
--header "Accept: text/plain, text/html" \
-F die-on=warning \
-F md-Text-Macro="COMMIT-SHA LOCAL COPY" \
-F [email protected]) && \
[[ "$$HTTP_STATUS" -eq "200" ]]) || ( \
echo ""; cat index.html; echo ""; \
rm -f index.html; \
exit 22 \
);

local: index.bs
bikeshed spec index.bs index.html.postbs --md-Text-Macro="SNAPSHOT-LINK LOCAL COPY"
node_modules/.bin/emu-algify --throwing-indicators < index.html.postbs > index.html
bikeshed spec index.bs index.html --md-Text-Macro="COMMIT-SHA LOCAL COPY"

deploy: index.bs
curl --remote-name --fail https://resources.whatwg.org/build/deploy.sh
EXTRA_FILES="demos/* demos/**/*" \
POST_BUILD_STEP='node_modules/.bin/emu-algify --throwing-indicators < "$$DIR/index.html" > "$$DIR/index.html.tmp"; mv "$$DIR/index.html.tmp" "$$DIR/index.html"' \
bash ./deploy.sh

review: index.bs
Expand Down
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ implementation in order to pass those tests.

## Building "locally"

This standard requires a recent version of [Node.js](https://nodejs.org/en/) to be installed as a
prerequisite. Once that's done, you'll need to do a one-time run of `npm install` to set up our
tooling.

For quick local iteration, run `make`. To verify your changes locally, run `make deploy`. See more
in the
[WHATWG Contributor Guidelines](https://github.com/whatwg/meta/blob/master/CONTRIBUTING.md#building).
Expand Down
10,870 changes: 5,541 additions & 5,329 deletions index.bs

Large diffs are not rendered by default.

83 changes: 0 additions & 83 deletions local-watch.js

This file was deleted.

11 changes: 0 additions & 11 deletions package.json

This file was deleted.

1 change: 1 addition & 0 deletions reference-implementation/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
web-platform-tests/
coverage/
generated/
12 changes: 4 additions & 8 deletions reference-implementation/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
"env": {
"node": true,
"browser": true,
"es6": true
"es2020": true
},
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2020
},
"globals": {
"ReadableStream": false,
"WritableStream": false,
"TransformStream": false,
"ByteLengthQueuingStrategy": false,
"CountQueuingStrategy": false,
"GCController": false,
"gc": false
"gc": false,
"globalThis": false
},
"rules": {
// Possible errors
Expand Down
1 change: 1 addition & 0 deletions reference-implementation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ package-lock.json

.nyc_output/
coverage/
generated/
22 changes: 22 additions & 0 deletions reference-implementation/compile-idl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
/* eslint-disable no-console, no-process-exit */
const { mkdirSync } = require('fs');
const path = require('path');
const Transformer = require('webidl2js');

const input = path.resolve(__dirname, './lib');
const output = path.resolve(__dirname, './generated');

mkdirSync(output, { recursive: true });

const transformer = new Transformer({
implSuffix: '-impl',
suppressErrors: true // until https://github.com/jsdom/webidl2js/pull/123 lands
});

transformer.addSource(input, input);
transformer.generate(output)
.catch(err => {
console.error(err.stack);
process.exit(1);
});
26 changes: 26 additions & 0 deletions reference-implementation/lib/ByteLengthQueuingStrategy-impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

exports.implementation = class ByteLengthQueuingStrategyImpl {
constructor(globalObject, [{ highWaterMark }]) {
this._globalObject = globalObject;
this.highWaterMark = highWaterMark;
}

get size() {
initializeSizeFunction(this._globalObject);
return sizeFunctionWeakMap.get(this._globalObject);
}
};

const sizeFunctionWeakMap = new WeakMap();
function initializeSizeFunction(globalObject) {
if (sizeFunctionWeakMap.has(globalObject)) {
return;
}

// We need to set the 'name' property:
// eslint-disable-next-line prefer-arrow-callback
sizeFunctionWeakMap.set(globalObject, function size(chunk) {
return chunk.byteLength;
});
}
7 changes: 7 additions & 0 deletions reference-implementation/lib/ByteLengthQueuingStrategy.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Exposed=(Window,Worker,Worklet)]
interface ByteLengthQueuingStrategy {
constructor(QueuingStrategyInit init);

readonly attribute unrestricted double highWaterMark;
readonly attribute Function size;
};
26 changes: 26 additions & 0 deletions reference-implementation/lib/CountQueuingStrategy-impl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

exports.implementation = class CountQueuingStrategyImpl {
constructor(globalObject, [{ highWaterMark }]) {
this._globalObject = globalObject;
this.highWaterMark = highWaterMark;
}

get size() {
initializeSizeFunction(this._globalObject);
return sizeFunctionWeakMap.get(this._globalObject);
}
};

const sizeFunctionWeakMap = new WeakMap();
function initializeSizeFunction(globalObject) {
if (sizeFunctionWeakMap.has(globalObject)) {
return;
}

// We need to set the 'name' property:
// eslint-disable-next-line prefer-arrow-callback
sizeFunctionWeakMap.set(globalObject, function size() {
return 1;
});
}
7 changes: 7 additions & 0 deletions reference-implementation/lib/CountQueuingStrategy.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Exposed=(Window,Worker,Worklet)]
interface CountQueuingStrategy {
constructor(QueuingStrategyInit init);

readonly attribute unrestricted double highWaterMark;
readonly attribute Function size;
};
6 changes: 6 additions & 0 deletions reference-implementation/lib/QueuingStrategy.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dictionary QueuingStrategy {
unrestricted double highWaterMark;
QueuingStrategySize size;
};

callback QueuingStrategySize = unrestricted double (optional any chunk);
3 changes: 3 additions & 0 deletions reference-implementation/lib/QueuingStrategyInit.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dictionary QueuingStrategyInit {
required unrestricted double highWaterMark;
};
Loading

0 comments on commit 7dbcfed

Please sign in to comment.