2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2014-04-24 15:13:12 +04:00
|
|
|
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2015-06-03 00:52:49 +03:00
|
|
|
const promise = require("promise");
|
2016-05-06 10:19:00 +03:00
|
|
|
const { method } = require("devtools/shared/protocol");
|
2015-06-03 00:52:49 +03:00
|
|
|
|
2014-09-16 14:00:00 +04:00
|
|
|
/**
|
|
|
|
* Creates "registered" actors factory meant for creating another kind of
|
|
|
|
* factories, ObservedActorFactory, during the call to listTabs.
|
|
|
|
* These factories live in DebuggerServer.{tab|global}ActorFactories.
|
|
|
|
*
|
|
|
|
* These actors only exposes:
|
|
|
|
* - `name` string attribute used to match actors by constructor name
|
|
|
|
* in DebuggerServer.remove{Global,Tab}Actor.
|
|
|
|
* - `createObservedActorFactory` function to create "observed" actors factory
|
|
|
|
*
|
|
|
|
* @param options object, function
|
|
|
|
* Either an object or a function.
|
|
|
|
* If given an object:
|
|
|
|
*
|
|
|
|
* If given a function (deprecated):
|
|
|
|
* Constructor function of an actor.
|
|
|
|
* The constructor function for this actor type.
|
|
|
|
* This expects to be called as a constructor (i.e. with 'new'),
|
|
|
|
* and passed two arguments: the DebuggerServerConnection, and
|
|
|
|
* the BrowserTabActor with which it will be associated.
|
|
|
|
* Only used for deprecated eagerly loaded actors.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function RegisteredActorFactory(options, prefix) {
|
|
|
|
// By default the actor name will also be used for the actorID prefix.
|
|
|
|
this._prefix = prefix;
|
2016-05-17 21:25:54 +03:00
|
|
|
if (typeof (options) != "function") {
|
2014-10-03 15:49:00 +04:00
|
|
|
// actors definition registered by actorRegistryActor
|
|
|
|
if (options.constructorFun) {
|
|
|
|
this._getConstructor = () => options.constructorFun;
|
|
|
|
} else {
|
|
|
|
// Lazy actor definition, where options contains all the information
|
|
|
|
// required to load the actor lazily.
|
|
|
|
this._getConstructor = function () {
|
|
|
|
// Load the module
|
|
|
|
let mod;
|
|
|
|
try {
|
|
|
|
mod = require(options.id);
|
2016-05-17 21:25:54 +03:00
|
|
|
} catch (e) {
|
2014-10-03 15:49:00 +04:00
|
|
|
throw new Error("Unable to load actor module '" + options.id + "'.\n" +
|
|
|
|
e.message + "\n" + e.stack + "\n");
|
|
|
|
}
|
|
|
|
// Fetch the actor constructor
|
|
|
|
let c = mod[options.constructorName];
|
|
|
|
if (!c) {
|
|
|
|
throw new Error("Unable to find actor constructor named '" +
|
|
|
|
options.constructorName + "'. (Is it exported?)");
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// Exposes `name` attribute in order to allow removeXXXActor to match
|
|
|
|
// the actor by its actor constructor name.
|
|
|
|
this.name = options.constructorName;
|
2014-09-16 14:00:00 +04:00
|
|
|
} else {
|
|
|
|
// Old actor case, where options is a function that is the actor constructor.
|
|
|
|
this._getConstructor = () => options;
|
|
|
|
// Exposes `name` attribute in order to allow removeXXXActor to match
|
2014-10-03 15:49:00 +04:00
|
|
|
// the actor by its actor constructor name.
|
2014-09-16 14:00:00 +04:00
|
|
|
this.name = options.name;
|
2014-10-03 15:49:00 +04:00
|
|
|
|
2014-09-16 14:00:00 +04:00
|
|
|
// For old actors, we allow the use of a different prefix for actorID
|
|
|
|
// than for listTabs actor names, by fetching a prefix on the actor prototype.
|
|
|
|
// (Used by ChromeDebuggerActor)
|
2014-10-03 15:49:00 +04:00
|
|
|
if (options.prototype && options.prototype.actorPrefix) {
|
2014-09-16 14:00:00 +04:00
|
|
|
this._prefix = options.prototype.actorPrefix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-16 20:51:00 +03:00
|
|
|
RegisteredActorFactory.prototype.createObservedActorFactory = function (conn,
|
|
|
|
parentActor) {
|
2014-09-16 14:00:00 +04:00
|
|
|
return new ObservedActorFactory(this._getConstructor, this._prefix, conn, parentActor);
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|
2014-09-16 14:00:00 +04:00
|
|
|
exports.RegisteredActorFactory = RegisteredActorFactory;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates "observed" actors factory meant for creating real actor instances.
|
|
|
|
* These factories lives in actor pools and fake various actor attributes.
|
|
|
|
* They will be replaced in actor pools by final actor instances during
|
|
|
|
* the first request for the same actorID from DebuggerServer._getOrCreateActor.
|
|
|
|
*
|
|
|
|
* ObservedActorFactory fakes the following actors attributes:
|
|
|
|
* actorPrefix (string) Used by ActorPool.addActor to compute the actor id
|
2014-10-03 15:49:00 +04:00
|
|
|
* actorID (string) Set by ActorPool.addActor just after being instantiated
|
2014-09-16 14:00:00 +04:00
|
|
|
* registeredPool (object) Set by ActorPool.addActor just after being
|
2014-10-03 15:49:00 +04:00
|
|
|
* instantiated
|
2014-09-16 14:00:00 +04:00
|
|
|
* And exposes the following method:
|
|
|
|
* createActor (function) Instantiate an actor that is going to replace
|
|
|
|
* this factory in the actor pool.
|
|
|
|
*/
|
|
|
|
function ObservedActorFactory(getConstructor, prefix, conn, parentActor) {
|
|
|
|
this._getConstructor = getConstructor;
|
|
|
|
this._conn = conn;
|
|
|
|
this._parentActor = parentActor;
|
|
|
|
|
|
|
|
this.actorPrefix = prefix;
|
|
|
|
|
|
|
|
this.actorID = null;
|
|
|
|
this.registeredPool = null;
|
|
|
|
}
|
|
|
|
ObservedActorFactory.prototype.createActor = function () {
|
|
|
|
// Fetch the actor constructor
|
2017-01-16 20:51:00 +03:00
|
|
|
let C = this._getConstructor();
|
2014-09-16 14:00:00 +04:00
|
|
|
// Instantiate a new actor instance
|
2017-01-16 20:51:00 +03:00
|
|
|
let instance = new C(this._conn, this._parentActor);
|
2014-09-16 14:00:00 +04:00
|
|
|
instance.conn = this._conn;
|
|
|
|
instance.parentID = this._parentActor.actorID;
|
|
|
|
// We want the newly-constructed actor to completely replace the factory
|
|
|
|
// actor. Reusing the existing actor ID will make sure ActorPool.addActor
|
|
|
|
// does the right thing.
|
|
|
|
instance.actorID = this.actorID;
|
|
|
|
this.registeredPool.addActor(instance);
|
|
|
|
return instance;
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|
2014-09-16 14:00:00 +04:00
|
|
|
exports.ObservedActorFactory = ObservedActorFactory;
|
|
|
|
|
2014-04-24 15:13:12 +04:00
|
|
|
/**
|
|
|
|
* Methods shared between RootActor and BrowserTabActor.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-01-16 20:51:00 +03:00
|
|
|
* Populate |this._extraActors| as specified by |factories|, reusing whatever
|
2014-04-24 15:13:12 +04:00
|
|
|
* actors are already there. Add all actors in the final extra actors table to
|
2017-01-16 20:51:00 +03:00
|
|
|
* |pool|.
|
2014-04-24 15:13:12 +04:00
|
|
|
*
|
|
|
|
* The root actor and the tab actor use this to instantiate actors that other
|
2014-10-03 15:49:00 +04:00
|
|
|
* parts of the browser have specified with DebuggerServer.addTabActor and
|
2014-04-24 15:13:12 +04:00
|
|
|
* DebuggerServer.addGlobalActor.
|
|
|
|
*
|
2017-01-16 20:51:00 +03:00
|
|
|
* @param factories
|
2014-04-24 15:13:12 +04:00
|
|
|
* An object whose own property names are the names of properties to add to
|
|
|
|
* some reply packet (say, a tab actor grip or the "listTabs" response
|
|
|
|
* form), and whose own property values are actor constructor functions, as
|
|
|
|
* documented for addTabActor and addGlobalActor.
|
|
|
|
*
|
|
|
|
* @param this
|
|
|
|
* The BrowserRootActor or BrowserTabActor with which the new actors will
|
2017-01-16 20:51:00 +03:00
|
|
|
* be associated. It should support whatever API the |factories|
|
2014-04-24 15:13:12 +04:00
|
|
|
* constructor functions might be interested in, as it is passed to them.
|
|
|
|
* For the sake of CommonCreateExtraActors itself, it should have at least
|
|
|
|
* the following properties:
|
|
|
|
*
|
|
|
|
* - _extraActors
|
|
|
|
* An object whose own property names are factory table (and packet)
|
|
|
|
* property names, and whose values are no-argument actor constructors,
|
|
|
|
* of the sort that one can add to an ActorPool.
|
|
|
|
*
|
|
|
|
* - conn
|
|
|
|
* The DebuggerServerConnection in which the new actors will participate.
|
|
|
|
*
|
|
|
|
* - actorID
|
|
|
|
* The actor's name, for use as the new actors' parentID.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
exports.createExtraActors = function createExtraActors(factories, pool) {
|
2014-04-24 15:13:12 +04:00
|
|
|
// Walk over global actors added by extensions.
|
2017-01-16 20:51:00 +03:00
|
|
|
for (let name in factories) {
|
2014-04-24 15:13:12 +04:00
|
|
|
let actor = this._extraActors[name];
|
|
|
|
if (!actor) {
|
2014-09-16 14:00:00 +04:00
|
|
|
// Register another factory, but this time specific to this connection.
|
|
|
|
// It creates a fake actor that looks like an regular actor in the pool,
|
|
|
|
// but without actually instantiating the actor.
|
2014-10-03 15:49:00 +04:00
|
|
|
// It will only be instantiated on the first request made to the actor.
|
2017-01-16 20:51:00 +03:00
|
|
|
actor = factories[name].createObservedActorFactory(this.conn, this);
|
2014-04-24 15:13:12 +04:00
|
|
|
this._extraActors[name] = actor;
|
|
|
|
}
|
2014-10-03 15:49:00 +04:00
|
|
|
|
|
|
|
// If the actor already exists in the pool, it may have been instantiated,
|
|
|
|
// so make sure not to overwrite it by a non-instantiated version.
|
2017-01-16 20:51:00 +03:00
|
|
|
if (!pool.has(actor.actorID)) {
|
|
|
|
pool.addActor(actor);
|
2014-10-03 15:49:00 +04:00
|
|
|
}
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|
2014-04-24 15:13:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append the extra actors in |this._extraActors|, constructed by a prior call
|
2017-01-16 20:51:00 +03:00
|
|
|
* to CommonCreateExtraActors, to |object|.
|
2014-04-24 15:13:12 +04:00
|
|
|
*
|
2017-01-16 20:51:00 +03:00
|
|
|
* @param object
|
2014-04-24 15:13:12 +04:00
|
|
|
* The object to which the extra actors should be added, under the
|
2017-01-16 20:51:00 +03:00
|
|
|
* property names given in the |factories| table passed to
|
2014-04-24 15:13:12 +04:00
|
|
|
* CommonCreateExtraActors.
|
|
|
|
*
|
|
|
|
* @param this
|
|
|
|
* The BrowserRootActor or BrowserTabActor whose |_extraActors| table we
|
|
|
|
* should use; see above.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
exports.appendExtraActors = function appendExtraActors(object) {
|
2014-04-24 15:13:12 +04:00
|
|
|
for (let name in this._extraActors) {
|
|
|
|
let actor = this._extraActors[name];
|
2017-01-16 20:51:00 +03:00
|
|
|
object[name] = actor.actorID;
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|
2014-04-24 15:13:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct an ActorPool.
|
|
|
|
*
|
|
|
|
* ActorPools are actorID -> actor mapping and storage. These are
|
|
|
|
* used to accumulate and quickly dispose of groups of actors that
|
|
|
|
* share a lifetime.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
function ActorPool(connection) {
|
|
|
|
this.conn = connection;
|
2014-04-24 15:13:12 +04:00
|
|
|
this._actors = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
ActorPool.prototype = {
|
|
|
|
/**
|
2015-11-13 12:19:55 +03:00
|
|
|
* Destroy the pool. This will remove all actors from the pool.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
destroy: function APDestroy() {
|
2015-11-13 12:19:55 +03:00
|
|
|
for (let id in this._actors) {
|
|
|
|
this.removeActor(this._actors[id]);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an actor to the pool. If the actor doesn't have an ID, allocate one
|
|
|
|
* from the connection.
|
2014-04-24 15:13:12 +04:00
|
|
|
*
|
2017-01-16 20:51:00 +03:00
|
|
|
* @param Object actor
|
2015-11-13 12:19:55 +03:00
|
|
|
* The actor to be added to the pool.
|
2014-04-24 15:13:12 +04:00
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
addActor: function APAddActor(actor) {
|
|
|
|
actor.conn = this.conn;
|
|
|
|
if (!actor.actorID) {
|
|
|
|
let prefix = actor.actorPrefix;
|
|
|
|
if (!prefix && typeof actor == "function") {
|
2014-04-24 15:13:12 +04:00
|
|
|
// typeName is a convention used with protocol.js-based actors
|
2017-01-16 20:51:00 +03:00
|
|
|
prefix = actor.prototype.actorPrefix || actor.prototype.typeName;
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
2017-01-16 20:51:00 +03:00
|
|
|
actor.actorID = this.conn.allocID(prefix || undefined);
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
|
|
|
|
2015-11-13 12:19:55 +03:00
|
|
|
// If the actor is already in a pool, remove it without destroying it.
|
2017-01-16 20:51:00 +03:00
|
|
|
if (actor.registeredPool) {
|
|
|
|
delete actor.registeredPool._actors[actor.actorID];
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
2017-01-16 20:51:00 +03:00
|
|
|
actor.registeredPool = this;
|
2014-04-24 15:13:12 +04:00
|
|
|
|
2017-01-16 20:51:00 +03:00
|
|
|
this._actors[actor.actorID] = actor;
|
2015-11-13 12:19:55 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2016-11-12 03:24:58 +03:00
|
|
|
* Remove an actor from the pool. If the actor has a destroy method, call it.
|
2015-11-13 12:19:55 +03:00
|
|
|
*/
|
2016-11-12 03:24:58 +03:00
|
|
|
removeActor(actor) {
|
|
|
|
delete this._actors[actor.actorID];
|
|
|
|
if (actor.destroy) {
|
|
|
|
actor.destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Obsolete destruction method name (might still be used by custom actors)
|
|
|
|
if (actor.disconnect) {
|
|
|
|
actor.disconnect();
|
2014-04-24 15:13:12 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-01-16 20:51:00 +03:00
|
|
|
get: function APGet(actorID) {
|
|
|
|
return this._actors[actorID] || undefined;
|
2014-04-24 15:13:12 +04:00
|
|
|
},
|
|
|
|
|
2017-01-16 20:51:00 +03:00
|
|
|
has: function APHas(actorID) {
|
|
|
|
return actorID in this._actors;
|
2014-04-24 15:13:12 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the pool is empty.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
isEmpty: function APIsEmpty() {
|
2014-04-24 15:13:12 +04:00
|
|
|
return Object.keys(this._actors).length == 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Match the api expected by the protocol library.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
unmanage: function (actor) {
|
|
|
|
return this.removeActor(actor);
|
2014-04-24 15:13:12 +04:00
|
|
|
},
|
|
|
|
|
2016-05-17 21:25:54 +03:00
|
|
|
forEach: function (callback) {
|
2014-10-03 15:49:00 +04:00
|
|
|
for (let name in this._actors) {
|
|
|
|
callback(this._actors[name]);
|
|
|
|
}
|
|
|
|
},
|
2016-05-17 21:25:54 +03:00
|
|
|
};
|
2014-04-24 15:13:12 +04:00
|
|
|
|
|
|
|
exports.ActorPool = ActorPool;
|
|
|
|
|
2015-02-23 11:36:58 +03:00
|
|
|
/**
|
|
|
|
* An OriginalLocation represents a location in an original source.
|
|
|
|
*
|
|
|
|
* @param SourceActor actor
|
|
|
|
* A SourceActor representing an original source.
|
|
|
|
* @param Number line
|
|
|
|
* A line within the given source.
|
|
|
|
* @param Number column
|
|
|
|
* A column within the given line.
|
|
|
|
* @param String name
|
|
|
|
* The name of the symbol corresponding to this OriginalLocation.
|
|
|
|
*/
|
|
|
|
function OriginalLocation(actor, line, column, name) {
|
|
|
|
this._connection = actor ? actor.conn : null;
|
|
|
|
this._actorID = actor ? actor.actorID : undefined;
|
|
|
|
this._line = line;
|
|
|
|
this._column = column;
|
|
|
|
this._name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
OriginalLocation.fromGeneratedLocation = function (generatedLocation) {
|
|
|
|
return new OriginalLocation(
|
|
|
|
generatedLocation.generatedSourceActor,
|
|
|
|
generatedLocation.generatedLine,
|
|
|
|
generatedLocation.generatedColumn
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
OriginalLocation.prototype = {
|
|
|
|
get originalSourceActor() {
|
|
|
|
return this._connection ? this._connection.getActor(this._actorID) : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalUrl() {
|
|
|
|
let actor = this.originalSourceActor;
|
|
|
|
let source = actor.source;
|
|
|
|
return source ? source.url : actor._originalUrl;
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalLine() {
|
|
|
|
return this._line;
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalColumn() {
|
|
|
|
return this._column;
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalName() {
|
|
|
|
return this._name;
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedSourceActor() {
|
|
|
|
throw new Error("Shouldn't access generatedSourceActor from an OriginalLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedLine() {
|
|
|
|
throw new Error("Shouldn't access generatedLine from an OriginalLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedColumn() {
|
|
|
|
throw new Error("Shouldn't access generatedColumn from an Originallocation");
|
2015-03-11 17:15:40 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
equals: function (other) {
|
|
|
|
return this.originalSourceActor.url == other.originalSourceActor.url &&
|
2015-04-03 15:46:27 +03:00
|
|
|
this.originalLine === other.originalLine &&
|
|
|
|
(this.originalColumn === undefined ||
|
|
|
|
other.originalColumn === undefined ||
|
|
|
|
this.originalColumn === other.originalColumn);
|
2015-03-11 17:15:40 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
toJSON: function () {
|
|
|
|
return {
|
|
|
|
source: this.originalSourceActor.form(),
|
|
|
|
line: this.originalLine,
|
|
|
|
column: this.originalColumn
|
|
|
|
};
|
2015-02-23 11:36:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.OriginalLocation = OriginalLocation;
|
|
|
|
|
|
|
|
/**
|
2015-06-03 01:50:18 +03:00
|
|
|
* A GeneratedLocation represents a location in a generated source.
|
2015-02-23 11:36:58 +03:00
|
|
|
*
|
|
|
|
* @param SourceActor actor
|
|
|
|
* A SourceActor representing a generated source.
|
|
|
|
* @param Number line
|
|
|
|
* A line within the given source.
|
|
|
|
* @param Number column
|
|
|
|
* A column within the given line.
|
|
|
|
*/
|
2015-03-27 09:49:16 +03:00
|
|
|
function GeneratedLocation(actor, line, column, lastColumn) {
|
2015-02-23 11:36:58 +03:00
|
|
|
this._connection = actor ? actor.conn : null;
|
|
|
|
this._actorID = actor ? actor.actorID : undefined;
|
|
|
|
this._line = line;
|
|
|
|
this._column = column;
|
2015-03-27 09:49:16 +03:00
|
|
|
this._lastColumn = (lastColumn !== undefined) ? lastColumn : column + 1;
|
2015-02-23 11:36:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
GeneratedLocation.fromOriginalLocation = function (originalLocation) {
|
|
|
|
return new GeneratedLocation(
|
|
|
|
originalLocation.originalSourceActor,
|
|
|
|
originalLocation.originalLine,
|
|
|
|
originalLocation.originalColumn
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
GeneratedLocation.prototype = {
|
|
|
|
get originalSourceActor() {
|
|
|
|
throw new Error();
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalUrl() {
|
|
|
|
throw new Error("Shouldn't access originalUrl from a GeneratedLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalLine() {
|
|
|
|
throw new Error("Shouldn't access originalLine from a GeneratedLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalColumn() {
|
|
|
|
throw new Error("Shouldn't access originalColumn from a GeneratedLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get originalName() {
|
|
|
|
throw new Error("Shouldn't access originalName from a GeneratedLocation");
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedSourceActor() {
|
|
|
|
return this._connection ? this._connection.getActor(this._actorID) : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedLine() {
|
|
|
|
return this._line;
|
|
|
|
},
|
|
|
|
|
|
|
|
get generatedColumn() {
|
|
|
|
return this._column;
|
2015-03-27 09:49:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get generatedLastColumn() {
|
|
|
|
return this._lastColumn;
|
|
|
|
},
|
|
|
|
|
|
|
|
equals: function (other) {
|
|
|
|
return this.generatedSourceActor.url == other.generatedSourceActor.url &&
|
2015-04-03 15:46:27 +03:00
|
|
|
this.generatedLine === other.generatedLine &&
|
|
|
|
(this.generatedColumn === undefined ||
|
|
|
|
other.generatedColumn === undefined ||
|
|
|
|
this.generatedColumn === other.generatedColumn);
|
2015-03-27 09:49:16 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
toJSON: function () {
|
|
|
|
return {
|
|
|
|
source: this.generatedSourceActor.form(),
|
|
|
|
line: this.generatedLine,
|
|
|
|
column: this.generatedColumn,
|
|
|
|
lastColumn: this.generatedLastColumn
|
|
|
|
};
|
2015-02-23 11:36:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.GeneratedLocation = GeneratedLocation;
|
|
|
|
|
2015-06-03 00:52:49 +03:00
|
|
|
/**
|
|
|
|
* A method decorator that ensures the actor is in the expected state before
|
|
|
|
* proceeding. If the actor is not in the expected state, the decorated method
|
|
|
|
* returns a rejected promise.
|
|
|
|
*
|
|
|
|
* The actor's state must be at this.state property.
|
|
|
|
*
|
|
|
|
* @param String expectedState
|
|
|
|
* The expected state.
|
|
|
|
* @param String activity
|
|
|
|
* Additional info about what's going on.
|
2017-01-16 20:51:00 +03:00
|
|
|
* @param Function methodFunc
|
2015-06-03 00:52:49 +03:00
|
|
|
* The actor method to proceed with when the actor is in the expected
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @returns Function
|
|
|
|
* The decorated method.
|
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
function expectState(expectedState, methodFunc, activity) {
|
2016-05-17 21:25:54 +03:00
|
|
|
return function (...args) {
|
2015-06-03 00:52:49 +03:00
|
|
|
if (this.state !== expectedState) {
|
|
|
|
const msg = `Wrong state while ${activity}:` +
|
|
|
|
`Expected '${expectedState}', ` +
|
|
|
|
`but current state is '${this.state}'.`;
|
|
|
|
return promise.reject(new Error(msg));
|
|
|
|
}
|
|
|
|
|
2017-01-16 20:51:00 +03:00
|
|
|
return methodFunc.apply(this, args);
|
2015-06-03 00:52:49 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.expectState = expectState;
|
2015-06-10 03:01:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Proxies a call from an actor to an underlying module, stored
|
|
|
|
* as `bridge` on the actor. This allows a module to be defined in one
|
|
|
|
* place, usable by other modules/actors on the server, but a separate
|
|
|
|
* module defining the actor/RDP definition.
|
|
|
|
*
|
2015-10-08 00:08:55 +03:00
|
|
|
* @see Framerate implementation: devtools/server/performance/framerate.js
|
2015-09-21 20:07:31 +03:00
|
|
|
* @see Framerate actor definition: devtools/server/actors/framerate.js
|
2015-06-10 03:01:30 +03:00
|
|
|
*/
|
2016-05-17 21:25:54 +03:00
|
|
|
function actorBridge(methodName, definition = {}) {
|
2015-06-10 03:01:30 +03:00
|
|
|
return method(function () {
|
|
|
|
return this.bridge[methodName].apply(this.bridge, arguments);
|
|
|
|
}, definition);
|
|
|
|
}
|
|
|
|
exports.actorBridge = actorBridge;
|
2016-06-08 16:51:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Like `actorBridge`, but without a spec definition, for when the actor is
|
2016-08-22 17:25:57 +03:00
|
|
|
* created with `ActorClassWithSpec` rather than vanilla `ActorClass`.
|
2016-06-08 16:51:55 +03:00
|
|
|
*/
|
2017-01-16 20:51:00 +03:00
|
|
|
function actorBridgeWithSpec(methodName) {
|
2016-06-08 16:51:55 +03:00
|
|
|
return method(function () {
|
|
|
|
return this.bridge[methodName].apply(this.bridge, arguments);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
exports.actorBridgeWithSpec = actorBridgeWithSpec;
|