mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 12:49:10 +00:00
This reverts commit 382a978859
.
This commit is contained in:
parent
56ea75817e
commit
b7b6b9c9e5
8 changed files with 109 additions and 642 deletions
474
cli/cdp.rs
474
cli/cdp.rs
|
@ -1,474 +0,0 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/
|
|
||||||
use deno_core::serde_json;
|
|
||||||
use deno_core::serde_json::Value;
|
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-awaitPromise
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct AwaitPromiseArgs {
|
|
||||||
pub promise_object_id: RemoteObjectId,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub return_by_value: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub generate_preview: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-awaitPromise
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct AwaitPromiseResponse {
|
|
||||||
pub result: RemoteObject,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-callFunctionOn
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CallFunctionOnArgs {
|
|
||||||
pub function_declaration: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_id: Option<RemoteObjectId>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub arguments: Option<Vec<CallArgument>>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub silent: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub return_by_value: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub generate_preview: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub user_gesture: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub await_promise: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub execution_context_id: Option<ExecutionContextId>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_group: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub throw_on_side_effect: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-callFunctionOn
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CallFunctionOnResponse {
|
|
||||||
pub result: RemoteObject,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-compileScript
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CompileScriptArgs {
|
|
||||||
pub expression: String,
|
|
||||||
#[serde(rename = "sourceURL")]
|
|
||||||
pub source_url: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub execution_context_id: Option<ExecutionContextId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-compileScript
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CompileScriptResponse {
|
|
||||||
pub script_id: Option<ScriptId>,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-evaluate
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct EvaluateArgs {
|
|
||||||
pub expression: String,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_group: Option<String>,
|
|
||||||
#[serde(
|
|
||||||
rename = "includeCommandLineAPI",
|
|
||||||
skip_serializing_if = "Option::is_none"
|
|
||||||
)]
|
|
||||||
pub include_command_line_api: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub silent: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub context_id: Option<ExecutionContextId>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub return_by_value: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub generate_preview: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub user_gesture: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub await_promise: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub throw_on_side_effect: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub timeout: Option<TimeDelta>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub disable_breaks: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub repl_mode: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
#[serde(rename = "allowUnsafeEvalBlockedByCSP")]
|
|
||||||
pub allow_unsafe_eval_blocked_by_csp: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub unique_context_id: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-evaluate
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct EvaluateResponse {
|
|
||||||
pub result: RemoteObject,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-getProperties
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct GetPropertiesArgs {
|
|
||||||
pub object_id: RemoteObjectId,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub own_properties: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub accessor_properties_only: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub generate_preview: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub non_indexed_properties_only: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-getProperties
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct GetPropertiesResponse {
|
|
||||||
pub result: Vec<PropertyDescriptor>,
|
|
||||||
pub internal_properties: Vec<InternalPropertyDescriptor>,
|
|
||||||
pub private_properties: Vec<PrivatePropertyDescriptor>,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-globalLexicalScopeNames
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct GlobalLexicalScopeNamesArgs {
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub execution_context_id: Option<ExecutionContextId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-globalLexicalScopeNames
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct GlobalLexicalScopeNamesResponse {
|
|
||||||
pub names: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-queryObjects
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct QueryObjectsArgs {
|
|
||||||
pub prototype_object_id: RemoteObjectId,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_group: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-queryObjects
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct QueryObjectsResponse {
|
|
||||||
pub objects: RemoteObject,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-releaseObject
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ReleaseObjectArgs {
|
|
||||||
pub object_id: RemoteObjectId,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-releaseObjectGroup
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ReleaseObjectGroupArgs {
|
|
||||||
pub object_group: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-runScript
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct RunScriptArgs {
|
|
||||||
pub script_id: ScriptId,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub execution_context_id: Option<ExecutionContextId>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_group: Option<String>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub silent: Option<bool>,
|
|
||||||
#[serde(
|
|
||||||
rename = "includeCommandLineAPI",
|
|
||||||
skip_serializing_if = "Option::is_none"
|
|
||||||
)]
|
|
||||||
pub include_command_line_api: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub return_by_value: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub generate_preview: Option<bool>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub await_promise: Option<bool>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-runScript
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct RunScriptResponse {
|
|
||||||
pub result: RemoteObject,
|
|
||||||
pub exception_details: Option<ExceptionDetails>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-setAsyncCallStackDepth
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct SetAsyncCallStackDepthArgs {
|
|
||||||
pub max_depth: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
// types
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub enum RemoteObjectType {
|
|
||||||
Object,
|
|
||||||
Function,
|
|
||||||
Undefined,
|
|
||||||
String,
|
|
||||||
Number,
|
|
||||||
Boolean,
|
|
||||||
Symbol,
|
|
||||||
Bigint,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for RemoteObjectType {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.write_str(&format!("{:?}", self).to_lowercase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub enum RemoteObjectSubType {
|
|
||||||
Array,
|
|
||||||
Null,
|
|
||||||
Node,
|
|
||||||
Regexp,
|
|
||||||
Date,
|
|
||||||
Map,
|
|
||||||
Set,
|
|
||||||
Weakmap,
|
|
||||||
Weakset,
|
|
||||||
Iterator,
|
|
||||||
Generator,
|
|
||||||
Error,
|
|
||||||
Proxy,
|
|
||||||
Promise,
|
|
||||||
Typedarray,
|
|
||||||
Arraybuffer,
|
|
||||||
Dataview,
|
|
||||||
Webassemblymemory,
|
|
||||||
Wasmvalue,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObject
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct RemoteObject {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub kind: RemoteObjectType,
|
|
||||||
pub subtype: Option<RemoteObjectSubType>,
|
|
||||||
pub class_name: Option<String>,
|
|
||||||
pub value: Option<Value>,
|
|
||||||
pub unserializable_value: Option<UnserializableValue>,
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub object_id: Option<RemoteObjectId>,
|
|
||||||
pub preview: Option<ObjectPreview>,
|
|
||||||
pub custom_preview: Option<CustomPreview>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ObjectPreview
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ObjectPreview {
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub kind: RemoteObjectType,
|
|
||||||
pub subtype: Option<RemoteObjectSubType>,
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub overflow: bool,
|
|
||||||
pub properties: Vec<PropertyPreview>,
|
|
||||||
pub entries: Option<Vec<EntryPreview>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-PropertyPreview
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PropertyPreview {
|
|
||||||
pub name: String,
|
|
||||||
#[serde(rename = "type")]
|
|
||||||
pub kind: PropertyPreviewType,
|
|
||||||
pub value: Option<String>,
|
|
||||||
pub value_preview: Option<ObjectPreview>,
|
|
||||||
pub subtype: Option<RemoteObjectSubType>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-PropertyPreview
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub enum PropertyPreviewType {
|
|
||||||
Object,
|
|
||||||
Function,
|
|
||||||
Undefined,
|
|
||||||
String,
|
|
||||||
Number,
|
|
||||||
Boolean,
|
|
||||||
Symbol,
|
|
||||||
Accessor,
|
|
||||||
Bigint,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-EntryPreview
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct EntryPreview {
|
|
||||||
pub key: Option<ObjectPreview>,
|
|
||||||
pub value: ObjectPreview,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-CustomPreview
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CustomPreview {
|
|
||||||
pub header: String,
|
|
||||||
pub body_getter_id: RemoteObjectId,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ExceptionDetails
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct ExceptionDetails {
|
|
||||||
pub exception_id: u64,
|
|
||||||
pub text: String,
|
|
||||||
pub line_number: u64,
|
|
||||||
pub column_number: u64,
|
|
||||||
pub script_id: Option<ScriptId>,
|
|
||||||
pub url: Option<String>,
|
|
||||||
pub stack_trace: Option<StackTrace>,
|
|
||||||
pub exception: Option<RemoteObject>,
|
|
||||||
pub execution_context_id: Option<ExecutionContextId>,
|
|
||||||
pub exception_meta_data: Option<serde_json::Map<String, Value>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-StackTrace
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct StackTrace {
|
|
||||||
pub description: Option<String>,
|
|
||||||
pub call_frames: Vec<CallFrame>,
|
|
||||||
pub parent: Option<Box<StackTrace>>,
|
|
||||||
pub parent_id: Option<StackTraceId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-CallFrame
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CallFrame {
|
|
||||||
pub function_name: String,
|
|
||||||
pub script_id: ScriptId,
|
|
||||||
pub url: String,
|
|
||||||
pub line_number: u64,
|
|
||||||
pub column_number: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-StackTraceId
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct StackTraceId {
|
|
||||||
pub id: String,
|
|
||||||
pub debugger_id: Option<UniqueDebuggerId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-CallArgument
|
|
||||||
#[derive(Debug, Clone, Serialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct CallArgument {
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub value: Option<Value>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub unserializable_value: Option<UnserializableValue>,
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
|
||||||
pub object_id: Option<RemoteObjectId>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<&RemoteObject> for CallArgument {
|
|
||||||
fn from(obj: &RemoteObject) -> Self {
|
|
||||||
Self {
|
|
||||||
value: obj.value.clone(),
|
|
||||||
unserializable_value: obj.unserializable_value.clone(),
|
|
||||||
object_id: obj.object_id.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-InternalPropertyDescriptor
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PropertyDescriptor {
|
|
||||||
pub name: String,
|
|
||||||
pub value: Option<RemoteObject>,
|
|
||||||
pub writable: Option<bool>,
|
|
||||||
pub get: Option<RemoteObject>,
|
|
||||||
pub set: Option<RemoteObject>,
|
|
||||||
pub configurable: bool,
|
|
||||||
pub enumerable: bool,
|
|
||||||
pub was_thrown: Option<bool>,
|
|
||||||
pub is_own: Option<bool>,
|
|
||||||
pub symbol: Option<RemoteObject>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-InternalPropertyDescriptor
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct InternalPropertyDescriptor {
|
|
||||||
pub name: String,
|
|
||||||
pub value: Option<RemoteObject>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-PrivatePropertyDescriptor
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct PrivatePropertyDescriptor {
|
|
||||||
pub name: String,
|
|
||||||
pub value: Option<RemoteObject>,
|
|
||||||
pub get: Option<RemoteObject>,
|
|
||||||
pub set: Option<RemoteObject>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-RemoteObjectId
|
|
||||||
pub type RemoteObjectId = String;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ExecutionContextId
|
|
||||||
pub type ExecutionContextId = u64;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-ScriptId
|
|
||||||
pub type ScriptId = String;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-TimeDelta
|
|
||||||
pub type TimeDelta = u64;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-UnserializableValue
|
|
||||||
pub type UnserializableValue = String;
|
|
||||||
|
|
||||||
/// https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#type-UniqueDebuggerId
|
|
||||||
pub type UniqueDebuggerId = String;
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
mod auth_tokens;
|
mod auth_tokens;
|
||||||
mod cache;
|
mod cache;
|
||||||
mod cdp;
|
|
||||||
mod checksum;
|
mod checksum;
|
||||||
mod compat;
|
mod compat;
|
||||||
mod config_file;
|
mod config_file;
|
||||||
|
|
|
@ -43,34 +43,22 @@ impl CoverageCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn enable_debugger(&mut self) -> Result<(), AnyError> {
|
async fn enable_debugger(&mut self) -> Result<(), AnyError> {
|
||||||
self
|
self.session.post_message("Debugger.enable", None).await?;
|
||||||
.session
|
|
||||||
.post_message::<()>("Debugger.enable", None)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn enable_profiler(&mut self) -> Result<(), AnyError> {
|
async fn enable_profiler(&mut self) -> Result<(), AnyError> {
|
||||||
self
|
self.session.post_message("Profiler.enable", None).await?;
|
||||||
.session
|
|
||||||
.post_message::<()>("Profiler.enable", None)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn disable_debugger(&mut self) -> Result<(), AnyError> {
|
async fn disable_debugger(&mut self) -> Result<(), AnyError> {
|
||||||
self
|
self.session.post_message("Debugger.disable", None).await?;
|
||||||
.session
|
|
||||||
.post_message::<()>("Debugger.disable", None)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn disable_profiler(&mut self) -> Result<(), AnyError> {
|
async fn disable_profiler(&mut self) -> Result<(), AnyError> {
|
||||||
self
|
self.session.post_message("Profiler.disable", None).await?;
|
||||||
.session
|
|
||||||
.post_message::<()>("Profiler.disable", None)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +66,10 @@ impl CoverageCollector {
|
||||||
&mut self,
|
&mut self,
|
||||||
parameters: StartPreciseCoverageParameters,
|
parameters: StartPreciseCoverageParameters,
|
||||||
) -> Result<StartPreciseCoverageReturnObject, AnyError> {
|
) -> Result<StartPreciseCoverageReturnObject, AnyError> {
|
||||||
|
let parameters_value = serde_json::to_value(parameters)?;
|
||||||
let return_value = self
|
let return_value = self
|
||||||
.session
|
.session
|
||||||
.post_message("Profiler.startPreciseCoverage", Some(parameters))
|
.post_message("Profiler.startPreciseCoverage", Some(parameters_value))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let return_object = serde_json::from_value(return_value)?;
|
let return_object = serde_json::from_value(return_value)?;
|
||||||
|
@ -93,7 +82,7 @@ impl CoverageCollector {
|
||||||
) -> Result<TakePreciseCoverageReturnObject, AnyError> {
|
) -> Result<TakePreciseCoverageReturnObject, AnyError> {
|
||||||
let return_value = self
|
let return_value = self
|
||||||
.session
|
.session
|
||||||
.post_message::<()>("Profiler.takePreciseCoverage", None)
|
.post_message("Profiler.takePreciseCoverage", None)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let return_object = serde_json::from_value(return_value)?;
|
let return_object = serde_json::from_value(return_value)?;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use deno_core::anyhow::anyhow;
|
use deno_core::anyhow::anyhow;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::serde_json;
|
|
||||||
use deno_core::serde_json::Value;
|
use deno_core::serde_json::Value;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use tokio::sync::mpsc::channel;
|
use tokio::sync::mpsc::channel;
|
||||||
|
@ -56,19 +55,17 @@ pub struct RustylineSyncMessageSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RustylineSyncMessageSender {
|
impl RustylineSyncMessageSender {
|
||||||
pub fn post_message<T: serde::Serialize>(
|
pub fn post_message(
|
||||||
&self,
|
&self,
|
||||||
method: &str,
|
method: &str,
|
||||||
params: Option<T>,
|
params: Option<Value>,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
if let Err(err) =
|
if let Err(err) =
|
||||||
self
|
self
|
||||||
.message_tx
|
.message_tx
|
||||||
.blocking_send(RustylineSyncMessage::PostMessage {
|
.blocking_send(RustylineSyncMessage::PostMessage {
|
||||||
method: method.to_string(),
|
method: method.to_string(),
|
||||||
params: params
|
params,
|
||||||
.map(|params| serde_json::to_value(params))
|
|
||||||
.transpose()?,
|
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
Err(anyhow!("{}", err))
|
Err(anyhow!("{}", err))
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::cdp;
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use deno_ast::swc::parser::error::SyntaxError;
|
use deno_ast::swc::parser::error::SyntaxError;
|
||||||
use deno_ast::swc::parser::token::Token;
|
use deno_ast::swc::parser::token::Token;
|
||||||
use deno_ast::swc::parser::token::Word;
|
use deno_ast::swc::parser::token::Word;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::parking_lot::Mutex;
|
use deno_core::parking_lot::Mutex;
|
||||||
use deno_core::serde_json;
|
use deno_core::serde_json::json;
|
||||||
|
use deno_core::serde_json::Value;
|
||||||
use rustyline::completion::Completer;
|
use rustyline::completion::Completer;
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::highlight::Highlighter;
|
use rustyline::highlight::Highlighter;
|
||||||
|
@ -39,14 +39,20 @@ impl EditorHelper {
|
||||||
.sync_sender
|
.sync_sender
|
||||||
.post_message(
|
.post_message(
|
||||||
"Runtime.globalLexicalScopeNames",
|
"Runtime.globalLexicalScopeNames",
|
||||||
Some(cdp::GlobalLexicalScopeNamesArgs {
|
Some(json!({
|
||||||
execution_context_id: Some(self.context_id),
|
"executionContextId": self.context_id,
|
||||||
}),
|
})),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let evaluate_response: cdp::GlobalLexicalScopeNamesResponse =
|
|
||||||
serde_json::from_value(evaluate_response).unwrap();
|
evaluate_response
|
||||||
evaluate_response.names
|
.get("names")
|
||||||
|
.unwrap()
|
||||||
|
.as_array()
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|n| n.as_str().unwrap().to_string())
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_expression_property_names(&self, expr: &str) -> Vec<String> {
|
pub fn get_expression_property_names(&self, expr: &str) -> Vec<String> {
|
||||||
|
@ -75,8 +81,11 @@ impl EditorHelper {
|
||||||
|
|
||||||
fn get_expression_type(&self, expr: &str) -> Option<String> {
|
fn get_expression_type(&self, expr: &str) -> Option<String> {
|
||||||
self
|
self
|
||||||
.evaluate_expression(expr)
|
.evaluate_expression(expr)?
|
||||||
.map(|res| res.result.kind.to_string())
|
.get("result")?
|
||||||
|
.get("type")?
|
||||||
|
.as_str()
|
||||||
|
.map(|s| s.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_object_expr_properties(
|
fn get_object_expr_properties(
|
||||||
|
@ -84,60 +93,44 @@ impl EditorHelper {
|
||||||
object_expr: &str,
|
object_expr: &str,
|
||||||
) -> Option<Vec<String>> {
|
) -> Option<Vec<String>> {
|
||||||
let evaluate_result = self.evaluate_expression(object_expr)?;
|
let evaluate_result = self.evaluate_expression(object_expr)?;
|
||||||
let object_id = evaluate_result.result.object_id?;
|
let object_id = evaluate_result.get("result")?.get("objectId")?;
|
||||||
|
|
||||||
let get_properties_response = self
|
let get_properties_response = self
|
||||||
.sync_sender
|
.sync_sender
|
||||||
.post_message(
|
.post_message(
|
||||||
"Runtime.getProperties",
|
"Runtime.getProperties",
|
||||||
Some(cdp::GetPropertiesArgs {
|
Some(json!({
|
||||||
object_id,
|
"objectId": object_id,
|
||||||
own_properties: None,
|
})),
|
||||||
accessor_properties_only: None,
|
|
||||||
generate_preview: None,
|
|
||||||
non_indexed_properties_only: None,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let get_properties_response: cdp::GetPropertiesResponse =
|
|
||||||
serde_json::from_value(get_properties_response).ok()?;
|
|
||||||
Some(
|
Some(
|
||||||
get_properties_response
|
get_properties_response
|
||||||
.result
|
.get("result")?
|
||||||
.into_iter()
|
.as_array()
|
||||||
.map(|prop| prop.name)
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.get("name").unwrap().as_str().unwrap().to_string())
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn evaluate_expression(&self, expr: &str) -> Option<cdp::EvaluateResponse> {
|
fn evaluate_expression(&self, expr: &str) -> Option<Value> {
|
||||||
let evaluate_response = self
|
let evaluate_response = self
|
||||||
.sync_sender
|
.sync_sender
|
||||||
.post_message(
|
.post_message(
|
||||||
"Runtime.evaluate",
|
"Runtime.evaluate",
|
||||||
Some(cdp::EvaluateArgs {
|
Some(json!({
|
||||||
expression: expr.to_string(),
|
"contextId": self.context_id,
|
||||||
object_group: None,
|
"expression": expr,
|
||||||
include_command_line_api: None,
|
"throwOnSideEffect": true,
|
||||||
silent: None,
|
"timeout": 200,
|
||||||
context_id: Some(self.context_id),
|
})),
|
||||||
return_by_value: None,
|
|
||||||
generate_preview: None,
|
|
||||||
user_gesture: None,
|
|
||||||
await_promise: None,
|
|
||||||
throw_on_side_effect: Some(true),
|
|
||||||
timeout: Some(200),
|
|
||||||
disable_breaks: None,
|
|
||||||
repl_mode: None,
|
|
||||||
allow_unsafe_eval_blocked_by_csp: None,
|
|
||||||
unique_context_id: None,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.ok()?;
|
.ok()?;
|
||||||
let evaluate_response: cdp::EvaluateResponse =
|
|
||||||
serde_json::from_value(evaluate_response).ok()?;
|
|
||||||
|
|
||||||
if evaluate_response.exception_details.is_some() {
|
if evaluate_response.get("exceptionDetails").is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(evaluate_response)
|
Some(evaluate_response)
|
||||||
|
|
|
@ -33,7 +33,10 @@ async fn read_line_and_poll(
|
||||||
}
|
}
|
||||||
result = message_handler.recv() => {
|
result = message_handler.recv() => {
|
||||||
match result {
|
match result {
|
||||||
Some(RustylineSyncMessage::PostMessage { method, params }) => {
|
Some(RustylineSyncMessage::PostMessage {
|
||||||
|
method,
|
||||||
|
params
|
||||||
|
}) => {
|
||||||
let result = repl_session
|
let result = repl_session
|
||||||
.post_message_with_event_loop(&method, params)
|
.post_message_with_event_loop(&method, params)
|
||||||
.await;
|
.await;
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::cdp;
|
|
||||||
use crate::colors;
|
use crate::colors;
|
||||||
use crate::lsp::ReplLanguageServer;
|
use crate::lsp::ReplLanguageServer;
|
||||||
use deno_ast::DiagnosticsError;
|
use deno_ast::DiagnosticsError;
|
||||||
use deno_ast::ImportsNotUsedAsValues;
|
use deno_ast::ImportsNotUsedAsValues;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::futures::FutureExt;
|
use deno_core::futures::FutureExt;
|
||||||
use deno_core::serde_json;
|
use deno_core::serde_json::json;
|
||||||
use deno_core::serde_json::Value;
|
use deno_core::serde_json::Value;
|
||||||
use deno_core::LocalInspectorSession;
|
use deno_core::LocalInspectorSession;
|
||||||
use deno_runtime::worker::MainWorker;
|
use deno_runtime::worker::MainWorker;
|
||||||
|
@ -59,7 +58,7 @@ impl std::fmt::Display for EvaluationOutput {
|
||||||
|
|
||||||
struct TsEvaluateResponse {
|
struct TsEvaluateResponse {
|
||||||
ts_code: String,
|
ts_code: String,
|
||||||
value: cdp::EvaluateResponse,
|
value: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ReplSession {
|
pub struct ReplSession {
|
||||||
|
@ -76,9 +75,7 @@ impl ReplSession {
|
||||||
|
|
||||||
worker
|
worker
|
||||||
.with_event_loop(
|
.with_event_loop(
|
||||||
session
|
session.post_message("Runtime.enable", None).boxed_local(),
|
||||||
.post_message::<()>("Runtime.enable", None)
|
|
||||||
.boxed_local(),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -118,8 +115,9 @@ impl ReplSession {
|
||||||
let closed = self
|
let closed = self
|
||||||
.evaluate_expression("(this.closed)")
|
.evaluate_expression("(this.closed)")
|
||||||
.await?
|
.await?
|
||||||
.result
|
.get("result")
|
||||||
.value
|
.unwrap()
|
||||||
|
.get("value")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_bool()
|
.as_bool()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -127,10 +125,10 @@ impl ReplSession {
|
||||||
Ok(closed)
|
Ok(closed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post_message_with_event_loop<T: serde::Serialize>(
|
pub async fn post_message_with_event_loop(
|
||||||
&mut self,
|
&mut self,
|
||||||
method: &str,
|
method: &str,
|
||||||
params: Option<T>,
|
params: Option<Value>,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
self
|
self
|
||||||
.worker
|
.worker
|
||||||
|
@ -158,24 +156,23 @@ impl ReplSession {
|
||||||
|
|
||||||
match self.evaluate_line_with_object_wrapping(line).await {
|
match self.evaluate_line_with_object_wrapping(line).await {
|
||||||
Ok(evaluate_response) => {
|
Ok(evaluate_response) => {
|
||||||
let cdp::EvaluateResponse {
|
let evaluate_result = evaluate_response.value.get("result").unwrap();
|
||||||
result,
|
let evaluate_exception_details =
|
||||||
exception_details,
|
evaluate_response.value.get("exceptionDetails");
|
||||||
} = evaluate_response.value;
|
|
||||||
|
|
||||||
if exception_details.is_some() {
|
if evaluate_exception_details.is_some() {
|
||||||
self.set_last_thrown_error(&result).await?;
|
self.set_last_thrown_error(evaluate_result).await?;
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
.language_server
|
.language_server
|
||||||
.commit_text(&evaluate_response.ts_code)
|
.commit_text(&evaluate_response.ts_code)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
self.set_last_eval_result(&result).await?;
|
self.set_last_eval_result(evaluate_result).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = self.get_eval_value(&result).await?;
|
let value = self.get_eval_value(evaluate_result).await?;
|
||||||
Ok(match exception_details {
|
Ok(match evaluate_exception_details {
|
||||||
Some(_) => EvaluationOutput::Error(format!("Uncaught {}", value)),
|
Some(_) => EvaluationOutput::Error(format!("Uncaught {}", value)),
|
||||||
None => EvaluationOutput::Value(value),
|
None => EvaluationOutput::Value(value),
|
||||||
})
|
})
|
||||||
|
@ -227,7 +224,7 @@ impl ReplSession {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.value
|
.value
|
||||||
.exception_details
|
.get("exceptionDetails")
|
||||||
.is_some())
|
.is_some())
|
||||||
{
|
{
|
||||||
self.evaluate_ts_expression(line).await
|
self.evaluate_ts_expression(line).await
|
||||||
|
@ -238,90 +235,66 @@ impl ReplSession {
|
||||||
|
|
||||||
async fn set_last_thrown_error(
|
async fn set_last_thrown_error(
|
||||||
&mut self,
|
&mut self,
|
||||||
error: &cdp::RemoteObject,
|
error: &Value,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
self.post_message_with_event_loop(
|
self.post_message_with_event_loop(
|
||||||
"Runtime.callFunctionOn",
|
"Runtime.callFunctionOn",
|
||||||
Some(cdp::CallFunctionOnArgs {
|
Some(json!({
|
||||||
function_declaration: "function (object) { Deno[Deno.internal].lastThrownError = object; }".to_string(),
|
"executionContextId": self.context_id,
|
||||||
object_id: None,
|
"functionDeclaration": "function (object) { Deno[Deno.internal].lastThrownError = object; }",
|
||||||
arguments: Some(vec![error.into()]),
|
"arguments": [
|
||||||
silent: None,
|
error,
|
||||||
return_by_value: None,
|
],
|
||||||
generate_preview: None,
|
})),
|
||||||
user_gesture: None,
|
|
||||||
await_promise: None,
|
|
||||||
execution_context_id: Some(self.context_id),
|
|
||||||
object_group: None,
|
|
||||||
throw_on_side_effect: None
|
|
||||||
}),
|
|
||||||
).await?;
|
).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn set_last_eval_result(
|
async fn set_last_eval_result(
|
||||||
&mut self,
|
&mut self,
|
||||||
evaluate_result: &cdp::RemoteObject,
|
evaluate_result: &Value,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
self
|
self.post_message_with_event_loop(
|
||||||
.post_message_with_event_loop(
|
"Runtime.callFunctionOn",
|
||||||
"Runtime.callFunctionOn",
|
Some(json!({
|
||||||
Some(cdp::CallFunctionOnArgs {
|
"executionContextId": self.context_id,
|
||||||
function_declaration:
|
"functionDeclaration": "function (object) { Deno[Deno.internal].lastEvalResult = object; }",
|
||||||
"function (object) { Deno[Deno.internal].lastEvalResult = object; }"
|
"arguments": [
|
||||||
.to_string(),
|
evaluate_result,
|
||||||
object_id: None,
|
],
|
||||||
arguments: Some(vec![evaluate_result.into()]),
|
})),
|
||||||
silent: None,
|
).await?;
|
||||||
return_by_value: None,
|
|
||||||
generate_preview: None,
|
|
||||||
user_gesture: None,
|
|
||||||
await_promise: None,
|
|
||||||
execution_context_id: Some(self.context_id),
|
|
||||||
object_group: None,
|
|
||||||
throw_on_side_effect: None,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_eval_value(
|
pub async fn get_eval_value(
|
||||||
&mut self,
|
&mut self,
|
||||||
evaluate_result: &cdp::RemoteObject,
|
evaluate_result: &Value,
|
||||||
) -> Result<String, AnyError> {
|
) -> Result<String, AnyError> {
|
||||||
// TODO(caspervonb) we should investigate using previews here but to keep things
|
// TODO(caspervonb) we should investigate using previews here but to keep things
|
||||||
// consistent with the previous implementation we just get the preview result from
|
// consistent with the previous implementation we just get the preview result from
|
||||||
// Deno.inspectArgs.
|
// Deno.inspectArgs.
|
||||||
let inspect_response = self.post_message_with_event_loop(
|
let inspect_response = self.post_message_with_event_loop(
|
||||||
"Runtime.callFunctionOn",
|
"Runtime.callFunctionOn",
|
||||||
Some(cdp::CallFunctionOnArgs {
|
Some(json!({
|
||||||
function_declaration: r#"function (object) {
|
"executionContextId": self.context_id,
|
||||||
|
"functionDeclaration": r#"function (object) {
|
||||||
try {
|
try {
|
||||||
return Deno[Deno.internal].inspectArgs(["%o", object], { colors: !Deno.noColor });
|
return Deno[Deno.internal].inspectArgs(["%o", object], { colors: !Deno.noColor });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return Deno[Deno.internal].inspectArgs(["%o", err]);
|
return Deno[Deno.internal].inspectArgs(["%o", err]);
|
||||||
}
|
}
|
||||||
}"#.to_string(),
|
}"#,
|
||||||
object_id: None,
|
"arguments": [
|
||||||
arguments: Some(vec![evaluate_result.into()]),
|
evaluate_result,
|
||||||
silent: None,
|
],
|
||||||
return_by_value: None,
|
})),
|
||||||
generate_preview: None,
|
|
||||||
user_gesture: None,
|
|
||||||
await_promise: None,
|
|
||||||
execution_context_id: Some(self.context_id),
|
|
||||||
object_group: None,
|
|
||||||
throw_on_side_effect: None
|
|
||||||
}),
|
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
let response: cdp::CallFunctionOnResponse =
|
let inspect_result = inspect_response.get("result").unwrap();
|
||||||
serde_json::from_value(inspect_response)?;
|
let value = inspect_result.get("value").unwrap().as_str().unwrap();
|
||||||
let value = response.result.value.unwrap();
|
|
||||||
let s = value.as_str().unwrap();
|
|
||||||
|
|
||||||
Ok(s.to_string())
|
Ok(value.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn evaluate_ts_expression(
|
async fn evaluate_ts_expression(
|
||||||
|
@ -371,29 +344,16 @@ impl ReplSession {
|
||||||
async fn evaluate_expression(
|
async fn evaluate_expression(
|
||||||
&mut self,
|
&mut self,
|
||||||
expression: &str,
|
expression: &str,
|
||||||
) -> Result<cdp::EvaluateResponse, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
self
|
self
|
||||||
.post_message_with_event_loop(
|
.post_message_with_event_loop(
|
||||||
"Runtime.evaluate",
|
"Runtime.evaluate",
|
||||||
Some(cdp::EvaluateArgs {
|
Some(json!({
|
||||||
expression: expression.to_string(),
|
"expression": expression,
|
||||||
object_group: None,
|
"contextId": self.context_id,
|
||||||
include_command_line_api: None,
|
"replMode": true,
|
||||||
silent: None,
|
})),
|
||||||
context_id: Some(self.context_id),
|
|
||||||
return_by_value: None,
|
|
||||||
generate_preview: None,
|
|
||||||
user_gesture: None,
|
|
||||||
await_promise: None,
|
|
||||||
throw_on_side_effect: None,
|
|
||||||
timeout: None,
|
|
||||||
disable_breaks: None,
|
|
||||||
repl_mode: Some(true),
|
|
||||||
allow_unsafe_eval_blocked_by_csp: None,
|
|
||||||
unique_context_id: None,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.and_then(|res| serde_json::from_value(res).map_err(|e| e.into()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -649,10 +649,10 @@ impl LocalInspectorSession {
|
||||||
self.notification_queue.split_off(0)
|
self.notification_queue.split_off(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post_message<T: serde::Serialize>(
|
pub async fn post_message(
|
||||||
&mut self,
|
&mut self,
|
||||||
method: &str,
|
method: &str,
|
||||||
params: Option<T>,
|
params: Option<serde_json::Value>,
|
||||||
) -> Result<serde_json::Value, Error> {
|
) -> Result<serde_json::Value, Error> {
|
||||||
let id = self.next_message_id;
|
let id = self.next_message_id;
|
||||||
self.next_message_id += 1;
|
self.next_message_id += 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue