Skip to content
Permalink
Browse files

Use Heap for dictionary and union members.

  • Loading branch information
Ms2ger committed Feb 16, 2017
1 parent 5eaa19b commit 8ce9ca624367c8e5737b8673548b230b69f4558b
@@ -1031,21 +1031,22 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,

if type.isAny():
assert not isEnforceRange and not isClamp
assert isMember != "Union"

if isMember == "Dictionary":
# TODO: Need to properly root dictionaries
# https://github.com/servo/servo/issues/6381
declType = CGGeneric("JSVal")
declType = CGGeneric("Heap<JSVal>")

if defaultValue is None:
default = None
elif isinstance(defaultValue, IDLNullValue):
default = "NullValue()"
default = "Heap::new(NullValue())"
elif isinstance(defaultValue, IDLUndefinedValue):
default = "UndefinedValue()"
default = "Heap::new(UndefinedValue())"
else:
raise TypeError("Can't handle non-null, non-undefined default value here")
return handleOptional("${val}", declType, default)
return handleOptional("Heap::new(${val}.get())", declType, default)

declType = CGGeneric("HandleValue")

@@ -1065,13 +1066,22 @@ def wrapObjectTemplate(templateBody, nullValue, isDefinitelyObject, type,

# TODO: Need to root somehow
# https://github.com/servo/servo/issues/6382
declType = CGGeneric("*mut JSObject")
default = "ptr::null_mut()"
templateBody = wrapObjectTemplate("${val}.get().to_object()",
"ptr::null_mut()",
default,
isDefinitelyObject, type, failureCode)

if isMember in ("Dictionary", "Union"):
declType = CGGeneric("Heap<*mut JSObject>")
templateBody = "Heap::new(%s)" % templateBody
default = "Heap::new(%s)" % default
else:
# TODO: Need to root somehow
# https://github.com/servo/servo/issues/6382
declType = CGGeneric("*mut JSObject")

return handleOptional(templateBody, declType,
handleDefaultNull("ptr::null_mut()"))
handleDefaultNull(default))

if type.isDictionary():
# There are no nullable dictionaries
@@ -2230,6 +2240,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
'dom::types::*',
'js::error::throw_type_error',
'js::jsapi::HandleValue',
'js::jsapi::Heap',
'js::jsapi::JSContext',
'js::jsapi::JSObject',
'js::jsapi::MutableHandleValue',
@@ -4049,7 +4060,7 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
typeName = builtinNames[type.tag()]
elif type.isObject():
name = type.name
typeName = "*mut JSObject"
typeName = "Heap<*mut JSObject>"
else:
raise TypeError("Can't handle %s in unions yet" % type)

@@ -5993,8 +6004,6 @@ def indent(s):
default = info.default
replacements = {"val": "rval.handle()"}
conversion = string.Template(templateBody).substitute(replacements)
if memberType.isAny():
conversion = "%s.get()" % conversion

assert (member.defaultValue is None) == (default is None)
if not member.optional:
@@ -15,7 +15,7 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
use dom::bindings::trace::JSTraceable;
use dom::globalscope::GlobalScope;
use js::conversions::ToJSValConvertible;
use js::jsapi::{HandleValue, JSContext, JSObject, MutableHandleObject};
use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject};
use js::jsval::UndefinedValue;
use std::cell::Cell;
use std::ptr;
@@ -116,7 +116,7 @@ fn dict_return(cx: *mut JSContext,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
dict.done = done;
dict.value = value.get();
dict.value.set(value.get());
rooted!(in(cx) let mut dict_value = UndefinedValue());
unsafe {
dict.to_jsval(cx, dict_value.handle_mut());
@@ -131,7 +131,7 @@ fn key_and_value_return(cx: *mut JSContext,
value: HandleValue) -> Fallible<()> {
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
dict.done = false;
dict.value = Some(vec![key.get(), value.get()]);
dict.value = Some(vec![Heap::new(key.get()), Heap::new(value.get())]);
rooted!(in(cx) let mut dict_value = UndefinedValue());
unsafe {
dict.to_jsval(cx, dict_value.handle_mut());
@@ -57,7 +57,7 @@ impl CustomEvent {
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
unsafe { HandleValue::from_marked_location(&init.detail) }))
init.detail.handle()))
}

