From cf909d38a704fe52b0e8f297fe08d332684478db Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 24 Jan 2024 18:50:37 +0000 Subject: [PATCH] Minor webidl binder fixes (#21152) 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. --- test/webidl/post.js | 6 +++--- tools/webidl_binder.py | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/test/webidl/post.js b/test/webidl/post.js index ed08f6c5bd73..cb76024ad3d7 100644 --- a/test/webidl/post.js +++ b/test/webidl/post.js @@ -186,13 +186,13 @@ console.log('int_array[0] == ' + arrayClass.get_int_array(0)); console.log('int_array[7] == ' + arrayClass.get_int_array(7)); try { - arrayClass.set_int_array(-1, struct); + arrayClass.set_int_array(-1, 42); } catch (e) { console.log('idx -1: ' + e); } try { - arrayClass.set_int_array(8, struct); + arrayClass.set_int_array(8, 42); } catch (e) { console.log('idx 8: ' + e); } @@ -270,7 +270,7 @@ if (isMemoryGrowthAllowed) { intArray = intArray.concat(intArray); storeArray.setArray(intArray); } - + // Make sure the array was copied to the newly allocated HEAP var numCopiedEntries = 0; for (var i = 0; i < intArray.length; i++) { diff --git a/tools/webidl_binder.py b/tools/webidl_binder.py index 0996e5a13fbd..16bc5520cf2a 100644 --- a/tools/webidl_binder.py +++ b/tools/webidl_binder.py @@ -32,17 +32,24 @@ # DEBUG=1 will print debug info in render_function DEBUG = os.environ.get('IDL_VERBOSE') == '1' -if DEBUG: - print(f'Debug print ON, CHECKS=${CHECKS}') + +def dbg(*args): + if DEBUG: + print(*args, file=sys.stderr) + + +dbg(f'Debug print ON, CHECKS=${CHECKS}') # We need to avoid some closure errors on the constructors we define here. CONSTRUCTOR_CLOSURE_SUPPRESSIONS = '/** @suppress {undefinedVars, duplicate} @this{Object} */' class Dummy: - def __init__(self, init): - for k, v in init.items(): - self.__dict__[k] = v + def __init__(self, type): + self.type = type + + def __repr__(self): + return f'' def getExtendedAttribute(self, _name): return None @@ -392,13 +399,12 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer, all_args = sigs.get(max_args) if DEBUG: - print('renderfunc', class_name, func_name, list(sigs.keys()), return_type, constructor) - for i in range(max_args): - a = all_args[i] + dbg('renderfunc', class_name, func_name, list(sigs.keys()), return_type, constructor) + for i, a in enumerate(all_args): if isinstance(a, WebIDL.IDLArgument): - print(' ', a.identifier.name, a.identifier, a.type, a.optional) + dbg(' ', a.identifier.name, a.identifier, a.type, a.optional) else: - print(' arg%d' % i) + dbg(' arg%d (%s)' % (i, a)) # JS @@ -726,9 +732,9 @@ def add_bounds_check_impl(): attr = m.identifier.name if m.type.isArray(): - get_sigs = {1: [Dummy({'type': WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]})]} - set_sigs = {2: [Dummy({'type': WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]}), - Dummy({'type': m.type})]} + get_sigs = {1: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long])]} + set_sigs = {2: [Dummy(type=WebIDL.BuiltinTypes[WebIDL.IDLBuiltinType.Types.long]), + Dummy(type=m.type.inner)]} get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr + '[arg0]' set_call_content = 'self->' + attr + '[arg0] = ' + deref_if_nonpointer(m) + 'arg1' if m.getExtendedAttribute('BoundsChecked'): @@ -740,7 +746,7 @@ def add_bounds_check_impl(): set_call_content = "(%s, %s)" % (bounds_check, set_call_content) else: get_sigs = {0: []} - set_sigs = {1: [Dummy({'type': m.type})]} + set_sigs = {1: [Dummy(type=m.type)]} get_call_content = take_addr_if_nonpointer(m) + 'self->' + attr set_call_content = 'self->' + attr + ' = ' + deref_if_nonpointer(m) + 'arg0'