Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dictionaries in unions #11612

Closed
nox opened this issue Jun 4, 2016 · 4 comments
Closed

Support dictionaries in unions #11612

nox opened this issue Jun 4, 2016 · 4 comments

Comments

@nox
Copy link
Member

@nox nox commented Jun 4, 2016

We currently can't do (FooInit or boolean) where FooInit is a dictionary in a WebIDL interface.

@KiChjang
Copy link
Member

@KiChjang KiChjang commented Jun 4, 2016

Related to #10605.

@nox nox added the E-hard label Jun 7, 2016
@nox
Copy link
Member Author

@nox nox commented Jun 7, 2016

So the problem is that for a dictionary Foo, the generated Foo::new function do not let callers choose whether they want to report exceptions or not.

I think the FromJSValConvertible trait should be changed to return Result<T, Cow<str>>, where callers can use that string to raise a TypeError if needed.

@jdm
Copy link
Member

@jdm jdm commented Jan 19, 2017

With the following added to a WebIDL file:

dictionary EventListenerOptions {
  boolean capture = false;
};

void foo(optional (EventListenerOptions or boolean) options);

we get

TypeError: Can't handle EventListenerOptions (Wrapper) in unions yet

The following patch:

diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index f531937..6138abb 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -4028,6 +4028,9 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
     elif type.isEnum():
         name = type.inner.identifier.name
         typeName = name
+    elif type.isDictionary():
+        name = type.name
+        typeName = name
     elif type.isSequence() or type.isMozMap():
         name = type.name
         inner = getUnionTypeTemplateVars(innerContainerType(type), descriptorProvider)

makes this error appear instead:

TypeError: Can't handle dictionaries when failureCode is not None
@Ms2ger
Copy link
Contributor

@Ms2ger Ms2ger commented Jan 20, 2017

I'm having a look.

Ms2ger added a commit that referenced this issue Jan 20, 2017
Fixes #11612.
Ms2ger added a commit that referenced this issue Jan 20, 2017
Fixes #11612.
bors-servo added a commit that referenced this issue Jan 20, 2017
Support dictionaries in unions.

Fixes #11612.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15125)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.