Skip to content

Commit

Permalink
Require default dictionary value for optional dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanaz committed Jul 12, 2019
1 parent 56f31c8 commit 0115127
Show file tree
Hide file tree
Showing 71 changed files with 105 additions and 98 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -17,6 +17,7 @@
from WebIDL import (
BuiltinTypes,
IDLBuiltinType,
IDLDefaultDictionaryValue,
IDLEmptySequenceValue,
IDLInterfaceMember,
IDLNullableType,
Expand Down Expand Up @@ -678,13 +679,16 @@ def handleDefault(nullValue):
return None

if isinstance(defaultValue, IDLNullValue):
assert type.nullable() or type.isDictionary()
assert type.nullable()
return nullValue
elif isinstance(defaultValue, IDLDefaultDictionaryValue):
assert type.isDictionary()
return nullValue
elif isinstance(defaultValue, IDLEmptySequenceValue):
assert type.isSequence()
return "Vec::new()"

raise TypeError("Can't handle non-null or non-empty sequence default value here")
raise TypeError("Can't handle non-null, non-empty sequence or non-empty dictionary default value here")

# A helper function for wrapping up the template body for
# possibly-nullable objecty stuff
Expand Down Expand Up @@ -747,17 +751,19 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,
for memberType in type.unroll().flatMemberTypes
if memberType.isDictionary()
]
if defaultValue and not isinstance(defaultValue, IDLNullValue):
if (defaultValue and
not isinstance(defaultValue, IDLNullValue) and
not isinstance(defaultValue, IDLDefaultDictionaryValue)):
tag = defaultValue.type.tag()
if tag is IDLType.Tags.bool:
default = "%s::Boolean(%s)" % (
union_native_type(type),
"true" if defaultValue.value else "false")
else:
raise("We don't currently support default values that aren't null or boolean")
raise("We don't currently support default values that aren't null, boolean or default dictionary")
elif dictionaries:
if defaultValue:
assert isinstance(defaultValue, IDLNullValue)
assert isinstance(defaultValue, IDLDefaultDictionaryValue)
dictionary, = dictionaries
default = "%s::%s(%s::%s::empty())" % (
union_native_type(type),
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/AnalyserNode.webidl
Expand Up @@ -14,7 +14,7 @@ dictionary AnalyserOptions : AudioNodeOptions {
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional AnalyserOptions options)]
Constructor (BaseAudioContext context, optional AnalyserOptions options = {})]
interface AnalyserNode : AudioNode {
void getFloatFrequencyData (Float32Array array);
void getByteFrequencyData (Uint8Array array);
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/AudioBufferSourceNode.webidl
Expand Up @@ -16,7 +16,7 @@ dictionary AudioBufferSourceOptions {
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional AudioBufferSourceOptions options)]
Constructor (BaseAudioContext context, optional AudioBufferSourceOptions options = {})]
interface AudioBufferSourceNode : AudioScheduledSourceNode {
[Throws] attribute AudioBuffer? buffer;
readonly attribute AudioParam playbackRate;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/AudioContext.webidl
Expand Up @@ -23,7 +23,7 @@ dictionary AudioTimestamp {
};

[Exposed=Window,
Constructor(optional AudioContextOptions contextOptions)]
Constructor(optional AudioContextOptions contextOptions = {})]
interface AudioContext : BaseAudioContext {
readonly attribute double baseLatency;
readonly attribute double outputLatency;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/BiquadFilterNode.webidl
Expand Up @@ -26,7 +26,7 @@ dictionary BiquadFilterOptions : AudioNodeOptions {
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional BiquadFilterOptions options)]
Constructor (BaseAudioContext context, optional BiquadFilterOptions options = {})]
interface BiquadFilterNode : AudioNode {
attribute BiquadFilterType type;
readonly attribute AudioParam frequency;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Blob.webidl
Expand Up @@ -5,7 +5,7 @@
// https://w3c.github.io/FileAPI/#blob

[Constructor(optional sequence<BlobPart> blobParts,
optional BlobPropertyBag options),
optional BlobPropertyBag options = {}),
Exposed=(Window,Worker)]
interface Blob {

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Bluetooth.webidl
Expand Up @@ -34,7 +34,7 @@ interface Bluetooth : EventTarget {
// [SecureContext, SameObject]
// readonly attribute BluetoothDevice? referringDevice;
[SecureContext]
Promise<BluetoothDevice> requestDevice(optional RequestDeviceOptions options);
Promise<BluetoothDevice> requestDevice(optional RequestDeviceOptions options = {});
};

// Bluetooth implements BluetoothDeviceEventHandlers;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ChannelMergerNode.webidl
Expand Up @@ -11,6 +11,6 @@ dictionary ChannelMergerOptions : AudioNodeOptions {
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional ChannelMergerOptions options)]
Constructor (BaseAudioContext context, optional ChannelMergerOptions options = {})]
interface ChannelMergerNode : AudioNode {
};
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ChannelSplitterNode.webidl
Expand Up @@ -11,6 +11,6 @@ dictionary ChannelSplitterOptions : AudioNodeOptions {
};

