Open Bug 763860 Opened 12 years ago Updated 2 years ago

xpidl needs to reject overloaded methods in scriptable interfaces even if the first letter is different case

Categories

(Core :: XPCOM, defect)

defect

Tracking

()

People

(Reporter: ayg, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(3 files)

See bug 762841.  Attachment 631846 [details] [diff] there did

     nsISelection getSelection(in short type);
+    [noscript,notxpcom,nostdcall] Selection GetSelection(in short type);

When I wrote "getSelection" for the second method, it complained that there was a naming conflict, but when I capitalized it, it worked happily.  But then it broke horribly on Windows, because the generated C++ methods had the same name and that breaks on Windows for scriptable interfaces for some reason.  The parser should refuse to do this.
It breaks on windows for any interface if you call it through XPConnect, because MSVC will reorder the members in some cases and then the vtable info XPConnect no longer matches the actual vtable.
Boris, does that apply to overloaded methods only?
or can that error occur for any [noscript,notxpcom,nostdcall]
method in a scriptable interface?
That applies to overloaded methods.
Note that if all of the overloaded methods are noscript/notxpcom (whichever makes them impossible to get called through xpconnect) this should be fine...  Although I personally wouldn't go through the trouble of special casing that!
(In reply to Boris Zbarsky (:bz) from comment #1)
> It breaks on windows for any interface if you call it through XPConnect,
> because MSVC will reorder the members in some cases and then the vtable info
> XPConnect no longer matches the actual vtable.

Is that the case also if we use two separate classes?

If we generate the scriptable class with a different name:

class NS_NO_VTABLE NS_SCRIPTABLE nsISelectionControllerScriptable 
  : public nsISelectionDisplay {
   ... IDL stuff ...
};

and then declare the internal type like so:

class NS_NO_VTABLE nsISelectionController
  : public nsISelectionControllerScriptable {
 public: 
  using nsISelectionControllerS::GetSelection;
  virtual already_AddRefed<mozilla::Selection> GetSelection(PRInt16 type) = 0;
};


I tested this briefly on Linux and Win7 and it seemed to work...
> Is that the case also if we use two separate classes?

No, that can't be reordered, because the superclass vtable needs to not include the subclass methods.
This patch implements a 'separate_scriptable_name' interface attribute
that generates a separate class with the name given name and only
includes scriptable methods/attributes and constants in that class.
The non-scriptable stuff goes into a sub-class.
I've also added a 'overloaded' method attribute to indicate an
scriptable/non-scriptable overloaded method (to generate the
"using ..." bit), but this is probably redundant since it can be
deduced from the internal method table I think.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: