diff options
author | bors-servo <servo-ops@mozilla.com> | 2020-03-31 02:33:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 02:33:53 -0400 |
commit | f9e7c6b9dc65fc178ef5e7e516bd777ef3bb5052 (patch) | |
tree | 481cf6eda0528a4475cb53d3edb6902ef52611e0 /components/script/dom/bindings/codegen | |
parent | 687156ac90d0cead80e89b63b9394d1a6f7a808e (diff) | |
parent | 74995a5287dc0af8afe62e9b537db5141b854765 (diff) | |
download | servo-f9e7c6b9dc65fc178ef5e7e516bd777ef3bb5052.tar.gz servo-f9e7c6b9dc65fc178ef5e7e516bd777ef3bb5052.zip |
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. -->
Diffstat (limited to 'components/script/dom/bindings/codegen')
-rw-r--r-- | components/script/dom/bindings/codegen/CodegenRust.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8f0281be802..96947d83ec7 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2966,24 +2966,35 @@ 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( """ - rooted!(in(cx) let mut temp = UndefinedValue()); - if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) { - return false; - } - if !JS_DefineProperty(cx, result.handle().into(), - ${nameAsArray} as *const u8 as *const libc::c_char, - temp.handle(), JSPROP_ENUMERATE as u32) { - return false; + 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; + } + if !JS_DefineProperty(cx, result.handle().into(), + ${nameAsArray} as *const u8 as *const libc::c_char, + 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) |