You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
WebIDL Binder: Add 'BindTo' extended attribute to pick the called function (#22779)
This attribute can be used to change the C++ function that will be
called. It can be used expose functions that have multiple overloads
with the same number of parameters.
Example:
// C++
class BindToTest {
public:
int test(const char*) { return 1; }
int test(int) { return 2; }
};
// WebIDL
interface BindToTest {
void BindToTest();
[BindTo="test"] long testString([Const] DOMString arg);
[BindTo="test"] long testInt(long arg);
};
Copy file name to clipboardExpand all lines: site/source/docs/porting/connecting_cpp_and_javascript/WebIDL-Binder.rst
+49Lines changed: 49 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -416,6 +416,55 @@ When C++ code has a pointer to a ``Base`` instance and calls ``virtualFunc()``,
416
416
- You *must* implement all the methods you mentioned in the IDL of the ``JSImplementation`` class (``ImplJS``) or compilation will fail with an error.
417
417
- You will also need to provide an interface definition for the ``Base`` class in the IDL file.
418
418
419
+
Function overloads
420
+
==================
421
+
422
+
C++ allows function overloads, where multiple member functions have the same name but different arguments. By default, the *WebIDL Binder* allows you to bind overloaded functions if they differ only in the number of arguments:
423
+
424
+
.. code-block:: cpp
425
+
426
+
// C++
427
+
class OverloadTest {
428
+
public:
429
+
void test(int arg1, int arg2) { ... }
430
+
void test(int arg) { ... }
431
+
};
432
+
433
+
.. code-block:: idl
434
+
435
+
// WebIDL
436
+
interface OverloadTest {
437
+
void OverloadTest();
438
+
void test(long arg1, long arg2);
439
+
void test(long arg);
440
+
};
441
+
442
+
If your overloaded functions differ in some other way (say, in the types) then you can use the ``[BindTo]`` attribute to tell the tool what function name to bind to (that is, to call):
0 commit comments