305 | | void func1(in int a, in int b, in [Optional] int c, in [Optional] int d); |
306 | | void func2(in int a, in int b, in [Optional=DefaultIsUndefined] int c); |
307 | | void func3(in int a, in int b, in [Optional=DefaultIsUndefined] DOMString c, in [Optional=DefaultIsNullString] DOMString d); |
308 | | }; |
309 | | }}} |
310 | | |
311 | | 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 should be marked with [Optional=...]. |
312 | | |
313 | | The difference between [Optional] and [Optional=DefaultIsUndefined] is whether the WebCore implementation has overloaded methods or not, as explained below. |
314 | | |
315 | | In case of func1(...), if JavaScript calls func1(100, 200), then HTMLFoo::func1(int a, int b) is called in WebCore. |
316 | | If JavaScript calls func1(100, 200, 300), then HTMLFoo::func1(int a, int b, int c) is called in WebCore. |
317 | | If JavaScript calls func1(100, 200, 300, 400), then HTMLFoo::func1(int a, int b, int c, int d) is called in WebCore. |
318 | | In other words, if the WebCore implementation has overloaded methods, you can use [Optional]. |
319 | | |
320 | | In case of func2(...), if JavaScript calls func2(100, 200), then it behaves as if JavaScript called func2(100, 200, undefined). |
321 | | Consequently, HTMLFoo::func2(int a, int b, int c) is called in WebCore. |
322 | | 100 is passed to a, 200 is passed to b, and 0 is passed to c. |
323 | | (A JavaScript undefined is converted to 0, following the value conversion rule in the Web IDL spec.) |
324 | | In this way, WebCore needs to just implement func2(int a, int b, int c) and needs not to implement both func2(int a, int b) and func2(int a, int b, int c). |
325 | | |
326 | | The difference between [Optional=DefalutIsUndefined] and [Optional=DefaultIsNullString] appears only when the parameter type is DOMString. |
327 | | In [Optional=DefalutIsUndefined], the "supplemented" JavaScript undefined is converted to a WebKit string "undefined". |
328 | | On the other hand, in [Optional=DefaultIsNullString], the "supplemented" JavaScript undefined is converted to a WebKit null string. |
329 | | For example, if JavaScript calls func3(100, 200), then HTMLFoo::func3(int a, int b, String c, String d) is called in WebCore. |
330 | | At this point, 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. |
331 | | d.IsEmpty() and d.IsNull() return true. |
| 306 | void func1(int a, int b, optional int c, optional int d); |
| 307 | void func2(int a, int b, [Default=Undefined] optional int c); |
| 308 | void func3(int a, int b, [Default=Undefined] optional DOMString c, [Default=NullString] optional DOMString d); |
| 309 | }; |
| 310 | }}} |
| 311 | |
| 312 | The parameters marked with the standard Web IDL optional qualifier are optional, and JavaScript can omit the parameters. Obviously, if parameter X is marked with optional then all subsequent parameters of X should be marked with optional. |
| 313 | |
| 314 | The difference between optional and [Default=Undefined] optional is whether the WebCore implementation has overloaded methods or not, as explained below. |
| 315 | |
| 316 | In case of func1(...), if JavaScript calls func1(100, 200), then HTMLFoo::func1(int a, int b) is called in WebCore. If JavaScript calls func1(100, 200, 300), then HTMLFoo::func1(int a, int b, int c) is called in WebCore. 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 the WebCore implementation has overloaded methods, you can use optional. |
| 317 | |
| 318 | In case of func2(...) which adds [Default=Undefined], if JavaScript calls func2(100, 200), then it behaves as if JavaScript called func2(100, 200, undefined). Consequently, HTMLFoo::func2(int a, int b, int c) is called in WebCore. 100 is passed to a, 200 is passed to b, and 0 is passed to c. (A JavaScript undefined is converted to 0, following the value conversion rule in the Web IDL spec.) In this way, WebCore needs to just implement func2(int a, int b, int c) and needs not to implement both func2(int a, int b) and func2(int a, int b, int c). |
| 319 | |
| 320 | The difference between [Default=Undefined] and [Default=NullString] appears only when the parameter type is DOMString. In [Default=Undefined] the "supplemented" JavaScript undefined is converted to a WebKit string "undefined". On the other hand, in [Default=NullString] the "supplemented" JavaScript undefined is converted to a WebKit null string. For example, if JavaScript calls func3(100, 200), then HTMLFoo::func3(int a, int b, String c, String d) is called in WebCore. At this point, 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. d.IsEmpty() and d.IsNull() return true. |