webdriver: Reuse JSValue as WebDriverJSValue (#38751)

After #38748, `WebDriverJSValue` is almost same as `JSValue`. Now we
turn "potentially merge into one in the future" into reality. The only
thing we should be cautious is to properly serialize `WebFrame`,
`WebWindow`, `WebElement` for WebDriver.

Testing: No regression. Some error is fixed previously by #38709 which
didn't update test :)
Binary size reduced by 134KB.

---------

Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This commit is contained in:
Euclid Ye 2025-08-19 01:38:48 +08:00 committed by GitHub
parent 7471ad7730
commit ec5872992b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 57 additions and 101 deletions

View file

@ -1003,29 +1003,6 @@ pub enum JSValue {
Object(HashMap<String, JSValue>),
}
impl From<&WebDriverJSValue> for JSValue {
fn from(value: &WebDriverJSValue) -> Self {
match value {
WebDriverJSValue::Undefined => Self::Undefined,
WebDriverJSValue::Null => Self::Null,
WebDriverJSValue::Boolean(value) => Self::Boolean(*value),
WebDriverJSValue::Number(value) => Self::Number(*value),
WebDriverJSValue::String(value) => Self::String(value.clone()),
WebDriverJSValue::Element(web_element) => Self::Element(web_element.0.clone()),
WebDriverJSValue::Frame(web_frame) => Self::Frame(web_frame.0.clone()),
WebDriverJSValue::Window(web_window) => Self::Window(web_window.0.clone()),
WebDriverJSValue::ArrayLike(vector) => {
Self::Array(vector.iter().map(Into::into).collect())
},
WebDriverJSValue::Object(map) => Self::Object(
map.iter()
.map(|(key, value)| (key.clone(), value.into()))
.collect(),
),
}
}
}
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub enum JavaScriptEvaluationError {
/// The script could not be compiled

View file

@ -19,11 +19,10 @@ use serde::{Deserialize, Serialize};
use servo_geometry::DeviceIndependentIntRect;
use servo_url::ServoUrl;
use style_traits::CSSPixel;
use webdriver::common::{WebElement, WebFrame, WebWindow};
use webdriver::error::ErrorStatus;
use webrender_api::units::DevicePixel;
use crate::{FocusId, MouseButton, MouseButtonAction, TraversalId};
use crate::{FocusId, JSValue, MouseButton, MouseButtonAction, TraversalId};
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
pub struct WebDriverMessageId(pub usize);
@ -226,11 +225,7 @@ pub enum WebDriverScriptCommand {
String,
IpcSender<Result<Option<String>, ErrorStatus>>,
),
GetElementProperty(
String,
String,
IpcSender<Result<WebDriverJSValue, ErrorStatus>>,
),
GetElementProperty(String, String, IpcSender<Result<JSValue, ErrorStatus>>),
GetElementCSS(String, String, IpcSender<Result<String, ErrorStatus>>),
GetElementRect(String, IpcSender<Result<UntypedRect<f64>, ErrorStatus>>),
GetElementTagName(String, IpcSender<Result<String, ErrorStatus>>),
@ -254,33 +249,19 @@ pub enum WebDriverScriptCommand {
GetWindowHandle(IpcSender<Result<String, ErrorStatus>>),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebDriverJSValue {
Undefined,
Null,
Boolean(bool),
Number(f64),
String(String),
Element(WebElement),
Frame(WebFrame),
Window(WebWindow),
ArrayLike(Vec<WebDriverJSValue>),
Object(HashMap<String, WebDriverJSValue>),
}
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverJSError {
/// Occurs when handler received an event message for a layout channel that is not
/// associated with the current script thread
BrowsingContextNotFound,
JSException(WebDriverJSValue),
JSException(JSValue),
JSError,
StaleElementReference,
Timeout,
UnknownType,
}
pub type WebDriverJSResult = Result<WebDriverJSValue, WebDriverJSError>;
pub type WebDriverJSResult = Result<JSValue, WebDriverJSError>;
#[derive(Debug, Deserialize, Serialize)]
pub enum WebDriverFrameId {