From 80b2a87be718d81032a14bc96d94bb37318c31d8 Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Sat, 28 Mar 2020 20:17:16 +0900 Subject: [PATCH 1/6] fixed #25281 --- components/script/dom/bindings/codegen/CodegenRust.py | 11 +++++++++-- components/script/dom/bindings/guard.rs | 2 +- components/script/dom/bindings/interface.rs | 3 +++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 8f0281be802..3191a7acc4d 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2968,12 +2968,19 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod): def definition_body(self): ret = '' 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 = 'vec![' + ",".join(conditions) + "]" ret += fill( """ - rooted!(in(cx) let mut temp = UndefinedValue()); + let conditions = ${conditions}; + if !conditions.iter().any(|c| c.is_satisfied(SafeJSContext::from_ptr(cx), HandleObject::from_raw(obj), HandleObject::from_raw(obj))) { + return false; + } + rooted!(in(cx) let mut temp = UndefinedValue()); if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) { return false; } @@ -2983,7 +2990,7 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod): 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) diff --git a/components/script/dom/bindings/guard.rs b/components/script/dom/bindings/guard.rs index bba30e1581c..188d36fee17 100644 --- a/components/script/dom/bindings/guard.rs +++ b/components/script/dom/bindings/guard.rs @@ -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), diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index d0b3771890e..0faecf2a91b 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -375,6 +375,9 @@ pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { unsafe { let unwrapped = UncheckedUnwrapObject(object.get(), /* stopAtWindowProxy = */ 0); let dom_class = get_dom_class(unwrapped).unwrap(); + if (dom_class.global.is_empty()) && (!globals.is_empty()) { + return false + } globals.contains(dom_class.global) } } From 096f3d73be4d9d646700e8c025c5beabbfc6e162 Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Sat, 28 Mar 2020 20:17:35 +0900 Subject: [PATCH 2/6] updated test --- tests/wpt/metadata/hr-time/idlharness.any.js.ini | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/wpt/metadata/hr-time/idlharness.any.js.ini b/tests/wpt/metadata/hr-time/idlharness.any.js.ini index e7e8c641ef8..286747ba9de 100644 --- a/tests/wpt/metadata/hr-time/idlharness.any.js.ini +++ b/tests/wpt/metadata/hr-time/idlharness.any.js.ini @@ -13,10 +13,4 @@ [idlharness.https.any.serviceworker.html] expected: TIMEOUT [idlharness] - expected: FAIL - - -[idlharness.any.html] - -[idlharness.any.worker.html] - expected: CRASH + expected: FAIL \ No newline at end of file From f7d4a37f784ad8ce5d904e125167e4e4ef6a2e2a Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Sat, 28 Mar 2020 23:21:35 +0900 Subject: [PATCH 3/6] fixed fmt --- components/script/dom/bindings/codegen/CodegenRust.py | 8 ++++++-- components/script/dom/bindings/interface.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 3191a7acc4d..30c33f47077 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2977,10 +2977,14 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod): ret += fill( """ let conditions = ${conditions}; - if !conditions.iter().any(|c| c.is_satisfied(SafeJSContext::from_ptr(cx), HandleObject::from_raw(obj), HandleObject::from_raw(obj))) { + if !conditions.iter().any(|c| + c.is_satisfied( + SafeJSContext::from_ptr(cx), + HandleObject::from_raw(obj), + HandleObject::from_raw(obj))) { return false; } - rooted!(in(cx) let mut temp = UndefinedValue()); + rooted!(in(cx) let mut temp = UndefinedValue()); if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) { return false; } diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index 0faecf2a91b..fec137d9163 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -376,7 +376,7 @@ pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { let unwrapped = UncheckedUnwrapObject(object.get(), /* stopAtWindowProxy = */ 0); let dom_class = get_dom_class(unwrapped).unwrap(); if (dom_class.global.is_empty()) && (!globals.is_empty()) { - return false + return false; } globals.contains(dom_class.global) } From fa8afbb1b0455493ba4859346eda6114e7a0720a Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Mon, 30 Mar 2020 02:32:17 +0900 Subject: [PATCH 4/6] remove unnecessary condition --- components/script/dom/bindings/interface.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/components/script/dom/bindings/interface.rs b/components/script/dom/bindings/interface.rs index fec137d9163..d0b3771890e 100644 --- a/components/script/dom/bindings/interface.rs +++ b/components/script/dom/bindings/interface.rs @@ -375,9 +375,6 @@ pub fn is_exposed_in(object: HandleObject, globals: Globals) -> bool { unsafe { let unwrapped = UncheckedUnwrapObject(object.get(), /* stopAtWindowProxy = */ 0); let dom_class = get_dom_class(unwrapped).unwrap(); - if (dom_class.global.is_empty()) && (!globals.is_empty()) { - return false; - } globals.contains(dom_class.global) } } From d8c1dc60e8f48f05ecd3ec01fbc91d7743734460 Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Mon, 30 Mar 2020 02:32:46 +0900 Subject: [PATCH 5/6] fixed is_satisfied condition --- .../dom/bindings/codegen/CodegenRust.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 30c33f47077..ed0e1223e72 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2976,22 +2976,24 @@ class CGCollectJSONAttributesMethod(CGAbstractMethod): ret_conditions = 'vec![' + ",".join(conditions) + "]" ret += fill( """ + let incumbent_global = GlobalScope::incumbent().expect("no incumbent global"); + let global = incumbent_global.reflector().get_jsobject(); let conditions = ${conditions}; - if !conditions.iter().any(|c| + let is_satisfied = conditions.iter().any(|c| c.is_satisfied( SafeJSContext::from_ptr(cx), HandleObject::from_raw(obj), - HandleObject::from_raw(obj))) { - return false; - } - 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; + 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), conditions=ret_conditions) From 74995a5287dc0af8afe62e9b537db5141b854765 Mon Sep 17 00:00:00 2001 From: Shinichi Morimoto Date: Tue, 31 Mar 2020 09:37:07 +0900 Subject: [PATCH 6/6] fixed CGCollectJSONAttributesMethod --- components/script/dom/bindings/codegen/CodegenRust.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index ed0e1223e72..96947d83ec7 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -2966,18 +2966,16 @@ 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 = 'vec![' + ",".join(conditions) + "]" + ret_conditions = '&[' + ", ".join(conditions) + "]" ret += fill( """ - let incumbent_global = GlobalScope::incumbent().expect("no incumbent global"); - let global = incumbent_global.reflector().get_jsobject(); let conditions = ${conditions}; let is_satisfied = conditions.iter().any(|c| c.is_satisfied(