Skip to content

Commit

Permalink
servo: Merge #19180 - Fix binding generation for overloaded functions…
Browse files Browse the repository at this point in the history
… with optionals and de… (from ferjm:optional.overloaded.webidl); r=jdm

…fault values

The generated bindings for an interface like this:

```webidl
void someFunction(Foo foo, optional long a = 0, optional long b = 1);
void someFunction(Bar bar, optional long a = 0);
```
are failing to build with an error like:

```bash
    error[E0425]: cannot find function `Throw` in this scope
         --> /Users/ferjm/dev/mozilla/servo/target/debug/build/script-7b1a12ddd08207e3/out/Bindings/TestBindingBinding.rs:15395:24
          |
    15395 |                 return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
          |                        ^^^^^ not found in this scope

    error[E0425]: cannot find value `NS_ERROR_XPC_BAD_CONVERT_JS` in this scope
         --> /Users/ferjm/dev/mozilla/servo/target/debug/build/script-7b1a12ddd08207e3/out/Bindings/TestBindingBinding.rs:15395:34
          |
    15395 |                 return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
          |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

    error[E0425]: cannot find function `Throw` in this scope
         --> /Users/ferjm/dev/mozilla/servo/target/debug/build/script-7b1a12ddd08207e3/out/Bindings/TestBindingBinding.rs:15468:24
          |
    15468 |                 return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
          |                        ^^^^^ not found in this scope

    error[E0425]: cannot find value `NS_ERROR_XPC_BAD_CONVERT_JS` in this scope
         --> /Users/ferjm/dev/mozilla/servo/target/debug/build/script-7b1a12ddd08207e3/out/Bindings/TestBindingBinding.rs:15468:34
          |
    15468 |                 return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);
          |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

    error: aborting due to 4 previous errors

    error: Could not compile `script`.
```
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] There are tests for these changes

** Note that this depends** on servo/rust-mozjs#379

Source-Repo: https://github.com/servo/servo
Source-Revision: 9d055522d355b711c7837ba5997089ba8a7641ae

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : f39f5160149998e40ae2a740706c4385b46f8415
  • Loading branch information
ferjm committed Nov 11, 2017
1 parent beaea27 commit e57da99
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions servo/Cargo.lock

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

2 changes: 1 addition & 1 deletion servo/components/malloc_size_of/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ app_units = "0.5.5"
cssparser = "0.22.0"
euclid = "0.15"
hashglobe = { path = "../hashglobe" }
mozjs = { version = "0.1.7", features = ["promises"], optional = true }
mozjs = { version = "0.1.8", features = ["promises"], optional = true }
servo_arc = { path = "../servo_arc" }
smallbitvec = "1.0.3"
smallvec = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion servo/components/script/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ hyper = "0.10"
hyper_serde = "0.7"
image = "0.16"
ipc-channel = "0.9"
mozjs = { version = "0.1.7", features = ["promises"]}
jstraceable_derive = {path = "../jstraceable_derive"}
lazy_static = "0.2"
libc = "0.2"
Expand All @@ -62,6 +61,7 @@ metrics = {path = "../metrics"}
mitochondria = "1.1.2"
mime = "0.2.1"
mime_guess = "1.8.0"
mozjs = { version = "0.1.8", features = ["promises"]}
msg = {path = "../msg"}
net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"}
Expand Down
4 changes: 3 additions & 1 deletion servo/components/script/dom/bindings/codegen/CodegenRust.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ def pickFirstSignature(condition, filterLambda):
else:
# Just throw; we have no idea what we're supposed to
# do with this.
caseBody.append(CGGeneric("return Throw(cx, NS_ERROR_XPC_BAD_CONVERT_JS);"))
caseBody.append(CGGeneric("throw_internal_error(cx, \"Could not convert JavaScript argument\");\n"
"return false;"))

argCountCases.append(CGCase(str(argCount),
CGList(caseBody, "\n")))
Expand Down Expand Up @@ -5591,6 +5592,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::JSCLASS_RESERVED_SLOTS_MASK',
'js::JS_CALLEE',
'js::error::throw_type_error',
'js::error::throw_internal_error',
'js::jsapi::AutoIdVector',
'js::jsapi::Call',
'js::jsapi::CallArgs',
Expand Down
2 changes: 2 additions & 0 deletions servo/components/script/dom/testbinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ impl TestBindingMethods for TestBinding {
fn PassOptionalNullableStringWithNonNullDefault(&self, _: Option<DOMString>) {}
fn PassOptionalNullableUsvstringWithNonNullDefault(&self, _: Option<USVString>) {}
// fn PassOptionalNullableEnumWithNonNullDefault(self, _: Option<TestEnum>) {}
fn PassOptionalOverloaded(&self, a: &TestBinding, _: u32, _: u32) -> DomRoot<TestBinding> { DomRoot::from_ref(a) }
fn PassOptionalOverloaded_(&self, _: &Blob, _: u32) { }

fn PassVariadicBoolean(&self, _: Vec<bool>) {}
fn PassVariadicBooleanAndDefault(&self, _: bool, _: Vec<bool>) {}
Expand Down
3 changes: 3 additions & 0 deletions servo/components/script/dom/webidls/TestBinding.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ interface TestBinding {
// void passOptionalNullableEnumWithNonNullDefault(optional TestEnum? arg = "foo");
// void passOptionalNullableUnionWithNonNullDefault(optional (HTMLElement or long)? arg = 7);
// void passOptionalNullableUnion2WithNonNullDefault(optional (Event or DOMString)? data = "foo");
TestBinding passOptionalOverloaded(TestBinding arg0, optional unsigned long arg1 = 0,
optional unsigned long arg2 = 0);
void passOptionalOverloaded(Blob arg0, optional unsigned long arg1 = 0);

void passVariadicBoolean(boolean... args);
void passVariadicBooleanAndDefault(optional boolean arg = true, boolean... args);
Expand Down

0 comments on commit e57da99

Please sign in to comment.