diff --git a/Cargo.lock b/Cargo.lock index 9945f74a439..b7fc348c28a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1620,7 +1620,7 @@ dependencies = [ "cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.17.2 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", - "mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "selectors 0.19.0", "servo_arc 0.1.1", "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1795,13 +1795,13 @@ dependencies = [ [[package]] name = "mozjs" -version = "0.1.11" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "mozjs_sys 0.50.1 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2462,7 +2462,7 @@ dependencies = [ "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)", "mozangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3844,7 +3844,7 @@ dependencies = [ "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 mozangle 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4d916e4f2d39a00eeeb082ceb7c63c741e7c9d4f7915945f9225ae5e3b284092" -"checksum mozjs 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "199f707066bf05b559ef6e46741c20e4f7bca8ae3a9c9d953d728dbb840f4eaa" +"checksum mozjs 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "23e86a4da33f9325da4ccc652506284e00ff20f06d63f721eaebeb804eaca62d" "checksum mozjs_sys 0.50.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e61a792a125b1364c5ec50255ed8343ce02dc56098f8868dd209d472c8de006a" "checksum mp3-metadata 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ab5f1d2693586420208d1200ce5a51cd44726f055b635176188137aff42c7de" "checksum mp4parse 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f821e3799bc0fd16d9b861fb02fa7ee1b5fba29f45ad591dade105c48ca9a1a0" diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index d2d090f8350..55e72086f12 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -1075,20 +1075,24 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, if type.isObject(): assert not isEnforceRange and not isClamp - # TODO: Need to root somehow - # https://github.com/servo/servo/issues/6382 + templateBody = "${val}.get().to_object()" default = "ptr::null_mut()" - templateBody = wrapObjectTemplate("${val}.get().to_object()", - default, - isDefinitelyObject, type, failureCode) - if isMember in ("Dictionary", "Union"): + # TODO: Do we need to do the same for dictionaries? + if isMember == "Union": + templateBody = "RootedTraceableBox::from_box(Heap::boxed(%s))" % templateBody + default = "RootedTraceableBox::new(Heap::default())" + declType = CGGeneric("RootedTraceableBox>") + elif isMember == "Dictionary": declType = CGGeneric("Heap<*mut JSObject>") else: # TODO: Need to root somehow # https://github.com/servo/servo/issues/6382 declType = CGGeneric("*mut JSObject") + templateBody = wrapObjectTemplate(templateBody, default, + isDefinitelyObject, type, failureCode) + return handleOptional(templateBody, declType, handleDefaultNull(default)) @@ -4291,11 +4295,13 @@ class CGUnionConversionStruct(CGThing): else: mozMapObject = None - hasObjectTypes = interfaceObject or arrayObject or dateObject or object or mozMapObject + hasObjectTypes = object or interfaceObject or arrayObject or dateObject or mozMapObject if hasObjectTypes: # "object" is not distinguishable from other types assert not object or not (interfaceObject or arrayObject or dateObject or callbackObject or mozMapObject) templateBody = CGList([], "\n") + if object: + templateBody.append(object) if interfaceObject: templateBody.append(interfaceObject) if arrayObject: @@ -4363,11 +4369,6 @@ class CGUnionConversionStruct(CGThing): returnType = "Result, ()>" % actualType jsConversion = templateVars["jsConversion"] - # Any code to convert to Object is unused, since we're already converting - # from an Object value. - if t.name == 'Object': - return CGGeneric('') - return CGWrapper( CGIndenter(jsConversion, 4), pre="unsafe fn TryConvertTo%s(cx: *mut JSContext, value: HandleValue) -> %s {\n" diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index 5153b70e72f..f0c704b0b0a 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -765,7 +765,12 @@ unsafe impl JSTraceable for RootedTraceableBox { impl RootedTraceableBox { /// DomRoot a JSTraceable thing for the life of this RootedTraceable pub fn new(traceable: T) -> RootedTraceableBox { - let traceable = Box::into_raw(Box::new(traceable)); + Self::from_box(Box::new(traceable)) + } + + /// Consumes a boxed JSTraceable and roots it for the life of this RootedTraceable. + pub fn from_box(boxed_traceable: Box) -> RootedTraceableBox { + let traceable = Box::into_raw(boxed_traceable); unsafe { RootedTraceableSet::add(traceable); } diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 2dd77427590..11bcbfc5bd7 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -293,6 +293,14 @@ impl TestBindingMethods for TestBinding { fn ReceiveInterfaceSequence(&self) -> Vec> { vec![Blob::new(&self.global(), BlobImpl::new_from_bytes(vec![]), "".to_owned())] } + #[allow(unsafe_code)] + unsafe fn ReceiveUnionIdentity( + &self, + _: *mut JSContext, + arg: UnionTypes::StringOrObject, + ) -> UnionTypes::StringOrObject { + arg + } fn ReceiveNullableBoolean(&self) -> Option { Some(false) } fn ReceiveNullableByte(&self) -> Option { Some(0) } diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 25292953d60..22c22f43dae 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -228,6 +228,8 @@ interface TestBinding { TestDictionary receiveTestDictionaryWithSuccessOnKeyword(); boolean dictMatchesPassedValues(TestDictionary arg); + (DOMString or object) receiveUnionIdentity((DOMString or object) arg); + void passBoolean(boolean arg); void passByte(byte arg); void passOctet(octet arg); diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index c8778734319..c0d45b5f2f7 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -31972,6 +31972,12 @@ {} ] ], + "mozilla/codegen_unions.html": [ + [ + "/_mozilla/mozilla/codegen_unions.html", + {} + ] + ], "mozilla/collections.html": [ [ "/_mozilla/mozilla/collections.html", @@ -64751,6 +64757,10 @@ "5183977a0d29ba4d74d049c9391090e3c27264a8", "testharness" ], + "mozilla/codegen_unions.html": [ + "7f772fffb75acc92f9c949a482d387b3ed18d0ed", + "testharness" + ], "mozilla/collections.html": [ "d0bebe808ebb45b6c853f4b88e1a6ebbf9b91345", "testharness" diff --git a/tests/wpt/mozilla/meta/mozilla/codegen_unions.html.ini b/tests/wpt/mozilla/meta/mozilla/codegen_unions.html.ini new file mode 100644 index 00000000000..6a8744c375d --- /dev/null +++ b/tests/wpt/mozilla/meta/mozilla/codegen_unions.html.ini @@ -0,0 +1,3 @@ +[codegen_unions.html] + type: testharness + prefs: [dom.testbinding.enabled:true] diff --git a/tests/wpt/mozilla/tests/mozilla/codegen_unions.html b/tests/wpt/mozilla/tests/mozilla/codegen_unions.html new file mode 100644 index 00000000000..1fff0e01c89 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/codegen_unions.html @@ -0,0 +1,21 @@ + + + +WebIDL conversions are performed correctly and don't lose values + + + + + +