WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
214160
[Bindings] Add default value support for union types in dictionary members
https://bugs.webkit.org/show_bug.cgi?id=214160
Summary
[Bindings] Add default value support for union types in dictionary members
Chris Dumez
Reported
2020-07-09 13:55:11 PDT
Add default value support for union types in dictionary members. This is needed for the WebAudio Specification: -
https://www.w3.org/TR/webaudio/#AudioContextOptions
(AudioContextOptions.latencyHint)
Attachments
Patch
(9.49 KB, patch)
2020-07-09 14:05 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(11.48 KB, patch)
2020-07-09 15:04 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(11.48 KB, patch)
2020-07-09 15:06 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2020-07-09 14:05:32 PDT
Created
attachment 403916
[details]
Patch
Sam Weinig
Comment 2
2020-07-09 14:13:07 PDT
Comment on
attachment 403916
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=403916&action=review
> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2214 > + # In case of union types, assume the type of the default value has same type as first type in the union. > + $type = (GetFlattenedMemberTypes($type))[0] if $type->isUnion and !($defaultValue eq "null" && $type->isNullable);
Is this a WebIDL requirement?
Chris Dumez
Comment 3
2020-07-09 14:14:51 PDT
(In reply to Sam Weinig from
comment #2
)
> Comment on
attachment 403916
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=403916&action=review
> > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2214 > > + # In case of union types, assume the type of the default value has same type as first type in the union. > > + $type = (GetFlattenedMemberTypes($type))[0] if $type->isUnion and !($defaultValue eq "null" && $type->isNullable); > > Is this a WebIDL requirement?
Good question. I don't think so but I'll check the spec right now. I did this because trying to do better would likely be a decent amount more code and this unblocks our intern working on Web Audio.
Chris Dumez
Comment 4
2020-07-09 14:21:07 PDT
(In reply to Chris Dumez from
comment #3
)
> (In reply to Sam Weinig from
comment #2
) > > Comment on
attachment 403916
[details]
> > Patch > > > > View in context: > >
https://bugs.webkit.org/attachment.cgi?id=403916&action=review
> > > > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2214 > > > + # In case of union types, assume the type of the default value has same type as first type in the union. > > > + $type = (GetFlattenedMemberTypes($type))[0] if $type->isUnion and !($defaultValue eq "null" && $type->isNullable); > > > > Is this a WebIDL requirement? > > Good question. I don't think so but I'll check the spec right now. I did > this because trying to do better would likely be a decent amount more code > and this unblocks our intern working on Web Audio.
I don't see any such restriction in the Web IDL specification. This is a simplification on my part so that we can generate the correct code with minor or no IDL changes.
Sam Weinig
Comment 5
2020-07-09 14:32:28 PDT
(In reply to Chris Dumez from
comment #4
)
> (In reply to Chris Dumez from
comment #3
) > > (In reply to Sam Weinig from
comment #2
) > > > Comment on
attachment 403916
[details]
> > > Patch > > > > > > View in context: > > >
https://bugs.webkit.org/attachment.cgi?id=403916&action=review
> > > > > > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2214 > > > > + # In case of union types, assume the type of the default value has same type as first type in the union. > > > > + $type = (GetFlattenedMemberTypes($type))[0] if $type->isUnion and !($defaultValue eq "null" && $type->isNullable); > > > > > > Is this a WebIDL requirement? > > > > Good question. I don't think so but I'll check the spec right now. I did > > this because trying to do better would likely be a decent amount more code > > and this unblocks our intern working on Web Audio. > > I don't see any such restriction in the Web IDL specification. This is a > simplification on my part so that we can generate the correct code with > minor or no IDL changes.
Seems like this will lead to confusing error cases if someone doesn't know about this restriction. What do you see as the complexity of getting this fully supported?
Chris Dumez
Comment 6
2020-07-09 14:38:50 PDT
(In reply to Sam Weinig from
comment #5
)
> (In reply to Chris Dumez from
comment #4
) > > (In reply to Chris Dumez from
comment #3
) > > > (In reply to Sam Weinig from
comment #2
) > > > > Comment on
attachment 403916
[details]
> > > > Patch > > > > > > > > View in context: > > > >
https://bugs.webkit.org/attachment.cgi?id=403916&action=review
> > > > > > > > > Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2214 > > > > > + # In case of union types, assume the type of the default value has same type as first type in the union. > > > > > + $type = (GetFlattenedMemberTypes($type))[0] if $type->isUnion and !($defaultValue eq "null" && $type->isNullable); > > > > > > > > Is this a WebIDL requirement? > > > > > > Good question. I don't think so but I'll check the spec right now. I did > > > this because trying to do better would likely be a decent amount more code > > > and this unblocks our intern working on Web Audio. > > > > I don't see any such restriction in the Web IDL specification. This is a > > simplification on my part so that we can generate the correct code with > > minor or no IDL changes. > > Seems like this will lead to confusing error cases if someone doesn't know > about this restriction.
But currently it does not work already. So my opinion is that this was a step in the right direction, even though definitely not perfect.
> What do you see as the complexity of getting this > fully supported?
I honestly have no idea how do map a particular default value to a given type in the union. I guess we could implementation some kind of heuristic like: - If it is quoted, then it is either a DOMString or enum - If it is false/true, then it is a boolean - If it is a number, then it is one of the IDL number types - ... Seems complex for such an edge case and would likely still not be perfect.
Chris Dumez
Comment 7
2020-07-09 14:44:08 PDT
Comment on
attachment 403916
[details]
Patch Let me try and come up with something slightly better.
Sam Weinig
Comment 8
2020-07-09 14:55:56 PDT
(In reply to Chris Dumez from
comment #7
)
> Comment on
attachment 403916
[details]
> Patch > > Let me try and come up with something slightly better.
These seem like the relevant sections:
https://heycam.github.io/webidl/#dfn-optional-argument-default-value
https://heycam.github.io/webidl/#dfn-constant
I think it should be a pretty small mapping as the grammar only allows the following for default values: ConstValue :: BooleanLiteral FloatLiteral integer DefaultValue :: ConstValue string [ ] { } null string -> DOMString, ByteString, USVString, enum BooleanLiteral -> boolean integer -> any of the ints FloatLiteral -> any of the floats [] -> " sequence type, a nullable type whose inner type is a sequence type or a union type or nullable union type that has a sequence type in its flattened member types" {} -> " dictionary type, or a union type that has a dictionary type in its flattened member types." And bail if it's ambiguous.
Chris Dumez
Comment 9
2020-07-09 15:04:39 PDT
Created
attachment 403921
[details]
Patch
Chris Dumez
Comment 10
2020-07-09 15:06:45 PDT
Created
attachment 403922
[details]
Patch
Chris Dumez
Comment 11
2020-07-09 15:16:43 PDT
Comment on
attachment 403922
[details]
Patch Ok. Hopefully less controversial now.
Sam Weinig
Comment 12
2020-07-09 15:25:04 PDT
Comment on
attachment 403922
[details]
Patch Thank you :)
EWS
Comment 13
2020-07-09 15:41:26 PDT
Committed
r264201
: <
https://trac.webkit.org/changeset/264201
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 403922
[details]
.
Radar WebKit Bug Importer
Comment 14
2020-07-09 15:42:14 PDT
<
rdar://problem/65295454
>
Darin Adler
Comment 15
2020-07-10 12:23:09 PDT
Comment on
attachment 403922
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=403922&action=review
> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2227 > return "nullptr" if $codeGenerator->IsWrapperType($type) || $codeGenerator->IsBufferSourceType($type); > - return "String()" if $codeGenerator->IsStringType($type); > + if ($codeGenerator->IsStringType($type)) { > + my $useAtomString = $type->extendedAttributes->{AtomString}; > + return $useAtomString ? "nullAtom()" : "String()"; > + } > return "WTF::nullopt";
Can we just use "{ }" for all of these?
> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2251 > + return $useAtomString ? "emptyAtom()" : "emptyString()";
Why not always use emptyAtom()?
Chris Dumez
Comment 16
2020-07-10 12:39:25 PDT
Comment on
attachment 403922
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=403922&action=review
>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2251 >> + return $useAtomString ? "emptyAtom()" : "emptyString()"; > > Why not always use emptyAtom()?
It is used in ternaries: /Volumes/Work/WebKit/OpenSource/WebKitBuild/Release/DerivedSources/WebCore/JSHTMLMediaElement.cpp:1764:50: error: conditional expression is ambiguous; 'const WTF::AtomString' can be converted to 'typename Converter<IDLDOMString>::ReturnType' (aka 'WTF::String') and vice versa auto label = argument1.value().isUndefined() ? emptyAtom() : convert<IDLDOMString>(*lexicalGlobalObject, argument1.value());
Chris Dumez
Comment 17
2020-07-10 12:40:15 PDT
Comment on
attachment 403922
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=403922&action=review
>> Source/WebCore/bindings/scripts/CodeGeneratorJS.pm:2227 >> return "WTF::nullopt"; > > Can we just use "{ }" for all of these?
It is used in ternaries: In file included from /Volumes/Work/WebKit/OpenSource/WebKitBuild/Release/DerivedSources/WebCore/unified-sources/UnifiedSource5.cpp:13: /Volumes/Work/WebKit/OpenSource/WebKitBuild/Release/DerivedSources/WebCore/JSDOMImplementation.cpp:259:52: error: initializer list cannot be used on the right hand side of operator '?' auto title = argument0.value().isUndefined() ? { } : convert<IDLDOMString>(*lexicalGlobalObject, argument0.value());
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug