Root sequence<{any,object}> IDL arguments using CustomAutoRooter

Also pulls in mozjs 0.1.10 to support the change.
This commit is contained in:
Igor Matuszewski 2017-12-24 20:44:41 +01:00
parent dfd8e85338
commit a01d1eabef
8 changed files with 91 additions and 10 deletions

8
Cargo.lock generated
View file

@ -1692,7 +1692,7 @@ dependencies = [
"cssparser 0.23.2 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "euclid 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashglobe 0.1.0", "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", "servo_arc 0.0.1",
"smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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]] [[package]]
name = "mozjs" name = "mozjs"
version = "0.1.9" version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "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 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)", "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)", "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", "msg 0.0.1",
"net_traits 0.0.1", "net_traits 0.0.1",
"nonzero 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 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 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 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 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 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" "checksum mp4parse 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f821e3799bc0fd16d9b861fb02fa7ee1b5fba29f45ad591dade105c48ca9a1a0"

View file

@ -65,7 +65,7 @@ metrics = {path = "../metrics"}
mitochondria = "1.1.2" mitochondria = "1.1.2"
mime = "0.2.1" mime = "0.2.1"
mime_guess = "1.8.0" mime_guess = "1.8.0"
mozjs = { version = "0.1.9", features = ["promises"]} mozjs = { version = "0.1.10", features = ["promises"]}
msg = {path = "../msg"} msg = {path = "../msg"}
net_traits = {path = "../net_traits"} net_traits = {path = "../net_traits"}
nonzero = {path = "../nonzero"} nonzero = {path = "../nonzero"}

View file

@ -562,6 +562,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
isDefinitelyObject=False, isDefinitelyObject=False,
isMember=False, isMember=False,
isArgument=False, isArgument=False,
isAutoRooted=False,
invalidEnumValueFatal=True, invalidEnumValueFatal=True,
defaultValue=None, defaultValue=None,
treatNullAs="Default", treatNullAs="Default",
@ -702,7 +703,8 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isSequence() or type.isRecord(): if type.isSequence() or type.isRecord():
innerInfo = getJSToNativeConversionInfo(innerContainerType(type), innerInfo = getJSToNativeConversionInfo(innerContainerType(type),
descriptorProvider, descriptorProvider,
isMember=isMember) isMember=isMember,
isAutoRooted=isAutoRooted)
declType = wrapInNativeContainerType(type, innerInfo.declType) declType = wrapInNativeContainerType(type, innerInfo.declType)
config = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs) config = getConversionConfigForType(type, isEnforceRange, isClamp, treatNullAs)
@ -1038,10 +1040,14 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
assert not isEnforceRange and not isClamp assert not isEnforceRange and not isClamp
assert isMember != "Union" assert isMember != "Union"
if isMember == "Dictionary": if isMember == "Dictionary" or isAutoRooted:
# TODO: Need to properly root dictionaries # TODO: Need to properly root dictionaries
# https://github.com/servo/servo/issues/6381 # 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: if defaultValue is None:
default = None default = None
@ -1238,6 +1244,7 @@ class CGArgumentConverter(CGThing):
isEnforceRange=argument.enforceRange, isEnforceRange=argument.enforceRange,
isClamp=argument.clamp, isClamp=argument.clamp,
isMember="Variadic" if argument.variadic else False, isMember="Variadic" if argument.variadic else False,
isAutoRooted=type_needs_auto_root(argument.type),
allowTreatNonObjectAsNull=argument.allowTreatNonCallableAsNull()) allowTreatNonObjectAsNull=argument.allowTreatNonCallableAsNull())
template = info.template template = info.template
default = info.default default = info.default
@ -1260,8 +1267,15 @@ class CGArgumentConverter(CGThing):
else: else:
assert not default assert not default
arg = "arg%d" % index
self.converter = instantiateJSToNativeConversionTemplate( 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: else:
assert argument.optional assert argument.optional
variadicConversion = { variadicConversion = {
@ -5698,6 +5712,7 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
'js::panic::maybe_resume_unwind', 'js::panic::maybe_resume_unwind',
'js::panic::wrap_panic', 'js::panic::wrap_panic',
'js::rust::GCMethods', 'js::rust::GCMethods',
'js::rust::CustomAutoRooterGuard',
'js::rust::define_methods', 'js::rust::define_methods',
'js::rust::define_properties', 'js::rust::define_properties',
'js::rust::get_object_class', 'js::rust::get_object_class',
@ -6421,9 +6436,24 @@ def type_needs_tracing(t):
assert False, (t, type(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): def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, variadic=False):
info = getJSToNativeConversionInfo( info = getJSToNativeConversionInfo(
ty, descriptorProvider, isArgument=True) ty, descriptorProvider, isArgument=True,
isAutoRooted=type_needs_auto_root(ty))
declType = info.declType declType = info.declType
if variadic: 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): if ty.isDictionary() and not type_needs_tracing(ty):
declType = CGWrapper(declType, pre="&") declType = CGWrapper(declType, pre="&")
if type_needs_auto_root(ty):
declType = CGTemplatedType("CustomAutoRooterGuard", declType)
return declType.define() return declType.define()

View file

@ -38,6 +38,7 @@ use dom_struct::dom_struct;
use js::jsapi::{HandleObject, HandleValue, Heap, JSContext, JSObject}; use js::jsapi::{HandleObject, HandleValue, Heap, JSContext, JSObject};
use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray}; use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray};
use js::jsval::{JSVal, NullValue}; use js::jsval::{JSVal, NullValue};
use js::rust::CustomAutoRooterGuard;
use script_traits::MsDuration; use script_traits::MsDuration;
use servo_config::prefs::PREFS; use servo_config::prefs::PREFS;
use std::borrow::ToOwned; use std::borrow::ToOwned;
@ -449,6 +450,14 @@ impl TestBindingMethods for TestBinding {
fn PassCallbackFunction(&self, _: Rc<Function>) {} fn PassCallbackFunction(&self, _: Rc<Function>) {}
fn PassCallbackInterface(&self, _: Rc<EventListener>) {} fn PassCallbackInterface(&self, _: Rc<EventListener>) {}
fn PassSequence(&self, _: Vec<i32>) {} 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 PassStringSequence(&self, _: Vec<DOMString>) {}
fn PassInterfaceSequence(&self, _: Vec<DomRoot<Blob>>) {} fn PassInterfaceSequence(&self, _: Vec<DomRoot<Blob>>) {}

View file

@ -263,6 +263,9 @@ interface TestBinding {
void passCallbackFunction(Function fun); void passCallbackFunction(Function fun);
void passCallbackInterface(EventListener listener); void passCallbackInterface(EventListener listener);
void passSequence(sequence<long> seq); 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 passStringSequence(sequence<DOMString> seq);
void passInterfaceSequence(sequence<Blob> seq); void passInterfaceSequence(sequence<Blob> seq);

View file

@ -32845,6 +32845,12 @@
{} {}
] ]
], ],
"mozilla/custom_auto_rooter.html": [
[
"/_mozilla/mozilla/custom_auto_rooter.html",
{}
]
],
"mozilla/deep_serialization_succeeds.html": [ "mozilla/deep_serialization_succeeds.html": [
[ [
"/_mozilla/mozilla/deep_serialization_succeeds.html", "/_mozilla/mozilla/deep_serialization_succeeds.html",
@ -66036,6 +66042,10 @@
"67d8cdd3e3a1656ba315fcbf6dae7236680bac16", "67d8cdd3e3a1656ba315fcbf6dae7236680bac16",
"reftest" "reftest"
], ],
"mozilla/custom_auto_rooter.html": [
"3466095fb0846b848c948dd1596764fff456fa9b",
"testharness"
],
"mozilla/deep_serialization_succeeds.html": [ "mozilla/deep_serialization_succeeds.html": [
"cb3d201d577c17d19babf1f6c04ba882fa42048e", "cb3d201d577c17d19babf1f6c04ba882fa42048e",
"testharness" "testharness"

View file

@ -0,0 +1,3 @@
[custom_auto_rooter.html]
type: testharness
prefs: [dom.testbinding.enabled:true]

View file

@ -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>