| 405 | == `[CustomBinding]` == #CustomBinding |
| 406 | |
| 407 | Summary: They allow you to write bindings code even more manually than `[Custom]`. |
| 408 | |
| 409 | Usage: `[CustomBinding]` can be specified only on methods: |
| 410 | {{{ |
| 411 | [CustomBinding] void myMethod(); |
| 412 | }}} |
| 413 | |
| 414 | We should minimize the number of custom bindings as much as possible, since they are likely to be buggy. |
| 415 | Before using `[CustomBinding]`, you should doubly consider if you really need custom bindings. |
| 416 | You are recommended to modify code generators to avoid using `[CustomBinding]`. |
| 417 | |
| 418 | Before explaining the details, let us clarify the relationship of these IDL attributes. |
| 419 | |
| 420 | * `[CustomBinding]` on a method indicates that you can write JavaScriptCore custom bindings for the method at a higher level than `[Custom]`. |
| 421 | |
| 422 | You can write custom bindings with JavaScriptCore for a method as follows: |
| 423 | |
| 424 | {{{ |
| 425 | interface XXX { |
| 426 | [CustomBinding] void myMethod(int a, int b); |
| 427 | }; |
| 428 | }}} |
| 429 | You can write custom bindings in WebCore/bindings/js/JSXXXCustom.cpp: |
| 430 | {{{ |
| 431 | EncodedJSValue JSC_HOST_CALL jsXXXPrototypeFunctionMyMethod(ExecState*) |
| 432 | { |
| 433 | // Read parameters manually if any. |
| 434 | // Get the called object from the ExecState if needed and wanted. |
| 435 | // Call the object and implementation if needed and wanted. |
| 436 | // Return a value. |
| 437 | return JSValue::encode(...); |
| 438 | } |
| 439 | }}} |
| 440 | Refer to WebCore/bindings/js/JSXXXCustom.cpp for more details. |
| 441 | |
| 442 | The main difference between `[Custom]` and `[CustomBinding]` is that `[Custom]` generates a `jsXXXPrototypeFunctionMyMethod` where it performs the parameters management, casting to the object and calls the `JSXXX::myMethod` with the parameters and the instance. With `[CustomBinding]`, the implementation of `jsXXXPrototypeFunctionMyMethod` is not done automatically and it is up to the developer to do all the parameter, casting and call operations. |
| 443 | |
| 444 | Note: ObjC, GObject and CPP bindings do not support `[CustomBinding]` bindings. |
| 445 | |