John Lenz - Sept 21, 2010
Currently, the Closure Compiler currently supports a single annotation “@nosideeffects” which can be used on function declarations to indicate that it does not make any changes to external state.
There are five classes function behavior that to which are of interest for classifying function side-effects:
- no modifications are made to either any state of interest
- modifications to a functions “this” object
- modifications to one or more of a functions parameters
- modifications to global state
- is the function result a possible reference to global state
To allow these different scopes of changes to be categorized, new annotations are needed. The annotations will continue to be used only for extern file defintions. For each of these states, the proposed changes are:
If both “this” and function arguments are modified only a single @modifies annotation is used and combined into a single comma separated list.
[a]So modification to global state doesn’t include modification to this? This doesn’t sound safe. -acleung
[b]@sideeffects {modifies_this} was also proposed. But @modifies {x} or seems more concise and clearer
- concavelenz
[c]I’m not really happy with the @safeReturn name and am looking for something better. -concavelenz
I believe your intention is to annotate functions that return a value that can’t possibly be global “this”. Would something like “@factoryMethod” or “@objectFactory” do the trick? - avd
[d]I don’t have any immediate plans to implement this.
- concavelenz