Skip to content

Commit c782f8d

Browse files
committed
Minor webidl binder fixes
Split out from #21151. The only semantic change here is the fix the type of second argument to to the array member getter function (previously it was using `m.type` which is the array type itself, but that second argument to the setter function is actually the inner type `m.type.inner`. This enables the type of this argument to be checked correctly, which in turn required a minor fix to the test case. This only effects `IDL_CHECKS=all` builds.
1 parent 50a7531 commit c782f8d

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

test/webidl/post.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ console.log('int_array[0] == ' + arrayClass.get_int_array(0));
186186
console.log('int_array[7] == ' + arrayClass.get_int_array(7));
187187

188188
try {
189-
arrayClass.set_int_array(-1, struct);
189+
arrayClass.set_int_array(-1, 42);
190190
} catch (e) {
191191
console.log('idx -1: ' + e);
192192
}
193193

194194
try {
195-
arrayClass.set_int_array(8, struct);
195+
arrayClass.set_int_array(8, 42);
196196
} catch (e) {
197197
console.log('idx 8: ' + e);
198198
}
@@ -270,7 +270,7 @@ if (isMemoryGrowthAllowed) {
270270
intArray = intArray.concat(intArray);
271271
storeArray.setArray(intArray);
272272
}
273-
273+
274274
// Make sure the array was copied to the newly allocated HEAP
275275
var numCopiedEntries = 0;
276276
for (var i = 0; i < intArray.length; i++) {

tools/webidl_binder.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,24 @@
3232
# DEBUG=1 will print debug info in render_function
3333
DEBUG = os.environ.get('IDL_VERBOSE') == '1'
3434

35-
if DEBUG:
36-
print(f'Debug print ON, CHECKS=${CHECKS}')
35+
36+
def dbg(*args):
37+
if DEBUG:
38+
print(*args, file=sys.stderr)
39+
40+
41+
dbg(f'Debug print ON, CHECKS=${CHECKS}')
3742

3843
# We need to avoid some closure errors on the constructors we define here.
3944
CONSTRUCTOR_CLOSURE_SUPPRESSIONS = '/** @suppress {undefinedVars, duplicate} @this{Object} */'
4045

4146

4247
class Dummy:
43-
def __init__(self, init):
44-
for k, v in init.items():
45-
self.__dict__[k] = v
48+
def __init__(self, type):
49+
self.type = type
50+
51+
def __repr__(self):
52+
return f'<Dummy type:{self.type}>'
4653

4754
def getExtendedAttribute(self, _name):
4855
return None
@@ -392,13 +399,12 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer,
392399
all_args = sigs.get(max_args)
393400

394401
if DEBUG:
395-
print('renderfunc', class_name, func_name, list(sigs.keys()), return_type, constructor)
396-
for i in range(max_args):
397-
a = all_args[i]
402+
dbg('renderfunc', class_name, func_name, list(sigs.keys()), return_type, constructor)
403+
for i, a in enumerate(all_args):
398404
if isinstance(a, WebIDL.IDLArgument):
399-
print(' ', a.identifier.name, a.identifier, a.type, a.optional)
405+
dbg(' ', a.identifier.name, a.identifier, a.type, a.optional)
400406
else:
401-
print(' arg%d' % i)
407+
dbg(' arg%d (%s)' % (i, a))
402408

403409
# JS
404410

@@ -726,9 +732,9 @@ def add_bounds_check_impl():
726732
attr = m.identifier.name
727733

728734
if m.type.isArray():
729-
get_sigs = {1: [Dummy({'type': WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]})]}
730-
set_sigs = {2: [Dummy({'type': WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]}),
731-
Dummy({'type': m.type})]}
735+
get_sigs = {1: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long])]}
736+
set_sigs = {2: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]),
737+
Dummy(type=m.type.inner)]}
732738
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr + '[arg0]'
733739
set_call_content = 'self->' + attr + '[arg0] = ' + deref_if_nonpointer(m) + 'arg1'
734740
if m.getExtendedAttribute('BoundsChecked'):
@@ -740,7 +746,7 @@ def add_bounds_check_impl():
740746
set_call_content = "(%s, %s)" % (bounds_check, set_call_content)
741747
else:
742748
get_sigs = {0: []}
743-
set_sigs = {1: [Dummy({'type': m.type})]}
749+
set_sigs = {1: [Dummy(type=m.type)]}
744750
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr
745751
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
746752

0 commit comments

Comments
 (0)