25 | | == IDL attributes around operations, attributes and parameters == |
26 | | |
27 | | In the following explanations, (i), (o), (a) and (p) means that the IDL attribute can be specified on interfaces, operations, attributes and parameters, respectively. For example, (a,p) means that the IDL attribute can be specified on attributes and parameters. |
| 25 | == IDL attributes around methods, attributes and parameters == |
| 26 | |
| 27 | In the following explanations, (i), (m), (a) and (p) means that the IDL attribute can be specified on interfaces, methods, attributes and parameters, respectively. For example, (a,p) means that the IDL attribute can be specified on attributes and parameters. |
69 | | [TreatReturnedNullStringAs=Null] indicates that if the returned string is a null string in WebKit, the returned value is converted to a JavaScript null. |
70 | | |
71 | | [TreatReturnedNullStringAs=Undefined] indicates that if the returned string is a null string in WebKit, the returned value is converted to a JavaScript undefined. |
72 | | |
73 | | [TreatReturnedNullStringAs=False] indicates that if the returned string is a null string in WebKit, the returned value is converted to a JavaScript false. |
74 | | |
75 | | Without [TreatReturnedNullStringAs=...], if the returned string is a null string in WebKit, the returned value becomes a JavaScript empty string ''. Note that what should be specified depends on the spec of each attribute or operation. |
| 73 | [TreatReturnedNullStringAs=Null] indicates that if the returned string is a WebKit null string, the returned value is converted to a JavaScript null. |
| 74 | |
| 75 | [TreatReturnedNullStringAs=Undefined] indicates that if the returned string is a WebKit null string, the returned value is converted to a JavaScript undefined. |
| 76 | |
| 77 | [TreatReturnedNullStringAs=False] indicates that if the returned string is a WebKit null string, the returned value is converted to a JavaScript false. |
| 78 | |
| 79 | Without [TreatReturnedNullStringAs=...], if the returned string is a WebKit null string, the returned value becomes a JavaScript empty string ''. Note that what should be specified depends on the spec of each attribute or method. |
| 83 | Summary: It allows method overloading for methods whose argument count are different with each other. |
| 84 | |
| 85 | The possible usage is [Optional], [Optional=DefaultIsUndefined] or [Optional=DefaultIsNullString]. |
| 86 | [Optional] and [Optional=DefaultIsUndefined] can be specified on parameters. |
| 87 | [Optional=DefaultIsNullString] can be specified on DOMString parameters, like this: |
| 88 | |
| 89 | {{{ |
| 90 | interface HTMLFoo { |
| 91 | void func1(in int a, in int b, in [Optional] int c, in [Optional] int d); |
| 92 | void func2(in int a, in int b, in [Optional=DefaultIsUndefined] int c); |
| 93 | void func3(in int a, in int b, in [Optional=DefaultIsUndefined] DOMString c, in [Optional=DefaultIsNullString] DOMString d); |
| 94 | } |
| 95 | }}} |
| 96 | |
| 97 | The parameters marked with [Optional=...] are optional, and JavaScript can omit the parameters. Obviously, if parameter X is marked with [Optional=...], then all subsequent parameters of X must be marked with [Optional=...]. The difference between [Optional] and [Optional=DefaultIsUndefined] is whether your WebCore implementation has overloaded methods or not, as explained below. |
| 98 | |
| 99 | In case of func1(...), if JavaScript calls func1(100, 200), then HTMLFoo::func1(int a, int b) is called in WebCore. |
| 100 | If JavaScript calls func1(100, 200, 300), then HTMLFoo::func1(int a, int b, int c) is called in WebCore. |
| 101 | If JavaScript calls func1(100, 200, 300, 400), then HTMLFoo::func1(int a, int b, int c, int d) is called in WebCore. In other words, if your WebCore implementation has overloaded methods, you can use [Optional]. |
| 102 | |
| 103 | In case of func2(...), if JavaScript calls func2(100, 200), then it behaves as if JavaScript called func2(100, 200, undefined, undefined). |
| 104 | Consequently, HTMLFoo::func1(int a, int b, int c, int d) is called in WebCore. |
| 105 | 100 is passed to a, 200 is passed to b, 0 is passed to c, and 0 is passed to d. |
| 106 | (A JavaScript undefined is converted to 0, following the value conversion rule in the Web IDL spec.) |
| 107 | In this way, WebCore needs to implement func2(int a, int b, int c, int d) only, and needs not to implement overloaded methods like func2(int a, int b) or func2(int a, int b, int c). |
| 108 | |
| 109 | The difference between [Optional=DefalutIsUndefined] and [Optional=DefaultIsNullString] appears only when the parameter type is DOMString. |
| 110 | While in [Optional=DefalutIsUndefined] the "supplemented" JavaScript undefined is converted to a WebKit string "undefined", in [Optional=DefaultIsNullString] the "supplemented" JavaScript undefined is converted to a WebKit null string. Specifically, if JavaScript calls func3(100, 200), then HTMLFoo::func3(int a, int b, String c, String d) is called in WebCore. Here 100 is passed to a, 200 is passed to b, a WebKit string "undefined" is passed to c, and a WebKit null string is passed to d. |
83 | | === * [Custom](o,a), [JSCustom](o,a), [V8Custom](o,a), [CustomGetter](a), [JSCustomGetter](a), [V8CustomGetter](a), [CustomSetter](a), [JSCustomSetter](a), [V8CustomSetter](a) === |
84 | | |
85 | | === * [CallWith](o,a) === |
86 | | |
87 | | === * [CheckAccessToNode](o,a) === |
88 | | |
89 | | === * [StrictTypeChecking](o,a) === |
90 | | |
91 | | === * [ReturnNewObject](o,a) === |
92 | | |
93 | | === * [ImplementedAs](o) === |
| 115 | Summary: ??? |
| 116 | |
| 117 | The possible usage is [Callback]. [Callback] can be specified on interfaces and parameters. |
| 118 | |
| 119 | FIXME: ADD EXPLANATIONS |
| 120 | |
| 121 | === * [Custom](m,a), [JSCustom](m,a), [V8Custom](m,a), [CustomGetter](a), [JSCustomGetter](a), [V8CustomGetter](a), [CustomSetter](a), [JSCustomSetter](a), [V8CustomSetter](a) === |
| 122 | |
| 123 | === * [CallWith](m,a) === |
| 124 | |
| 125 | === * [CheckAccessToNode](m,a) === |
| 126 | |
| 127 | === * [StrictTypeChecking](m,a) === |
| 128 | |
| 129 | === * [ReturnNewObject](m,a) === |
| 130 | |
| 131 | === * [ImplementedAs](m) === |