From e108143a086948f261e4f929bd17e58911fee184 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight <saschanaz@outlook.com> Date: Wed, 27 Sep 2017 11:28:32 +0900 Subject: [PATCH 1/2] add browser.webidl.json --- TS.fsx | 187 +++++++++++-- baselines/dom.generated.d.ts | 44 ++- baselines/webworker.generated.d.ts | 41 ++- inputfiles/addedTypes.json | 5 - inputfiles/browser.webidl.json | 97 +++++++ inputfiles/knownWorkerInterfaces.json | 4 + inputfiles/removedTypes.json | 6 +- inputfiles/sample.webidl.json | 381 ++++++++++++++++++++++++++ 8 files changed, 723 insertions(+), 42 deletions(-) create mode 100644 inputfiles/browser.webidl.json create mode 100644 inputfiles/sample.webidl.json diff --git a/TS.fsx b/TS.fsx index 68099763a..30d392fd6 100644 --- a/TS.fsx +++ b/TS.fsx @@ -34,6 +34,11 @@ module Helpers = match FSharpValue.GetUnionFields(x, typeof<'a>) with | case, _ -> case.Name + let inline toNameMap< ^a when ^a: (member Name: string) > (data: array< ^a > ) = + data + |> Array.map (fun x -> ((^a: (member Name: string) x), x)) + |> Map.ofArray + module Option = let runIfSome f x = match x with @@ -132,6 +137,131 @@ module Types = type ExtendConflict = { BaseType: string; ExtendType: string list; MemberNames: string list } +module InputIdlJson = + open Helpers + open System.Xml.Linq + + type InputIdlJsonType = JsonProvider<"inputfiles/sample.webidl.json"> + + let inputIdl = + File.ReadAllText(GlobalVars.inputFolder + @"/browser.webidl.json") |> InputIdlJsonType.Parse + + let allCallbackFunctionsMap = + inputIdl.CallbackFunctions |> toNameMap + + let allInterfacesMap = + inputIdl.Interfaces |> toNameMap + + let allDictionariesMap = + inputIdl.Dictionaries |> toNameMap + + let allTypedefsMap = + inputIdl.Typedefs |> toNameMap + + let hasType itemName = + allCallbackFunctionsMap.ContainsKey itemName || + allInterfacesMap.ContainsKey itemName || + allDictionariesMap.ContainsKey itemName || + allTypedefsMap.ContainsKey itemName + + module Compat = + let xNamespace = XNamespace.Get "http://schemas.microsoft.com/ie/webidl-xml" + let convertArgument (i: InputIdlJsonType.Argument) = + let param = XElement(xNamespace + "param", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type)) + if OptionCheckValue true i.Optional then + param.Add (XAttribute(XName.Get "optional", "1")) + if OptionCheckValue true i.Nullable then + param.Add (XAttribute(XName.Get "nullable", "1")) + if OptionCheckValue true i.Variadic then + param.Add (XAttribute(XName.Get "variadic", "1")) + param + + let convertOperation (i: InputIdlJsonType.Operation) = + let method = XElement(xNamespace + "method", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type)) + + method.Add(i.Arguments |> Array.map convertArgument) + if OptionCheckValue true i.Static then + method.Add(XAttribute(XName.Get "static", "1")) + if OptionCheckValue true i.Nullable then + method.Add(XAttribute(XName.Get "nullable", "1")) + + method + + let convertConstructor(i: InputIdlJsonType.Constructor) = + let constructor = XElement(xNamespace + "constructor") + + if not (Array.isEmpty i.Arguments) then + constructor.Add(i.Arguments |> Array.map convertArgument) + + constructor + + let convertAttribute (i: InputIdlJsonType.Attribute) = + let property = XElement(xNamespace + "property", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type)) + + if OptionCheckValue true i.Readonly then + property.Add(XAttribute(XName.Get "read-only", "1")) + if OptionCheckValue true i.Static then + property.Add(XAttribute(XName.Get "static", "1")) + if OptionCheckValue true i.Stringifier then + property.Add(XAttribute(XName.Get "stringifier", "1")) + if OptionCheckValue true i.Nullable then + property.Add(XAttribute(XName.Get "nullable", "1")) + + property + + let convertConstant (i: InputIdlJsonType.Constant) = + XElement(xNamespace + "constant", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type), XAttribute (XName.Get "value", i.Value)) + + let convertCallbackFunction (i: InputIdlJsonType.CallbackFunction) = + let callbackFunction = XElement(xNamespace + "callback-function", XAttribute (XName.Get "name", i.Name), XAttribute (XName.Get "type", i.Type)) + + callbackFunction.Add(i.Arguments |> Array.map convertArgument) + if OptionCheckValue true i.Nullable then + callbackFunction.Add(XAttribute(XName.Get "nullable", "1")) + + Types.Browser.CallbackFunction callbackFunction + + let convertInterface (i: InputIdlJsonType.Interfacis) = + let interfaceEl = XElement(xNamespace + "interface", XAttribute (XName.Get "name", i.Name)) + + interfaceEl.Add (XAttribute (XName.Get "extends", if i.Extends.IsSome then i.Extends.Value else "Object")) + if not (Array.isEmpty i.Constructors) then + interfaceEl.Add(i.Constructors |> Array.map convertConstructor) + if not (Array.isEmpty i.Operations) then + interfaceEl.Add(XElement(xNamespace + "methods", i.Operations |> Array.map convertOperation)) + if not (Array.isEmpty i.Attributes) then + interfaceEl.Add(XElement(xNamespace + "properties", i.Attributes |> Array.map convertAttribute)) + if not (Array.isEmpty i.Constants) then + interfaceEl.Add(XElement(xNamespace + "constants", i.Constants |> Array.map convertConstant)) + + Types.Browser.Interface interfaceEl + + let convertDictionary (i: InputIdlJsonType.Dictionary) = + let dictionary = XElement(xNamespace + "dictionary", XAttribute (XName.Get "name", i.Name)) + + dictionary.Add (XAttribute (XName.Get "extends", if i.Extends.IsSome then i.Extends.Value else "Object")) + let members = + [ for memberDef in i.Members do + let memberEl = XElement(xNamespace + "member", XAttribute (XName.Get "name", memberDef.Name), XAttribute (XName.Get "type", memberDef.Type)) + + if OptionCheckValue true memberDef.Nullable then + memberEl.Add(XAttribute(XName.Get "nullable", "1")) + if OptionCheckValue true memberDef.Required then + memberEl.Add(XAttribute(XName.Get "required", "1")) + + yield memberEl ] + + dictionary.Add(XElement(xNamespace + "members", members)) + Types.Browser.Dictionary dictionary + + let convertTypedef (i: InputIdlJsonType.Typedef) = + let typedef = XElement(xNamespace + "typedef", XAttribute (XName.Get "new-type", i.Name), XAttribute (XName.Get "type", i.Type)) + + if OptionCheckValue true i.Nullable then + typedef.Add(XAttribute(XName.Get "nullable", "1")) + + Types.Browser.Typedef typedef + module InputJson = open Helpers open Types @@ -301,11 +431,6 @@ module Data = let allInterfaces = Array.concat [| allWebInterfaces; allWorkerAdditionalInterfaces |] - let inline toNameMap< ^a when ^a: (member Name: string) > (data: array< ^a > ) = - data - |> Array.map (fun x -> ((^a: (member Name: string) x), x)) - |> Map.ofArray - let allInterfacesMap = allInterfaces |> toNameMap @@ -699,7 +824,6 @@ module Emit = | "CanvasPixelArray" -> "number[]" | "DOMHighResTimeStamp" -> "number" | "DOMString" -> "string" - | "DOMTimeStamp" -> "number" | "EndOfStreamError" -> "number" | "EventListener" -> "EventListenerOrEventListenerObject" | "double" | "float" -> "number" @@ -717,7 +841,8 @@ module Emit = if allInterfacesMap.ContainsKey objDomType || allCallbackFuncs.ContainsKey objDomType || allDictionariesMap.ContainsKey objDomType || - allEnumsMap.ContainsKey objDomType then + allEnumsMap.ContainsKey objDomType || + InputIdlJson.hasType objDomType then objDomType // Name of a type alias. Just return itself elif typeDefSet.Contains objDomType then objDomType @@ -882,7 +1007,12 @@ module Emit = getAddedItems ItemKind.Callback flavor |> Array.iter emitCallbackFunctionsFromJson - GetCallbackFuncsByFlavor flavor |> Array.iter emitCallBackFunction + let map = GetCallbackFuncsByFlavor flavor |> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary + InputIdlJson.inputIdl.CallbackFunctions + |> Array.filter (fun i -> flavor <> Worker || knownWorkerInterfaces.Contains i.Name) + |> Array.iter (InputIdlJson.Compat.convertCallbackFunction >> (fun i -> map.[i.Name] <- i)) + + map.Values |> Array.ofSeq |> Array.iter emitCallBackFunction let EmitEnums flavor = let emitEnum (e: Browser.Enum) = @@ -1378,7 +1508,7 @@ module Emit = if hasNonStaticMember then emitStaticInterfaceWithNonStaticMembers() else emitPureStaticInterface() let EmitNonCallbackInterfaces flavor = - for i in GetNonCallbackInterfacesByFlavor flavor do + let emitNonCallbackInterface (i: Browser.Interface) = // If the static attribute has a value, it means the type doesn't have a constructor if i.Static.IsSome then EmitStaticInterface flavor i @@ -1388,6 +1518,13 @@ module Emit = EmitInterface flavor i EmitConstructor flavor i + let map = GetNonCallbackInterfacesByFlavor flavor |> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary + InputIdlJson.inputIdl.Interfaces + |> Array.filter (fun i -> flavor <> Worker || i.Exposed |> Array.contains "Worker") + |> Array.iter (InputIdlJson.Compat.convertInterface >> (fun i -> map.[i.Name] <- i)) + + map.Values |> Array.ofSeq |> Array.iter emitNonCallbackInterface + let EmitDictionaries flavor = let emitDictionary (dict:Browser.Dictionary) = @@ -1427,12 +1564,19 @@ module Emit = Pt.Printl "}" Pt.Printl "" - browser.Dictionaries - |> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name) - |> Array.iter emitDictionary + let map = + browser.Dictionaries + |> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name) + |> Array.map(fun i -> (i.Name, i)) |> dict |> Dictionary if flavor = Worker then - worker.Dictionaries |> Array.iter emitDictionary + worker.Dictionaries |> Array.iter (fun dict -> map.[dict.Name] <- dict) + + InputIdlJson.inputIdl.Dictionaries + |> Array.filter (fun dict -> flavor <> Worker || knownWorkerInterfaces.Contains dict.Name) + |> Array.iter (InputIdlJson.Compat.convertDictionary >> (fun i -> map.[i.Name] <- i)) + + map.Values |> Array.ofSeq |> Array.iter emitDictionary let EmitAddedInterface (ai: InputJsonType.Root) = match ai.Extends with @@ -1478,15 +1622,14 @@ module Emit = let emitTypeDefFromJson (typeDef: InputJsonType.Root) = Pt.Printl "type %s = %s;" typeDef.Name.Value typeDef.Type.Value - match flavor with - | Flavor.Worker -> - browser.Typedefs - |> Array.filter (fun typedef -> knownWorkerInterfaces.Contains typedef.NewType) - |> Array.iter emitTypeDef - | _ -> - browser.Typedefs - |> Array.filter (fun typedef -> getRemovedItemByName typedef.NewType ItemKind.TypeDef "" |> Option.isNone) - |> Array.iter emitTypeDef + let mutable map = browser.Typedefs |> Array.map(fun i -> (i.NewType, i)) |> Map.ofArray + InputIdlJson.inputIdl.Typedefs + |> Array.iter (InputIdlJson.Compat.convertTypedef >> (fun i -> map <- map.Add(i.NewType, i))) + + map |> Map.toArray |> Array.map snd + |> Array.filter (fun typedef -> getRemovedItemByName typedef.NewType ItemKind.TypeDef "" |> Option.isNone) + |> Array.filter (fun i -> (flavor <> Flavor.Worker || knownWorkerInterfaces.Contains i.NewType)) + |> Array.iter emitTypeDef InputJson.getAddedItems ItemKind.TypeDef flavor |> Array.iter emitTypeDefFromJson diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index e4e2d9025..36891b8dc 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -1169,6 +1169,15 @@ interface WheelEventInit extends MouseEventInit { deltaZ?: number; } +interface TextDecodeOptions { + stream?: boolean; +} + +interface TextDecoderOptions { + fatal?: boolean; + ignoreBOM?: boolean; +} + interface EventListener { (evt: Event): void; } @@ -3364,7 +3373,6 @@ interface DOMException { readonly code: number; readonly message: string; readonly name: string; - toString(): string; readonly ABORT_ERR: number; readonly DATA_CLONE_ERR: number; readonly DOMSTRING_SIZE_ERR: number; @@ -3382,10 +3390,8 @@ interface DOMException { readonly NO_MODIFICATION_ALLOWED_ERR: number; readonly NOT_FOUND_ERR: number; readonly NOT_SUPPORTED_ERR: number; - readonly PARSE_ERR: number; readonly QUOTA_EXCEEDED_ERR: number; readonly SECURITY_ERR: number; - readonly SERIALIZE_ERR: number; readonly SYNTAX_ERR: number; readonly TIMEOUT_ERR: number; readonly TYPE_MISMATCH_ERR: number; @@ -3414,10 +3420,8 @@ declare var DOMException: { readonly NO_MODIFICATION_ALLOWED_ERR: number; readonly NOT_FOUND_ERR: number; readonly NOT_SUPPORTED_ERR: number; - readonly PARSE_ERR: number; readonly QUOTA_EXCEEDED_ERR: number; readonly SECURITY_ERR: number; - readonly SERIALIZE_ERR: number; readonly SYNTAX_ERR: number; readonly TIMEOUT_ERR: number; readonly TYPE_MISMATCH_ERR: number; @@ -9077,7 +9081,7 @@ declare var PopStateEvent: { interface Position { readonly coords: Coordinates; - readonly timestamp: number; + readonly timestamp: DOMTimeStamp; } declare var Position: { @@ -14242,6 +14246,28 @@ interface XMLHttpRequestEventTarget { removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } +interface TextDecoder { + readonly encoding: string; + readonly fatal: boolean; + readonly ignoreBOM: boolean; + decode(input?: BufferSource, options?: TextDecodeOptions): USVString; +} + +declare var TextDecoder: { + prototype: TextDecoder; + new(label?: string, options?: TextDecoderOptions): TextDecoder; +}; + +interface TextEncoder { + readonly encoding: string; + encode(input?: USVString): Uint8Array; +} + +declare var TextEncoder: { + prototype: TextEncoder; + new(): TextEncoder; +}; + interface BroadcastChannel extends EventTarget { readonly name: string; onmessage: (ev: MessageEvent) => any; @@ -14928,6 +14954,9 @@ interface RTCStatsCallback { interface VoidFunction { (): void; } +interface Function { + (...arguments: any[]): any; +} interface HTMLElementTagNameMap { "a": HTMLAnchorElement; "abbr": HTMLElement; @@ -15332,12 +15361,14 @@ declare function removeEventListener(type: string, listener: EventListenerOrEven type AAGUID = string; type AlgorithmIdentifier = string | Algorithm; type BodyInit = Blob | BufferSource | FormData | string; +type BufferSource = ArrayBufferView | ArrayBuffer; type ByteString = string; type ConstrainBoolean = boolean | ConstrainBooleanParameters; type ConstrainDOMString = string | string[] | ConstrainDOMStringParameters; type ConstrainDouble = number | ConstrainDoubleRange; type ConstrainLong = number | ConstrainLongRange; type CryptoOperationData = ArrayBufferView; +type DOMTimeStamp = number; type GLbitfield = number; type GLboolean = boolean; type GLbyte = number; @@ -15367,7 +15398,6 @@ type payloadtype = number; type ScrollBehavior = "auto" | "instant" | "smooth"; type ScrollLogicalPosition = "start" | "center" | "end" | "nearest"; type IDBValidKey = number | string | Date | IDBArrayKey; -type BufferSource = ArrayBuffer | ArrayBufferView; type MouseWheelEvent = WheelEvent; type ScrollRestoration = "auto" | "manual"; type FormDataEntryValue = string | File; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index af8fb4d4c..5b46167b5 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -128,6 +128,15 @@ interface SyncEventInit extends ExtendableEventInit { lastChance?: boolean; } +interface TextDecodeOptions { + stream?: boolean; +} + +interface TextDecoderOptions { + fatal?: boolean; + ignoreBOM?: boolean; +} + interface EventListener { (evt: Event): void; } @@ -283,7 +292,6 @@ interface DOMException { readonly code: number; readonly message: string; readonly name: string; - toString(): string; readonly ABORT_ERR: number; readonly DATA_CLONE_ERR: number; readonly DOMSTRING_SIZE_ERR: number; @@ -301,10 +309,8 @@ interface DOMException { readonly NO_MODIFICATION_ALLOWED_ERR: number; readonly NOT_FOUND_ERR: number; readonly NOT_SUPPORTED_ERR: number; - readonly PARSE_ERR: number; readonly QUOTA_EXCEEDED_ERR: number; readonly SECURITY_ERR: number; - readonly SERIALIZE_ERR: number; readonly SYNTAX_ERR: number; readonly TIMEOUT_ERR: number; readonly TYPE_MISMATCH_ERR: number; @@ -333,10 +339,8 @@ declare var DOMException: { readonly NO_MODIFICATION_ALLOWED_ERR: number; readonly NOT_FOUND_ERR: number; readonly NOT_SUPPORTED_ERR: number; - readonly PARSE_ERR: number; readonly QUOTA_EXCEEDED_ERR: number; readonly SECURITY_ERR: number; - readonly SERIALIZE_ERR: number; readonly SYNTAX_ERR: number; readonly TIMEOUT_ERR: number; readonly TYPE_MISMATCH_ERR: number; @@ -854,7 +858,7 @@ declare var PerformanceTiming: { interface Position { readonly coords: Coordinates; - readonly timestamp: number; + readonly timestamp: DOMTimeStamp; } declare var Position: { @@ -1542,6 +1546,28 @@ interface WorkerUtils extends Object, WindowBase64 { setTimeout(handler: any, timeout?: any, ...args: any[]): number; } +interface TextDecoder { + readonly encoding: string; + readonly fatal: boolean; + readonly ignoreBOM: boolean; + decode(input?: BufferSource, options?: TextDecodeOptions): USVString; +} + +declare var TextDecoder: { + prototype: TextDecoder; + new(label?: string, options?: TextDecoderOptions): TextDecoder; +}; + +interface TextEncoder { + readonly encoding: string; + encode(input?: USVString): Uint8Array; +} + +declare var TextEncoder: { + prototype: TextEncoder; + new(): TextEncoder; +}; + interface BroadcastChannel extends EventTarget { readonly name: string; onmessage: (ev: MessageEvent) => any; @@ -1924,11 +1950,12 @@ declare function removeEventListener<K extends keyof DedicatedWorkerGlobalScopeE declare function removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; type AlgorithmIdentifier = string | Algorithm; type BodyInit = Blob | BufferSource | FormData | string; +type BufferSource = ArrayBufferView | ArrayBuffer; +type DOMTimeStamp = number; type IDBKeyPath = string; type RequestInfo = Request | string; type USVString = string; type IDBValidKey = number | string | Date | IDBArrayKey; -type BufferSource = ArrayBuffer | ArrayBufferView; type FormDataEntryValue = string | File; type HeadersInit = Headers | string[][] | { [key: string]: string }; type IDBCursorDirection = "next" | "nextunique" | "prev" | "prevunique"; diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index b2fbd5d99..4ea819162 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -815,11 +815,6 @@ "name": "failIfMajorPerformanceCaveat?", "type": "boolean" }, - { - "kind": "typedef", - "name": "BufferSource", - "type": "ArrayBuffer | ArrayBufferView" - }, { "kind": "interface", "name": "RsaKeyGenParams", diff --git a/inputfiles/browser.webidl.json b/inputfiles/browser.webidl.json new file mode 100644 index 000000000..c20d4c4c2 --- /dev/null +++ b/inputfiles/browser.webidl.json @@ -0,0 +1,97 @@ +{ + "callbackInterfaces": [], "enums": [], "namespaces": [], + "callbackFunctions": [ + { + "name": "Function", "type": "any", + "arguments": [{ "name": "arguments", "type": "any", "variadic": true }] + }, + { "name": "VoidFunction", "type": "void", "arguments": [] } + ], + "dictionaries": [{ + "name": "TextDecodeOptions", + "members": [{ "name": "stream", "type": "boolean", "default": "false" }] + }, { + "name": "TextDecoderOptions", + "members": [ + { "name": "fatal", "type": "boolean", "default": "false" }, + { "name": "ignoreBOM", "type": "boolean", "default": "false" } + ] + }], + "interfaces": [{ + "name": "DOMException", + "exposed": ["Window", "Worker"], + "constructors": [{ + "arguments": [ + { "name": "message", "type": "DOMString", "optional": true, "default": "\"\"" }, + { "name": "name", "type": "DOMString", "optional": true, "default": "\"Error\"" } + ] + }], + "constants": [ + { "name": "ABORT_ERR", "type": "unsigned short", "value": "20" }, + { "name": "DATA_CLONE_ERR", "type": "unsigned short", "value": "25" }, + { "name": "DOMSTRING_SIZE_ERR", "type": "unsigned short", "value": "2" }, + { "name": "HIERARCHY_REQUEST_ERR", "type": "unsigned short", "value": "3" }, + { "name": "INDEX_SIZE_ERR", "type": "unsigned short", "value": "1" }, + { "name": "INUSE_ATTRIBUTE_ERR", "type": "unsigned short", "value": "10" }, + { "name": "INVALID_ACCESS_ERR", "type": "unsigned short", "value": "15" }, + { "name": "INVALID_CHARACTER_ERR", "type": "unsigned short", "value": "5" }, + { "name": "INVALID_MODIFICATION_ERR", "type": "unsigned short", "value": "13" }, + { "name": "INVALID_NODE_TYPE_ERR", "type": "unsigned short", "value": "24" }, + { "name": "INVALID_STATE_ERR", "type": "unsigned short", "value": "11" }, + { "name": "NAMESPACE_ERR", "type": "unsigned short", "value": "14" }, + { "name": "NETWORK_ERR", "type": "unsigned short", "value": "19" }, + { "name": "NO_DATA_ALLOWED_ERR", "type": "unsigned short", "value": "6" }, + { "name": "NO_MODIFICATION_ALLOWED_ERR", "type": "unsigned short", "value": "7" }, + { "name": "NOT_FOUND_ERR", "type": "unsigned short", "value": "8" }, + { "name": "NOT_SUPPORTED_ERR", "type": "unsigned short", "value": "9" }, + { "name": "QUOTA_EXCEEDED_ERR", "type": "unsigned short", "value": "22" }, + { "name": "SECURITY_ERR", "type": "unsigned short", "value": "18" }, + { "name": "SYNTAX_ERR", "type": "unsigned short", "value": "12" }, + { "name": "TIMEOUT_ERR", "type": "unsigned short", "value": "23" }, + { "name": "TYPE_MISMATCH_ERR", "type": "unsigned short", "value": "17" }, + { "name": "URL_MISMATCH_ERR", "type": "unsigned short", "value": "21" }, + { "name": "VALIDATION_ERR", "type": "unsigned short", "value": "16" }, + { "name": "WRONG_DOCUMENT_ERR", "type": "unsigned short", "value": "4" } + ], + "attributes": [ + { "name": "code", "type": "unsigned short", "readonly": true }, + { "name": "message", "type": "DOMString", "readonly": true }, + { "name": "name", "type": "DOMString", "readonly": true } + ] + }, { + "name": "TextDecoder", + "constructors": [{ + "arguments": [ + { "name": "label", "type": "DOMString", "optional": true, "default": "\"utf-8\"" }, + { "name": "options", "type": "TextDecoderOptions", "optional": true } + ] + }], + "exposed": ["Window", "Worker"], + "operations": [{ + "name": "decode", "type": "USVString", + "arguments": [ + { "name": "input", "type": "BufferSource", "optional": true }, + { "name": "options", "type": "TextDecodeOptions", "optional": true } + ] + }], + "attributes": [ + { "name": "encoding", "type": "DOMString", "readonly": true }, + { "name": "fatal", "type": "boolean", "readonly": true }, + { "name": "ignoreBOM", "type": "boolean", "readonly": true } + ] + }, { + "name": "TextEncoder", + "constructors": [{ "arguments": [] }], + "exposed": ["Window", "Worker"], + "operations": [{ + "name": "encode", "type": "Uint8Array", + "arguments": [{ "name": "input", "type": "USVString", "optional": true, "default": "\"\"" }] + }], + "attributes": [{ "name": "encoding", "type": "DOMString", "readonly": true }] + }], + "typedefs": [ + { "name": "ArrayBufferView", "type": "(Int8Array or Int16Array or Int32Array or Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or Float32Array or Float64Array or DataView)" }, + { "name": "BufferSource", "type": "(ArrayBufferView or ArrayBuffer)" }, + { "name": "DOMTimeStamp", "type": "unsigned long long" } + ] +} \ No newline at end of file diff --git a/inputfiles/knownWorkerInterfaces.json b/inputfiles/knownWorkerInterfaces.json index c8e8d36dc..4d13eed72 100644 --- a/inputfiles/knownWorkerInterfaces.json +++ b/inputfiles/knownWorkerInterfaces.json @@ -6,6 +6,7 @@ "Blob", "Body", "BodyInit", + "BufferSource", "Cache", "CacheQueryOptions", "CacheStorage", @@ -18,6 +19,7 @@ "DOMError", "DOMException", "DOMStringList", + "DOMTimeStamp", "DecodeErrorCallback", "DecodeSuccessCallback", "ErrorEvent", @@ -92,6 +94,8 @@ "ServiceWorkerRegistration", "SyncEventInit", "SyncManager", + "TextDecodeOptions", + "TextDecoderOptions", "USVString", "URL", "URLSearchParams", diff --git a/inputfiles/removedTypes.json b/inputfiles/removedTypes.json index 3fe4fe43f..72a2955b1 100644 --- a/inputfiles/removedTypes.json +++ b/inputfiles/removedTypes.json @@ -83,5 +83,9 @@ { "kind": "typedef", "name": "HeadersInit" + }, + { + "kind": "typedef", + "name": "ArrayBufferView" } -] \ No newline at end of file +] diff --git a/inputfiles/sample.webidl.json b/inputfiles/sample.webidl.json new file mode 100644 index 000000000..dc38afbf7 --- /dev/null +++ b/inputfiles/sample.webidl.json @@ -0,0 +1,381 @@ +{ + "callbackInterfaces": [], + "enums": [], + "namespaces": [], + "callbackFunctions": [ + { + "name": "Function", + "type": "any", + "nullable": true, + "arguments": [ + { + "name": "label", + "type": "DOMString", + "optional": true, + "default": "\"utf-8\"" + }, + { + "name": "options", + "type": "TextDecoderOptions", + "optional": true + }, + { + "name": "dummy", + "type": "TextDecodeOptions", + "nullable": true, + "variadic": true + } + ] + }, + { + "name": "VoidFunction", + "type": "void", + "arguments": [] + } + ], + "dictionaries": [ + { + "name": "TextDecodeOptions", + "extends": "Object", + "partial": true, + "members": [ + { + "name": "stream", + "type": "boolean", + "default": "false" + }, + { + "name": "dummy", + "type": "boolean", + "nullable": true, + "required": true + } + ] + }, + { + "name": "TextDecoderOptions", + "members": [ + { + "name": "fatal", + "type": "boolean", + "default": "false" + }, + { + "name": "ignoreBOM", + "type": "boolean", + "default": "false" + } + ] + } + ], + "interfaces": [ + { + "name": "TextDecoder", + "extends": "Object", + "partial": true, + "constructors": [ + { + "arguments": [ + { + "name": "label", + "type": "DOMString", + "optional": true, + "default": "\"utf-8\"" + }, + { + "name": "options", + "type": "TextDecoderOptions", + "optional": true + }, + { + "name": "dummy", + "type": "TextDecodeOptions", + "nullable": true, + "variadic": true + } + ] + } + ], + "exposed": [ "Window", "Worker" ], + "operations": [ + { + "name": "decode", + "type": "USVString", + "arguments": [ + { + "name": "input", + "type": "BufferSource", + "optional": true + }, + { + "name": "options", + "type": "TextDecodeOptions", + "optional": true + }, + { + "name": "dummy", + "type": "TextDecodeOptions", + "nullable": true, + "variadic": true, + "default": "null" + } + ] + }, + { + "name": "decode", + "type": "USVString", + "nullable": true, + "static": true, + "arguments": [] + } + ], + "anonymousOperations": [ + { + "type": "USVString", + "nullable": true, + "getter": true, + "setter": true, + "creator": true, + "deleter": true, + "stringifier": true, + "arguments": [] + } + ], + "attributes": [ + { + "name": "encoding", + "type": "DOMString", + "readonly": true + }, + { + "name": "fatal", + "type": "boolean", + "readonly": true + }, + { + "name": "ignoreBOM", + "type": "boolean", + "readonly": true + }, + { + "name": "dummy", + "type": "boolean", + "nullable": true, + "static": true, + "stringifier": true + } + ] + }, + { + "name": "TextEncoder", + "extends": "Object", + "constructors": [ { "arguments": [] } ], + "exposed": [ "Window", "Worker" ], + "operations": [ + { + "name": "encode", + "type": "Uint8Array", + "arguments": [ + { + "name": "input", + "type": "USVString", + "optional": true, + "default": "\"\"" + } + ] + } + ], + "attributes": [ + { + "name": "encoding", + "type": "DOMString", + "readonly": true + } + ] + }, + { + "name": "TextEncoder" + }, + { + "name": "DOMException", + "exposed": [ "Window", "Worker" ], + "constructors": [ + { + "arguments": [ + { + "name": "message", + "type": "DOMString", + "optional": true, + "default": "\"\"" + }, + { + "name": "name", + "type": "DOMString", + "optional": true, + "default": "\"Error\"" + } + ] + } + ], + "constants": [ + { + "name": "ABORT_ERR", + "type": "unsigned short", + "value": "20" + }, + { + "name": "DATA_CLONE_ERR", + "type": "unsigned short", + "value": "25" + }, + { + "name": "DOMSTRING_SIZE_ERR", + "type": "unsigned short", + "value": "2" + }, + { + "name": "HIERARCHY_REQUEST_ERR", + "type": "unsigned short", + "value": "3" + }, + { + "name": "INDEX_SIZE_ERR", + "type": "unsigned short", + "value": "1" + }, + { + "name": "INUSE_ATTRIBUTE_ERR", + "type": "unsigned short", + "value": "10" + }, + { + "name": "INVALID_ACCESS_ERR", + "type": "unsigned short", + "value": "15" + }, + { + "name": "INVALID_CHARACTER_ERR", + "type": "unsigned short", + "value": "5" + }, + { + "name": "INVALID_MODIFICATION_ERR", + "type": "unsigned short", + "value": "13" + }, + { + "name": "INVALID_NODE_TYPE_ERR", + "type": "unsigned short", + "value": "24" + }, + { + "name": "INVALID_STATE_ERR", + "type": "unsigned short", + "value": "11" + }, + { + "name": "NAMESPACE_ERR", + "type": "unsigned short", + "value": "14" + }, + { + "name": "NETWORK_ERR", + "type": "unsigned short", + "value": "19" + }, + { + "name": "NO_DATA_ALLOWED_ERR", + "type": "unsigned short", + "value": "6" + }, + { + "name": "NO_MODIFICATION_ALLOWED_ERR", + "type": "unsigned short", + "value": "7" + }, + { + "name": "NOT_FOUND_ERR", + "type": "unsigned short", + "value": "8" + }, + { + "name": "NOT_SUPPORTED_ERR", + "type": "unsigned short", + "value": "9" + }, + { + "name": "QUOTA_EXCEEDED_ERR", + "type": "unsigned short", + "value": "22" + }, + { + "name": "SECURITY_ERR", + "type": "unsigned short", + "value": "18" + }, + { + "name": "SYNTAX_ERR", + "type": "unsigned short", + "value": "12" + }, + { + "name": "TIMEOUT_ERR", + "type": "unsigned short", + "value": "23" + }, + { + "name": "TYPE_MISMATCH_ERR", + "type": "unsigned short", + "value": "17" + }, + { + "name": "URL_MISMATCH_ERR", + "type": "unsigned short", + "value": "21" + }, + { + "name": "VALIDATION_ERR", + "type": "unsigned short", + "value": "16" + }, + { + "name": "WRONG_DOCUMENT_ERR", + "type": "unsigned short", + "value": "4" + } + ], + "attributes": [ + { + "name": "code", + "type": "unsigned short", + "readonly": true + }, + { + "name": "message", + "type": "DOMString", + "readonly": true + }, + { + "name": "name", + "type": "DOMString", + "readonly": true + } + ] + } + ], + "typedefs": [ + { + "name": "ArrayBufferView", + "type": "(Int8Array or Int16Array or Int32Array or Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or Float32Array or Float64Array or DataView)" + }, + { + "name": "BufferSource", + "type": "(ArrayBufferView or ArrayBuffer)", + "nullable": true + }, + { + "name": "DOMTimeStamp", + "type": "unsigned long long" + } + ] +} From a1360ac0d77d564165ab27d9f8249b41d02424bb Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight <saschanaz@outlook.com> Date: Tue, 9 Jan 2018 21:24:53 +0900 Subject: [PATCH 2/2] splitted idls + simple merging --- TS.fsx | 15 ++++++- inputfiles/idls/Encoding.webidl.json | 44 +++++++++++++++++++ .../Web IDL.webidl.json} | 42 +----------------- 3 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 inputfiles/idls/Encoding.webidl.json rename inputfiles/{browser.webidl.json => idls/Web IDL.webidl.json} (67%) diff --git a/TS.fsx b/TS.fsx index 30d392fd6..75789ee1c 100644 --- a/TS.fsx +++ b/TS.fsx @@ -144,8 +144,19 @@ module InputIdlJson = type InputIdlJsonType = JsonProvider<"inputfiles/sample.webidl.json"> let inputIdl = - File.ReadAllText(GlobalVars.inputFolder + @"/browser.webidl.json") |> InputIdlJsonType.Parse - + let jsons = + DirectoryInfo(GlobalVars.inputFolder + @"/idls").GetFiles() + |> Array.map (fun file -> file.FullName |> File.ReadAllText |> InputIdlJsonType.Parse) + + let inline extractJsonArray f = + jsons |> Array.collect f |> Array.map (fun item -> (^a: (member JsonValue: JsonValue) item)) |> JsonValue.Array; + + let list = [| ("callbackFunctions", extractJsonArray (fun json -> json.CallbackFunctions)); + ("interfaces", extractJsonArray (fun json -> json.Interfaces)); + ("dictionaries", extractJsonArray (fun json -> json.Dictionaries)); + ("typedefs", extractJsonArray (fun json -> json.Typedefs)) |] + InputIdlJsonType.Root(JsonValue.Record list) + let allCallbackFunctionsMap = inputIdl.CallbackFunctions |> toNameMap diff --git a/inputfiles/idls/Encoding.webidl.json b/inputfiles/idls/Encoding.webidl.json new file mode 100644 index 000000000..f573fd6b2 --- /dev/null +++ b/inputfiles/idls/Encoding.webidl.json @@ -0,0 +1,44 @@ +{ + "callbackFunctions": [], "callbackInterfaces": [], "enums": [], "typedefs": [], "namespaces": [], + "dictionaries": [{ + "name": "TextDecodeOptions", + "members": [{ "name": "stream", "type": "boolean", "default": "false" }] + }, { + "name": "TextDecoderOptions", + "members": [ + { "name": "fatal", "type": "boolean", "default": "false" }, + { "name": "ignoreBOM", "type": "boolean", "default": "false" } + ] + }], + "interfaces": [{ + "name": "TextDecoder", + "constructors": [{ + "arguments": [ + { "name": "label", "type": "DOMString", "optional": true, "default": "\"utf-8\"" }, + { "name": "options", "type": "TextDecoderOptions", "optional": true } + ] + }], + "exposed": ["Window", "Worker"], + "operations": [{ + "name": "decode", "type": "USVString", + "arguments": [ + { "name": "input", "type": "BufferSource", "optional": true }, + { "name": "options", "type": "TextDecodeOptions", "optional": true } + ] + }], + "attributes": [ + { "name": "encoding", "type": "DOMString", "readonly": true }, + { "name": "fatal", "type": "boolean", "readonly": true }, + { "name": "ignoreBOM", "type": "boolean", "readonly": true } + ] + }, { + "name": "TextEncoder", + "constructors": [{ "arguments": [] }], + "exposed": ["Window", "Worker"], + "operations": [{ + "name": "encode", "type": "Uint8Array", + "arguments": [{ "name": "input", "type": "USVString", "optional": true, "default": "\"\"" }] + }], + "attributes": [{ "name": "encoding", "type": "DOMString", "readonly": true }] + }] +} \ No newline at end of file diff --git a/inputfiles/browser.webidl.json b/inputfiles/idls/Web IDL.webidl.json similarity index 67% rename from inputfiles/browser.webidl.json rename to inputfiles/idls/Web IDL.webidl.json index c20d4c4c2..b64646e35 100644 --- a/inputfiles/browser.webidl.json +++ b/inputfiles/idls/Web IDL.webidl.json @@ -1,5 +1,5 @@ { - "callbackInterfaces": [], "enums": [], "namespaces": [], + "callbackInterfaces": [], "dictionaries": [], "enums": [], "namespaces": [], "callbackFunctions": [ { "name": "Function", "type": "any", @@ -7,16 +7,6 @@ }, { "name": "VoidFunction", "type": "void", "arguments": [] } ], - "dictionaries": [{ - "name": "TextDecodeOptions", - "members": [{ "name": "stream", "type": "boolean", "default": "false" }] - }, { - "name": "TextDecoderOptions", - "members": [ - { "name": "fatal", "type": "boolean", "default": "false" }, - { "name": "ignoreBOM", "type": "boolean", "default": "false" } - ] - }], "interfaces": [{ "name": "DOMException", "exposed": ["Window", "Worker"], @@ -58,36 +48,6 @@ { "name": "message", "type": "DOMString", "readonly": true }, { "name": "name", "type": "DOMString", "readonly": true } ] - }, { - "name": "TextDecoder", - "constructors": [{ - "arguments": [ - { "name": "label", "type": "DOMString", "optional": true, "default": "\"utf-8\"" }, - { "name": "options", "type": "TextDecoderOptions", "optional": true } - ] - }], - "exposed": ["Window", "Worker"], - "operations": [{ - "name": "decode", "type": "USVString", - "arguments": [ - { "name": "input", "type": "BufferSource", "optional": true }, - { "name": "options", "type": "TextDecodeOptions", "optional": true } - ] - }], - "attributes": [ - { "name": "encoding", "type": "DOMString", "readonly": true }, - { "name": "fatal", "type": "boolean", "readonly": true }, - { "name": "ignoreBOM", "type": "boolean", "readonly": true } - ] - }, { - "name": "TextEncoder", - "constructors": [{ "arguments": [] }], - "exposed": ["Window", "Worker"], - "operations": [{ - "name": "encode", "type": "Uint8Array", - "arguments": [{ "name": "input", "type": "USVString", "optional": true, "default": "\"\"" }] - }], - "attributes": [{ "name": "encoding", "type": "DOMString", "readonly": true }] }], "typedefs": [ { "name": "ArrayBufferView", "type": "(Int8Array or Int16Array or Int32Array or Uint8Array or Uint16Array or Uint32Array or Uint8ClampedArray or Float32Array or Float64Array or DataView)" },