mirror of
https://github.com/denoland/deno.git
synced 2025-01-11 08:33:43 -05:00
fix(jupyter): await Jupyter.display evaluation (#20646)
This commit is contained in:
parent
1ad097c4bf
commit
b1ca67ac01
1 changed files with 27 additions and 13 deletions
|
@ -540,19 +540,29 @@ async fn get_jupyter_display(
|
|||
evaluate_result: &cdp::RemoteObject,
|
||||
) -> Result<Option<HashMap<String, serde_json::Value>>, AnyError> {
|
||||
let response = session
|
||||
.call_function_on_args(
|
||||
r#"function (object) {
|
||||
.post_message_with_event_loop(
|
||||
"Runtime.callFunctionOn",
|
||||
Some(json!({
|
||||
"functionDeclaration": r#"function (object) {
|
||||
const display = object[Symbol.for("Jupyter.display")];
|
||||
if (typeof display === "function") {
|
||||
return JSON.stringify(display());
|
||||
} else {
|
||||
|
||||
if (typeof display !== "function") {
|
||||
return null;
|
||||
}
|
||||
}"#
|
||||
.to_string(),
|
||||
&[evaluate_result.clone()],
|
||||
|
||||
try {
|
||||
return JSON.stringify(display());
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}"#,
|
||||
"arguments": [cdp::CallArgument::from(evaluate_result)],
|
||||
"executionContextId": session.context_id,
|
||||
"awaitPromise": true,
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
let response: cdp::CallFunctionOnResponse = serde_json::from_value(response)?;
|
||||
|
||||
if let Some(exception_details) = &response.exception_details {
|
||||
// If the object doesn't have a Jupyter.display method or it throws an
|
||||
|
@ -599,9 +609,13 @@ async fn get_jupyter_display_or_eval_value(
|
|||
return Ok(HashMap::default());
|
||||
}
|
||||
|
||||
// If the response is a primitive value we don't need to try and format
|
||||
// Jupyter response.
|
||||
if evaluate_result.object_id.is_some() {
|
||||
if let Some(data) = get_jupyter_display(session, evaluate_result).await? {
|
||||
return Ok(data);
|
||||
}
|
||||
}
|
||||
|
||||
let response = session
|
||||
.call_function_on_args(
|
||||
|
|
Loading…
Reference in a new issue