mirror of
https://github.com/lexmount/moli.git
synced 2026-11-25 08:02:28 +00:00
Encode carets in hierarchical paths and encode only the final opaque-path space before query or fragment delimiters. Preserve the encoded path across suffix mutations and remove the obsolete parser trimming and V8 query-removal workaround. Add five shared-parser and three VM regressions covering constructors, setters, URLSearchParams, DOM links, and cross-realm behavior. Synchronize 11 stale vendored WPT expected records with pinned current WPT data; inputs, the WPT driver, and the remaining expected-failure entry are unchanged. Validation: cargo fmt --all; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo nextest run --no-fail-fast (17632 passed, 13 skipped). Vendored all-features unit tests, WPT driver, and 67 doctests pass. On the same 50 URL/Location WPT cases, CLI and CDP both improve from 42 to 48 passing cases and from 7036 to 7085 passing subtests (+49), with no new failures. The two remaining failures are the existing webkitURL alias and srcdoc scrolling cases. Move the verified non-file anchor case to passed. CDP smoke: 42/43 groups pass. Puppeteer cannot run because node is absent, reproduced with the before binary. Artifacts: target/wpt-url-encoding-20260908-AP6CI1. WPT revision: db95fafd1fcef8428805e41eb5705d444e8c67ce. Release SHA256: f132f0afe7f49d627ed9b5d397b1d5b71d80432180b08b1d076aa67637efdd65.
158 lines
4.7 KiB
Rust
158 lines
4.7 KiB
Rust
use super::helpers::{
|
|
can_parse_url_input, require_url_receiver, resolve_url_constructor_input, url_href_slot,
|
|
};
|
|
use super::*;
|
|
use crate::interfaces as web_api_interfaces;
|
|
use moli_v8_util::get_private_value;
|
|
use moli_v8_util::{global_constructor_object, throw_error};
|
|
use moli_webapi_declare::WebApiObject;
|
|
use moli_webidl as webidl;
|
|
|
|
#[derive(WebApiObject)]
|
|
#[webapi(interface = web_api_interfaces::URL)]
|
|
struct UrlObjectDeclaration<'s> {
|
|
#[webapi(slot = URL_HREF_SLOT)]
|
|
href: String,
|
|
#[webapi(slot = URL_SEARCH_PARAMS_SLOT)]
|
|
search_params: Option<v8::Local<'s, v8::Object>>,
|
|
}
|
|
|
|
#[derive(webidl::WebIdlArgs)]
|
|
#[webidl(prefix = "URL")]
|
|
struct UrlConstructorArgs {
|
|
#[webidl(required, converter = "usv_string")]
|
|
input: String,
|
|
#[webidl(index = 1, converter = "usv_string")]
|
|
base: Option<String>,
|
|
}
|
|
|
|
#[derive(webidl::WebIdlArgs)]
|
|
#[webidl(prefix = "URL.parse")]
|
|
struct UrlParseArgs {
|
|
#[webidl(required, converter = "usv_string")]
|
|
input: String,
|
|
#[webidl(index = 1, converter = "usv_string")]
|
|
base: Option<String>,
|
|
}
|
|
|
|
#[derive(webidl::WebIdlArgs)]
|
|
#[webidl(prefix = "URL.canParse")]
|
|
struct UrlCanParseArgs {
|
|
#[webidl(required, converter = "usv_string")]
|
|
input: String,
|
|
#[webidl(index = 1, converter = "usv_string")]
|
|
base: Option<String>,
|
|
}
|
|
|
|
pub(super) fn url_constructor_callback<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
args: v8::FunctionCallbackArguments<'s>,
|
|
mut rv: v8::ReturnValue<'_, v8::Value>,
|
|
) {
|
|
if !args.is_construct_call() {
|
|
throw_type_error(
|
|
scope,
|
|
"Failed to construct 'URL': Please use the 'new' operator.",
|
|
);
|
|
return;
|
|
}
|
|
|
|
let Some(parsed) = webidl::parse_args::<UrlConstructorArgs>(scope, &args) else {
|
|
return;
|
|
};
|
|
let Ok(url) = resolve_url_constructor_input(&parsed.input, parsed.base.as_deref()) else {
|
|
throw_type_error(scope, "Failed to construct 'URL': Invalid URL.");
|
|
return;
|
|
};
|
|
|
|
let this = args.this();
|
|
let href = url.as_str().to_owned();
|
|
let has_search_params = get_private_value(scope, this, URL_SEARCH_PARAMS_SLOT)
|
|
.is_some_and(|value| !value.is_undefined());
|
|
let search_params = if has_search_params {
|
|
None
|
|
} else {
|
|
new_url_search_params_object(scope, Some(this), Some(url_query_pairs(&url)))
|
|
};
|
|
UrlObjectDeclaration::new(href, search_params)
|
|
.initialize(scope, this)
|
|
.expect("URL declaration should initialize object");
|
|
rv.set(this.into());
|
|
}
|
|
|
|
pub(super) fn url_to_string_callback<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
args: v8::FunctionCallbackArguments<'s>,
|
|
mut rv: v8::ReturnValue<'_, v8::Value>,
|
|
) {
|
|
let Some(this) = require_url_receiver(scope, args.this()) else {
|
|
return;
|
|
};
|
|
if let Some(href) = url_href_slot(scope, this)
|
|
&& let Some(href) = v8_string(scope, &href)
|
|
{
|
|
rv.set(href.into());
|
|
return;
|
|
}
|
|
rv.set(v8::undefined(scope).into());
|
|
}
|
|
|
|
pub(super) fn url_to_json_callback<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
args: v8::FunctionCallbackArguments<'s>,
|
|
rv: v8::ReturnValue<'_, v8::Value>,
|
|
) {
|
|
url_to_string_callback(scope, args, rv);
|
|
}
|
|
|
|
pub(super) fn url_parse_callback<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
args: v8::FunctionCallbackArguments<'s>,
|
|
mut rv: v8::ReturnValue<'_, v8::Value>,
|
|
) {
|
|
let Some(parsed) = webidl::parse_args::<UrlParseArgs>(scope, &args) else {
|
|
return;
|
|
};
|
|
let Ok(url) = resolve_url_constructor_input(&parsed.input, parsed.base.as_deref()) else {
|
|
rv.set(v8::null(scope).into());
|
|
return;
|
|
};
|
|
let Some(url_value) = v8_string(scope, url.as_str()) else {
|
|
rv.set(v8::null(scope).into());
|
|
return;
|
|
};
|
|
// The factory creates a URL in its own realm, regardless of author changes
|
|
// to the public URL binding (including during argument conversion).
|
|
let Some(constructor) = global_constructor_object(scope, "URL")
|
|
.and_then(|value| v8::Local::<v8::Function>::try_from(value).ok())
|
|
else {
|
|
throw_error(
|
|
scope,
|
|
"Failed to create URL: intrinsic constructor is unavailable",
|
|
);
|
|
return;
|
|
};
|
|
let Some(object) = constructor.new_instance(scope, &[url_value.into()]) else {
|
|
rv.set(v8::null(scope).into());
|
|
return;
|
|
};
|
|
rv.set(object.into());
|
|
}
|
|
|
|
pub(super) fn url_can_parse_callback<'s>(
|
|
scope: &mut v8::PinScope<'s, '_>,
|
|
args: v8::FunctionCallbackArguments<'s>,
|
|
mut rv: v8::ReturnValue<'_, v8::Value>,
|
|
) {
|
|
let Some(parsed) = webidl::parse_args::<UrlCanParseArgs>(scope, &args) else {
|
|
return;
|
|
};
|
|
rv.set(
|
|
v8::Boolean::new(
|
|
scope,
|
|
can_parse_url_input(&parsed.input, parsed.base.as_deref()),
|
|
)
|
|
.into(),
|
|
);
|
|
}
|