Skip to content

Commit e108143

Browse files
committed
add browser.webidl.json
1 parent f9d0e09 commit e108143

8 files changed

+723
-42
lines changed

TS.fsx

+165-22
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ module Helpers =
3434
match FSharpValue.GetUnionFields(x, typeof<'a>) with
3535
| case, _ -> case.Name
3636

37+
let inline toNameMap< ^a when ^a: (member Name: string) > (data: array< ^a > ) =
38+
data
39+
|> Array.map (fun x -> ((^a: (member Name: string) x), x))
40+
|> Map.ofArray
41+
3742
module Option =
3843
let runIfSome f x =
3944
match x with
@@ -132,6 +137,131 @@ module Types =
132137

133138
type ExtendConflict = { BaseType: string; ExtendType: string list; MemberNames: string list }
134139

140+
module InputIdlJson =
141+
open Helpers
142+
open System.Xml.Linq
143+
144+
type InputIdlJsonType = JsonProvider<"inputfiles/sample.webidl.json">
145+
146+
let inputIdl =
147+
File.ReadAllText(GlobalVars.inputFolder + @"/browser.webidl.json") |> InputIdlJsonType.Parse
148+
149+
let allCallbackFunctionsMap =
150+
inputIdl.CallbackFunctions |> toNameMap
151+
152+
let allInterfacesMap =
153+
inputIdl.Interfaces |> toNameMap
154+
155+
let allDictionariesMap =
156+
inputIdl.Dictionaries |> toNameMap
157+
158+
let allTypedefsMap =
159+
inputIdl.Typedefs |> toNameMap
160+
161+
let hasType itemName =
162+
allCallbackFunctionsMap.ContainsKey itemName ||
163+
allInterfacesMap.ContainsKey itemName ||
164+
allDictionariesMap.ContainsKey itemName ||
165+
allTypedefsMap.ContainsKey itemName
166+
167+
module Compat =
168+
let xNamespace = XNamespace.Get "http://schemas.microsoft.com/ie/webidl-xml"
169+
let convertArgument (i: InputIdlJsonType.Argument) =
170+
let param = XElement(xNamespace + "param", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type))
171+
if OptionCheckValue true i.Optional then
172+
param.Add (XAttribute(XName.Get "optional", "1"))
173+
if OptionCheckValue true i.Nullable then
174+
param.Add (XAttribute(XName.Get "nullable", "1"))
175+
if OptionCheckValue true i.Variadic then
176+
param.Add (XAttribute(XName.Get "variadic", "1"))
177+
param
178+
179+
let convertOperation (i: InputIdlJsonType.Operation) =
180+
let method = XElement(xNamespace + "method", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type))
181+
182+
method.Add(i.Arguments |> Array.map convertArgument)
183+
if OptionCheckValue true i.Static then
184+
method.Add(XAttribute(XName.Get "static", "1"))
185+
if OptionCheckValue true i.Nullable then
186+
method.Add(XAttribute(XName.Get "nullable", "1"))
187+
188+
method
189+
190+
let convertConstructor(i: InputIdlJsonType.Constructor) =
191+
let constructor = XElement(xNamespace + "constructor")
192+
193+
if not (Array.isEmpty i.Arguments) then
194+
constructor.Add(i.Arguments |> Array.map convertArgument)
195+
196+
constructor
197+
198+
let convertAttribute (i: InputIdlJsonType.Attribute) =
199+
let property = XElement(xNamespace + "property", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type))
200+
201+
if OptionCheckValue true i.Readonly then
202+
property.Add(XAttribute(XName.Get "read-only", "1"))
203+
if OptionCheckValue true i.Static then
204+
property.Add(XAttribute(XName.Get "static", "1"))
205+
if OptionCheckValue true i.Stringifier then
206+
property.Add(XAttribute(XName.Get "stringifier", "1"))
207+
if OptionCheckValue true i.Nullable then
208+
property.Add(XAttribute(XName.Get "nullable", "1"))
209+
210+
property
211+
212+
let convertConstant (i: InputIdlJsonType.Constant) =
213+
XElement(xNamespace + "constant", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type), XAttribute (XName.Get "value", i.Value))
214+
215+
let convertCallbackFunction (i: InputIdlJsonType.CallbackFunction) =
216+
let callbackFunction = XElement(xNamespace + "callback-function", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type))
217+
218+
callbackFunction.Add(i.Arguments |> Array.map convertArgument)
219+
if OptionCheckValue true i.Nullable then
220+
callbackFunction.Add(XAttribute(XName.Get "nullable", "1"))
221+
222+
Types.Browser.CallbackFunction callbackFunction
223+
224+
let convertInterface (i: InputIdlJsonType.Interfacis) =
225+
let interfaceEl = XElement(xNamespace + "interface", XAttribute (XName.Get "name", i.Name))
226+
227+
interfaceEl.Add (XAttribute (XName.Get "extends", if i.Extends.IsSome then i.Extends.Value else "Object"))
228+
if not (Array.isEmpty i.Constructors) then
229+
interfaceEl.Add(i.Constructors |> Array.map convertConstructor)
230+
if not (Array.isEmpty i.Operations) then
231+
interfaceEl.Add(XElement(xNamespace + "methods", i.Operations |> Array.map convertOperation))
232+
if not (Array.isEmpty i.Attributes) then
233+
interfaceEl.Add(XElement(xNamespace + "properties", i.Attributes |> Array.map convertAttribute))
234+
if not (Array.isEmpty i.Constants) then
235+
interfaceEl.Add(XElement(xNamespace + "constants", i.Constants |> Array.map convertConstant))
236+
237+
Types.Browser.Interface interfaceEl
238+
239+
let convertDictionary (i: InputIdlJsonType.Dictionary) =
240+
let dictionary = XElement(xNamespace + "dictionary", XAttribute (XName.Get "name", i.Name))
241+
242+
dictionary.Add (XAttribute (XName.Get "extends", if i.Extends.IsSome then i.Extends.Value else "Object"))
243+
let members =
244+
[ for memberDef in i.Members do
245+
let memberEl = XElement(xNamespace + "member", XAttribute (XName.Get "name", memberDef.Name), XAttribute (XName.Get "type", memberDef.Type))
246+
247+
if OptionCheckValue true memberDef.Nullable then
248+
memberEl.Add(XAttribute(XName.Get "nullable", "1"))
249+
if OptionCheckValue true memberDef.Required then
250+
memberEl.Add(XAttribute(XName.Get "required", "1"))
251+
252+
yield memberEl ]
253+
254+
dictionary.Add(XElement(xNamespace + "members", members))
255+
Types.Browser.Dictionary dictionary
256+
257+
let convertTypedef (i: InputIdlJsonType.Typedef) =
258+
let typedef = XElement(xNamespace + "typedef", XAttribute (XName.Get "new-type", i.Name), XAttribute (XName.Get "type", i.Type))
259+
260+
if OptionCheckValue true i.Nullable then
261+
typedef.Add(XAttribute(XName.Get "nullable", "1"))
262+
263+
Types.Browser.Typedef typedef
264+
135265
module InputJson =
136266
open Helpers
137267
open Types
@@ -301,11 +431,6 @@ module Data =
301431
let allInterfaces =
302432
Array.concat [| allWebInterfaces; allWorkerAdditionalInterfaces |]
303433

