servo: Merge #19180 - Fix binding generation for overloaded functions with optionals and de… (from ferjm:optional.overloaded.webidl); r=jdm
authorFernando Jiménez Moreno <ferjmoreno@gmail.com>
Sat, 11 Nov 2017 08:59:20 -0600
changeset 444669 a336d5f352e07c34dd33e6ac8522007d7d7b3447
parent 444668 75381304ee9a3c3c8787192ab3704db0a5be9f37
child 444670 1c459f5c05e8d13452ce5eeea3b191720a03ae2e
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs19180, 15395, 15468
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
servo: Merge #19180 - Fix binding generation for overloaded functions 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 https://github.com/servo/rust-mozjs/pull/379 Source-Repo: https://github.com/servo/servo Source-Revision: 9d055522d355b711c7837ba5997089ba8a7641ae
servo/Cargo.lock
servo/components/malloc_size_of/Cargo.toml
servo/components/script/Cargo.toml
servo/components/script/dom/bindings/codegen/CodegenRust.py
servo/components/script/dom/testbinding.rs
servo/components/script/dom/webidls/TestBinding.webidl
--- a/servo/Cargo.lock
+++ b/servo/Cargo.lock
@@ -1656,17 +1656,17 @@ dependencies = [
 [[package]]
 name = "malloc_size_of"
 version = "0.0.1"
 dependencies = [
  "app_units 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "cssparser 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.15.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "hashglobe 0.1.0",
- "mozjs 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mozjs 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "servo_arc 0.0.1",
  "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "string_cache 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "webrender_api 0.53.1 (git+https://github.com/servo/webrender)",
  "xml5ever 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -1806,17 +1806,17 @@ dependencies = [
 
 [[package]]
 name = "mitochondria"
 version = "1.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "mozjs"
-version = "0.1.7"
+version = "0.1.8"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cmake 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "mozjs_sys 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2531,17 +2531,17 @@ dependencies = [
  "libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "malloc_size_of 0.0.1",
  "malloc_size_of_derive 0.0.1",
  "metrics 0.0.1",
  "mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
- "mozjs 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
+ "mozjs 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "msg 0.0.1",
  "net_traits 0.0.1",
  "nonzero 0.0.1",
  "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
  "offscreen_gl_context 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "open 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "phf 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3789,17 +3789,17 @@ dependencies = [
 "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4"
 "checksum metadeps 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b122901b3a675fac8cecf68dcb2f0d3036193bc861d1ac0e1c337f7d5254c2"
 "checksum mime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "9d69889cdc6336ed56b174514ce876c4c3dc564cc23dd872e7bca589bb2a36c8"
 "checksum mime_guess 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76da6df85047af8c0edfa53f48eb1073012ce1cc95c8fedc0a374f659a89dd65"
 "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726"
 "checksum mio 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "9e965267d4d58496fc4f740e9861118367f13570cadf66316ed2c3f2f14d87c7"
 "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919"
 "checksum mitochondria 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9de3eca27871df31c33b807f834b94ef7d000956f57aa25c5aed9c5f0aae8f6f"
-"checksum mozjs 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a77c99a22091d3e6f7cd93caaf18bcb9ce5ff0a5d93c45aa73e443a447ab4296"
+"checksum mozjs 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "722aeeec7049d03494ef79190343c2dea89c743c2d66acfb4555aef69dd77061"
 "checksum mozjs_sys 0.50.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1e24df9f76502cd4459919098ec1ac3af75ce694ec5b8837aa91f69f2ad0eb"
 "checksum mp3-metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ab5f1d2693586420208d1200ce5a51cd44726f055b635176188137aff42c7de"
 "checksum mp4parse 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b81651f9ede53d59281b54c7eb51ae50a868ac4765dd3bdfbbc79ce3d8aca7a"
 "checksum multistr 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "90fb6e1b4f6ca2f2098a437e1c7f09c122da62bbf2bde45b3693defc1eb61e2d"
 "checksum net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bc01404e7568680f1259aa5729539f221cb1e6d047a0d9053cab4be8a73b5d67"
 "checksum nodrop 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0dbbadd3f4c98dea0bd3d9b4be4c0cdaf1ab57035cb2e41fce3983db5add7cc5"
 "checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
 "checksum num-integer 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "ef1a4bf6f9174aa5783a9b4cc892cacd11aebad6c69ad027a0b65c6ca5f8aa37"
--- a/servo/components/malloc_size_of/Cargo.toml
+++ b/servo/components/malloc_size_of/Cargo.toml
@@ -11,16 +11,16 @@ path = "lib.rs"
 [features]
 servo = ["mozjs", "string_cache", "url", "webrender_api", "xml5ever"]
 
 [dependencies]
 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"
 string_cache = { version = "0.6", optional = true }
 url = { version = "1.2", optional = true }
 webrender_api = { git = "https://github.com/servo/webrender", features = ["ipc"], optional = true }
 xml5ever = { version = "0.11", optional = true }
--- a/servo/components/script/Cargo.toml
+++ b/servo/components/script/Cargo.toml
@@ -46,27 +46,27 @@ euclid = "0.15"
 fnv = "1.0"
 gleam = "0.4"
 half = "1.0"
 html5ever = "0.21"
 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"
 log = "0.3.5"
 malloc_size_of = { path = "../malloc_size_of" }
 malloc_size_of_derive = { path = "../malloc_size_of_derive" }
 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"}
 num-traits = "0.1.32"
 offscreen_gl_context = { version = "0.12", features = ["serde"] }
 open = "1.1.1"
 parking_lot = "0.4"
 phf = "0.7.18"
--- a/servo/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/servo/components/script/dom/bindings/codegen/CodegenRust.py
@@ -478,17 +478,18 @@ class CGMethodCall(CGThing):
                 pass
             # Check for "any"
             elif pickFirstSignature(None,
                                     lambda s: s[1][distinguishingIndex].type.isAny()):
                 pass
             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")))
 
         overloadCGThings = []
         overloadCGThings.append(
             CGGeneric("let argcount = cmp::min(argc, %d);" %
                       maxArgCount))
@@ -5586,16 +5587,17 @@ def generate_imports(config, cgthings, d
     return CGImports(cgthings, descriptors, callbacks, dictionaries, enums, typedefs, [
         'js',
         'js::JSCLASS_GLOBAL_SLOT_COUNT',
         'js::JSCLASS_IS_DOMJSCLASS',
         'js::JSCLASS_IS_GLOBAL',
         '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',
         'js::jsapi::CurrentGlobalOrNull',
         'js::jsapi::FreeOp',
         'js::jsapi::GetPropertyKeys',
         'js::jsapi::GetWellKnownSymbol',
         'js::jsapi::Handle',
--- a/servo/components/script/dom/testbinding.rs
+++ b/servo/components/script/dom/testbinding.rs
@@ -596,16 +596,18 @@ impl TestBindingMethods for TestBinding 
     fn PassOptionalNullableUnsignedLongLongWithNonNullDefault(&self, _: Option<u64>) {}
     // fn PassOptionalNullableUnrestrictedFloatWithNonNullDefault(self, _: Option<f32>) {}
     // fn PassOptionalNullableFloatWithNonNullDefault(self, _: Option<Finite<f32>>) {}
     // fn PassOptionalNullableUnrestrictedDoubleWithNonNullDefault(self, _: Option<f64>) {}
     // fn PassOptionalNullableDoubleWithNonNullDefault(self, _: Option<Finite<f64>>) {}
     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>) {}
     fn PassVariadicByte(&self, _: Vec<i8>) {}
     fn PassVariadicOctet(&self, _: Vec<u8>) {}
     fn PassVariadicShort(&self, _: Vec<i16>) {}
     fn PassVariadicUnsignedShort(&self, _: Vec<u16>) {}
     fn PassVariadicLong(&self, _: Vec<i32>) {}
--- a/servo/components/script/dom/webidls/TestBinding.webidl
+++ b/servo/components/script/dom/webidls/TestBinding.webidl
@@ -404,16 +404,19 @@ interface TestBinding {
   // void passOptionalNullableFloatWithNonNullDefault(optional float? arg = 0.0);
   // void passOptionalNullableUnrestrictedDoubleWithNonNullDefault(optional unrestricted double? arg = 0.0);
   // void passOptionalNullableDoubleWithNonNullDefault(optional double? arg = 0.0);
   void passOptionalNullableStringWithNonNullDefault(optional DOMString? arg = "x");
   void passOptionalNullableUsvstringWithNonNullDefault(optional USVString? arg = "x");
   // 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);
   void passVariadicByte(byte... args);
   void passVariadicOctet(octet... args);
   void passVariadicShort(short... args);
   void passVariadicUnsignedShort(unsigned short... args);
   void passVariadicLong(long... args);