mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
dom: Convert parent dictionary values when converting dictionaries to JS.
This commit is contained in:
parent
a34d1573b6
commit
edf86d1bdc
7 changed files with 57 additions and 4 deletions
|
@ -6557,7 +6557,10 @@ class CGDictionary(CGThing):
|
|||
(name, name, varInsert(name, member.identifier.name).define()))
|
||||
return CGGeneric("%s\n" % insertion.define())
|
||||
|
||||
memberInserts = CGList([memberInsert(m) for m in self.memberInfo])
|
||||
memberInserts = [memberInsert(m) for m in self.memberInfo]
|
||||
|
||||
if d.parent:
|
||||
memberInserts = [CGGeneric("self.parent.to_jsobject(cx, obj);\n")] + memberInserts
|
||||
|
||||
selfName = self.makeClassName(d)
|
||||
if self.membersNeedTracing():
|
||||
|
@ -6602,10 +6605,16 @@ class CGDictionary(CGThing):
|
|||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"impl ${selfName} {\n"
|
||||
" pub(crate) unsafe fn to_jsobject(&self, cx: *mut JSContext, mut obj: MutableHandleObject) {\n"
|
||||
"${insertMembers}"
|
||||
" }\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"impl ToJSValConvertible for ${selfName} {\n"
|
||||
" unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {\n"
|
||||
" rooted!(in(cx) let obj = JS_NewObject(cx, ptr::null()));\n"
|
||||
"${insertMembers}"
|
||||
" rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));\n"
|
||||
" self.to_jsobject(cx, obj.handle_mut());\n"
|
||||
" rval.set(ObjectOrNullValue(obj.get()))\n"
|
||||
" }\n"
|
||||
"}\n").substitute({
|
||||
|
@ -6614,7 +6623,7 @@ class CGDictionary(CGThing):
|
|||
"empty": CGIndenter(CGGeneric(self.makeEmpty()), indentLevel=4).define(),
|
||||
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=16).define(),
|
||||
"initMembers": CGIndenter(memberInits, indentLevel=16).define(),
|
||||
"insertMembers": CGIndenter(memberInserts, indentLevel=8).define(),
|
||||
"insertMembers": CGIndenter(CGList(memberInserts), indentLevel=8).define(),
|
||||
"preInitial": CGIndenter(CGGeneric(preInitial), indentLevel=8).define(),
|
||||
"postInitial": CGIndenter(CGGeneric(postInitial), indentLevel=8).define(),
|
||||
})
|
||||
|
|
|
@ -8,6 +8,8 @@ use crate::dom::bindings::callback::ExceptionHandling;
|
|||
use crate::dom::bindings::codegen::Bindings::EventListenerBinding::EventListener;
|
||||
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::SimpleCallback;
|
||||
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::TestDictionaryParent;
|
||||
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::TestDictionaryWithParent;
|
||||
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::{
|
||||
TestBindingMethods, TestDictionary,
|
||||
};
|
||||
|
@ -1079,6 +1081,15 @@ impl TestBindingMethods for TestBinding {
|
|||
fn SemiExposedBoolFromPartialInterface(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn GetDictionaryWithParent(&self, s1: DOMString, s2: DOMString) -> TestDictionaryWithParent {
|
||||
TestDictionaryWithParent {
|
||||
parent: TestDictionaryParent {
|
||||
parentStringMember: Some(s1),
|
||||
},
|
||||
stringMember: Some(s2),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
|
|
|
@ -45,6 +45,14 @@ dictionary TestDictionary {
|
|||
DOMString? nonRequiredNullable2;
|
||||
};
|
||||
|
||||
dictionary TestDictionaryParent {
|
||||
DOMString parentStringMember;
|
||||
};
|
||||
|
||||
dictionary TestDictionaryWithParent : TestDictionaryParent {
|
||||
DOMString stringMember;
|
||||
};
|
||||
|
||||
dictionary TestDictionaryDefaults {
|
||||
boolean booleanValue = false;
|
||||
byte byteValue = 7;
|
||||
|
@ -571,6 +579,8 @@ interface TestBinding {
|
|||
|
||||
[Exposed=(Window)]
|
||||
readonly attribute boolean semiExposedBoolFromInterface;
|
||||
|
||||
TestDictionaryWithParent getDictionaryWithParent(DOMString parent, DOMString child);
|
||||
};
|
||||
|
||||
[Exposed=(Window)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue