mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Auto merge of #26054 - shnmorimoto:fix_tojson_unconditionally_serializes, r=jdm
Fix tojson unconditionally serializes <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #25281 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
f9e7c6b9dc
3 changed files with 23 additions and 18 deletions
|
@ -2966,13 +2966,23 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod):
|
|||
self.toJSONMethod = toJSONMethod
|
||||
|
||||
def definition_body(self):
|
||||
ret = ''
|
||||
ret = """let incumbent_global = GlobalScope::incumbent().expect("no incumbent global");
|
||||
let global = incumbent_global.reflector().get_jsobject();\n"""
|
||||
interface = self.descriptor.interface
|
||||
for m in interface.members:
|
||||
if m.isAttr() and not m.isStatic() and m.type.isJSONType():
|
||||
name = m.identifier.name
|
||||
conditions = MemberCondition(None, None, m.exposureSet)
|
||||
ret_conditions = '&[' + ", ".join(conditions) + "]"
|
||||
ret += fill(
|
||||
"""
|
||||
let conditions = ${conditions};
|
||||
let is_satisfied = conditions.iter().any(|c|
|
||||
c.is_satisfied(
|
||||
SafeJSContext::from_ptr(cx),
|
||||
HandleObject::from_raw(obj),
|
||||
global));
|
||||
if is_satisfied {
|
||||
rooted!(in(cx) let mut temp = UndefinedValue());
|
||||
if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) {
|
||||
return false;
|
||||
|
@ -2982,8 +2992,9 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod):
|
|||
temp.handle(), JSPROP_ENUMERATE as u32) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
""",
|
||||
name=name, nameAsArray=str_to_const_array(name))
|
||||
name=name, nameAsArray=str_to_const_array(name), conditions=ret_conditions)
|
||||
ret += 'return true;\n'
|
||||
return CGGeneric(ret)
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ pub enum Condition {
|
|||
}
|
||||
|
||||
impl Condition {
|
||||
fn is_satisfied(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> bool {
|
||||
pub fn is_satisfied(&self, cx: JSContext, obj: HandleObject, global: HandleObject) -> bool {
|
||||
match *self {
|
||||
Condition::Pref(name) => prefs::pref_map().get(name).as_bool().unwrap_or(false),
|
||||
Condition::Func(f) => f(cx, obj),
|
||||
|
|
|
@ -14,9 +14,3 @@
|
|||
expected: TIMEOUT
|
||||
[idlharness]
|
||||
expected: FAIL
|
||||
|
||||
|
||||
[idlharness.any.html]
|
||||
|
||||
[idlharness.any.worker.html]
|
||||
expected: CRASH
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue