mirror of
https://github.com/servo/servo.git
synced 2025-06-08 00:23:30 +00:00
* Remove script_plugins * Use crown instead of script_plugins * crown_is_not_used * Use crown in command base * bootstrap crown * tidy happy * disable sccache * Bring crown in tree * Install crown from tree * fix windows ci * fix warning * fix mac libscript_plugins.dylib is not available anymore * Update components/script/lib.rs Co-authored-by: Martin Robinson <mrobinson@igalia.com> * Update for nightly-2023-03-18 Mostly just based off https://github.com/servo/servo/pull/30630 * Always install crown it's slow only when there is new version * Run crown test with `mach test-unit` * Small fixups; better trace_in_no_trace tests * Better doc * crown in config.toml * Fix tidy for real * no sccache on rustc_wrapper * document rustc overrides * fixup of compiletest * Make a few minor comment adjustments * Fix a typo in python/servo/platform/base.py Co-authored-by: Samson <16504129+sagudev@users.noreply.github.com> * Proper test types * Ignore tidy on crown/tests --------- Co-authored-by: Martin Robinson <mrobinson@igalia.com>
82 lines
2.5 KiB
Rust
82 lines
2.5 KiB
Rust
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
#![allow(crown::unrooted_must_root)]
|
|
|
|
use html5ever::tokenizer::TokenizerResult;
|
|
use js::jsapi::JSTracer;
|
|
use servo_url::ServoUrl;
|
|
use xml5ever::buffer_queue::BufferQueue;
|
|
use xml5ever::tokenizer::XmlTokenizer;
|
|
use xml5ever::tree_builder::{Tracer as XmlTracer, XmlTreeBuilder};
|
|
|
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
|
use crate::dom::bindings::trace::{CustomTraceable, JSTraceable};
|
|
use crate::dom::document::Document;
|
|
use crate::dom::htmlscriptelement::HTMLScriptElement;
|
|
use crate::dom::node::Node;
|
|
use crate::dom::servoparser::{ParsingAlgorithm, Sink};
|
|
|
|
#[derive(JSTraceable, MallocSizeOf)]
|
|
#[crown::unrooted_must_root_lint::must_root]
|
|
pub struct Tokenizer {
|
|
#[ignore_malloc_size_of = "Defined in xml5ever"]
|
|
inner: XmlTokenizer<XmlTreeBuilder<Dom<Node>, Sink>>,
|
|
}
|
|
|
|
impl Tokenizer {
|
|
pub fn new(document: &Document, url: ServoUrl) -> Self {
|
|
let sink = Sink {
|
|
base_url: url,
|
|
document: Dom::from_ref(document),
|
|
current_line: 1,
|
|
script: Default::default(),
|
|
parsing_algorithm: ParsingAlgorithm::Normal,
|
|
};
|
|
|
|
let tb = XmlTreeBuilder::new(sink, Default::default());
|
|
let tok = XmlTokenizer::new(tb, Default::default());
|
|
|
|
Tokenizer { inner: tok }
|
|
}
|
|
|
|
#[must_use]
|
|
pub fn feed(&mut self, input: &mut BufferQueue) -> TokenizerResult<DomRoot<HTMLScriptElement>> {
|
|
self.inner.run(input);
|
|
match self.inner.sink.sink.script.take() {
|
|
Some(script) => TokenizerResult::Script(script),
|
|
None => TokenizerResult::Done,
|
|
}
|
|
}
|
|
|
|
pub fn end(&mut self) {
|
|
self.inner.end()
|
|
}
|
|
|
|
pub fn url(&self) -> &ServoUrl {
|
|
&self.inner.sink.sink.base_url
|
|
}
|
|
}
|
|
|
|
#[allow(unsafe_code)]
|
|
unsafe impl CustomTraceable for XmlTokenizer<XmlTreeBuilder<Dom<Node>, Sink>> {
|
|
unsafe fn trace(&self, trc: *mut JSTracer) {
|
|
struct Tracer(*mut JSTracer);
|
|
let tracer = Tracer(trc);
|
|
|
|
impl XmlTracer for Tracer {
|
|
type Handle = Dom<Node>;
|
|
#[allow(crown::unrooted_must_root)]
|
|
fn trace_handle(&self, node: &Dom<Node>) {
|
|
unsafe {
|
|
node.trace(self.0);
|
|
}
|
|
}
|
|
}
|
|
|
|
let tree_builder = &self.sink;
|
|
tree_builder.trace_handles(&tracer);
|
|
tree_builder.sink.trace(trc);
|
|
}
|
|
}
|