Skip to content

Commit f8fdafb

Browse files
authored
Update to latest JavaScriptKit (#8)
Pending the merger of swiftwasm/JavaScriptKit#26, everything needed for the output of `webidl2swift` to work will be included in the shipping version of JavaScriptKit! I made several changes to align the APIs and fixed a bug where callback protocols could not be passed as a function. * Mostly working, except for when it doesn’t (enums containing objects and primitives) JavaScriptKit a87af4e * More changes to get it finished! * Correctly set the ancestor for callback interfaces * It works! * Updates to match latest JSKit * Fix lint errors * Last updates for compatibility * Remove unnecessary fatalError in failable initializer * Record the file name tokenization errors occurred in * Address spec update that replaces void with undefined * Update Parser.swift * Fixes to asynciterable * Update Parser.swift * Update Parser.swift * Update IntermediateRepresentation.swift * Sort list of undefined types so it’s stable * Throw a fatalError when a member type is unimplemented * Add updates from review * void → undefined * Also update the other webidl files * Re-add void support * Update Sources/WebIDL/IntermediateRepresentation/Member Nodes/MethodNode.swift Co-authored-by: Max Desiatov <[email protected]> Co-authored-by: Max Desiatov <[email protected]>
2 parents 9b45903 + a14fa2f commit f8fdafb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+521
-460
lines changed

Example/WebIDL-files/CommonDefinitions.webidl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ typedef unsigned long long DOMTimeStamp;
4444

4545
callback Function = any (any... arguments);
4646

47-
callback VoidFunction = void ();
47+
callback VoidFunction = undefined ();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
interface DOMStringMap {
33
getter DOMString (DOMString name);
4-
[CEReactions] setter void (DOMString name, DOMString value);
5-
[CEReactions] deleter void (DOMString name);
4+
[CEReactions] setter undefined (DOMString name, DOMString value);
5+
[CEReactions] deleter undefined (DOMString name);
66
};

Example/WebIDL-files/FileAPI.webidl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ interface FileList {
4949
interface FileReader: EventTarget {
5050
constructor();
5151
// async read methods
52-
void readAsArrayBuffer(Blob blob);
53-
void readAsBinaryString(Blob blob);
54-
void readAsText(Blob blob, optional DOMString encoding);
55-
void readAsDataURL(Blob blob);
52+
undefined readAsArrayBuffer(Blob blob);
53+
undefined readAsBinaryString(Blob blob);
54+
undefined readAsText(Blob blob, optional DOMString encoding);
55+
undefined readAsDataURL(Blob blob);
5656

57-
void abort();
57+
undefined abort();
5858

5959
// states
6060
const unsigned short EMPTY = 0;
@@ -91,5 +91,5 @@ interface FileReaderSync {
9191
[Exposed=(Window,DedicatedWorker,SharedWorker)]
9292
partial interface URL {
9393
static DOMString createObjectURL((Blob or MediaSource) obj);
94-
static void revokeObjectURL(DOMString url);
94+
static undefined revokeObjectURL(DOMString url);
9595
};

Example/WebIDL-files/FormData.webidl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ typedef (File or USVString) FormDataEntryValue;
55
interface FormData {
66
constructor(optional HTMLFormElement form);
77

8-
void append(USVString name, USVString value);
9-
void append(USVString name, Blob blobValue, optional USVString filename);
10-
void delete(USVString name);
8+
undefined append(USVString name, USVString value);
9+
undefined append(USVString name, Blob blobValue, optional USVString filename);
10+
undefined delete(USVString name);
1111
FormDataEntryValue? get(USVString name);
1212
sequence<FormDataEntryValue> getAll(USVString name);
1313
boolean has(USVString name);
14-
void set(USVString name, USVString value);
15-
void set(USVString name, Blob blobValue, optional USVString filename);
14+
undefined set(USVString name, USVString value);
15+
undefined set(USVString name, Blob blobValue, optional USVString filename);
1616
iterable<USVString, FormDataEntryValue>;
1717
};

Example/WebIDL-files/HTMLFormElement.webidl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ interface HTMLFormElement : HTMLElement {
2222
getter Element (unsigned long index);
2323
getter (RadioNodeList or Element) (DOMString name);
2424

25-
void submit();
26-
void requestSubmit(optional HTMLElement? submitter = null);
27-
[CEReactions] void reset();
25+
undefined submit();
26+
undefined requestSubmit(optional HTMLElement? submitter = null);
27+
[CEReactions] undefined reset();
2828
boolean checkValidity();
2929
boolean reportValidity();
3030
};
@@ -41,7 +41,7 @@ interface HTMLElement : Element {
4141

4242
// user interaction
4343
[CEReactions] attribute boolean hidden;
44-
void click();
44+
undefined click();
4545
[CEReactions] attribute DOMString accessKey;
4646
readonly attribute DOMString accessKeyLabel;
4747
[CEReactions] attribute boolean draggable;
@@ -76,12 +76,12 @@ interface RadioNodeList : NodeList {
7676
interface ElementInternals {
7777
// Form-associated custom elements
7878

79-
void setFormValue((File or USVString or FormData)? value,
79+
undefined setFormValue((File or USVString or FormData)? value,
8080
optional (File or USVString or FormData)? state);
8181

8282
readonly attribute HTMLFormElement? form;
8383

84-
void setValidity(ValidityStateFlags flags,
84+
undefined setValidity(ValidityStateFlags flags,
8585
optional DOMString message,
8686
optional HTMLElement anchor);
8787
readonly attribute boolean willValidate;

Example/WebIDL-files/HTMLOrSVGElement.webidl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ interface mixin HTMLOrSVGElement {
55

66
[CEReactions] attribute boolean autofocus;
77
[CEReactions] attribute long tabIndex;
8-
void focus(optional FocusOptions options = {});
9-
void blur();
8+
undefined focus(optional FocusOptions options = {});
9+
undefined blur();
1010
};
1111

1212
dictionary FocusOptions {

Example/WebIDL-files/console.webidl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
[Exposed=(Window,Worker,Worklet)]
22
namespace console { // but see namespace object requirements below
33
// Logging
4-
void assert(optional boolean condition = false, any... data);
5-
void clear();
6-
void debug(any... data);
7-
void error(any... data);
8-
void info(any... data);
9-
void log(any... data);
10-
void table(optional any tabularData, optional sequence<DOMString> properties);
11-
void trace(any... data);
12-
void warn(any... data);
13-
void dir(optional any item, optional object? options);
14-
void dirxml(any... data);
4+
undefined assert(optional boolean condition = false, any... data);
5+
undefined clear();
6+
undefined debug(any... data);
7+
undefined error(any... data);
8+
undefined info(any... data);
9+
undefined log(any... data);
10+
undefined table(optional any tabularData, optional sequence<DOMString> properties);
11+
undefined trace(any... data);
12+
undefined warn(any... data);
13+
undefined dir(optional any item, optional object? options);
14+
undefined dirxml(any... data);
1515

1616
// Counting
17-
void count(optional DOMString label = "default");
18-
void countReset(optional DOMString label = "default");
17+
undefined count(optional DOMString label = "default");
18+
undefined countReset(optional DOMString label = "default");
1919

2020
// Grouping
21-
void group(any... data);
22-
void groupCollapsed(any... data);
23-
void groupEnd();
21+
undefined group(any... data);
22+
undefined groupCollapsed(any... data);
23+
undefined groupEnd();
2424

2525
// Timing
26-
void time(optional DOMString label = "default");
27-
void timeLog(optional DOMString label = "default", any... data);
28-
void timeEnd(optional DOMString label = "default");
26+
undefined time(optional DOMString label = "default");
27+
undefined timeLog(optional DOMString label = "default", any... data);
28+
undefined timeEnd(optional DOMString label = "default");
2929
};

Example/WebIDL-files/dom.webidl

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ interface Event {
1414
const unsigned short BUBBLING_PHASE = 3;
1515
readonly attribute unsigned short eventPhase;
1616

17-
void stopPropagation();
17+
undefined stopPropagation();
1818
attribute boolean cancelBubble; // historical alias of .stopPropagation
19-
void stopImmediatePropagation();
19+
undefined stopImmediatePropagation();
2020

2121
readonly attribute boolean bubbles;
2222
readonly attribute boolean cancelable;
2323
attribute boolean returnValue; // historical
24-
void preventDefault();
24+
undefined preventDefault();
2525
readonly attribute boolean defaultPrevented;
2626
readonly attribute boolean composed;
2727

2828
[Unforgeable] readonly attribute boolean isTrusted;
2929
readonly attribute DOMHighResTimeStamp timeStamp;
3030

31-
void initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); // historical
31+
undefined initEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false); // historical
3232
};
3333

3434
dictionary EventInit {
@@ -47,7 +47,7 @@ interface CustomEvent : Event {
4747

4848
readonly attribute any detail;
4949

50-
void initCustomEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional any detail = null); // historical
50+
undefined initCustomEvent(DOMString type, optional boolean bubbles = false, optional boolean cancelable = false, optional any detail = null); // historical
5151
};
5252

5353
dictionary CustomEventInit : EventInit {
@@ -58,13 +58,13 @@ dictionary CustomEventInit : EventInit {
5858
interface EventTarget {
5959
constructor();
6060

61-
void addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
62-
void removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
61+
undefined addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options = {});
62+
undefined removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options = {});
6363
boolean dispatchEvent(Event event);
6464
};
6565

6666
callback interface EventListener {
67-
void handleEvent(Event event);
67+
undefined handleEvent(Event event);
6868
};
6969

7070
dictionary EventListenerOptions {
@@ -82,7 +82,7 @@ interface AbortController {
8282

8383
[SameObject] readonly attribute AbortSignal signal;
8484

85-
void abort();
85+
undefined abort();
8686
};
8787

8888
[Exposed=(Window,Worker)]
@@ -108,8 +108,8 @@ interface mixin ParentNode {
108108
readonly attribute Element? lastElementChild;
109109
readonly attribute unsigned long childElementCount;
110110

111-
[CEReactions, Unscopable] void prepend((Node or DOMString)... nodes);
112-
[CEReactions, Unscopable] void append((Node or DOMString)... nodes);
111+
[CEReactions, Unscopable] undefined prepend((Node or DOMString)... nodes);
112+
[CEReactions, Unscopable] undefined append((Node or DOMString)... nodes);
113113

114114
Element? querySelector(DOMString selectors);
115115
[NewObject] NodeList querySelectorAll(DOMString selectors);
@@ -126,10 +126,10 @@ Element includes NonDocumentTypeChildNode;
126126
CharacterData includes NonDocumentTypeChildNode;
127127

128128
interface mixin ChildNode {
129-
[CEReactions, Unscopable] void before((Node or DOMString)... nodes);
130-
[CEReactions, Unscopable] void after((Node or DOMString)... nodes);
131-
[CEReactions, Unscopable] void replaceWith((Node or DOMString)... nodes);
132-
[CEReactions, Unscopable] void remove();
129+
[CEReactions, Unscopable] undefined before((Node or DOMString)... nodes);
130+
[CEReactions, Unscopable] undefined after((Node or DOMString)... nodes);
131+
[CEReactions, Unscopable] undefined replaceWith((Node or DOMString)... nodes);
132+
[CEReactions, Unscopable] undefined remove();
133133
};
134134
DocumentType includes ChildNode;
135135
Element includes ChildNode;
@@ -159,12 +159,12 @@ interface HTMLCollection {
159159
interface MutationObserver {
160160
constructor(MutationCallback callback);
161161

162-
void observe(Node target, optional MutationObserverInit options = {});
163-
void disconnect();
162+
undefined observe(Node target, optional MutationObserverInit options = {});
163+
undefined disconnect();
164164
sequence<MutationRecord> takeRecords();
165165
};
166166

167-
callback MutationCallback = void (sequence<MutationRecord> mutations, MutationObserver observer);
167+
callback MutationCallback = undefined (sequence<MutationRecord> mutations, MutationObserver observer);
168168

169169
dictionary MutationObserverInit {
170170
boolean childList = false;
@@ -222,7 +222,7 @@ interface Node : EventTarget {
222222

223223
[CEReactions] attribute DOMString? nodeValue;
224224
[CEReactions] attribute DOMString? textContent;
225-
[CEReactions] void normalize();
225+
[CEReactions] undefined normalize();
226226

227227
[CEReactions, NewObject] Node cloneNode(optional boolean deep = false);
228228
boolean isEqualNode(Node? otherNode);
@@ -347,10 +347,10 @@ interface Element : Node {
347347
sequence<DOMString> getAttributeNames();
348348
DOMString? getAttribute(DOMString qualifiedName);
349349
DOMString? getAttributeNS(DOMString? namespace, DOMString localName);
350-
[CEReactions] void setAttribute(DOMString qualifiedName, DOMString value);
351-
[CEReactions] void setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
352-
[CEReactions] void removeAttribute(DOMString qualifiedName);
353-
[CEReactions] void removeAttributeNS(DOMString? namespace, DOMString localName);
350+
[CEReactions] undefined setAttribute(DOMString qualifiedName, DOMString value);
351+
[CEReactions] undefined setAttributeNS(DOMString? namespace, DOMString qualifiedName, DOMString value);
352+
[CEReactions] undefined removeAttribute(DOMString qualifiedName);
353+
[CEReactions] undefined removeAttributeNS(DOMString? namespace, DOMString localName);
354354
[CEReactions] boolean toggleAttribute(DOMString qualifiedName, optional boolean force);
355355
boolean hasAttribute(DOMString qualifiedName);
356356
boolean hasAttributeNS(DOMString? namespace, DOMString localName);
@@ -373,7 +373,7 @@ interface Element : Node {
373373
HTMLCollection getElementsByClassName(DOMString classNames);
374374

375375
[CEReactions] Element? insertAdjacentElement(DOMString where, Element element); // historical
376-
void insertAdjacentText(DOMString where, DOMString data); // historical
376+
undefined insertAdjacentText(DOMString where, DOMString data); // historical
377377
};
378378

379379
dictionary ShadowRootInit {
@@ -411,10 +411,10 @@ interface CharacterData : Node {
411411
attribute [TreatNullAs=EmptyString] DOMString data;
412412
readonly attribute unsigned long length;
413413
DOMString substringData(unsigned long offset, unsigned long count);
414-
void appendData(DOMString data);
415-
void insertData(unsigned long offset, DOMString data);
416-
void deleteData(unsigned long offset, unsigned long count);
417-
void replaceData(unsigned long offset, unsigned long count, DOMString data);
414+
undefined appendData(DOMString data);
415+
undefined insertData(unsigned long offset, DOMString data);
416+
undefined deleteData(unsigned long offset, unsigned long count);
417+
undefined replaceData(unsigned long offset, unsigned long count, DOMString data);
418418
};
419419

420420
[Exposed=Window]
@@ -464,30 +464,30 @@ interface Range : AbstractRange {
464464

465465
readonly attribute Node commonAncestorContainer;
466466

467-
void setStart(Node node, unsigned long offset);
468-
void setEnd(Node node, unsigned long offset);
469-
void setStartBefore(Node node);
470-
void setStartAfter(Node node);
471-
void setEndBefore(Node node);
472-
void setEndAfter(Node node);
473-
void collapse(optional boolean toStart = false);
474-
void selectNode(Node node);
475-
void selectNodeContents(Node node);
467+
undefined setStart(Node node, unsigned long offset);
468+
undefined setEnd(Node node, unsigned long offset);
469+
undefined setStartBefore(Node node);
470+
undefined setStartAfter(Node node);
471+
undefined setEndBefore(Node node);
472+
undefined setEndAfter(Node node);
473+
undefined collapse(optional boolean toStart = false);
474+
undefined selectNode(Node node);
475+
undefined selectNodeContents(Node node);
476476

477477
const unsigned short START_TO_START = 0;
478478
const unsigned short START_TO_END = 1;
479479
const unsigned short END_TO_END = 2;
480480
const unsigned short END_TO_START = 3;
481481
short compareBoundaryPoints(unsigned short how, Range sourceRange);
482482

483-
[CEReactions] void deleteContents();
483+
[CEReactions] undefined deleteContents();
484484
[CEReactions, NewObject] DocumentFragment extractContents();
485485
[CEReactions, NewObject] DocumentFragment cloneContents();
486-
[CEReactions] void insertNode(Node node);
487-
[CEReactions] void surroundContents(Node newParent);
486+
[CEReactions] undefined insertNode(Node node);
487+
[CEReactions] undefined surroundContents(Node newParent);
488488

489489
[NewObject] Range cloneRange();
490-
void detach();
490+
undefined detach();
491491

492492
boolean isPointInRange(Node node, unsigned long offset);
493493
short comparePoint(Node node, unsigned long offset);
@@ -508,7 +508,7 @@ interface NodeIterator {
508508
Node? nextNode();
509509
Node? previousNode();
510510

511-
void detach();
511+
undefined detach();
512512
};
513513

514514
[Exposed=Window]
@@ -556,8 +556,8 @@ interface DOMTokenList {
556556
readonly attribute unsigned long length;
557557
getter DOMString? item(unsigned long index);
558558
boolean contains(DOMString token);
559-
[CEReactions] void add(DOMString... tokens);
560-
[CEReactions] void remove(DOMString... tokens);
559+
[CEReactions] undefined add(DOMString... tokens);
560+
[CEReactions] undefined remove(DOMString... tokens);
561561
[CEReactions] boolean toggle(DOMString token, optional boolean force);
562562
[CEReactions] boolean replace(DOMString token, DOMString newToken);
563563
boolean supports(DOMString token);

Sources/Commands/GenerateCode.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public struct GenerateCode: ParsableCommand {
7474

7575
guard undefinedTypes.isEmpty else {
7676
print("Error: The following types are undefined:")
77-
print(undefinedTypes.map { "\t- \($0.0)" }.joined(separator: "\n"))
77+
print(undefinedTypes.map { "\t- \($0.0)" }.sorted().joined(separator: "\n"))
7878
Self.exit(withError: ExitCode.failure)
7979
}
8080

@@ -85,7 +85,6 @@ public struct GenerateCode: ParsableCommand {
8585
*/
8686
8787
import JavaScriptKit
88-
import ECMAScript
8988
9089
9190
"""

0 commit comments

Comments
 (0)