aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py53
-rw-r--r--components/script/dom/bindings/mod.rs12
-rw-r--r--components/script/dom/event.rs7
-rw-r--r--components/script/dom/extendableevent.rs8
4 files changed, 48 insertions, 32 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index d3229fb3dd2..891f24f95ac 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -40,11 +40,11 @@ from Configuration import (
)
AUTOGENERATED_WARNING_COMMENT = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n\n"
-IGNORED_WARNING_LIST = ['non_camel_case_types', 'non_upper_case_globals', 'unused_imports',
+ALLOWED_WARNING_LIST = ['non_camel_case_types', 'non_upper_case_globals', 'unused_imports',
'unused_variables', 'unused_assignments', 'unused_mut',
'clippy::approx_constant', 'clippy::let_unit_value', 'clippy::needless_return',
- 'clippy::too_many_arguments', 'clippy::unnecessary_cast']
-IGNORED_WARNINGS = f"#![allow({','.join(IGNORED_WARNING_LIST)})]\n\n"
+ 'clippy::too_many_arguments', 'clippy::unnecessary_cast', 'clippy::upper_case_acronyms']
+ALLOWED_WARNINGS = f"#![allow({','.join(ALLOWED_WARNING_LIST)})]\n\n"
FINALIZE_HOOK_NAME = '_finalize'
TRACE_HOOK_NAME = '_trace'
@@ -1402,14 +1402,16 @@ class CGArgumentConverter(CGThing):
innerConverter.append(CGGeneric("%s.push(slot);" % arg))
inner = CGIndenter(CGList(innerConverter, "\n"), 8).define()
+ sub = "" if index == 0 else "- %s" % index
+
self.converter = CGGeneric("""\
%(init)s;
if %(argc)s > %(index)s {
- %(arg)s.reserve(%(argc)s as usize - %(index)s);
+ %(arg)s.reserve(%(argc)s as usize%(sub)s);
for variadicArg in %(index)s..%(argc)s {
%(inner)s
}
-}""" % {'arg': arg, 'argc': argc, 'index': index, 'inner': inner, 'init': init})
+}""" % {'arg': arg, 'argc': argc, 'index': index, 'inner': inner, 'init': init, 'sub': sub})
def define(self):
return self.converter.define()
@@ -2564,8 +2566,11 @@ class CGList(CGThing):
class CGIfElseWrapper(CGList):
def __init__(self, condition, ifTrue, ifFalse):
- kids = [CGIfWrapper(condition, ifTrue),
- CGWrapper(CGIndenter(ifFalse), pre=" else {\n", post="\n}")]
+ if ifFalse.text.strip().startswith("if"):
+ elseBranch = CGWrapper(ifFalse, pre=" else ")
+ else:
+ elseBranch = CGWrapper(CGIndenter(ifFalse), pre=" else {\n", post="\n}")
+ kids = [CGIfWrapper(condition, ifTrue), elseBranch]
CGList.__init__(self, kids)
@@ -2758,6 +2763,15 @@ class CGAbstractMethod(CGThing):
if self.returnType == "void":
pre = "wrap_panic(&mut || {\n"
post = "\n})"
+ elif "return" not in body.define():
+ pre = (
+ "let mut result = false;\n"
+ "wrap_panic(&mut || result = {\n"
+ )
+ post = (
+ "\n});\n"
+ "result"
+ )
else:
pre = (
"let mut result = false;\n"
@@ -3225,7 +3239,7 @@ let global = incumbent_global.reflector().get_jsobject();\n"""
if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) {
return false;
}
- if !JS_DefineProperty(cx, result.handle().into(),
+ if !JS_DefineProperty(cx, result.handle(),
${nameAsArray} as *const u8 as *const libc::c_char,
temp.handle(), JSPROP_ENUMERATE as u32) {
return false;
@@ -6125,7 +6139,7 @@ let global = DomRoot::downcast::<dom::types::%s>(global).unwrap();
constructorCall = CGGeneric("""dom::bindings::htmlconstructor::call_html_constructor::<dom::types::%s>(
cx,
&args,
- &*global,
+ &global,
PrototypeList::ID::%s,
CreateInterfaceObjects,
)""" % (self.descriptor.name, MakeNativeName(self.descriptor.name)))
@@ -6947,7 +6961,7 @@ class CGBindingRoot(CGThing):
imports=['crate::dom::bindings::import::base::*'], config=config)
# Add the auto-generated comment.
- curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT + IGNORED_WARNINGS)
+ curr = CGWrapper(curr, pre=AUTOGENERATED_WARNING_COMMENT + ALLOWED_WARNINGS)
# Store the final result.
self.root = curr
@@ -7294,9 +7308,8 @@ class CallbackMember(CGNativeMember):
# Check for variadic arguments
lastArg = args[self.argCount - 1]
if lastArg.variadic:
- argCount = "0" if self.argCount == 1 else f"({self.argCount} - 1)"
self.argCountStr = (
- "%s + %s.len()" % (argCount, lastArg.identifier.name))
+ "%s + %s.len()" % (self.argCount - 1, lastArg.identifier.name)).removeprefix("0 + ")
else:
self.argCountStr = "%d" % self.argCount
self.needThisHandling = needThisHandling
@@ -7397,7 +7410,7 @@ class CallbackMember(CGNativeMember):
else:
jsvalIndex = "%d" % i
if arg.optional and not arg.defaultValue:
- argval += ".clone().unwrap()"
+ argval += ".unwrap()"
conversion = wrapForType(
"argv_root.handle_mut()", result=argval,
@@ -7405,7 +7418,7 @@ class CallbackMember(CGNativeMember):
"let arg = &mut argv[%s];\n"
"*arg = Heap::default();\n"
"arg.set(argv_root.get());\n"
- "}") % jsvalIndex,
+ "}") % jsvalIndex.removeprefix("0 + "),
pre="rooted!(in(*cx) let mut argv_root = UndefinedValue());")
if arg.variadic:
conversion = string.Template(
@@ -7612,14 +7625,14 @@ class CGMaplikeOrSetlikeMethodGenerator(CGGeneric):
elif methodName in ["size", "clear"]: # zero arguments
CGGeneric.__init__(self, fill(
"""
- let result = ${trt}::${method}(&*this);
+ let result = ${trt}::${method}(this);
""",
trt=trait,
method=methodName.lower()))
elif methodName == "add": # special case one argumet
CGGeneric.__init__(self, fill(
"""
- ${trt}::${method}(&*this, arg0);
+ ${trt}::${method}(this, arg0);
// Returns itself per https://webidl.spec.whatwg.org/#es-set-add
let result = this;
""",
@@ -7628,14 +7641,14 @@ class CGMaplikeOrSetlikeMethodGenerator(CGGeneric):
elif methodName in ["has", "delete", "get"]: # one argument
CGGeneric.__init__(self, fill(
"""
- let result = ${trt}::${method}(&*this, arg0);
+ let result = ${trt}::${method}(this, arg0);
""",
trt=trait,
method=methodName))
elif methodName == "set": # two arguments
CGGeneric.__init__(self, fill(
"""
- ${trt}::${method}(&*this, arg0, arg1);
+ ${trt}::${method}(this, arg0, arg1);
// Returns itself per https://webidl.spec.whatwg.org/#es-map-set
let result = this;
""",
@@ -7663,7 +7676,7 @@ class CGIterableMethodGenerator(CGGeneric):
rooted!(in(*cx) let arg0 = ObjectValue(arg0));
rooted!(in(*cx) let mut call_arg1 = UndefinedValue());
rooted!(in(*cx) let mut call_arg2 = UndefinedValue());
- let mut call_args = vec![UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)];
+ let mut call_args = [UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)];
rooted!(in(*cx) let mut ignoredReturnVal = UndefinedValue());
// This has to be a while loop since get_iterable_length() may change during
@@ -7694,7 +7707,7 @@ class CGIterableMethodGenerator(CGGeneric):
return
CGGeneric.__init__(self, fill(
"""
- let result = ${iterClass}::new(&*this, IteratorType::${itrMethod});
+ let result = ${iterClass}::new(this, IteratorType::${itrMethod});
""",
iterClass=iteratorNativeType(descriptor, True),
ifaceName=descriptor.interface.identifier.name,
diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs
index a2713e1c95f..e31d79cc494 100644
--- a/components/script/dom/bindings/mod.rs
+++ b/components/script/dom/bindings/mod.rs
@@ -176,17 +176,25 @@ pub mod codegen {
pub mod InterfaceObjectMap {
include!(concat!(env!("OUT_DIR"), "/InterfaceObjectMap.rs"));
}
- #[allow(dead_code, unused_imports)]
+ #[allow(dead_code, unused_imports, clippy::enum_variant_names)]
pub mod InheritTypes {
include!(concat!(env!("OUT_DIR"), "/InheritTypes.rs"));
}
+ #[allow(clippy::upper_case_acronyms)]
pub mod PrototypeList {
include!(concat!(env!("OUT_DIR"), "/PrototypeList.rs"));
}
pub mod RegisterBindings {
include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs"));
}
- #[allow(non_camel_case_types, unused_imports, unused_variables)]
+ #[allow(
+ non_camel_case_types,
+ unused_imports,
+ unused_variables,
+ clippy::large_enum_variant,
+ clippy::upper_case_acronyms,
+ clippy::enum_variant_names
+ )]
pub mod UnionTypes {
include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs"));
}
diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs
index 106688273b0..78f03a882ce 100644
--- a/components/script/dom/event.rs
+++ b/components/script/dom/event.rs
@@ -755,10 +755,7 @@ fn inner_invoke(
}
impl Default for EventBinding::EventInit {
- fn default() -> EventBinding::EventInit {
- EventBinding::EventInit {
- bubbles: false,
- cancelable: false,
- }
+ fn default() -> Self {
+ Self::empty()
}
}
diff --git a/components/script/dom/extendableevent.rs b/components/script/dom/extendableevent.rs
index fa9a570be83..ad57747e5aa 100644
--- a/components/script/dom/extendableevent.rs
+++ b/components/script/dom/extendableevent.rs
@@ -6,7 +6,7 @@ use dom_struct::dom_struct;
use js::rust::{HandleObject, HandleValue};
use servo_atoms::Atom;
-use crate::dom::bindings::codegen::Bindings::EventBinding::{self, EventMethods};
+use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods;
use crate::dom::bindings::codegen::Bindings::ExtendableEventBinding;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
@@ -94,9 +94,7 @@ impl ExtendableEvent {
}
impl Default for ExtendableEventBinding::ExtendableEventInit {
- fn default() -> ExtendableEventBinding::ExtendableEventInit {
- ExtendableEventBinding::ExtendableEventInit {
- parent: EventBinding::EventInit::default(),
- }
+ fn default() -> Self {
+ Self::empty()
}
}