mirror of
https://github.com/servo/servo.git
synced 2025-08-15 10:25:32 +01:00
script: Send JS evaluation errors to constellation (#38602)
Send JS evaluation errors to constellation in `script_thread::handle_evaluate_javascript` instead of silently swallowing. Testing: New test cases in `tests/webview.rs`: one for compilation failure, another for evaluation failure. Fixes: #37810 Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
This commit is contained in:
parent
9effdce5a1
commit
e5a73ede17
2 changed files with 15 additions and 2 deletions
|
@ -4048,14 +4048,21 @@ impl ScriptThread {
|
||||||
let context = window.get_cx();
|
let context = window.get_cx();
|
||||||
|
|
||||||
rooted!(in(*context) let mut return_value = UndefinedValue());
|
rooted!(in(*context) let mut return_value = UndefinedValue());
|
||||||
_ = global_scope.evaluate_js_on_global_with_result(
|
if let Err(err) = global_scope.evaluate_js_on_global_with_result(
|
||||||
&script,
|
&script,
|
||||||
return_value.handle_mut(),
|
return_value.handle_mut(),
|
||||||
ScriptFetchOptions::default_classic_script(global_scope),
|
ScriptFetchOptions::default_classic_script(global_scope),
|
||||||
global_scope.api_base_url(),
|
global_scope.api_base_url(),
|
||||||
can_gc,
|
can_gc,
|
||||||
None, // No known `introductionType` for JS code from embedder
|
None, // No known `introductionType` for JS code from embedder
|
||||||
);
|
) {
|
||||||
|
_ = self.senders.pipeline_to_constellation_sender.send((
|
||||||
|
pipeline_id,
|
||||||
|
ScriptToConstellationMessage::FinishJavaScriptEvaluation(evaluation_id, Err(err)),
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
let result = match jsval_to_webdriver(
|
let result = match jsval_to_webdriver(
|
||||||
context,
|
context,
|
||||||
global_scope,
|
global_scope,
|
||||||
|
|
|
@ -125,6 +125,12 @@ fn test_evaluate_javascript_basic(servo_test: &ServoTest) -> Result<(), anyhow::
|
||||||
);
|
);
|
||||||
ensure!(matches!(result, Ok(JSValue::Frame(..))));
|
ensure!(matches!(result, Ok(JSValue::Frame(..))));
|
||||||
|
|
||||||
|
let result = evaluate_javascript(servo_test, webview.clone(), "lettt badsyntax = 123");
|
||||||
|
ensure!(result == Err(JavaScriptEvaluationError::CompilationFailure));
|
||||||
|
|
||||||
|
let result = evaluate_javascript(servo_test, webview.clone(), "throw new Error()");
|
||||||
|
ensure!(result == Err(JavaScriptEvaluationError::EvaluationFailure));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue