aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Matuszewski <Xanewok@gmail.com>2018-03-16 15:54:36 +0100
committerIgor Matuszewski <Xanewok@gmail.com>2018-03-16 16:53:38 +0100
commit64dc0c4b9eeba6f5c56a917a0d32125df9248ed2 (patch)
treef435c0934e3f32c4dc4edcfce27d94fe2f92d086
parent760e0a5b5792fb3c8967aee53cc41e1e25adf07d (diff)
downloadservo-64dc0c4b9eeba6f5c56a917a0d32125df9248ed2.tar.gz
servo-64dc0c4b9eeba6f5c56a917a0d32125df9248ed2.zip
Root `any` members in dictionaries
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py23
-rw-r--r--components/script/dom/bindings/conversions.rs21
-rw-r--r--components/script/dom/bindings/iterable.rs10
-rw-r--r--components/script/dom/testbinding.rs4
4 files changed, 39 insertions, 19 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 916c8770d34..24054de8e95 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -1084,13 +1084,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
assert isMember != "Union"
if isMember == "Dictionary" or isAutoRooted:
- # TODO: Need to properly root dictionaries
- # https://github.com/servo/servo/issues/6381
- if isMember == "Dictionary":
- declType = CGGeneric("Heap<JSVal>")
- # AutoRooter can trace properly inner raw GC thing pointers
- else:
- declType = CGGeneric("JSVal")
+ templateBody = "${val}.get()"
if defaultValue is None:
default = None
@@ -1100,7 +1094,17 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
default = "UndefinedValue()"
else:
raise TypeError("Can't handle non-null, non-undefined default value here")
- return handleOptional("${val}.get()", declType, default)
+
+ if isMember == "Dictionary":
+ templateBody = "RootedTraceableBox::from_box(Heap::boxed(%s))" % templateBody
+ if default is not None:
+ default = "RootedTraceableBox::from_box(Heap::boxed(%s))" % default
+ declType = CGGeneric("RootedTraceableBox<Heap<JSVal>>")
+ # AutoRooter can trace properly inner raw GC thing pointers
+ else:
+ declType = CGGeneric("JSVal")
+
+ return handleOptional(templateBody, declType, default)
declType = CGGeneric("HandleValue")
@@ -6165,9 +6169,6 @@ class CGDictionary(CGThing):
conversion = self.getMemberConversion(memberInfo, member.type)
if isInitial:
return CGGeneric("%s: %s,\n" % (name, conversion.define()))
- # TODO: Root Heap<JSVal> using RootedTraceableBox
- if member.type.isAny():
- return CGGeneric("dictionary.%s.set(%s);\n" % (name, conversion.define()))
return CGGeneric("dictionary.%s = %s;\n" % (name, conversion.define()))
def varInsert(varName, dictionaryName):
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index e40a1d7092b..3824ed33183 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -48,7 +48,7 @@ use js::error::throw_type_error;
use js::glue::{GetProxyPrivate, IsWrapper};
use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
-use js::jsapi::{HandleId, HandleObject, HandleValue, JSContext, JSObject, JSString};
+use js::jsapi::{HandleId, HandleObject, HandleValue, Heap, JSContext, JSObject, JSString};
use js::jsapi::{JS_GetLatin1StringCharsAndLength, JS_GetProperty, JS_GetReservedSlot};
use js::jsapi::{JS_GetTwoByteStringCharsAndLength, JS_IsArrayObject, JS_IsExceptionPending};
use js::jsapi::{JS_NewStringCopyN, JS_StringHasLatin1Chars, MutableHandleValue};
@@ -125,6 +125,25 @@ impl<T: ToJSValConvertible + JSTraceable> ToJSValConvertible for RootedTraceable
}
}
+impl<T> FromJSValConvertible for RootedTraceableBox<Heap<T>>
+ where
+ T: FromJSValConvertible + js::rust::GCMethods + Copy,
+ Heap<T>: JSTraceable + Default
+{
+ type Config = T::Config;
+
+ unsafe fn from_jsval(cx: *mut JSContext,
+ value: HandleValue,
+ config: Self::Config)
+ -> Result<ConversionResult<Self>, ()> {
+ T::from_jsval(cx, value, config).map(|result| match result {
+ ConversionResult::Success(inner) =>
+ ConversionResult::Success(RootedTraceableBox::from_box(Heap::boxed(inner))),
+ ConversionResult::Failure(msg) => ConversionResult::Failure(msg),
+ })
+ }
+}
+
/// Convert `id` to a `DOMString`. Returns `None` if `id` is not a string or
/// integer.
///
diff --git a/components/script/dom/bindings/iterable.rs b/components/script/dom/bindings/iterable.rs
index 15fbe7175cb..60331f6608e 100644
--- a/components/script/dom/bindings/iterable.rs
+++ b/components/script/dom/bindings/iterable.rs
@@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::IterableIteratorBinding::IterableKeyOrValu
use dom::bindings::error::Fallible;
use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::root::{Dom, DomRoot};
-use dom::bindings::trace::JSTraceable;
+use dom::bindings::trace::{JSTraceable, RootedTraceableBox};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use js::conversions::ToJSValConvertible;
@@ -131,10 +131,10 @@ fn key_and_value_return(cx: *mut JSContext,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
dict.done = false;
- let values = vec![Heap::default(), Heap::default()];
- values[0].set(key.get());
- values[1].set(value.get());
- dict.value = Some(values);
+ dict.value = Some(vec![key, value]
+ .into_iter()
+ .map(|handle| RootedTraceableBox::from_box(Heap::boxed(handle.get())))
+ .collect());
rooted!(in(cx) let mut dict_value = UndefinedValue());
unsafe {
dict.to_jsval(cx, dict_value.handle_mut());
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index d450c282885..a5bb29a7e76 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -348,12 +348,12 @@ impl TestBindingMethods for TestBinding {
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> RootedTraceableBox<TestDictionary> {
RootedTraceableBox::new(TestDictionary {
- anyValue: Heap::default(),
+ anyValue: RootedTraceableBox::new(Heap::default()),
booleanValue: None,
byteValue: None,
dict: RootedTraceableBox::new(TestDictionaryDefaults {
UnrestrictedDoubleValue: 0.0,
- anyValue: Heap::default(),
+ anyValue: RootedTraceableBox::new(Heap::default()),
booleanValue: false,
bytestringValue: ByteString::new(vec![]),
byteValue: 0,