Skip to content

Commit 267c95f

Browse files
committed
Minor webidl binder fixes
Split out from emscripten-core#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 267c95f

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-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: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,22 @@
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+
def dbg(*args):
36+
if DEBUG:
37+
print(*args, file=sys.stderr)
38+
39+
dbg(f'Debug print ON, CHECKS=${CHECKS}')
3740

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

4144

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

4752
def getExtendedAttribute(self, _name):
4853
return None
@@ -392,13 +397,12 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer,
392397
all_args = sigs.get(max_args)
393398

394399
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]
400+
dbg('renderfunc', class_name, func_name, list(sigs.keys()), return_type, constructor)
401+
for i, a in enumerate(all_args):
398402
if isinstance(a, WebIDL.IDLArgument):
399-
print(' ', a.identifier.name, a.identifier, a.type, a.optional)
403+
dbg(' ', a.identifier.name, a.identifier, a.type, a.optional)
400404
else:
401-
print(' arg%d' % i)
405+
dbg(' arg%d (%s)' % (i, a))
402406

403407
# JS
404408

@@ -726,9 +730,9 @@ def add_bounds_check_impl():
726730
attr = m.identifier.name
727731

728732
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})]}
733+
get_sigs = {1: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long])]}
734+
set_sigs = {2: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]),
735+
Dummy(type=m.type.inner)]}
732736
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr + '[arg0]'
733737
set_call_content = 'self->' + attr + '[arg0] = ' + deref_if_nonpointer(m) + 'arg1'
734738
if m.getExtendedAttribute('BoundsChecked'):
@@ -740,7 +744,7 @@ def add_bounds_check_impl():
740744
set_call_content = "(%s, %s)" % (bounds_check, set_call_content)
741745
else:
742746
get_sigs = {0: []}
743-
set_sigs = {1: [Dummy({'type': m.type})]}
747+
set_sigs = {1: [Dummy(type=m.type)]}
744748
get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr
745749
set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'
746750

0 commit comments

Comments
 (0)