304-
let inline toNameMap< ^a when ^a: (member Name: string) > (data: array< ^a > ) =
305-
data
306-
|> Array.map (fun x -> ((^a: (member Name: string) x), x))
307-
|> Map.ofArray
308-
309434
let allInterfacesMap =
310435
allInterfaces |> toNameMap
311436

@@ -699,7 +824,6 @@ module Emit =
699824
| "CanvasPixelArray" -> "number[]"
700825
| "DOMHighResTimeStamp" -> "number"
701826
| "DOMString" -> "string"
702-
| "DOMTimeStamp" -> "number"
703827
| "EndOfStreamError" -> "number"
704828
| "EventListener" -> "EventListenerOrEventListenerObject"
705829
| "double" | "float" -> "number"
@@ -717,7 +841,8 @@ module Emit =
717841
if allInterfacesMap.ContainsKey objDomType ||
718842
allCallbackFuncs.ContainsKey objDomType ||
719843
allDictionariesMap.ContainsKey objDomType ||
720-
allEnumsMap.ContainsKey objDomType then
844+
allEnumsMap.ContainsKey objDomType ||
845+
InputIdlJson.hasType objDomType then
721846
objDomType
722847
// Name of a type alias. Just return itself
723848
elif typeDefSet.Contains objDomType then objDomType
@@ -882,7 +1007,12 @@ module Emit =
8821007
getAddedItems ItemKind.Callback flavor
8831008
|> Array.iter emitCallbackFunctionsFromJson
8841009

885-
GetCallbackFuncsByFlavor flavor |> Array.iter emitCallBackFunction
1010+
let map = GetCallbackFuncsByFlavor flavor |> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary
1011+
InputIdlJson.inputIdl.CallbackFunctions
1012+
|> Array.filter (fun i -> flavor <> Worker || knownWorkerInterfaces.Contains i.Name)
1013+
|> Array.iter (InputIdlJson.Compat.convertCallbackFunction >> (fun i -> map.[i.Name] <- i))
1014+
1015+
map.Values |> Array.ofSeq |> Array.iter emitCallBackFunction
8861016

