GNOME Bugzilla – Bug 686864
object_instance_props_to_g_parameters should do more check on argv
Last modified: 2018-01-27 11:51:21 UTC
I just wasted one day of my life debugging a very weird bug in some js code. Turned out I wrote "new Clutter.BindConstraint(stage, Clutter.BindCoordinate.SIZE, 0);" instead of "Clutter.BindConstraint.new(stage, Clutter.BindCoordinate.SIZE, 0);" (yeah I suck at Javascript...). All this pain could have been avoided if gjs would have raised an exception rather than silently accepting invalid arguments. object_instance_props_to_g_parameters should raise an exception if: - argc > 1 - argv[0] is not dictionnary
Well, we do allow more parameters than requested everywhere else (as that's the standard JS convention), and we have no way to check if an object is a "dictionary" or not (other than checking for __proto__ == Object.prototype, but it looks wrong to me).
(In reply to comment #1) > Well, we do allow more parameters than requested everywhere else (as that's the > standard JS convention) Note that it's probably worthwhile to exclude it otherwise. This is being revisited for ES.next and having explicit rest parameters and splat instead.
(In reply to comment #1) > Well, we do allow more parameters than requested everywhere else (as that's the > standard JS convention), What's the rationale for this? This sounds like the perfect way to shoot yourself in the foot. > and we have no way to check if an object is a > "dictionary" or not (other than checking for __proto__ == Object.prototype, but > it looks wrong to me). I'm sure JS can't be that retarded. What's wrong with checking __proto__ exactly?
(In reply to comment #3) > (In reply to comment #1) > > Well, we do allow more parameters than requested everywhere else (as that's the > > standard JS convention), > > What's the rationale for this? This sounds like the perfect way to shoot > yourself in the foot. For ECMAScript in general? A lack of actual syntax for actual varadiac parameters. I think it's the right thing to violate JS convention here. > > and we have no way to check if an object is a > > "dictionary" or not (other than checking for __proto__ == Object.prototype, but > > it looks wrong to me). > > I'm sure JS can't be that retarded. What's wrong with checking __proto__ > exactly? I think we've had cases before where we pass actual instances of classes to initializers to use them as property bags.
*** Bug 774663 has been marked as a duplicate of this bug. ***
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gjs/issues/63.