1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00

refactor(cli/inspector): use &str for post_message (#7851)

This changes the signature of InspectorSession.post_message to take a
&str rather than a String avoiding the need call str.to_string at each
call site.
This commit is contained in:
Casper Beyer 2020-10-07 16:24:15 +08:00 committed by GitHub
parent 7ab645f512
commit cb3a3a1e95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 22 deletions

View file

@ -20,20 +20,14 @@ impl CoverageCollector {
} }
pub async fn start_collecting(&mut self) -> Result<(), AnyError> { pub async fn start_collecting(&mut self) -> Result<(), AnyError> {
self self.session.post_message("Debugger.enable", None).await?;
.session
.post_message("Debugger.enable".to_string(), None)
.await?;
self self.session.post_message("Profiler.enable", None).await?;
.session
.post_message("Profiler.enable".to_string(), None)
.await?;
self self
.session .session
.post_message( .post_message(
"Profiler.startPreciseCoverage".to_string(), "Profiler.startPreciseCoverage",
Some(json!({"callCount": true, "detailed": true})), Some(json!({"callCount": true, "detailed": true})),
) )
.await?; .await?;
@ -44,7 +38,7 @@ impl CoverageCollector {
pub async fn collect(&mut self) -> Result<Vec<Coverage>, AnyError> { pub async fn collect(&mut self) -> Result<Vec<Coverage>, AnyError> {
let result = self let result = self
.session .session
.post_message("Profiler.takePreciseCoverage".to_string(), None) .post_message("Profiler.takePreciseCoverage", None)
.await?; .await?;
let take_coverage_result: TakePreciseCoverageResult = let take_coverage_result: TakePreciseCoverageResult =
@ -55,7 +49,7 @@ impl CoverageCollector {
let result = self let result = self
.session .session
.post_message( .post_message(
"Debugger.getScriptSource".to_string(), "Debugger.getScriptSource",
Some(json!({ Some(json!({
"scriptId": script_coverage.script_id, "scriptId": script_coverage.script_id,
})), })),
@ -77,16 +71,10 @@ impl CoverageCollector {
pub async fn stop_collecting(&mut self) -> Result<(), AnyError> { pub async fn stop_collecting(&mut self) -> Result<(), AnyError> {
self self
.session .session
.post_message("Profiler.stopPreciseCoverage".to_string(), None) .post_message("Profiler.stopPreciseCoverage", None)
.await?;
self
.session
.post_message("Profiler.disable".to_string(), None)
.await?;
self
.session
.post_message("Debugger.disable".to_string(), None)
.await?; .await?;
self.session.post_message("Profiler.disable", None).await?;
self.session.post_message("Debugger.disable", None).await?;
Ok(()) Ok(())
} }

View file

@ -901,7 +901,7 @@ impl InspectorSession {
pub async fn post_message( pub async fn post_message(
&mut self, &mut self,
method: String, method: &str,
params: Option<serde_json::Value>, params: Option<serde_json::Value>,
) -> Result<serde_json::Value, AnyError> { ) -> Result<serde_json::Value, AnyError> {
let id = self.next_message_id; let id = self.next_message_id;

View file

@ -38,7 +38,7 @@ async fn post_message_and_poll(
method: &str, method: &str,
params: Option<Value>, params: Option<Value>,
) -> Result<Value, AnyError> { ) -> Result<Value, AnyError> {
let response = session.post_message(method.to_string(), params); let response = session.post_message(method, params);
tokio::pin!(response); tokio::pin!(response);
loop { loop {