Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert parent dictionary values when converting dictionaries to JS #26929

Merged
merged 1 commit into from Jun 16, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

dom: Convert parent dictionary values when converting dictionaries to…

… JS.
  • Loading branch information
jdm committed Jun 16, 2020
commit edf86d1bdcd501fc0f3c024f7296fbb3540cdfa6
@@ -6557,7 +6557,10 @@ def memberInsert(memberInfo):
(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 @@ def memberInsert(memberInfo):
" }\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 @@ def memberInsert(memberInfo):
"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)]
@@ -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": [
"aee3278ba84ca12a77286a1c03dbaec9fc3a7cd0",
[
@@ -0,0 +1,2 @@
[dictionary_to_jsval.html]
prefs: [dom.testbinding.enabled:true]
@@ -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>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.