Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor webidl binder fixes #21152

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator Author

@sbc100 sbc100 Jan 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change this check would now report the bad type error rather than the "index out of range" error which is checked for later on.

} 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