2018-02-02 11:57:00 +03:00
|
|
|
/* 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";
|
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
const { extend } = require("devtools/shared/extend");
|
|
|
|
const { ObjectActorProto } = require("devtools/server/actors/object");
|
|
|
|
const protocol = require("devtools/shared/protocol");
|
|
|
|
const { ActorClassWithSpec } = protocol;
|
|
|
|
const { objectSpec } = require("devtools/shared/specs/object");
|
2018-02-02 11:57:00 +03:00
|
|
|
|
|
|
|
/**
|
2018-04-20 08:56:26 +03:00
|
|
|
* Protocol.js expects only the prototype object, and does not maintain the prototype
|
|
|
|
* chain when it constructs the ActorClass. For this reason we are using extend to
|
|
|
|
* maintain the properties of ObjectActorProto.
|
|
|
|
**/
|
|
|
|
const proto = extend({}, ObjectActorProto);
|
|
|
|
|
|
|
|
Object.assign(proto, {
|
2018-02-02 11:57:00 +03:00
|
|
|
/**
|
2018-04-20 08:56:26 +03:00
|
|
|
* Creates a pause-scoped actor for the specified object.
|
|
|
|
* @see ObjectActor
|
2018-02-02 11:57:00 +03:00
|
|
|
*/
|
2018-04-20 08:56:26 +03:00
|
|
|
initialize: function(obj, hooks, conn) {
|
|
|
|
ObjectActorProto.initialize.call(this, obj, hooks, conn);
|
|
|
|
this.hooks.promote = hooks.promote;
|
|
|
|
this.hooks.isThreadLifetimePool = hooks.isThreadLifetimePool;
|
|
|
|
},
|
|
|
|
|
2018-03-12 21:24:38 +03:00
|
|
|
isPaused: function() {
|
2018-04-20 08:56:26 +03:00
|
|
|
return this.threadActor ? this.threadActor.state === "paused" : true;
|
2018-02-02 11:57:00 +03:00
|
|
|
},
|
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
withPaused: function(method) {
|
|
|
|
return function() {
|
|
|
|
if (this.isPaused()) {
|
|
|
|
return method.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
error: "wrongState",
|
|
|
|
message:
|
|
|
|
this.constructor.name +
|
|
|
|
" actors can only be accessed while the thread is paused.",
|
|
|
|
};
|
2018-02-02 11:57:00 +03:00
|
|
|
};
|
|
|
|
},
|
2018-04-20 08:56:26 +03:00
|
|
|
});
|
2018-02-02 11:57:00 +03:00
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
const guardWithPaused = [
|
|
|
|
"decompile",
|
|
|
|
"displayString",
|
|
|
|
"ownPropertyNames",
|
|
|
|
"parameterNames",
|
|
|
|
"property",
|
|
|
|
"prototype",
|
|
|
|
"prototypeAndProperties",
|
|
|
|
"scope",
|
|
|
|
];
|
|
|
|
|
|
|
|
guardWithPaused.forEach(f => {
|
|
|
|
proto[f] = proto.withPaused(ObjectActorProto[f]);
|
|
|
|
});
|
2018-02-02 11:57:00 +03:00
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
Object.assign(proto, {
|
2018-02-02 11:57:00 +03:00
|
|
|
/**
|
|
|
|
* Handle a protocol request to promote a pause-lifetime grip to a
|
|
|
|
* thread-lifetime grip.
|
|
|
|
*
|
|
|
|
* @param request object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2018-04-20 08:56:26 +03:00
|
|
|
threadGrip: proto.withPaused(function(request) {
|
2018-02-02 11:57:00 +03:00
|
|
|
this.hooks.promote();
|
|
|
|
return {};
|
|
|
|
}),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a protocol request to release a thread-lifetime grip.
|
|
|
|
*
|
|
|
|
* @param request object
|
|
|
|
* The protocol request object.
|
|
|
|
*/
|
2018-04-20 08:56:26 +03:00
|
|
|
destroy: proto.withPaused(function(request) {
|
2018-02-02 11:57:00 +03:00
|
|
|
if (this.hooks.isThreadLifetimePool()) {
|
|
|
|
return {
|
|
|
|
error: "notReleasable",
|
|
|
|
message: "Only thread-lifetime actors can be released.",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
return protocol.Actor.prototype.destroy.call(this);
|
2018-02-02 11:57:00 +03:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2018-04-20 08:56:26 +03:00
|
|
|
exports.PauseScopedObjectActor = ActorClassWithSpec(objectSpec, proto);
|
|
|
|
// ActorClassWithSpec(objectSpec, {...ObjectActorProto, ...proto});
|