660 | | === * [CustomConstructor](i), [JSCustomConstructor](i), [V8CustomConstructor](i) === |
| 661 | * [http://dev.w3.org/2006/webapi/WebIDL/#NamedConstructor The spec of NamedConstructor] |
| 662 | |
| 663 | Summary: If the interface name XXX and "new YYY()" name are different (i.e. XXX != YYY), you can use [NamedConstructor]. |
| 664 | |
| 665 | Usage: The possible usage of [NamedConstructor] is [NamedConstructor=YYY]. |
| 666 | [NamedConstructor] can be specified on interfaces: |
| 667 | {{{ |
| 668 | interface [ |
| 669 | NamedConstructor=Audio() |
| 670 | ] HTMLAudioElement { |
| 671 | } |
| 672 | }}} |
| 673 | |
| 674 | The semantics is the same as [Constructor], except that JavaScript can make a DOM object not by "new HTMLAudioElement(...)" but by "Audio()". |
| 675 | |
| 676 | Whether you should allow an interface to have a named constructor depends on the spec of the interface. |
| 677 | |
| 678 | === * [CustomConstructor](i), [JSCustomConstructor](i), [V8CustomConstructor](i), [ConstructorParameters](i) === |
| 679 | |
| 680 | Summary: They allow to write custom bindings for constructors. |
| 681 | |
| 682 | Usage: They can specified on interfaces. |
| 683 | Regarding [ConstructorParameters], the possible usage is [ConstructorParameters=X], where X is the maximum number of arguments of the constructor: |
| 684 | {{{ |
| 685 | interface [ |
| 686 | CustomConstructor, |
| 687 | ConstractorParameters=4 |
| 688 | ] XXX { |
| 689 | } |
| 690 | }}} |
| 691 | |
| 692 | We should minimize the number of custom bindings as less as possible. |
| 693 | Before using [CustomConstructor], you should doubly consider if you really need custom bindings. |
| 694 | You are recommended to modify code generators to avoid using [Custom]. |
| 695 | |
| 696 | Before explaining the details, let us clarify the relationship of these IDL attributes. |
| 697 | |
| 698 | * [JSCustomConstructor] on an interface indicates that you want to write JavaScriptCore custom bindings for the constructor. |
| 699 | * [V8CustomConstructor] on an interface indicates that you want to write V8 custom bindings for the constructor. |
| 700 | * [CustomConstructor] is equivalent to [JSCustomConstructor] and [V8CustomConstructor]. |
| 701 | |
| 702 | For example, if you specify [Constructor, JSCustomConstructor], |
| 703 | then the constructor is generated only for V8 and you need to write JavaScriptCore custom bindings for the constructor. |
| 704 | |
| 705 | How to write custom bindings are different between JavaScriptCore and V8. |
| 706 | |
| 707 | * JavaScriptCore |
| 708 | Consider the following example: |
| 709 | {{{ |
| 710 | interface [ |
| 711 | CustomConstructor, |
| 712 | ConstructorParameters=2 |
| 713 | ] XXX { |
| 714 | } |
| 715 | }}} |
| 716 | You need to prepare WebCore/bindings/js/JSXXXCustom.cpp and write custom bindings: |
| 717 | {{{ |
| 718 | EncodedJSValue JSC_HOST_CALL JSXXXConstructor::constructJSSharedWorker(ExecState* exec) |
| 719 | { |
| 720 | ...; |
| 721 | } |
| 722 | }}} |
| 723 | Refer to WebCore/bindings/js/JSXXXCustom.cpp for more details. |
| 724 | |
| 725 | * V8 |
| 726 | Consider the following example: |
| 727 | {{{ |
| 728 | interface [ |
| 729 | CustomConstructor, |
| 730 | ConstructorParameters=2 |
| 731 | ] XXX { |
| 732 | } |
| 733 | }}} |
| 734 | You need to prepare WebCore/bindings/v8/custom/V8XXXConstructor.cpp and write custom bindings: |
| 735 | {{{ |
| 736 | v8::Handle<v8::Value> V8XXX::constructorCallback(const v8::Arguments& args) |
| 737 | { |
| 738 | ...; |
| 739 | } |
| 740 | }}} |
| 741 | Refer to WebCore/bindings/v8/custom/V8XXXConstructor.cpp for more details. |
| 742 | |
| 743 | X of [ConstructorParameters=X] is the maximum number of arguments, including optional arguments. |
| 744 | For example, if the constructor signature is [Constructor(in int a, in int b, in [Optional] int c, in [Optional] int d)], then X is 4. |
| 745 | You do not need to specify [ConstructorParameters] if the interface does not have any of [JSCustomConstructor], [V8CustomConstructor] or [CustomConstructor]. |
| 749 | Summary: It inserts "#if ENABLE(SOME_FLAG) ... #endif" into the generated code. |
| 750 | |
| 751 | Usage: It can be specified on interfaces, methods and attributes: |
| 752 | {{{ |
| 753 | interface [ |
| 754 | Conditional=INDEXED_DATABASE |
| 755 | ] XXX { |
| 756 | } |
| 757 | }}} |
| 758 | {{{ |
| 759 | interface XXX { |
| 760 | attribute [Conditional=INDEXED_DATABASE] DOMString str; |
| 761 | [Conditional=INDEXED_DATABASE] void open(); |
| 762 | } |
| 763 | }}} |
| 764 | |
| 765 | [Conditional] is used to enable/disable the generated code based on the flag. |
| 766 | If the flag is enabled, the generated code is compiled. Otherwise, the generated code is not compiled. |
| 767 | Whether a flag is enabled or disabled is controlled by Tools/Scripts/build-webkit. |
| 768 | |
| 769 | If [Conditional] is specified on an interface, it means that [Conditional] is specified on all attributes and methods on the interface. |
| 770 | |
| 773 | Summary: In Chromium/V8, we can enable/disable a flag at runtime. |
| 774 | |
| 775 | Usage: The possible usage is [V8EnabledAtRuntime] or [V8EnabledAtRuntime=X], |
| 776 | where X is an arbitrary string which you want to use for identifying the flag getter. |
| 777 | It can be specified on interfaces, methods and attributes: |
| 778 | {{{ |
| 779 | interface [ |
| 780 | V8EnabledAtRuntime |
| 781 | ] XXX { |
| 782 | } |
| 783 | }}} |
| 784 | {{{ |
| 785 | interface XXX { |
| 786 | attribute [V8EnabledAtRuntime] DOMString str1; |
| 787 | attribute [V8EnabledAtRuntime=foo] DOMString str2; |
| 788 | [V8EnabledAtRuntime] void open1(); |
| 789 | [V8EnabledAtRuntime=foo] void open2(); |
| 790 | } |
| 791 | }}} |
| 792 | |
| 793 | In Chromium/V8, we can enable/disable flags in the about:flags page. |
| 794 | To make interfaces/methods/attributes controllable through about:flags, you can specify [V8EnabledAtRuntime]. |
| 795 | |
| 796 | If [V8EnabledAtRuntime] is specified on an interface, |
| 797 | it means that [V8EnabledAtRuntime] is specified on all attributes and methods on the interface....; |
| 798 | |
| 799 | If you add [V8EnabledAtRuntime], you need to write "flag-binding" code |
| 800 | in WebCore/bindings/generic/RuntimeEnabledFeatures.h, WebCore/bindings/generic/RuntimeEnabledFeatures.cpp |
| 801 | and WebKit/chromium/src/WebRuntimeFeatures.cpp. |
| 802 | |
| 803 | The method name of a flag getter in WebCore/bindings/generic/RuntimeEnabledFeatures.h |
| 804 | is determined by the name of interfaces/methods/attributes. |
| 805 | You can change the method name by using [V8EnabledAtRuntime=X]. |
| 806 | Refer to WebCore/bindings/generic/RuntimeEnabledFeatures.h, WebCore/bindings/generic/RuntimeEnabledFeatures.cpp |
| 807 | and WebKit/chromium/src/WebRuntimeFeatures.cpp for more details. |
| 808 | |