fn init_custom_event(&self,
@@ -93,7 +93,7 @@ impl ErrorEvent {

// Dictionaries need to be rooted
// https://github.com/servo/servo/issues/6381
rooted!(in(global.get_cx()) let error = init.error);
rooted!(in(global.get_cx()) let error = init.error.get());
let event = ErrorEvent::new(
global,
Atom::from(type_),
@@ -50,7 +50,7 @@ impl ExtendableMessageEvent {
init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
-> Fallible<Root<ExtendableMessageEvent>> {
let global = worker.upcast::<GlobalScope>();
rooted!(in(global.get_cx()) let data = init.data);
rooted!(in(global.get_cx()) let data = init.data.get());
let ev = ExtendableMessageEvent::new(global,
Atom::from(type_),
init.parent.parent.bubbles,
@@ -344,7 +344,7 @@ impl FileReaderMethods for FileReader {
FileReaderResult::String(ref string) =>
StringOrObject::String(string.clone()),
FileReaderResult::ArrayBuffer(ref arr_buffer) => {
StringOrObject::Object((*arr_buffer.ptr.get()).to_object())
StringOrObject::Object(Heap::new((*arr_buffer.ptr.get()).to_object()))
}
})
}
@@ -64,7 +64,7 @@ impl MessageEvent {
-> Fallible<Root<MessageEvent>> {
// Dictionaries need to be rooted
// https://github.com/servo/servo/issues/6381
rooted!(in(global.get_cx()) let data = init.data);
rooted!(in(global.get_cx()) let data = init.data.get());
let ev = MessageEvent::new(global,
Atom::from(type_),
init.parent.bubbles,
@@ -53,7 +53,6 @@ impl PopStateEvent {
ev
}

#[allow(unsafe_code)]
pub fn Constructor(window: &Window,
type_: DOMString,
init: &PopStateEventBinding::PopStateEventInit)
@@ -62,7 +61,7 @@ impl PopStateEvent {
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
unsafe { HandleValue::from_marked_location(&init.state) }))
init.state.handle()))
}
}

@@ -139,12 +139,12 @@ impl Request {
// TODO: `environment settings object` is not implemented in Servo yet.

// Step 10
if !init.window.is_undefined() && !init.window.is_null() {
if !init.window.handle().is_null_or_undefined() {
return Err(Error::Type("Window is present and is not null".to_string()))
}

// Step 11
if !init.window.is_undefined() {
if !init.window.handle().is_undefined() {
window = Window::NoWindow;
}

@@ -179,7 +179,7 @@ impl Request {
init.redirect.is_some() ||
init.referrer.is_some() ||
init.referrerPolicy.is_some() ||
!init.window.is_undefined() {
!init.window.handle().is_undefined() {
// Step 13.1
if request.mode == NetTraitsRequestMode::Navigate {
return Err(Error::Type(
@@ -33,7 +33,7 @@ use dom::globalscope::GlobalScope;
use dom::promise::Promise;
use dom::promisenativehandler::{PromiseNativeHandler, Callback};
use dom::url::URL;
use js::jsapi::{HandleObject, HandleValue, JSContext, JSObject, JSAutoCompartment};
use js::jsapi::{HandleObject, HandleValue, Heap, JSContext, JSObject, JSAutoCompartment};
use js::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray};
use js::jsval::{JSVal, NullValue};
use script_traits::MsDuration;
@@ -338,12 +338,12 @@ impl TestBindingMethods for TestBinding {
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> TestDictionary {
TestDictionary {
anyValue: NullValue(),
anyValue: Heap::new(NullValue()),
booleanValue: None,
byteValue: None,
dict: TestDictionaryDefaults {
UnrestrictedDoubleValue: 0.0,
anyValue: NullValue(),
anyValue: Heap::new(NullValue()),
booleanValue: false,
bytestringValue: ByteString::new(vec![]),
byteValue: 0,
@@ -359,7 +359,7 @@ impl TestBindingMethods for TestBinding {
nullableFloatValue: None,
nullableLongLongValue: None,
nullableLongValue: None,
nullableObjectValue: ptr::null_mut(),
nullableObjectValue: Heap::new(ptr::null_mut()),
nullableOctetValue: None,
nullableShortValue: None,
nullableStringValue: None,

0 comments on commit 8ce9ca6

Please sign in to comment.
You can’t perform that action at this time.