Skip to content

Commit

Permalink
fix: vfunc not found
Browse files Browse the repository at this point in the history
  • Loading branch information
romgrk committed Dec 22, 2023
1 parent 6583bb9 commit c040f8d
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 100 deletions.
49 changes: 24 additions & 25 deletions lib/register-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,14 @@ function setupVirtualFunctions(klass, klassGtype, parentGtype) {
}

function findVFunc(gtype, parentInfo, name) {
let [vfuncInfo, _] = findVFuncOnParents(parentInfo, name)
let vfuncInfo = findVFuncOnParents(parentInfo, name)
if (!vfuncInfo) {
vfuncInfo = findVFuncOnInterfaces(gtype, name)
// definedByParent = false
}
return vfuncInfo
}

function findVFuncOnParents(info, name) {
let definedByParent = false;

let parent = info

/* Since it isn't possible to override a vfunc on
Expand All @@ -91,15 +88,32 @@ function findVFuncOnParents(info, name) {
let [vfunc, _] =
GI.object_info_find_vfunc_using_interfaces(parent, name, null)

do {
if (parent)
vfunc = GI.object_info_find_vfunc(info, name)
if (vfunc) {
return vfunc
}

while (parent) {
vfunc = GI.object_info_find_vfunc(info, name)

if (vfunc) {
return vfunc
}

/* HACK: object_info_find_vfunc sometimes fail, so we also search for
* the matching entry manually. */
const n = GI.object_info_get_n_vfuncs(parent)
for (let i = 0; i < n; i++) {
const vfunc = GI.object_info_get_vfunc(parent, i)
const currentName = GI.BaseInfo_get_name.call(vfunc)
if (currentName === name) {
return vfunc
}
}

parent = GI.object_info_get_parent(parent)
definedByParent = true
} while (!vfunc && parent)
}

return [vfunc, definedByParent]
return null
}

function findVFuncOnInterfaces(gtype, name) {
Expand Down Expand Up @@ -163,18 +177,3 @@ function createGTypeName(klass) {
function sanitizeGType(s) {
return s.replace(/[^a-z0-9+_-]/gi, '_');
}

function getParents(klass) {
const parents = []

let current = klass
do {
let proto = Object.getPrototypeOf(current.prototype)
current = proto ? proto.constructor : null
if (!current)
break
parents.push(current)
} while (current)

return parents
}
176 changes: 101 additions & 75 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c040f8d

Please sign in to comment.