[Exposed=Window,
Constructor (BaseAudioContext context, optional ChannelSplitterOptions options)]
Constructor (BaseAudioContext context, optional ChannelSplitterOptions options = {})]
interface ChannelSplitterNode : AudioNode {
};
2 changes: 1 addition & 1 deletion components/script/dom/webidls/CloseEvent.webidl
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

//https://html.spec.whatwg.org/multipage/#the-closeevent-interfaces
[Constructor(DOMString type, optional CloseEventInit eventInitDict), Exposed=(Window,Worker)]
[Constructor(DOMString type, optional CloseEventInit eventInitDict = {}), Exposed=(Window,Worker)]
interface CloseEvent : Event {
readonly attribute boolean wasClean;
readonly attribute unsigned short code;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/CompositionEvent.webidl
Expand Up @@ -8,7 +8,7 @@
*/

// https://w3c.github.io/uievents/#idl-compositionevent
[Pref="dom.compositionevent.enabled", Constructor(DOMString type, optional CompositionEventInit eventInitDict)]
[Pref="dom.compositionevent.enabled", Constructor(DOMString type, optional CompositionEventInit eventInitDict = {})]
interface CompositionEvent : UIEvent {
readonly attribute DOMString data;
};
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/CustomElementRegistry.webidl
Expand Up @@ -6,7 +6,7 @@
[Pref="dom.customelements.enabled"]
interface CustomElementRegistry {
[Throws, CEReactions]
void define(DOMString name, CustomElementConstructor constructor_, optional ElementDefinitionOptions options);
void define(DOMString name, CustomElementConstructor constructor_, optional ElementDefinitionOptions options = {});

any get(DOMString name);

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/CustomEvent.webidl
Expand Up @@ -13,7 +13,7 @@
* http://www.openwebfoundation.org/legal/the-owf-1-0-agreements/owfa-1-0.
*/

[Constructor(DOMString type, optional CustomEventInit eventInitDict),
[Constructor(DOMString type, optional CustomEventInit eventInitDict = {}),
Exposed=(Window,Worker)]
interface CustomEvent : Event {
readonly attribute any detail;
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/webidls/DOMMatrix.webidl
Expand Up @@ -14,7 +14,7 @@
Exposed=(Window,Worker)]
interface DOMMatrix : DOMMatrixReadOnly {

[NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other);
[NewObject, Throws] static DOMMatrix fromMatrix(optional DOMMatrixInit other = {});
[NewObject, Throws] static DOMMatrix fromFloat32Array(Float32Array array32);
[NewObject, Throws] static DOMMatrix fromFloat64Array(Float64Array array64);

Expand Down Expand Up @@ -44,8 +44,8 @@ interface DOMMatrix : DOMMatrixReadOnly {
inherit attribute unrestricted double m44;

// Mutable transform methods
[Throws] DOMMatrix multiplySelf(optional DOMMatrixInit other);
[Throws] DOMMatrix preMultiplySelf(optional DOMMatrixInit other);
[Throws] DOMMatrix multiplySelf(optional DOMMatrixInit other = {});
[Throws] DOMMatrix preMultiplySelf(optional DOMMatrixInit other = {});
DOMMatrix translateSelf(optional unrestricted double tx = 0,
optional unrestricted double ty = 0,
optional unrestricted double tz = 0);
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/webidls/DOMMatrixReadOnly.webidl
Expand Up @@ -14,7 +14,7 @@
Exposed=(Window,Worker)]
interface DOMMatrixReadOnly {

[NewObject, Throws] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other);
[NewObject, Throws] static DOMMatrixReadOnly fromMatrix(optional DOMMatrixInit other = {});
[NewObject, Throws] static DOMMatrixReadOnly fromFloat32Array(Float32Array array32);
[NewObject, Throws] static DOMMatrixReadOnly fromFloat64Array(Float64Array array64);

Expand Down Expand Up @@ -73,12 +73,12 @@ interface DOMMatrixReadOnly {
optional unrestricted double angle = 0);
DOMMatrix skewX(optional unrestricted double sx = 0);
DOMMatrix skewY(optional unrestricted double sy = 0);
[Throws] DOMMatrix multiply(optional DOMMatrixInit other);
[Throws] DOMMatrix multiply(optional DOMMatrixInit other = {});
DOMMatrix flipX();
DOMMatrix flipY();
DOMMatrix inverse();

DOMPoint transformPoint(optional DOMPointInit point);
DOMPoint transformPoint(optional DOMPointInit point = {});
Float32Array toFloat32Array();
Float64Array toFloat64Array();
// stringifier;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMPoint.webidl
Expand Up @@ -14,7 +14,7 @@
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
interface DOMPoint : DOMPointReadOnly {
[NewObject] static DOMPoint fromPoint(optional DOMPointInit other = null);
[NewObject] static DOMPoint fromPoint(optional DOMPointInit other = {});

inherit attribute unrestricted double x;
inherit attribute unrestricted double y;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/DOMPointReadOnly.webidl
Expand Up @@ -14,7 +14,7 @@
optional unrestricted double z = 0, optional unrestricted double w = 1),
Exposed=(Window,Worker)]
interface DOMPointReadOnly {
[NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other = null);
[NewObject] static DOMPointReadOnly fromPoint(optional DOMPointInit other = {});

readonly attribute unrestricted double x;
readonly attribute unrestricted double y;
Expand Down
16 changes: 8 additions & 8 deletions components/script/dom/webidls/DOMQuad.webidl
Expand Up @@ -10,12 +10,12 @@
* related or neighboring rights to this work.
*/

[Constructor(optional DOMPointInit p1, optional DOMPointInit p2,
optional DOMPointInit p3, optional DOMPointInit p4),
[Constructor(optional DOMPointInit p1 = {}, optional DOMPointInit p2 = {},
optional DOMPointInit p3 = {}, optional DOMPointInit p4 = {}),
Exposed=(Window,Worker)]
interface DOMQuad {
[NewObject] static DOMQuad fromRect(optional DOMRectInit other);
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other);
[NewObject] static DOMQuad fromRect(optional DOMRectInit other = {});
[NewObject] static DOMQuad fromQuad(optional DOMQuadInit other = {});

[SameObject] readonly attribute DOMPoint p1;
[SameObject] readonly attribute DOMPoint p2;
Expand All @@ -25,8 +25,8 @@ interface DOMQuad {
};

dictionary DOMQuadInit {
DOMPointInit p1 = null;
DOMPointInit p2 = null;
DOMPointInit p3 = null;
DOMPointInit p4 = null;
DOMPointInit p1 = {};
DOMPointInit p2 = {};
DOMPointInit p3 = {};
DOMPointInit p4 = {};
};
4 changes: 2 additions & 2 deletions components/script/dom/webidls/Document.webidl
Expand Up @@ -33,9 +33,9 @@ interface Document : Node {
HTMLCollection getElementsByClassName(DOMString classNames);

[CEReactions, NewObject, Throws]
Element createElement(DOMString localName, optional ElementCreationOptions options);
Element createElement(DOMString localName, optional ElementCreationOptions options = {});
[CEReactions, NewObject, Throws]
Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options);
Element createElementNS(DOMString? namespace, DOMString qualifiedName, optional ElementCreationOptions options = {});
[NewObject]
DocumentFragment createDocumentFragment();
[NewObject]
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/webidls/Element.webidl
Expand Up @@ -91,12 +91,12 @@ partial interface Element {
[NewObject]
DOMRect getBoundingClientRect();

void scroll(optional ScrollToOptions options);
void scroll(optional ScrollToOptions options = {});
void scroll(unrestricted double x, unrestricted double y);

void scrollTo(optional ScrollToOptions options);
void scrollTo(optional ScrollToOptions options = {});
void scrollTo(unrestricted double x, unrestricted double y);
void scrollBy(optional ScrollToOptions options);
void scrollBy(optional ScrollToOptions options = {});
void scrollBy(unrestricted double x, unrestricted double y);
attribute unrestricted double scrollTop;
attribute unrestricted double scrollLeft;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ErrorEvent.webidl
Expand Up @@ -4,7 +4,7 @@

// https://html.spec.whatwg.org/multipage/#the-errorevent-interface

[Constructor(DOMString type, optional ErrorEventInit eventInitDict), Exposed=(Window,Worker)]
[Constructor(DOMString type, optional ErrorEventInit eventInitDict = {}), Exposed=(Window,Worker)]
interface ErrorEvent : Event {
readonly attribute DOMString message;
readonly attribute DOMString filename;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Event.webidl
Expand Up @@ -6,7 +6,7 @@
* https://dom.spec.whatwg.org/#event
*/

[Constructor(DOMString type, optional EventInit eventInitDict), Exposed=(Window,Worker)]
[Constructor(DOMString type, optional EventInit eventInitDict = {}), Exposed=(Window,Worker)]
interface Event {
[Pure]
readonly attribute DOMString type;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/EventSource.webidl
Expand Up @@ -6,7 +6,7 @@
* https://html.spec.whatwg.org/multipage/#eventsource
*/

[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict),
[Constructor(DOMString url, optional EventSourceInit eventSourceInitDict = {}),
Exposed=(Window,Worker)]
interface EventSource : EventTarget {
readonly attribute DOMString url;
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/EventTarget.webidl
Expand Up @@ -10,13 +10,13 @@ interface EventTarget {
void addEventListener(
DOMString type,
EventListener? callback,
optional (AddEventListenerOptions or boolean) options
optional (AddEventListenerOptions or boolean) options = {}
);

void removeEventListener(
DOMString type,
EventListener? callback,
optional (EventListenerOptions or boolean) options
optional (EventListenerOptions or boolean) options = {}
);

[Throws]
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ExtendableEvent.webidl
Expand Up @@ -5,7 +5,7 @@
// https://w3c.github.io/ServiceWorker/#extendable-event

[Constructor(DOMString type,
optional ExtendableEventInit eventInitDict),
optional ExtendableEventInit eventInitDict = {}),
Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled"]
interface ExtendableEvent : Event {
Expand Down
Expand Up @@ -4,7 +4,7 @@

// https://w3c.github.io/ServiceWorker/#extendablemessage-event-section

[Constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict),
[Constructor(DOMString type, optional ExtendableMessageEventInit eventInitDict = {}),
Exposed=ServiceWorker,
Pref="dom.serviceworker.enabled"]
interface ExtendableMessageEvent : ExtendableEvent {
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/Fetch.webidl
Expand Up @@ -7,5 +7,5 @@
[Exposed=(Window,Worker)]

partial interface WindowOrWorkerGlobalScope {
[NewObject] Promise<Response> fetch(RequestInfo input, optional RequestInit init);
[NewObject] Promise<Response> fetch(RequestInfo input, optional RequestInit init = {});
};
2 changes: 1 addition & 1 deletion components/script/dom/webidls/File.webidl
Expand Up @@ -6,7 +6,7 @@

[Constructor(sequence<BlobPart> fileBits,
DOMString fileName,
optional FilePropertyBag options),
optional FilePropertyBag options = {}),
Exposed=(Window,Worker)]
interface File : Blob {
readonly attribute DOMString name;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/FocusEvent.webidl
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// https://w3c.github.io/uievents/#interface-FocusEvent
[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict),
[Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict = {}),
Exposed=Window]
interface FocusEvent : UIEvent {
readonly attribute EventTarget? relatedTarget;
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/FormDataEvent.webidl
Expand Up @@ -4,7 +4,7 @@

// https://html.spec.whatwg.org/multipage/#the-formdataevent-interface
[Exposed=Window,
Constructor(DOMString type, optional FormDataEventInit eventInitDict)]
Constructor(DOMString type, optional FormDataEventInit eventInitDict = {})]
interface FormDataEvent : Event {
readonly attribute FormData formData;
};
Expand Down

0 comments on commit 0115127

Please sign in to comment.