8871017
let EmitEnums flavor =
8881018
let emitEnum (e: Browser.Enum) =
@@ -1378,7 +1508,7 @@ module Emit =
13781508
if hasNonStaticMember then emitStaticInterfaceWithNonStaticMembers() else emitPureStaticInterface()
13791509

13801510
let EmitNonCallbackInterfaces flavor =
1381-
for i in GetNonCallbackInterfacesByFlavor flavor do
1511+
let emitNonCallbackInterface (i: Browser.Interface) =
13821512
// If the static attribute has a value, it means the type doesn't have a constructor
13831513
if i.Static.IsSome then
13841514
EmitStaticInterface flavor i
@@ -1388,6 +1518,13 @@ module Emit =
13881518
EmitInterface flavor i
13891519
EmitConstructor flavor i
13901520

1521+
let map = GetNonCallbackInterfacesByFlavor flavor |> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary
1522+
InputIdlJson.inputIdl.Interfaces
1523+
|> Array.filter (fun i -> flavor <> Worker || i.Exposed |> Array.contains "Worker")
1524+
|> Array.iter (InputIdlJson.Compat.convertInterface >> (fun i -> map.[i.Name] <- i))
1525+
1526+
map.Values |> Array.ofSeq |> Array.iter emitNonCallbackInterface
1527+
13911528
let EmitDictionaries flavor =
13921529

13931530
let emitDictionary (dict:Browser.Dictionary) =
@@ -1427,12 +1564,19 @@ module Emit =
14271564
Pt.Printl "}"
14281565
Pt.Printl ""
14291566

1430-
browser.Dictionaries
1431-
|> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name)
1432-
|> Array.iter emitDictionary
1567+
let map =
1568+
browser.Dictionaries
1569+
|> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name)
1570+
|> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary
14331571

14341572
if flavor = Worker then
1435-
worker.Dictionaries |> Array.iter emitDictionary
1573+
worker.Dictionaries |> Array.iter (fun dict -> map.[dict.Name] <- dict)
1574+
1575+
InputIdlJson.inputIdl.Dictionaries
1576+
|> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name)
1577+
|> Array.iter (InputIdlJson.Compat.convertDictionary >> (fun i -> map.[i.Name] <- i))
1578+
1579+
map.Values |> Array.ofSeq |> Array.iter emitDictionary
14361580

14371581
let EmitAddedInterface (ai: InputJsonType.Root) =
14381582
match ai.Extends with
@@ -1478,15 +1622,14 @@ module Emit =
14781622
let emitTypeDefFromJson (typeDef: InputJsonType.Root) =
14791623
Pt.Printl "type %s = %s;" typeDef.Name.Value typeDef.Type.Value
14801624

1481-
match flavor with
1482-
| Flavor.Worker ->
1483-
browser.Typedefs
1484-
|> Array.filter (fun typedef -> knownWorkerInterfaces.Contains typedef.NewType)
1485-
|> Array.iter emitTypeDef
1486-
| _ ->
1487-
browser.Typedefs
1488-
|> Array.filter (fun typedef -> getRemovedItemByName typedef.NewType ItemKind.TypeDef "" |> Option.isNone)
1489-
|> Array.iter emitTypeDef
1625+
let mutable map = browser.Typedefs |> Array.map(fun i -> (i.NewType, i)) |> Map.ofArray
1626+
InputIdlJson.inputIdl.Typedefs
1627+
|> Array.iter (InputIdlJson.Compat.convertTypedef >> (fun i -> map <- map.Add(i.NewType, i)))
1628+
1629+
map |> Map.toArray |> Array.map snd
1630+
|> Array.filter (fun typedef -> getRemovedItemByName typedef.NewType ItemKind.TypeDef "" |> Option.isNone)
1631+
|> Array.filter (fun i -> (flavor <> Flavor.Worker || knownWorkerInterfaces.Contains i.NewType))
1632+
|> Array.iter emitTypeDef
14901633

14911634
InputJson.getAddedItems ItemKind.TypeDef flavor
14921635
|> Array.iter emitTypeDefFromJson

baselines/dom.generated.d.ts

+37-7
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,15 @@ interface WheelEventInit extends MouseEventInit {
11691169
deltaZ?: number;
11701170
}
11711171

