Skip to content

Commit

Permalink
Introduce ServoParser
Browse files Browse the repository at this point in the history
This is a common inline parent to ServoHTMLParser and ServoXMLParser.
  • Loading branch information
nox committed Oct 11, 2016
1 parent f43a14e commit ea27f9d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
5 changes: 3 additions & 2 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -2748,7 +2748,8 @@ def definition_body(self):
interface.get());
""" % {"id": name, "name": str_to_const_array(name)})

if len(self.descriptor.prototypeChain) == 1:
parentName = self.descriptor.getParentName()
if not parentName:
if self.descriptor.interface.getExtendedAttribute("ExceptionClass"):
getPrototypeProto = "prototype_proto.set(JS_GetErrorPrototype(cx))"
elif self.descriptor.interface.isIteratorInterface():
Expand All @@ -2757,7 +2758,7 @@ def definition_body(self):
getPrototypeProto = "prototype_proto.set(JS_GetObjectPrototype(cx, global))"
else:
getPrototypeProto = ("%s::GetProtoObject(cx, global, prototype_proto.handle_mut())" %
toBindingNamespace(self.descriptor.getParentName()))
toBindingNamespace(parentName))

code = [CGGeneric("""\
rooted!(in(cx) let mut prototype_proto = ptr::null_mut());
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/mod.rs
Expand Up @@ -387,6 +387,7 @@ pub mod serviceworkercontainer;
pub mod serviceworkerglobalscope;
pub mod serviceworkerregistration;
pub mod servohtmlparser;
pub mod servoparser;
pub mod servoxmlparser;
pub mod storage;
pub mod storageevent;
Expand Down
9 changes: 5 additions & 4 deletions components/script/dom/servohtmlparser.rs
Expand Up @@ -14,13 +14,14 @@ use dom::bindings::codegen::Bindings::ServoHTMLParserBinding;
use dom::bindings::inheritance::Castable;
use dom::bindings::js::{JS, Root};
use dom::bindings::refcounted::Trusted;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::str::DOMString;
use dom::bindings::trace::JSTraceable;
use dom::document::Document;
use dom::globalscope::GlobalScope;
use dom::htmlimageelement::HTMLImageElement;
use dom::node::Node;
use dom::servoparser::ServoParser;
use dom::window::Window;
use encoding::all::UTF_8;
use encoding::types::{DecoderTrap, Encoding};
Expand Down Expand Up @@ -212,7 +213,7 @@ impl PreInvoke for ParserContext {

#[dom_struct]
pub struct ServoHTMLParser {
reflector_: Reflector,
servoparser: ServoParser,
#[ignore_heap_size_of = "Defined in html5ever"]
tokenizer: DOMRefCell<Tokenizer>,
/// Input chunks received but not yet passed to the parser.
Expand Down Expand Up @@ -269,7 +270,7 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, Default::default());

let parser = ServoHTMLParser {
reflector_: Reflector::new(),
servoparser: ServoParser::new_inherited(),
tokenizer: DOMRefCell::new(tok),
pending_input: DOMRefCell::new(vec!()),
document: JS::from_ref(document),
Expand Down Expand Up @@ -305,7 +306,7 @@ impl ServoHTMLParser {
let tok = tokenizer::Tokenizer::new(tb, tok_opts);

let parser = ServoHTMLParser {
reflector_: Reflector::new(),
servoparser: ServoParser::new_inherited(),
tokenizer: DOMRefCell::new(tok),
pending_input: DOMRefCell::new(vec!()),
document: JS::from_ref(document),
Expand Down
18 changes: 18 additions & 0 deletions components/script/dom/servoparser.rs
@@ -0,0 +1,18 @@
/* 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 http://mozilla.org/MPL/2.0/. */

use dom::bindings::reflector::Reflector;

#[dom_struct]
pub struct ServoParser {
reflector: Reflector,
}

impl ServoParser {
pub fn new_inherited() -> Self {
ServoParser {
reflector: Reflector::new(),
}
}
}
7 changes: 4 additions & 3 deletions components/script/dom/servoxmlparser.rs
Expand Up @@ -5,10 +5,11 @@
use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::ServoXMLParserBinding;
use dom::bindings::js::{JS, Root};
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::bindings::reflector::reflect_dom_object;
use dom::bindings::trace::JSTraceable;
use dom::document::Document;
use dom::node::Node;
use dom::servoparser::ServoParser;
use dom::window::Window;
use js::jsapi::JSTracer;
use msg::constellation_msg::PipelineId;
Expand All @@ -31,7 +32,7 @@ pub struct Sink {
#[must_root]
#[dom_struct]
pub struct ServoXMLParser {
reflector_: Reflector,
servoparser: ServoParser,
#[ignore_heap_size_of = "Defined in xml5ever"]
tokenizer: DOMRefCell<Tokenizer>,
/// Input chunks received but not yet passed to the parser.
Expand Down Expand Up @@ -85,7 +86,7 @@ impl ServoXMLParser {
let tok = tokenizer::XmlTokenizer::new(tb, Default::default());

let parser = ServoXMLParser {
reflector_: Reflector::new(),
servoparser: ServoParser::new_inherited(),
tokenizer: DOMRefCell::new(tok),
pending_input: DOMRefCell::new(vec!()),
document: JS::from_ref(document),
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ServoHTMLParser.webidl
Expand Up @@ -7,5 +7,5 @@

// FIXME: find a better way to hide this from content (#3688)
[NoInterfaceObject, Exposed=(Window,Worker)]
interface ServoHTMLParser {
interface ServoHTMLParser : ServoParser {
};
10 changes: 10 additions & 0 deletions components/script/dom/webidls/ServoParser.webidl
@@ -0,0 +1,10 @@
/* 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 http://mozilla.org/MPL/2.0/. */

// This interface is entirely internal to Servo, and should not be accessible to
// web pages.

[Exposed=(Window,Worker),
Inline]
interface ServoParser {};
2 changes: 1 addition & 1 deletion components/script/dom/webidls/ServoXMLParser.webidl
Expand Up @@ -6,6 +6,6 @@
// web pages.

[NoInterfaceObject, Exposed=(Window,Worker)]
interface ServoXMLParser {
interface ServoXMLParser : ServoParser {
};

0 comments on commit ea27f9d

Please sign in to comment.