diff options
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | components/script/Cargo.toml | 2 | ||||
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 43 | ||||
-rw-r--r-- | components/script/dom/testbinding.rs | 9 | ||||
-rw-r--r-- | components/script/dom/webidls/TestBinding.webidl | 3 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/MANIFEST.json | 10 | ||||
-rw-r--r-- | tests/wpt/mozilla/meta/mozilla/custom_auto_rooter.html.ini | 3 | ||||
-rw-r--r-- | tests/wpt/mozilla/tests/mozilla/custom_auto_rooter.html | 23 |
8 files changed, 91 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock index ecdaed45bc1..7b8ab7496c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1692,7 +1692,7 @@ dependencies = [ "cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "hashglobe 0.1.0", - "mozjs 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.10 (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.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1862,7 +1862,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "mozjs" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2586,7 +2586,7 @@ dependencies = [ "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.9 (registry+https://github.com/rust-lang/crates.io-index)", + "mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "msg 0.0.1", "net_traits 0.0.1", "nonzero 0.0.1", @@ -3896,7 +3896,7 @@ dependencies = [ "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.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c9935bada5ea5d70291f21cce7b1bbad507edea12590ebe9cfb6b665fb716480" +"checksum mozjs 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2cd8370617e9a151ed9e7b49f38092075d0ae80bdf9f1dcd807a60cc9c3b7151" "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.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f821e3799bc0fd16d9b861fb02fa7ee1b5fba29f45ad591dade105c48ca9a1a0" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 704d07f39f6..a1beb33e8f8 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -65,7 +65,7 @@ metrics = {path = "../metrics"} mitochondria = "1.1.2" mime = "0.2.1" mime_guess = "1.8.0" -mozjs = { version = "0.1.9", features = ["promises"]} +mozjs = { version = "0.1.10", features = ["promises"]} msg = {path = "../msg"} net_traits = {path = "../net_traits"} nonzero = {path = "../nonzero"} diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index a0b73b40985..6f0dd003e8d 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -562,6 +562,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, isDefinitelyObject=False, isMember=False, isArgument=False, + isAutoRooted=False, invalidEnumValueFatal=True, defaultValue=None, treatNullAs="Default", @@ -702,7 +703,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, if type.isSequence() or type.isRecord(): innerInfo = getJSToNativeConversionInfo(innerContainerType(type), descriptorProvider, - isMember=isMember) + isMember=isMember, + isAutoRooted=isAutoRooted) declType = wrapInNativeContainerType(type, innerInfo.declType) config = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs) @@ -1038,10 +1040,14 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, assert not isEnforceRange and not isClamp assert isMember != "Union" - if isMember == "Dictionary": + if isMember == "Dictionary" or isAutoRooted: # TODO: Need to properly root dictionaries # https://github.com/servo/servo/issues/6381 - declType = CGGeneric("Heap<JSVal>") + if isMember == "Dictionary": + declType = CGGeneric("Heap<JSVal>") + # AutoRooter can trace properly inner raw GC thing pointers + else: + declType = CGGeneric("JSVal") if defaultValue is None: default = None @@ -1238,6 +1244,7 @@ class CGArgumentConverter(CGThing): isEnforceRange=argument.enforceRange, isClamp=argument.clamp, isMember="Variadic" if argument.variadic else False, + isAutoRooted=type_needs_auto_root(argument.type), allowTreatNonObjectAsNull=argument.allowTreatNonCallableAsNull()) template = info.template default = info.default @@ -1260,8 +1267,15 @@ class CGArgumentConverter(CGThing): else: assert not default + arg = "arg%d" % index + self.converter = instantiateJSToNativeConversionTemplate( - template, replacementVariables, declType, "arg%d" % index) + template, replacementVariables, declType, arg) + + # The auto rooting is done only after the conversion is performed + if type_needs_auto_root(argument.type): + self.converter.append(CGGeneric("auto_root!(in(cx) let %s = %s);" % (arg, arg))) + else: assert argument.optional variadicConversion = { @@ -5698,6 +5712,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries 'js::panic::maybe_resume_unwind', 'js::panic::wrap_panic', 'js::rust::GCMethods', + 'js::rust::CustomAutoRooterGuard', 'js::rust::define_methods', 'js::rust::define_properties', 'js::rust::get_object_class', @@ -6421,9 +6436,24 @@ def type_needs_tracing(t): assert False, (t, type(t)) +def type_needs_auto_root(t): + """ + Certain IDL types, such as `sequence<any>` or `sequence<object>` need to be + traced and wrapped via (Custom)AutoRooter + """ + assert isinstance(t, IDLObject), (t, type(t)) + + if t.isType(): + if t.isSequence() and (t.inner.isAny() or t.inner.isObject()): + return True + + return False + + def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, variadic=False): info = getJSToNativeConversionInfo( - ty, descriptorProvider, isArgument=True) + ty, descriptorProvider, isArgument=True, + isAutoRooted=type_needs_auto_root(ty)) declType = info.declType if variadic: @@ -6437,6 +6467,9 @@ def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, var if ty.isDictionary() and not type_needs_tracing(ty): declType = CGWrapper(declType, pre="&") + if type_needs_auto_root(ty): + declType = CGTemplatedType("CustomAutoRooterGuard", declType) + return declType.define() diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs index 9e1d5cf7de5..6ffe2efefdd 100644 --- a/components/script/dom/testbinding.rs +++ b/components/script/dom/testbinding.rs @@ -38,6 +38,7 @@ use dom_struct::dom_struct; use js::jsapi::{HandleObject, HandleValue, Heap, JSContext, JSObject}; use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray}; use js::jsval::{JSVal, NullValue}; +use js::rust::CustomAutoRooterGuard; use script_traits::MsDuration; use servo_config::prefs::PREFS; use std::borrow::ToOwned; @@ -449,6 +450,14 @@ impl TestBindingMethods for TestBinding { fn PassCallbackFunction(&self, _: Rc<Function>) {} fn PassCallbackInterface(&self, _: Rc<EventListener>) {} fn PassSequence(&self, _: Vec<i32>) {} + #[allow(unsafe_code)] + unsafe fn PassAnySequence(&self, _: *mut JSContext, _: CustomAutoRooterGuard<Vec<JSVal>>) {} + #[allow(unsafe_code)] + unsafe fn AnySequencePassthrough(&self, _: *mut JSContext, seq: CustomAutoRooterGuard<Vec<JSVal>>) -> Vec<JSVal> { + (*seq).clone() + } + #[allow(unsafe_code)] + unsafe fn PassObjectSequence(&self, _: *mut JSContext, _: CustomAutoRooterGuard<Vec<*mut JSObject>>) {} fn PassStringSequence(&self, _: Vec<DOMString>) {} fn PassInterfaceSequence(&self, _: Vec<DomRoot<Blob>>) {} diff --git a/components/script/dom/webidls/TestBinding.webidl b/components/script/dom/webidls/TestBinding.webidl index 7deb4eff4ff..25292953d60 100644 --- a/components/script/dom/webidls/TestBinding.webidl +++ b/components/script/dom/webidls/TestBinding.webidl @@ -263,6 +263,9 @@ interface TestBinding { void passCallbackFunction(Function fun); void passCallbackInterface(EventListener listener); void passSequence(sequence<long> seq); + void passAnySequence(sequence<any> seq); + sequence<any> anySequencePassthrough(sequence<any> seq); + void passObjectSequence(sequence<object> seq); void passStringSequence(sequence<DOMString> seq); void passInterfaceSequence(sequence<Blob> seq); diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 5d183740117..f7be4ffe38d 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -32845,6 +32845,12 @@ {} ] ], + "mozilla/custom_auto_rooter.html": [ + [ + "/_mozilla/mozilla/custom_auto_rooter.html", + {} + ] + ], "mozilla/deep_serialization_succeeds.html": [ [ "/_mozilla/mozilla/deep_serialization_succeeds.html", @@ -66036,6 +66042,10 @@ "67d8cdd3e3a1656ba315fcbf6dae7236680bac16", "reftest" ], + "mozilla/custom_auto_rooter.html": [ + "3466095fb0846b848c948dd1596764fff456fa9b", + "testharness" + ], "mozilla/deep_serialization_succeeds.html": [ "cb3d201d577c17d19babf1f6c04ba882fa42048e", "testharness" diff --git a/tests/wpt/mozilla/meta/mozilla/custom_auto_rooter.html.ini b/tests/wpt/mozilla/meta/mozilla/custom_auto_rooter.html.ini new file mode 100644 index 00000000000..def641a83ba --- /dev/null +++ b/tests/wpt/mozilla/meta/mozilla/custom_auto_rooter.html.ini @@ -0,0 +1,3 @@ +[custom_auto_rooter.html] + type: testharness + prefs: [dom.testbinding.enabled:true] diff --git a/tests/wpt/mozilla/tests/mozilla/custom_auto_rooter.html b/tests/wpt/mozilla/tests/mozilla/custom_auto_rooter.html new file mode 100644 index 00000000000..3d6f04e85b2 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/custom_auto_rooter.html @@ -0,0 +1,23 @@ +<!doctype html> +<html> +<meta charset="utf-8"> +<title>Types using Custom Auto Rooter work correctly</title> +<head> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +</head> +<script> +test(function() { + var t = new TestBinding; + + var seq = [5, "str", { key: "val" }, undefined]; + assert_array_equals(seq, t.anySequencePassthrough(seq), "Returned simple array is the same"); + + var seq = new Array(null, {'inner': 1, 'a': 'as'}, {'inner': 2}, null, undefined); + assert_array_equals(seq, t.anySequencePassthrough(seq), "Returned array using new Array is the same"); + + var seq = new Array(null, {'inner': 1, 'a': 'as', 'toString': function() { seq = null; return Object.prototype.toString(this); }}, {'inner': 2}, null, undefined); + assert_array_equals(seq, t.anySequencePassthrough(seq), "Returned array with closure member is the same"); +}, "sequence<any> conversion did not lose any values"); +</script> +</html> |