devtools/actors/
object.rs

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 https://mozilla.org/MPL/2.0/. */
4
5use serde_json::{Map, Value};
6
7use crate::StreamId;
8use crate::actor::{Actor, ActorError, ActorRegistry};
9use crate::protocol::ClientRequest;
10
11pub struct ObjectActor {
12    pub name: String,
13    pub _uuid: String,
14}
15
16impl Actor for ObjectActor {
17    fn name(&self) -> String {
18        self.name.clone()
19    }
20    fn handle_message(
21        &self,
22        _request: ClientRequest,
23        _: &ActorRegistry,
24        _: &str,
25        _: &Map<String, Value>,
26        _: StreamId,
27    ) -> Result<(), ActorError> {
28        // TODO: Handle enumSymbols for console object inspection
29        Err(ActorError::UnrecognizedPacketType)
30    }
31}
32
33impl ObjectActor {
34    pub fn register(registry: &ActorRegistry, uuid: String) -> String {
35        if !registry.script_actor_registered(uuid.clone()) {
36            let name = registry.new_name("object");
37            let actor = ObjectActor {
38                name: name.clone(),
39                _uuid: uuid.clone(),
40            };
41
42            registry.register_script_actor(uuid, name.clone());
43            registry.register_later(Box::new(actor));
44
45            name
46        } else {
47            registry.script_to_actor(uuid)
48        }
49    }
50}