Closed Bug 949501 Opened 11 years ago Closed 11 years ago

Fix support for nullable unions in sequences and dictionaries

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla29

People

(Reporter: bzbarsky, Assigned: bzbarsky)

References

Details

Attachments

(1 file)

This got missed in bug 767926.

Sequences and dictionaries assert that their member types have no holders.  Which is fine, but nullable unions were in fact producing a (unusable) holder.

Patch coming up.
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
Comment on attachment 8346609 [details] [diff] [review]
Make nullable unions that are isMember stop claiming to have a holder.

Review of attachment 8346609 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/bindings/Codegen.py
@@ +3320,5 @@
>                  holderArgs = "${declName}.SetValue()"
> +            if holderType is not None:
> +                holderType = CGTemplatedType("Maybe", holderType)
> +                constructHolder = CGGeneric("${holderName}.construct(%s);" % holderArgs)
> +            else:

I think this is getting a little complicated.  holderType is not None only when not isMember, so maybe this could be

if isMember:
  holderType = CGTempaltedType("Maybe", CGGeneric(argumentTypeName)) and set it to CGGeneric(argumentTypeName) in the else and to None otherwise?  

It's probably a little longer but maybe easier to reason about.
Attachment #8346609 - Flags: review?(dzbarsky) → review+
I'm not sure I follow.  We have three cases here:

1)  not isMember, nullable: holderType should be a "Maybe"
2)  not isMember, non-nullable: holderType should be argumentTypeName
3)  isMember: holderType should be None

which is fine, but case 1 has additional complexity, because the constructHolder depends on isOptional.

So I could basically structure this like so:

  if nullable:
    # do the optional bits
    if isMember:
      holderType = None
    else:
      holderType = CGTemplatedType("Maybe", CGGeneric(argumentTypeName))
  else:
    if isMember:
      holderType = None
    else:
      holderType = CGGeneric(argumentTypeName)

Is that what you're suggesting?  Or something else?
Flags: needinfo?(dzbarsky)
(In reply to Boris Zbarsky [:bz] (Vacation Dec 19 to Jan 1) from comment #3)
> I'm not sure I follow.  We have three cases here:
> 
> 1)  not isMember, nullable: holderType should be a "Maybe"
> 2)  not isMember, non-nullable: holderType should be argumentTypeName
> 3)  isMember: holderType should be None
> 
> which is fine, but case 1 has additional complexity, because the
> constructHolder depends on isOptional.
> 
> So I could basically structure this like so:
> 
>   if nullable:
>     # do the optional bits
>     if isMember:
>       holderType = None
>     else:
>       holderType = CGTemplatedType("Maybe", CGGeneric(argumentTypeName))
>   else:
>     if isMember:
>       holderType = None
>     else:
>       holderType = CGGeneric(argumentTypeName)
> 
> Is that what you're suggesting?  Or something else?

How about something like so:

if isMember:
  holderType = None
else:
  holderType = CGGeneric(argumentTypeName)
  if nullable:
    holderType = CGTemplatedType("Maybe", holderType)

and then initialize the rest of the holder and decl stuff after that?
Flags: needinfo?(dzbarsky)
With that change, https://hg.mozilla.org/integration/mozilla-inbound/rev/745ca55d396a
Flags: in-testsuite+
Target Milestone: --- → mozilla29
https://hg.mozilla.org/mozilla-central/rev/745ca55d396a
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Working on bug 949456 I still see errors:

MessageEventBinding.cpp:170:37: error: ‘class mozilla::dom::Optional<mozilla::dom::Nullable<mozilla::dom::OwningWindowProxyOrMessagePort> >’ has no member named ‘SetValue’
MessageEventBinding.cpp:171:37: error: ‘class mozilla::dom::Optional<mozilla::dom::Nullable<mozilla::dom::OwningWindowProxyOrMessagePort> >’ has no member named ‘SetValue’
MessageEventBinding.cpp:308:105: error: invalid initialization of reference of type ‘const mozilla::dom::Optional<mozilla::dom::Nullable<mozilla::dom::OwningWindowProxyOrMessagePort> >&’ from expression of type ‘const mozilla::dom::Nullable<mozilla::dom::OwningWindowProxyOrMessagePort>’
MessageEventBinding.cpp:309:24: error: ‘const class mozilla::dom::Optional<mozilla::dom::Nullable<mozilla::dom::OwningWindowProxyOrMessagePort> >’ has no member named ‘IsNull’
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Hmm.  That's actually a slightly separate issue which only affects dictionary member unions without default values, which I missed because the tests I added all used things with default values by accident.  I filed bug 952073 to deal with that.
Status: REOPENED → RESOLVED
Closed: 11 years ago11 years ago
Resolution: --- → FIXED
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: