mirror of
https://github.com/servo/servo.git
synced 2025-07-24 07:40:27 +01:00
Use Heap for dictionary and union members.
This commit is contained in:
parent
5eaa19bdd4
commit
8ce9ca6243
10 changed files with 35 additions and 27 deletions
|
@ -1031,21 +1031,22 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
if type.isAny():
|
if type.isAny():
|
||||||
assert not isEnforceRange and not isClamp
|
assert not isEnforceRange and not isClamp
|
||||||
|
assert isMember != "Union"
|
||||||
|
|
||||||
if isMember == "Dictionary":
|
if isMember == "Dictionary":
|
||||||
# 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("JSVal")
|
declType = CGGeneric("Heap<JSVal>")
|
||||||
|
|
||||||
if defaultValue is None:
|
if defaultValue is None:
|
||||||
default = None
|
default = None
|
||||||
elif isinstance(defaultValue, IDLNullValue):
|
elif isinstance(defaultValue, IDLNullValue):
|
||||||
default = "NullValue()"
|
default = "Heap::new(NullValue())"
|
||||||
elif isinstance(defaultValue, IDLUndefinedValue):
|
elif isinstance(defaultValue, IDLUndefinedValue):
|
||||||
default = "UndefinedValue()"
|
default = "Heap::new(UndefinedValue())"
|
||||||
else:
|
else:
|
||||||
raise TypeError("Can't handle non-null, non-undefined default value here")
|
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")
|
declType = CGGeneric("HandleValue")
|
||||||
|
|
||||||
|
@ -1065,13 +1066,22 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
|
|
||||||
# TODO: Need to root somehow
|
# TODO: Need to root somehow
|
||||||
# https://github.com/servo/servo/issues/6382
|
# https://github.com/servo/servo/issues/6382
|
||||||
declType = CGGeneric("*mut JSObject")
|
default = "ptr::null_mut()"
|
||||||
templateBody = wrapObjectTemplate("${val}.get().to_object()",
|
templateBody = wrapObjectTemplate("${val}.get().to_object()",
|
||||||
"ptr::null_mut()",
|
default,
|
||||||
isDefinitelyObject, type, failureCode)
|
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,
|
return handleOptional(templateBody, declType,
|
||||||
handleDefaultNull("ptr::null_mut()"))
|
handleDefaultNull(default))
|
||||||
|
|
||||||
if type.isDictionary():
|
if type.isDictionary():
|
||||||
# There are no nullable dictionaries
|
# There are no nullable dictionaries
|
||||||
|
@ -2230,6 +2240,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, typedefs, config):
|
||||||
'dom::types::*',
|
'dom::types::*',
|
||||||
'js::error::throw_type_error',
|
'js::error::throw_type_error',
|
||||||
'js::jsapi::HandleValue',
|
'js::jsapi::HandleValue',
|
||||||
|
'js::jsapi::Heap',
|
||||||
'js::jsapi::JSContext',
|
'js::jsapi::JSContext',
|
||||||
'js::jsapi::JSObject',
|
'js::jsapi::JSObject',
|
||||||
'js::jsapi::MutableHandleValue',
|
'js::jsapi::MutableHandleValue',
|
||||||
|
@ -4049,7 +4060,7 @@ def getUnionTypeTemplateVars(type, descriptorProvider):
|
||||||
typeName = builtinNames[type.tag()]
|
typeName = builtinNames[type.tag()]
|
||||||
elif type.isObject():
|
elif type.isObject():
|
||||||
name = type.name
|
name = type.name
|
||||||
typeName = "*mut JSObject"
|
typeName = "Heap<*mut JSObject>"
|
||||||
else:
|
else:
|
||||||
raise TypeError("Can't handle %s in unions yet" % type)
|
raise TypeError("Can't handle %s in unions yet" % type)
|
||||||
|
|
||||||
|
@ -5993,8 +6004,6 @@ class CGDictionary(CGThing):
|
||||||
default = info.default
|
default = info.default
|
||||||
replacements = {"val": "rval.handle()"}
|
replacements = {"val": "rval.handle()"}
|
||||||
conversion = string.Template(templateBody).substitute(replacements)
|
conversion = string.Template(templateBody).substitute(replacements)
|
||||||
if memberType.isAny():
|
|
||||||
conversion = "%s.get()" % conversion
|
|
||||||
|
|
||||||
assert (member.defaultValue is None) == (default is None)
|
assert (member.defaultValue is None) == (default is None)
|
||||||
if not member.optional:
|
if not member.optional:
|
||||||
|
|
|
@ -15,7 +15,7 @@ use dom::bindings::reflector::{DomObject, Reflector, reflect_dom_object};
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::globalscope::GlobalScope;
|
use dom::globalscope::GlobalScope;
|
||||||
use js::conversions::ToJSValConvertible;
|
use js::conversions::ToJSValConvertible;
|
||||||
use js::jsapi::{HandleValue, JSContext, JSObject, MutableHandleObject};
|
use js::jsapi::{HandleValue, Heap, JSContext, JSObject, MutableHandleObject};
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
@ -116,7 +116,7 @@ fn dict_return(cx: *mut JSContext,
|
||||||
value: HandleValue) -> Fallible<()> {
|
value: HandleValue) -> Fallible<()> {
|
||||||
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
|
let mut dict = unsafe { IterableKeyOrValueResult::empty(cx) };
|
||||||
dict.done = done;
|
dict.done = done;
|
||||||
dict.value = value.get();
|
dict.value.set(value.get());
|
||||||
rooted!(in(cx) let mut dict_value = UndefinedValue());
|
rooted!(in(cx) let mut dict_value = UndefinedValue());
|
||||||
unsafe {
|
unsafe {
|
||||||
dict.to_jsval(cx, dict_value.handle_mut());
|
dict.to_jsval(cx, dict_value.handle_mut());
|
||||||
|
@ -131,7 +131,7 @@ fn key_and_value_return(cx: *mut JSContext,
|
||||||
value: HandleValue) -> Fallible<()> {
|
value: HandleValue) -> Fallible<()> {
|
||||||
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
|
let mut dict = unsafe { IterableKeyAndValueResult::empty(cx) };
|
||||||
dict.done = false;
|
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());
|
rooted!(in(cx) let mut dict_value = UndefinedValue());
|
||||||
unsafe {
|
unsafe {
|
||||||
dict.to_jsval(cx, dict_value.handle_mut());
|
dict.to_jsval(cx, dict_value.handle_mut());
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl CustomEvent {
|
||||||
Atom::from(type_),
|
Atom::from(type_),
|
||||||
init.parent.bubbles,
|
init.parent.bubbles,
|
||||||
init.parent.cancelable,
|
init.parent.cancelable,
|
||||||
unsafe { HandleValue::from_marked_location(&init.detail) }))
|
init.detail.handle()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_custom_event(&self,
|
fn init_custom_event(&self,
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl ErrorEvent {
|
||||||
|
|
||||||
// Dictionaries need to be rooted
|
// Dictionaries need to be rooted
|
||||||
// https://github.com/servo/servo/issues/6381
|
// 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(
|
let event = ErrorEvent::new(
|
||||||
global,
|
global,
|
||||||
Atom::from(type_),
|
Atom::from(type_),
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl ExtendableMessageEvent {
|
||||||
init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
|
init: &ExtendableMessageEventBinding::ExtendableMessageEventInit)
|
||||||
-> Fallible<Root<ExtendableMessageEvent>> {
|
-> Fallible<Root<ExtendableMessageEvent>> {
|
||||||
let global = worker.upcast::<GlobalScope>();
|
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,
|
let ev = ExtendableMessageEvent::new(global,
|
||||||
Atom::from(type_),
|
Atom::from(type_),
|
||||||
init.parent.parent.bubbles,
|
init.parent.parent.bubbles,
|
||||||
|
|
|
@ -344,7 +344,7 @@ impl FileReaderMethods for FileReader {
|
||||||
FileReaderResult::String(ref string) =>
|
FileReaderResult::String(ref string) =>
|
||||||
StringOrObject::String(string.clone()),
|
StringOrObject::String(string.clone()),
|
||||||
FileReaderResult::ArrayBuffer(ref arr_buffer) => {
|
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>> {
|
-> Fallible<Root<MessageEvent>> {
|
||||||
// Dictionaries need to be rooted
|
// Dictionaries need to be rooted
|
||||||
// https://github.com/servo/servo/issues/6381
|
// 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,
|
let ev = MessageEvent::new(global,
|
||||||
Atom::from(type_),
|
Atom::from(type_),
|
||||||
init.parent.bubbles,
|
init.parent.bubbles,
|
||||||
|
|
|
@ -53,7 +53,6 @@ impl PopStateEvent {
|
||||||
ev
|
ev
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
pub fn Constructor(window: &Window,
|
pub fn Constructor(window: &Window,
|
||||||
type_: DOMString,
|
type_: DOMString,
|
||||||
init: &PopStateEventBinding::PopStateEventInit)
|
init: &PopStateEventBinding::PopStateEventInit)
|
||||||
|
@ -62,7 +61,7 @@ impl PopStateEvent {
|
||||||
Atom::from(type_),
|
Atom::from(type_),
|
||||||
init.parent.bubbles,
|
init.parent.bubbles,
|
||||||
init.parent.cancelable,
|
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.
|
// TODO: `environment settings object` is not implemented in Servo yet.
|
||||||
|
|
||||||
// Step 10
|
// 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()))
|
return Err(Error::Type("Window is present and is not null".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 11
|
// Step 11
|
||||||
if !init.window.is_undefined() {
|
if !init.window.handle().is_undefined() {
|
||||||
window = Window::NoWindow;
|
window = Window::NoWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ impl Request {
|
||||||
init.redirect.is_some() ||
|
init.redirect.is_some() ||
|
||||||
init.referrer.is_some() ||
|
init.referrer.is_some() ||
|
||||||
init.referrerPolicy.is_some() ||
|
init.referrerPolicy.is_some() ||
|
||||||
!init.window.is_undefined() {
|
!init.window.handle().is_undefined() {
|
||||||
// Step 13.1
|
// Step 13.1
|
||||||
if request.mode == NetTraitsRequestMode::Navigate {
|
if request.mode == NetTraitsRequestMode::Navigate {
|
||||||
return Err(Error::Type(
|
return Err(Error::Type(
|
||||||
|
|
|
@ -33,7 +33,7 @@ use dom::globalscope::GlobalScope;
|
||||||
use dom::promise::Promise;
|
use dom::promise::Promise;
|
||||||
use dom::promisenativehandler::{PromiseNativeHandler, Callback};
|
use dom::promisenativehandler::{PromiseNativeHandler, Callback};
|
||||||
use dom::url::URL;
|
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::jsapi::{JS_NewPlainObject, JS_NewUint8ClampedArray};
|
||||||
use js::jsval::{JSVal, NullValue};
|
use js::jsval::{JSVal, NullValue};
|
||||||
use script_traits::MsDuration;
|
use script_traits::MsDuration;
|
||||||
|
@ -338,12 +338,12 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
|
fn ReceiveNullableSequence(&self) -> Option<Vec<i32>> { Some(vec![1]) }
|
||||||
fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> TestDictionary {
|
fn ReceiveTestDictionaryWithSuccessOnKeyword(&self) -> TestDictionary {
|
||||||
TestDictionary {
|
TestDictionary {
|
||||||
anyValue: NullValue(),
|
anyValue: Heap::new(NullValue()),
|
||||||
booleanValue: None,
|
booleanValue: None,
|
||||||
byteValue: None,
|
byteValue: None,
|
||||||
dict: TestDictionaryDefaults {
|
dict: TestDictionaryDefaults {
|
||||||
UnrestrictedDoubleValue: 0.0,
|
UnrestrictedDoubleValue: 0.0,
|
||||||
anyValue: NullValue(),
|
anyValue: Heap::new(NullValue()),
|
||||||
booleanValue: false,
|
booleanValue: false,
|
||||||
bytestringValue: ByteString::new(vec![]),
|
bytestringValue: ByteString::new(vec![]),
|
||||||
byteValue: 0,
|
byteValue: 0,
|
||||||
|
@ -359,7 +359,7 @@ impl TestBindingMethods for TestBinding {
|
||||||
nullableFloatValue: None,
|
nullableFloatValue: None,
|
||||||
nullableLongLongValue: None,
|
nullableLongLongValue: None,
|
||||||
nullableLongValue: None,
|
nullableLongValue: None,
|
||||||
nullableObjectValue: ptr::null_mut(),
|
nullableObjectValue: Heap::new(ptr::null_mut()),
|
||||||
nullableOctetValue: None,
|
nullableOctetValue: None,
|
||||||
nullableShortValue: None,
|
nullableShortValue: None,
|
||||||
nullableStringValue: None,
|
nullableStringValue: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue