40
40
)
41
41
42
42
AUTOGENERATED_WARNING_COMMENT = "/* THIS FILE IS AUTOGENERATED - DO NOT EDIT */\n \n "
43
- IGNORED_WARNING_LIST = ['non_camel_case_types' , 'non_upper_case_globals' , 'unused_imports' ,
43
+ ALLOWED_WARNING_LIST = ['non_camel_case_types' , 'non_upper_case_globals' , 'unused_imports' ,
44
44
'unused_variables' , 'unused_assignments' , 'unused_mut' ,
45
45
'clippy::approx_constant' , 'clippy::let_unit_value' , 'clippy::needless_return' ,
46
- 'clippy::too_many_arguments' , 'clippy::unnecessary_cast' ]
47
- IGNORED_WARNINGS = f"#![allow({ ',' .join (IGNORED_WARNING_LIST )} )]\n \n "
46
+ 'clippy::too_many_arguments' , 'clippy::unnecessary_cast' , 'clippy::upper_case_acronyms' ]
47
+ ALLOWED_WARNINGS = f"#![allow({ ',' .join (ALLOWED_WARNING_LIST )} )]\n \n "
48
48
49
49
FINALIZE_HOOK_NAME = '_finalize'
50
50
TRACE_HOOK_NAME = '_trace'
@@ -1402,14 +1402,16 @@ def __init__(self, argument, index, args, argc, descriptorProvider,
1402
1402
innerConverter .append (CGGeneric ("%s.push(slot);" % arg ))
1403
1403
inner = CGIndenter (CGList (innerConverter , "\n " ), 8 ).define ()
1404
1404
1405
+ sub = "" if index == 0 else "- %s" % index
1406
+
1405
1407
self .converter = CGGeneric ("""\
1406
1408
%(init)s;
1407
1409
if %(argc)s > %(index)s {
1408
- %(arg)s.reserve(%(argc)s as usize - %(index )s);
1410
+ %(arg)s.reserve(%(argc)s as usize%(sub )s);
1409
1411
for variadicArg in %(index)s..%(argc)s {
1410
1412
%(inner)s
1411
1413
}
1412
- }""" % {'arg' : arg , 'argc' : argc , 'index' : index , 'inner' : inner , 'init' : init })
1414
+ }""" % {'arg' : arg , 'argc' : argc , 'index' : index , 'inner' : inner , 'init' : init , 'sub' : sub })
1413
1415
1414
1416
def define (self ):
1415
1417
return self .converter .define ()
@@ -2564,8 +2566,11 @@ def __len__(self):
2564
2566
2565
2567
class CGIfElseWrapper (CGList ):
2566
2568
def __init__ (self , condition , ifTrue , ifFalse ):
2567
- kids = [CGIfWrapper (condition , ifTrue ),
2568
- CGWrapper (CGIndenter (ifFalse ), pre = " else {\n " , post = "\n }" )]
2569
+ if ifFalse .text .strip ().startswith ("if" ):
2570
+ elseBranch = CGWrapper (ifFalse , pre = " else " )
2571
+ else :
2572
+ elseBranch = CGWrapper (CGIndenter (ifFalse ), pre = " else {\n " , post = "\n }" )
2573
+ kids = [CGIfWrapper (condition , ifTrue ), elseBranch ]
2569
2574
CGList .__init__ (self , kids )
2570
2575
2571
2576
@@ -2758,6 +2763,15 @@ def define(self):
2758
2763
if self .returnType == "void" :
2759
2764
pre = "wrap_panic(&mut || {\n "
2760
2765
post = "\n })"
2766
+ elif "return" not in body .define ():
2767
+ pre = (
2768
+ "let mut result = false;\n "
2769
+ "wrap_panic(&mut || result = {\n "
2770
+ )
2771
+ post = (
2772
+ "\n });\n "
2773
+ "result"
2774
+ )
2761
2775
else :
2762
2776
pre = (
2763
2777
"let mut result = false;\n "
@@ -3225,7 +3239,7 @@ def definition_body(self):
3225
3239
if !get_${name}(cx, obj, this, JSJitGetterCallArgs { _base: temp.handle_mut().into() }) {
3226
3240
return false;
3227
3241
}
3228
- if !JS_DefineProperty(cx, result.handle().into() ,
3242
+ if !JS_DefineProperty(cx, result.handle(),
3229
3243
${nameAsArray} as *const u8 as *const libc::c_char,
3230
3244
temp.handle(), JSPROP_ENUMERATE as u32) {
3231
3245
return false;
@@ -6125,7 +6139,7 @@ def definition_body(self):
6125
6139
constructorCall = CGGeneric ("""dom::bindings::htmlconstructor::call_html_constructor::<dom::types::%s>(
6126
6140
cx,
6127
6141
&args,
6128
- &* global,
6142
+ &global,
6129
6143
PrototypeList::ID::%s,
6130
6144
CreateInterfaceObjects,
6131
6145
)""" % (self .descriptor .name , MakeNativeName (self .descriptor .name )))
@@ -6947,7 +6961,7 @@ def __init__(self, config, prefix, webIDLFile):
6947
6961
imports = ['crate::dom::bindings::import::base::*' ], config = config )
6948
6962
6949
6963
# Add the auto-generated comment.
6950
- curr = CGWrapper (curr , pre = AUTOGENERATED_WARNING_COMMENT + IGNORED_WARNINGS )
6964
+ curr = CGWrapper (curr , pre = AUTOGENERATED_WARNING_COMMENT + ALLOWED_WARNINGS )
6951
6965
6952
6966
# Store the final result.
6953
6967
self .root = curr
@@ -7294,9 +7308,8 @@ def __init__(self, sig, name, descriptorProvider, needThisHandling):
7294
7308
# Check for variadic arguments
7295
7309
lastArg = args [self .argCount - 1 ]
7296
7310
if lastArg .variadic :
7297
- argCount = "0" if self .argCount == 1 else f"({ self .argCount } - 1)"
7298
7311
self .argCountStr = (
7299
- "%s + %s.len()" % (argCount , lastArg .identifier .name ))
7312
+ "%s + %s.len()" % (self . argCount - 1 , lastArg .identifier .name )). removeprefix ( "0 + " )
7300
7313
else :
7301
7314
self .argCountStr = "%d" % self .argCount
7302
7315
self .needThisHandling = needThisHandling
@@ -7397,15 +7410,15 @@ def getArgConversion(self, i, arg):
7397
7410
else :
7398
7411
jsvalIndex = "%d" % i
7399
7412
if arg .optional and not arg .defaultValue :
7400
- argval += ".clone(). unwrap()"
7413
+ argval += ".unwrap()"
7401
7414
7402
7415
conversion = wrapForType (
7403
7416
"argv_root.handle_mut()" , result = argval ,
7404
7417
successCode = ("{\n "
7405
7418
"let arg = &mut argv[%s];\n "
7406
7419
"*arg = Heap::default();\n "
7407
7420
"arg.set(argv_root.get());\n "
7408
- "}" ) % jsvalIndex ,
7421
+ "}" ) % jsvalIndex . removeprefix ( "0 + " ) ,
7409
7422
pre = "rooted!(in(*cx) let mut argv_root = UndefinedValue());" )
7410
7423
if arg .variadic :
7411
7424
conversion = string .Template (
@@ -7612,14 +7625,14 @@ def __init__(self, descriptor, likeable, methodName):
7612
7625
elif methodName in ["size" , "clear" ]: # zero arguments
7613
7626
CGGeneric .__init__ (self , fill (
7614
7627
"""
7615
- let result = ${trt}::${method}(&* this);
7628
+ let result = ${trt}::${method}(this);
7616
7629
""" ,
7617
7630
trt = trait ,
7618
7631
method = methodName .lower ()))
7619
7632
elif methodName == "add" : # special case one argumet
7620
7633
CGGeneric .__init__ (self , fill (
7621
7634
"""
7622
- ${trt}::${method}(&* this, arg0);
7635
+ ${trt}::${method}(this, arg0);
7623
7636
// Returns itself per https://webidl.spec.whatwg.org/#es-set-add
7624
7637
let result = this;
7625
7638
""" ,
@@ -7628,14 +7641,14 @@ def __init__(self, descriptor, likeable, methodName):
7628
7641
elif methodName in ["has" , "delete" , "get" ]: # one argument
7629
7642
CGGeneric .__init__ (self , fill (
7630
7643
"""
7631
- let result = ${trt}::${method}(&* this, arg0);
7644
+ let result = ${trt}::${method}(this, arg0);
7632
7645
""" ,
7633
7646
trt = trait ,
7634
7647
method = methodName ))
7635
7648
elif methodName == "set" : # two arguments
7636
7649
CGGeneric .__init__ (self , fill (
7637
7650
"""
7638
- ${trt}::${method}(&* this, arg0, arg1);
7651
+ ${trt}::${method}(this, arg0, arg1);
7639
7652
// Returns itself per https://webidl.spec.whatwg.org/#es-map-set
7640
7653
let result = this;
7641
7654
""" ,
@@ -7663,7 +7676,7 @@ def __init__(self, descriptor, iterable, methodName):
7663
7676
rooted!(in(*cx) let arg0 = ObjectValue(arg0));
7664
7677
rooted!(in(*cx) let mut call_arg1 = UndefinedValue());
7665
7678
rooted!(in(*cx) let mut call_arg2 = UndefinedValue());
7666
- let mut call_args = vec! [UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)];
7679
+ let mut call_args = [UndefinedValue(), UndefinedValue(), ObjectValue(*_obj)];
7667
7680
rooted!(in(*cx) let mut ignoredReturnVal = UndefinedValue());
7668
7681
7669
7682
// This has to be a while loop since get_iterable_length() may change during
@@ -7694,7 +7707,7 @@ def __init__(self, descriptor, iterable, methodName):
7694
7707
return
7695
7708
CGGeneric .__init__ (self , fill (
7696
7709
"""
7697
- let result = ${iterClass}::new(&* this, IteratorType::${itrMethod});
7710
+ let result = ${iterClass}::new(this, IteratorType::${itrMethod});
7698
7711
""" ,
7699
7712
iterClass = iteratorNativeType (descriptor , True ),
7700
7713
ifaceName = descriptor .interface .identifier .name ,
0 commit comments