Skip to content

Commit

Permalink
Minor webidl binder fixes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbc100 committed Jan 24, 2024
1 parent 50a7531 commit c782f8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions test/webidl/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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++) {
Expand Down
34 changes: 20 additions & 14 deletions tools/webidl_binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<Dummy type:{self.type}>'

def getExtendedAttribute(self, _name):
return None
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'):
Expand All @@ -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'

Expand Down

0 comments on commit c782f8d

Please sign in to comment.