Modular Layout Computation Clause Samples

Modular Layout Computation. Suppose you are a JavaScript developer who has just been assigned a maintenance task on a large AJAX application. In particular, you need to work on the code that performs a layout computation for a bunch of view objects. To start with, it would be advantageous to know which properties are modified by the code. Using our framework, a developer can gradually specify access contracts for the code until it runs without contract violation on a sufficiently large number of test cases. For example, the final specification may be as follows: /∗c {}.(int, int) → boolean with [this.x, this.y, this.w, this.h] ∗/ Frame.prototype.layout = function (width, height) { ... } ∗ ∗ The special comment / c ... / specifies a contract for a method. The part before with defines the type signature. In the subsequent access permission, this refers to the receiver object of the method call. The access paths specify that only properties named x,y, w, or h of the receiver object may be written. An access path starts with any variable name in scope followed by a sequence of property names. It permits reading any property reachable by dereferencing some prefix of the access path and writing the properties reachable by dereferencing the entire access path. The special variable names this, $1, $2, . . . refer to the receiver object of a method call and to the first, second, and so on parameter. They are synonymous to the respective parameter name. sequence of property names. The final @ stands for the empty set of property names. Thus, the first parameter must be read-only. Read permission is granted for all properties reachable from $1, but write permission is granted only for those access paths that end in a property name that is contained in the empty set, that is, for no access path.
Modular Layout Computation. Suppose you are a JavaScript developer who has just been assigned a mainte- ▇▇▇▇▇ task on a large AJAX application. In particular, you need to work on the code that performs a layout computation for a bunch of view objects. To start with, it would be advantageous to know which properties are modified by the code. Using our framework, a developer can gradually specify access permis- sions for the code until it runs without contract violation on a sufficiently large number of test cases. For example, the final specification may be as follows: /∗c {}.(int, int) → boolean with [this.x, this.y, this.w, this.h] ∗/ Frame.prototype.layout = function (width, height) { ... } ∗ ∗ The special comment / c ... / specifies a contract for a method. The part before with defines the type signature. In the subsequent access permission, this refers to the receiver object of the method call. The access paths specify that only properties named x,y, w, or h of the receiver object may be written. An access path starts with any variable name in scope followed by a sequence of property names. It permits reading any property reachable by dereferencing some prefix of the access path and writing the properties reachable by derefer- encing the entire access path. The special variable names this, $1, $2, . . . refer to the receiver object of a method call and to the first, second, and so on parameter.