After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 774663 - Handle static "constructor" methods better
Handle static "constructor" methods better
Status: RESOLVED DUPLICATE of bug 686864
Product: gjs
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gjs-maint
gjs-maint
Depends on:
Blocks:
 
 
Reported: 2016-11-18 07:18 UTC by Philip Chimento
Modified: 2016-11-18 08:16 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Philip Chimento 2016-11-18 07:18:05 UTC
Some binding-unfriendly C APIs will have a `something_something_new(param)` constructor without a matching property for param. This can be quite confusing and pose pitfalls for unsuspecting developers. An example from Stack Overflow [1] is this script that segfaults when you right-click on the webview:

const Gtk = imports.gi.Gtk;
const WebKit2 = imports.gi.WebKit2;
Gtk.init(null);
let win = new Gtk.Window();
let view = new WebKit2.WebView();
win.add(view);
win.connect('destroy', Gtk.main_quit);
view.connect('context-menu', (view, c_menu, event, hit_test) => {
    var action = new Gtk.Action({
        name: 'some_name',
        label: 'Some Label',
    });
    action.connect('activate', () => {
        print("Your Menu Item !");
    });

    c_menu.append(new WebKit2.ContextMenuItem(action));
    return false;
});
win.show_all();
Gtk.main();

The proper invocation would be c_menu.append(WebKit2.ContextMenuItem.new(action)).

This example is kind of a perfect storm because 1) the static method has one argument and it's an object, so the JS constructor doesn't bail out, and 2) WebKit deals really badly with the badly constructed object.

Should we mandate that the props hash passed into the JS constructor is a plain JS object and not a GObject?

[1] http://stackoverflow.com/q/40401664/172999
Comment 1 Philip Chimento 2016-11-18 08:16:46 UTC
Found it was a duplicate, as I was searching through the old bugs in the bug tracker for November Bug Squash Month...

*** This bug has been marked as a duplicate of bug 686864 ***