1172+
interface TextDecodeOptions {
1173+
stream?: boolean;
1174+
}
1175+
1176+
interface TextDecoderOptions {
1177+
fatal?: boolean;
1178+
ignoreBOM?: boolean;
1179+
}
1180+
11721181
interface EventListener {
11731182
(evt: Event): void;
11741183
}
@@ -3364,7 +3373,6 @@ interface DOMException {
33643373
readonly code: number;
33653374
readonly message: string;
33663375
readonly name: string;
3367-
toString(): string;
33683376
readonly ABORT_ERR: number;
33693377
readonly DATA_CLONE_ERR: number;
33703378
readonly DOMSTRING_SIZE_ERR: number;
@@ -3382,10 +3390,8 @@ interface DOMException {
33823390
readonly NO_MODIFICATION_ALLOWED_ERR: number;
33833391
readonly NOT_FOUND_ERR: number;
33843392
readonly NOT_SUPPORTED_ERR: number;
3385-
readonly PARSE_ERR: number;
33863393
readonly QUOTA_EXCEEDED_ERR: number;
33873394
readonly SECURITY_ERR: number;
3388-
readonly SERIALIZE_ERR: number;
33893395
readonly SYNTAX_ERR: number;
33903396
readonly TIMEOUT_ERR: number;
33913397
readonly TYPE_MISMATCH_ERR: number;
@@ -3414,10 +3420,8 @@ declare var DOMException: {
34143420
readonly NO_MODIFICATION_ALLOWED_ERR: number;
34153421
readonly NOT_FOUND_ERR: number;
34163422
readonly NOT_SUPPORTED_ERR: number;
3417-
readonly PARSE_ERR: number;
34183423
readonly QUOTA_EXCEEDED_ERR: number;
34193424
readonly SECURITY_ERR: number;
3420-
readonly SERIALIZE_ERR: number;
34213425
readonly SYNTAX_ERR: number;
34223426
readonly TIMEOUT_ERR: number;
34233427
readonly TYPE_MISMATCH_ERR: number;
@@ -9077,7 +9081,7 @@ declare var PopStateEvent: {
90779081

90789082
interface Position {
90799083
readonly coords: Coordinates;
9080-
readonly timestamp: number;
9084+
readonly timestamp: DOMTimeStamp;
90819085
}
90829086

90839087
declare var Position: {
@@ -14242,6 +14246,28 @@ interface XMLHttpRequestEventTarget {
1424214246
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
1424314247
}
1424414248

14249+
interface TextDecoder {
14250+
readonly encoding: string;
14251+
readonly fatal: boolean;
14252+
readonly ignoreBOM: boolean;
14253+
decode(input?: BufferSource, options?: TextDecodeOptions): USVString;
14254+
}
14255+
14256+
declare var TextDecoder: {
14257+
prototype: TextDecoder;
14258+
new(label?: string, options?: TextDecoderOptions): TextDecoder;
14259+
};
14260+
14261+
interface TextEncoder {
14262+
readonly encoding: string;
14263+
encode(input?: USVString): Uint8Array;
14264+
}
14265+
14266+
declare var TextEncoder: {
14267+
prototype: TextEncoder;
14268+
new(): TextEncoder;
14269+
};
14270+
1424514271
interface BroadcastChannel extends EventTarget {
1424614272
readonly name: string;
1424714273
onmessage: (ev: MessageEvent) => any;
@@ -14928,6 +14954,9 @@ interface RTCStatsCallback {
1492814954
interface VoidFunction {
1492914955
(): void;
1493014956
}
14957+
interface Function {
14958+
(...arguments: any[]): any;
14959+
}
1493114960
interface HTMLElementTagNameMap {
1493214961
"a": HTMLAnchorElement;
1493314962
"abbr": HTMLElement;
@@ -15332,12 +15361,14 @@ declare function removeEventListener(type: string, listener: EventListenerOrEven
1533215361
type AAGUID = string;
1533315362
type AlgorithmIdentifier = string | Algorithm;
1533415363
type BodyInit = Blob | BufferSource | FormData | string;
15364+
type BufferSource = ArrayBufferView | ArrayBuffer;
1533515365
type ByteString = string;
1533615366
type ConstrainBoolean = boolean | ConstrainBooleanParameters;
1533715367
type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters;
1533815368
type ConstrainDouble = number | ConstrainDoubleRange;
1533915369
type ConstrainLong = number | ConstrainLongRange;
1534015370
type CryptoOperationData = ArrayBufferView;
15371+
type DOMTimeStamp = number;
1534115372
type GLbitfield = number;
1534215373
type GLboolean = boolean;
1534315374
type GLbyte = number;
@@ -15367,7 +15398,6 @@ type payloadtype = number;
1536715398
type ScrollBehavior = "auto" | "instant" | "smooth";
1536815399
type ScrollLogicalPosition = "start" | "center" | "end" | "nearest";
1536915400
type IDBValidKey = number | string | Date | IDBArrayKey;
15370-
type BufferSource = ArrayBuffer | ArrayBufferView;
1537115401
type MouseWheelEvent = WheelEvent;
1537215402
type ScrollRestoration = "auto" | "manual";
1537315403
type FormDataEntryValue = string | File;

0 commit comments

Comments
 (0)