1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 * A SourceLocation represents a location in a source.
11 * @param SourceActor actor
12 * A SourceActor representing a source.
14 * A line within the given source.
15 * @param Number column
16 * A column within the given line.
18 constructor(actor, line, column) {
19 this._connection = actor ? actor.conn : null;
20 this._actorID = actor ? actor.actorID : undefined;
22 this._column = column;
26 return this._connection ? this._connection.getActor(this._actorID) : null;
30 return this.sourceActor.url;
42 return this.sourceActor.url;
47 this.sourceActor.url == other.sourceActor.url &&
48 this.line === other.line &&
49 (this.column === undefined ||
50 other.column === undefined ||
51 this.column === other.column)
57 source: this.sourceActor.form(),
64 exports.SourceLocation = SourceLocation;
67 * A method decorator that ensures the actor is in the expected state before
68 * proceeding. If the actor is not in the expected state, the decorated method
69 * returns a rejected promise.
71 * The actor's state must be at this.state property.
73 * @param String expectedState
75 * @param String activity
76 * Additional info about what's going on.
77 * @param Function methodFunc
78 * The actor method to proceed with when the actor is in the expected
82 * The decorated method.
84 function expectState(expectedState, methodFunc, activity) {
85 return function (...args) {
86 if (this.state !== expectedState) {
88 `Wrong state while ${activity}:` +
89 `Expected '${expectedState}', ` +
90 `but current state is '${this.state}'.`;
91 return Promise.reject(new Error(msg));
94 return methodFunc.apply(this, args);
98 exports.expectState = expectState;
101 * Autobind method from a `bridge` property set on some actors where the
102 * implementation is delegated to a separate class, and where `bridge` points
103 * to an instance of this class.
105 function actorBridgeWithSpec(methodName) {
107 return this.bridge[methodName].apply(this.bridge, arguments);
110 exports.actorBridgeWithSpec = actorBridgeWithSpec;