avm2: Implement ignoreComments/ignoreProcessingInstructions/ignoreWhitespace

This commit is contained in:
Nathan Adams 2023-07-31 21:47:00 +02:00
parent da7ee01730
commit 6f2420d983
11 changed files with 27 additions and 17 deletions

View File

@ -286,6 +286,9 @@ impl<'gc> E4XNode<'gc> {
pub fn parse( pub fn parse(
mut value: Value<'gc>, mut value: Value<'gc>,
activation: &mut Activation<'_, 'gc>, activation: &mut Activation<'_, 'gc>,
ignore_comments: bool,
ignore_processing_instructions: bool,
ignore_white: bool,
) -> Result<Vec<Self>, Error<'gc>> { ) -> Result<Vec<Self>, Error<'gc>> {
let string = match &value { let string = match &value {
// The docs claim that this throws a TypeError, but it actually doesn't // The docs claim that this throws a TypeError, but it actually doesn't
@ -305,11 +308,6 @@ impl<'gc> E4XNode<'gc> {
let mut parser = Reader::from_str(&data_utf8); let mut parser = Reader::from_str(&data_utf8);
let mut open_tags: Vec<E4XNode<'gc>> = vec![]; let mut open_tags: Vec<E4XNode<'gc>> = vec![];
// FIXME - look these up from static property and settings
let ignore_comments = true;
let ignore_processing_instructions = true;
let ignore_white = true;
let mut top_level = vec![]; let mut top_level = vec![];
// This can't be a closure that captures these variables, because we need to modify them // This can't be a closure that captures these variables, because we need to modify them

View File

@ -51,10 +51,10 @@ package {
} }
public function XML(value:* = undefined) { public function XML(value:* = undefined) {
this.init(value); this.init(value, XML.ignoreComments, XML.ignoreProcessingInstructions, XML.ignoreWhitespace);
} }
private native function init(value:*):void; private native function init(value:*, ignoreComments:Boolean, ignoreProcessingInstructions:Boolean, ignoreWhitespace:Boolean):void;
AS3 native function hasComplexContent():Boolean; AS3 native function hasComplexContent():Boolean;
AS3 native function hasSimpleContent():Boolean; AS3 native function hasSimpleContent():Boolean;

View File

@ -4,10 +4,10 @@ package {
public final dynamic class XMLList { public final dynamic class XMLList {
public function XMLList(value:* = undefined) { public function XMLList(value:* = undefined) {
this.init(value); this.init(value, XML.ignoreComments, XML.ignoreProcessingInstructions, XML.ignoreWhitespace);
} }
private native function init(value:*): void; private native function init(value:*, ignoreComments:Boolean, ignoreProcessingInstructions:Boolean, ignoreWhitespace:Boolean): void;
AS3 native function hasComplexContent():Boolean; AS3 native function hasComplexContent():Boolean;
AS3 native function hasSimpleContent():Boolean; AS3 native function hasSimpleContent():Boolean;

View File

@ -28,6 +28,9 @@ pub fn init<'gc>(
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
let this = this.as_xml_object().unwrap(); let this = this.as_xml_object().unwrap();
let value = args[0]; let value = args[0];
let ignore_comments = args.get_bool(1);
let ignore_processing_instructions = args.get_bool(2);
let ignore_whitespace = args.get_bool(3);
if let Some(obj) = value.as_object() { if let Some(obj) = value.as_object() {
if let Some(xml_list) = obj.as_xml_list_object() { if let Some(xml_list) = obj.as_xml_list_object() {
@ -41,7 +44,13 @@ pub fn init<'gc>(
} }
} }
let nodes = E4XNode::parse(value, activation)?; let nodes = E4XNode::parse(
value,
activation,
ignore_comments,
ignore_processing_instructions,
ignore_whitespace,
)?;
let node = match nodes.as_slice() { let node = match nodes.as_slice() {
// XML defaults to an empty text node when nothing was parsed // XML defaults to an empty text node when nothing was parsed

View File

@ -39,6 +39,9 @@ pub fn init<'gc>(
) -> Result<Value<'gc>, Error<'gc>> { ) -> Result<Value<'gc>, Error<'gc>> {
let this = this.as_xml_list_object().unwrap(); let this = this.as_xml_list_object().unwrap();
let value = args[0]; let value = args[0];
let ignore_comments = args.get_bool(1);
let ignore_processing_instructions = args.get_bool(2);
let ignore_whitespace = args.get_bool(3);
if let Some(obj) = value.as_object() { if let Some(obj) = value.as_object() {
if let Some(xml) = obj.as_xml_object() { if let Some(xml) = obj.as_xml_object() {
@ -51,7 +54,13 @@ pub fn init<'gc>(
} }
} }
match E4XNode::parse(value, activation) { match E4XNode::parse(
value,
activation,
ignore_comments,
ignore_processing_instructions,
ignore_whitespace,
) {
Ok(nodes) => { Ok(nodes) => {
this.set_children( this.set_children(
activation.context.gc_context, activation.context.gc_context,

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true # https://github.com/ruffle-rs/ruffle/issues/12351

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true

View File

@ -1,2 +1 @@
num_ticks = 1 num_ticks = 1
known_failure = true