Skip to content

Commit 821db2c

Browse files
atbrakhieerii
andauthored
devtools: Implement initial support for showing scope variables (servo#43232)
This change implements showing scope variable in Debugger tab. This is still early and we have more work to do. Next step is building correct data structure and showing different types of variables. Testing: Manual as well as current tests are passing. Fixes: part of servo#36027 Signed-off-by: atbrakhi <atbrakhi@igalia.com> Co-authored-by: eri <eri@igalia.com>
1 parent a27ab5a commit 821db2c

File tree

5 files changed

+59
-4
lines changed

5 files changed

+59
-4
lines changed

components/devtools/actors/environment.rs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

5+
use std::collections::HashMap;
6+
57
use devtools_traits::EnvironmentInfo;
68
use malloc_size_of_derive::MallocSizeOf;
79
use serde::Serialize;
8-
use serde_json::{Map, Value};
10+
use serde_json::Value;
911

1012
use crate::actor::{Actor, ActorEncode, ActorRegistry};
1113
use crate::actors::object::ObjectActorMsg;
1214

13-
#[derive(Default, Serialize)]
15+
#[derive(Serialize)]
1416
struct EnvironmentBindings {
1517
arguments: Vec<Value>,
16-
variables: Map<String, Value>,
18+
variables: HashMap<String, EnvironmentVariableDesc>,
1719
}
1820

1921
#[derive(Serialize)]
@@ -22,6 +24,14 @@ struct EnvironmentFunction {
2224
display_name: String,
2325
}
2426

27+
#[derive(Serialize)]
28+
struct EnvironmentVariableDesc {
29+
value: String,
30+
configurable: bool,
31+
enumerable: bool,
32+
writable: bool,
33+
}
34+
2535
#[derive(Serialize)]
2636
#[serde(rename_all = "camelCase")]
2737
pub(crate) struct EnvironmentActorMsg {
@@ -87,13 +97,32 @@ impl ActorEncode<EnvironmentActorMsg> for EnvironmentActor {
8797
type_: self.environment.type_.clone(),
8898
scope_kind: self.environment.scope_kind.clone(),
8999
parent,
90-
bindings: None,
91100
function: self
92101
.environment
93102
.function_display_name
94103
.clone()
95104
.map(|display_name| EnvironmentFunction { display_name }),
96105
object: None,
106+
bindings: Some(EnvironmentBindings {
107+
arguments: [].to_vec(),
108+
variables: self
109+
.environment
110+
.binding_variables
111+
.clone()
112+
.into_iter()
113+
.map(|(key, value)| {
114+
(
115+
key,
116+
EnvironmentVariableDesc {
117+
value,
118+
configurable: false,
119+
enumerable: true,
120+
writable: false,
121+
},
122+
)
123+
})
124+
.collect(),
125+
}),
97126
}
98127
}
99128
}

components/script/dom/debugger/debuggerglobalscope.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,13 @@ impl DebuggerGlobalScopeMethods<crate::DomTypeHolder> for DebuggerGlobalScope {
606606
type_: environment.type_.clone().map(String::from),
607607
scope_kind: environment.scopeKind.clone().map(String::from),
608608
function_display_name: environment.functionDisplayName.clone().map(String::from),
609+
binding_variables: environment
610+
.bindingVariables
611+
.as_deref()
612+
.into_iter()
613+
.flatten()
614+
.map(|(key, value)| (key.clone().into(), value.clone().into()))
615+
.collect(),
609616
};
610617

611618
let msg = ScriptToDevtoolsControlMsg::CreateEnvironmentActor(

components/script_bindings/webidls/DebuggerGetEnvironmentEvent.webidl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ dictionary EnvironmentInfo {
2323
DOMString type_;
2424
DOMString scopeKind;
2525
DOMString functionDisplayName;
26+
record<DOMString, DOMString> bindingVariables;
2627
};

components/shared/devtools/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ pub struct EnvironmentInfo {
611611
pub type_: Option<String>,
612612
pub scope_kind: Option<String>,
613613
pub function_display_name: Option<String>,
614+
pub binding_variables: HashMap<String, String>,
614615
}
615616

616617
#[derive(Clone, Debug, Deserialize, Serialize)]

resources/debugger.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,30 @@ function createEnvironmentActor(environment) {
411411
parent = createEnvironmentActor(environment.parent);
412412
}
413413

414+
if (environment.type == "declarative") {
415+
info.bindingVariables = buildBindings(environment)
416+
}
417+
418+
// TODO: Update this instead of registering
414419
actor = registerEnvironmentActor(info, parent);
415420
environmentActorsToEnvironments.set(actor, environment);
416421
}
417422

418423
return actor;
419424
}
420425

426+
function buildBindings(environment) {
427+
let bindingVar = new Map();
428+
for (const name of environment.names()) {
429+
const value = environment.getVariable(name);
430+
// <https://searchfox.org/firefox-main/source/devtools/server/actors/environment.js#87>
431+
// We should not do this, it is more of a place holder for now.
432+
// TODO: build and pass correct structure for this. This structure is very similar to "eval"
433+
bindingVar[name] = JSON.stringify(value);
434+
}
435+
return bindingVar;
436+
}
437+
421438
// Get a `Debugger.Environment` instance within which evaluation is taking place.
422439
// <https://searchfox.org/firefox-main/source/devtools/server/actors/frame.js#109>
423440
addEventListener("getEnvironment", event => {

0 commit comments

Comments
 (0)