GNOME Bugzilla – Bug 774663
Handle static "constructor" methods better
Last modified: 2016-11-18 08:16:46 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
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 ***