mirror of
https://github.com/servo/servo.git
synced 2025-06-25 09:34:32 +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()))
|
(name, name, varInsert(name, member.identifier.name).define()))
|
||||||
return CGGeneric("%s\n" % insertion.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)
|
selfName = self.makeClassName(d)
|
||||||
if self.membersNeedTracing():
|
if self.membersNeedTracing():
|
||||||
|
@ -6602,10 +6605,16 @@ class CGDictionary(CGThing):
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n"
|
"}\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"
|
"impl ToJSValConvertible for ${selfName} {\n"
|
||||||
" unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {\n"
|
" unsafe fn to_jsval(&self, cx: *mut JSContext, mut rval: MutableHandleValue) {\n"
|
||||||
" rooted!(in(cx) let obj = JS_NewObject(cx, ptr::null()));\n"
|
" rooted!(in(cx) let mut obj = JS_NewObject(cx, ptr::null()));\n"
|
||||||
"${insertMembers}"
|
" self.to_jsobject(cx, obj.handle_mut());\n"
|
||||||
" rval.set(ObjectOrNullValue(obj.get()))\n"
|
" rval.set(ObjectOrNullValue(obj.get()))\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n").substitute({
|
"}\n").substitute({
|
||||||
|
@ -6614,7 +6623,7 @@ class CGDictionary(CGThing):
|
||||||
"empty": CGIndenter(CGGeneric(self.makeEmpty()), indentLevel=4).define(),
|
"empty": CGIndenter(CGGeneric(self.makeEmpty()), indentLevel=4).define(),
|
||||||
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=16).define(),
|
"initParent": CGIndenter(CGGeneric(initParent), indentLevel=16).define(),
|
||||||
"initMembers": CGIndenter(memberInits, 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(),
|
"preInitial": CGIndenter(CGGeneric(preInitial), indentLevel=8).define(),
|
||||||
"postInitial": CGIndenter(CGGeneric(postInitial), 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::EventListenerBinding::EventListener;
|
||||||
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::SimpleCallback;
|
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::{
|
use crate::dom::bindings::codegen::Bindings::TestBindingBinding::{
|
||||||
TestBindingMethods, TestDictionary,
|
TestBindingMethods, TestDictionary,
|
||||||
};
|
};
|
||||||
|
@ -1079,6 +1081,15 @@ impl TestBindingMethods for TestBinding {
|
||||||
fn SemiExposedBoolFromPartialInterface(&self) -> bool {
|
fn SemiExposedBoolFromPartialInterface(&self) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn GetDictionaryWithParent(&self, s1: DOMString, s2: DOMString) -> TestDictionaryWithParent {
|
||||||
|
TestDictionaryWithParent {
|
||||||
|
parent: TestDictionaryParent {
|
||||||
|
parentStringMember: Some(s1),
|
||||||
|
},
|
||||||
|
stringMember: Some(s2),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
|
|
@ -45,6 +45,14 @@ dictionary TestDictionary {
|
||||||
DOMString? nonRequiredNullable2;
|
DOMString? nonRequiredNullable2;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dictionary TestDictionaryParent {
|
||||||
|
DOMString parentStringMember;
|
||||||
|
};
|
||||||
|
|
||||||
|
dictionary TestDictionaryWithParent : TestDictionaryParent {
|
||||||
|
DOMString stringMember;
|
||||||
|
};
|
||||||
|
|
||||||
dictionary TestDictionaryDefaults {
|
dictionary TestDictionaryDefaults {
|
||||||
boolean booleanValue = false;
|
boolean booleanValue = false;
|
||||||
byte byteValue = 7;
|
byte byteValue = 7;
|
||||||
|
@ -571,6 +579,8 @@ interface TestBinding {
|
||||||
|
|
||||||
[Exposed=(Window)]
|
[Exposed=(Window)]
|
||||||
readonly attribute boolean semiExposedBoolFromInterface;
|
readonly attribute boolean semiExposedBoolFromInterface;
|
||||||
|
|
||||||
|
TestDictionaryWithParent getDictionaryWithParent(DOMString parent, DOMString child);
|
||||||
};
|
};
|
||||||
|
|
||||||
[Exposed=(Window)]
|
[Exposed=(Window)]
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[dictionary_to_jsval.html]
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
|
@ -13357,6 +13357,13 @@
|
||||||
{}
|
{}
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
"dictionary_to_jsval.html": [
|
||||||
|
"e31a7e5cfaa0635d41ab2adac96318b574c58a10",
|
||||||
|
[
|
||||||
|
null,
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
],
|
||||||
"documentElement.html": [
|
"documentElement.html": [
|
||||||
"aee3278ba84ca12a77286a1c03dbaec9fc3a7cd0",
|
"aee3278ba84ca12a77286a1c03dbaec9fc3a7cd0",
|
||||||
[
|
[
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[dictionary_to_jsval.html]
|
||||||
|
prefs: [dom.testbinding.enabled:true]
|
12
tests/wpt/mozilla/tests/mozilla/dictionary_to_jsval.html
Normal file
12
tests/wpt/mozilla/tests/mozilla/dictionary_to_jsval.html
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
let b = new TestBinding();
|
||||||
|
let dict = b.getDictionaryWithParent("parent", "child");
|
||||||
|
assert_equals(dict.parentStringMember, "parent");
|
||||||
|
assert_equals(dict.stringMember, "child");
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue