Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: third_party/WebKit/Source/bindings/IDLExtendedAttributes.md

Issue 2544253002: Update documentation for [CallWith] and [ConstructorCallWith] (Closed)
Patch Set: temp Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Blink IDL Extended Attributes 1 # Blink IDL Extended Attributes
2 2
3 [TOC] 3 [TOC]
4 4
5 ## Introduction 5 ## Introduction
6 6
7 The main interest in extended attributes are their _semantics_: Blink implements many more extended attributes than the Web IDL standard, to specify various beh avior. 7 The main interest in extended attributes are their _semantics_: Blink implements many more extended attributes than the Web IDL standard, to specify various beh avior.
8 8
9 The authoritative list of allowed extended attributes and values is [bindings/ID LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/ src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl ete but not necessarily precise (there may be unused extended attributes or valu es), since validation is run on build, but coverage isn't checked. 9 The authoritative list of allowed extended attributes and values is [bindings/ID LExtendedAttributes.txt](https://code.google.com/p/chromium/codesearch#chromium/ src/third_party/WebKit/Source/bindings/IDLExtendedAttributes.txt). This is compl ete but not necessarily precise (there may be unused extended attributes or valu es), since validation is run on build, but coverage isn't checked.
10 10
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 543
544 * Valid values for attributes are: `GetterOnly`, `SetterOnly`, (no value) 544 * Valid values for attributes are: `GetterOnly`, `SetterOnly`, (no value)
545 * Valid values for methods are: (no value) 545 * Valid values for methods are: (no value)
546 546
547 For methods all calls are logged, and by default for attributes all access (call s to getter or setter) are logged, but this can be restricted to just read (gett er) or just write (setter). 547 For methods all calls are logged, and by default for attributes all access (call s to getter or setter) are logged, but this can be restricted to just read (gett er) or just write (setter).
548 548
549 ### [CallWith] _(m, a)_, [SetterCallWith] _(a)_, [ConstructorCallWith] _(i)_ 549 ### [CallWith] _(m, a)_, [SetterCallWith] _(a)_, [ConstructorCallWith] _(i)_
550 550
551 Summary: `[CallWith]` indicates that the bindings code calls the Blink implement ation with additional information. 551 Summary: `[CallWith]` indicates that the bindings code calls the Blink implement ation with additional information.
552 552
553 Each value changes the signature of the Blink methods by adding an additional pa rameter to the head of the parameter list, such as `&state` for `[CallWith=Scrip tState]`. 553 Each value changes the signature of the Blink methods by adding an additional pa rameter to the head of the parameter list, such as `ScriptState*` for `[CallWith =ScriptState]`.
554
555 Multiple values can be specified e.g. `[CallWith=ScriptState|ScriptArguments]`. The order of the values in the IDL file doesn't matter: the generated parameter list is always in a fixed order (specifically `&state`, `scriptContext`, `script Arguments.release()`, if present, corresponding to `ScriptState`, `ScriptExecuti onContext`, `ScriptArguments`, respectively).
haraken 2016/12/02 06:31:25 No one is using the multiple value version of [Cal
556 554
557 There are also three rarely used values: `CurrentWindow`, `EnteredWindow`, `This Value`. 555 There are also three rarely used values: `CurrentWindow`, `EnteredWindow`, `This Value`.
558 556
559 `[SetterCallWith]` applies to attributes, and only affects the signature of the setter; this is only used in Location.idl, with `CurrentWindow&EnteredWindow`. 557 `[SetterCallWith]` applies to attributes, and only affects the signature of the setter; this is only used in Location.idl, with `CurrentWindow&EnteredWindow`.
560 558
561 Syntax:
562 `CallWith=ScriptState|ScriptExecutionContext|ScriptArguments|CurrentWindow|Enter edWindow|ThisValue`
563
564 #### [CallWith=ScriptState] _(m, a*)_ 559 #### [CallWith=ScriptState] _(m, a*)_
565 `[CallWith=ScriptState]` is used in a number of places for methods. 560 `[CallWith=ScriptState]` is used in a number of places for methods.
566 561 ScriptState holds all information about script execution.
567 `[CallWith=ScriptState]` _can_ be used for attributes, but is not used in real I DL files. 562 You can retrieve Frame, ExcecutionContext, v8::Context, v8::Isolate etc
563 from ScriptState.
568 564
569 IDL example: 565 IDL example:
570 566
571 ```webidl 567 ```webidl
572 interface Example { 568 interface Example {
573 [CallWith=ScriptState] attribute DOMString str; 569 [CallWith=ScriptState] attribute DOMString str;
574 [CallWith=ScriptState] DOMString func(boolean a, boolean b); 570 [CallWith=ScriptState] DOMString func(boolean a, boolean b);
575 }; 571 };
576 ``` 572 ```
577 573
578 C++ Blink function signatures: 574 C++ Blink function signatures:
579 575
580 ```c++ 576 ```c++
581 String Example::str(ScriptState* state); 577 String Example::str(ScriptState* state);
582 String Example::func(ScriptState* state, bool a, bool b); 578 String Example::func(ScriptState* state, bool a, bool b);
583 ``` 579 ```
584 580
585 #### [CallWith=ExecutionContext] _(m,a)_ 581 #### [CallWith=ExecutionContext] _(m,a)_
586 582
583 `[CallWith=ExecutionContext]` is a less convenient version of `[CallWith=ScriptS tate]`
584 because you can just retrieve ExecutionContext from ScriptState.
585 Use `[CallWith=ScriptState]` instead.
Yuki 2016/12/02 06:39:18 Just curious. Are we going to deprecate CallWith=
haraken 2016/12/02 07:02:35 Yes. I think CallWith=ExecutionContext should just
586
587 IDL example: 587 IDL example:
588 588
589 ```webidl 589 ```webidl
590 interface Example { 590 interface Example {
591 [CallWith=ExecutionContext] attribute DOMString str; 591 [CallWith=ExecutionContext] attribute DOMString str;
592 [CallWith=ExecutionContext] DOMString func(boolean a, boolean b); 592 [CallWith=ExecutionContext] DOMString func(boolean a, boolean b);
593 }; 593 };
594 ``` 594 ```
595 595
596 C++ Blink function signatures: 596 C++ Blink function signatures:
597 597
598 ```c++ 598 ```c++
599 String Example::str(ExecutionContext* context); 599 String Example::str(ExecutionContext* context);
600 String Example::func(ExecutionContext* context, bool a, bool b); 600 String Example::func(ExecutionContext* context, bool a, bool b);
601 ``` 601 ```
602 602
603 You can retrieve the document and frame from a `ExecutionContext*`.
604
605 #### [CallWith=ScriptArguments] _(m)_
606
607 IDL example:
608
609 ```webidl
610 interface Example {
611 [CallWith=ScriptState] DOMString func(boolean a, boolean b);
612 };
613 ```
614
615 C++ Blink function signature:
616
617 ```c++
618 String Example::func(ScriptArguments* arguments, bool a, bool b);
619 ```
620
621 _(rare CallWith values)_ 603 _(rare CallWith values)_
622 604
623 #### [CallWith=CurrentWindow&EnteredWindow] _(m, a)_ 605 #### [CallWith=CurrentWindow&EnteredWindow] _(m, a)_
624 606
625 `EnteredWindow` is the `Window` object that corresponds to the responsible docum ent of the entry settings object. 607 `EnteredWindow` is the `Window` object that corresponds to the responsible docum ent of the entry settings object.
626 608
627 #### [CallWith=ThisValue] _(m)_ 609 #### [CallWith=ThisValue] _(m)_
628 610
629 `[CallWith=ThisValue]` only applies to methods in callback interfaces, and is us ed in only one place (CSSVariablesMapForEachCallback.idl). 611 `[CallWith=ThisValue]` only applies to methods in callback interfaces, and is us ed in only one place (CSSVariablesMapForEachCallback.idl).
630 612
(...skipping 17 matching lines...) Expand all
648 630
649 #### [ConstructorCallWith] _(i)_ 631 #### [ConstructorCallWith] _(i)_
650 632
651 Analogous to `[CallWith]`, but applied to interfaces with constructors, and take s different values. 633 Analogous to `[CallWith]`, but applied to interfaces with constructors, and take s different values.
652 634
653 If `[Constructor]` is specified on an interface, `[ConstructorCallWith]` can be also specified to refine the arguments passed to the callback: 635 If `[Constructor]` is specified on an interface, `[ConstructorCallWith]` can be also specified to refine the arguments passed to the callback:
654 636
655 ```webidl 637 ```webidl
656 [ 638 [
657 Constructor(float x, float y, DOMString str), 639 Constructor(float x, float y, DOMString str),
658 ConstructorCallWith=Document|ExecutionContext, 640 ConstructorCallWith=ExecutionContext,
659 ] 641 ]
660 interface XXX { 642 interface XXX {
661 ... 643 ...
662 }; 644 };
663 ``` 645 ```
664 646
665 Then XXX::create(...) can have the following signature 647 Then XXX::create(...) can have the following signature
666 648
667 *** note 649 *** note
668 **FIXME:** outdated 650 **FIXME:** outdated
669 *** 651 ***
670 652
671 ```c++ 653 ```c++
672 PassRefPtr<XXX> XXX::create(ScriptExecutionContext* context, ScriptState* state, float x, float y, String str) 654 PassRefPtr<XXX> XXX::create(ExecutionContext* context, float x, float y, String str)
673 { 655 {
674 ...; 656 ...;
675 } 657 }
676 ``` 658 ```
677 659
678 You can retrieve document or frame from ScriptExecutionContext. 660 Be careful when you use `[ConstructorCallWith=ScriptState]`.
bashi 2016/12/02 06:43:00 BTW, can this warning be said for [CallWith=Script
haraken 2016/12/02 07:02:35 I added a comment to [CallWith=ScriptState] as wel
661 You should not store the passed-in ScriptState on a DOM object (using RefPtr<Scr iptState>).
662 This is because if the stored ScriptState is used by some method called by a dif ferent
663 world (note that a DOM object is shared among multiple worlds), it leaks the Scr iptState
664 to the world.
679 665
680 ### [Custom] _(i, m, s, a, f)_ 666 ### [Custom] _(i, m, s, a, f)_
681 667
682 Summary: They allow you to write bindings code manually as you like: full bindin gs for methods and attributes, certain functions for interfaces. 668 Summary: They allow you to write bindings code manually as you like: full bindin gs for methods and attributes, certain functions for interfaces.
683 669
684 Custom bindings are _strongly discouraged_. They are likely to be buggy, a sourc e of security holes, and represent a significant maintenance burden. Before usin g `[Custom]`, you should doubly consider if you really need custom bindings. You are recommended to modify code generators and add specialized extended attribut es or special cases if necessary to avoid using `[Custom]`. 670 Custom bindings are _strongly discouraged_. They are likely to be buggy, a sourc e of security holes, and represent a significant maintenance burden. Before usin g `[Custom]`, you should doubly consider if you really need custom bindings. You are recommended to modify code generators and add specialized extended attribut es or special cases if necessary to avoid using `[Custom]`.
685 671
686 Usage: `[Custom]` can be specified on methods or attributes. `[Custom=CallEpilog ue]` can be specified on methods. `[Custom=Getter]` and `[Custom=Setter]` can be specified on attributes. `[Custom=A|B]` can be specified on interfaces, with va rious values (see below). 672 Usage: `[Custom]` can be specified on methods or attributes. `[Custom=CallEpilog ue]` can be specified on methods. `[Custom=Getter]` and `[Custom=Setter]` can be specified on attributes. `[Custom=A|B]` can be specified on interfaces, with va rious values (see below).
687 673
688 On read only attributes (that are not `[Replaceable]`), `[Custom]` is equivalent to `[Custom=Getter]` (since there is no setter) and `[Custom=Getter]` is prefer red. 674 On read only attributes (that are not `[Replaceable]`), `[Custom]` is equivalent to `[Custom=Getter]` (since there is no setter) and `[Custom=Getter]` is prefer red.
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 Copyright (C) 2009 Apple Inc. All rights reserved. 1613 Copyright (C) 2009 Apple Inc. All rights reserved.
1628 1614
1629 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1615 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1630 1616
1631 1. Redistributions of source code must retain the above copyright notice, this l ist of conditions and the following disclaimer. 1617 1. Redistributions of source code must retain the above copyright notice, this l ist of conditions and the following disclaimer.
1632 1618
1633 2. Redistributions in binary form must reproduce the above copyright notice, thi s list of conditions and the following disclaimer in the documentation and/or ot her materials provided with the distribution. 1619 2. Redistributions in binary form must reproduce the above copyright notice, thi s list of conditions and the following disclaimer in the documentation and/or ot her materials provided with the distribution.
1634 1620
1635 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI BILITY OF SUCH DAMAGE. 1621 THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXP RESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIE S OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, I NCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMI TED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFI TS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHE THER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI BILITY OF SUCH DAMAGE.
1636 *** 1622 ***
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698