Skip to content

Conversation

jarca0123
Copy link
Contributor

No description provided.

@n0samu n0samu added A-avm2 Area: AVM2 (ActionScript 3) xml T-compat Type: Compatibility with Flash Player labels Jul 16, 2025
core/src/avm2.rs Outdated
self.default_xml_namespace_stack
.last()
.copied()
.unwrap_or_else(|| AvmString::new_ascii_static(strings.gc(), b""))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this was working on Activation instead, you could just do istr!("") here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can specify the StringContext manually with istr!(strings, ""), too.

core/src/avm2.rs Outdated
Comment on lines 122 to 125
/// Default XML namespace stack for E4X operations.
/// The last element is the current default namespace.
default_xml_namespace_stack: Vec<AvmString<'gc>>,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a stack here? There's no PopDxns opcode, so a single default_xml_namespace: Option<AvmString<'gc>> on Activation would be enough.

@moulins
Copy link
Contributor

moulins commented Jul 18, 2025

Note: the AVM2 specification says that dxns/dxnslate opcodes should be rejected at verification time if the SET_DXNS method flag isn't set. (relevant avmplus code: https://github.com/adobe/avmplus/blob/master/core/Verifier.cpp#L1169)

@adrian17
Copy link
Collaborator

adrian17 commented Jul 18, 2025

I don't think the stack is correct here; what FP does kinda resembles the stack, in that when you call a function and set dxns, when you exit from the function the callee has its previous dxns back. But this alone could be implemented by just setting dxns as a field on the Activation - and maybe this is enough for an MVP?

But in reality, in FP this is more complex unfortunately, in avmplus (see MethodFrame::findDxns) it's a property of MethodFrames/MethodEnvs (kinda what our BoundMethods are)/scopes. It recurses MethodFrames... presumably because sometimes the current frame might inherit dxns from the parent? But in practice, with normal function calls, a function doesn't inherit and just uses its own default namespace so not sure what that's about.

The easily visible difference is that the default namespace of the MethodEnv depends on the environment (scope chain?) at the point in time when it was created, see the example:

function f(){
    var a = <xml xmlns:a="a" xmlns:b="b"><data x="1" a:x="2" b:x="3">asdf</data></xml>;

    trace(a.data.@x); // 1

    var inline_f1 = function(){ trace(a.data.@x); };

    default xml namespace = "a";
    trace(a.data.@x); // 12

    var inline_f2 = function(){ trace(a.data.@x); };

    default xml namespace = "b";
    trace(a.data.@x); // 13

    inline_f1(); // 1
    inline_f2(); // 12

    create_custom_function("")(a); // 1
    create_custom_function("a")(a); // 12
    create_custom_function("b")(a); // 13
}
function create_custom_function(nsname){
    default xml namespace = nsname;
    return function(a){ trace(a.data.@x); };
};

But again, I don't exactly understand how the chained MethodFrame iteration in avmplus relates to this, I don't know how to observe it.
For MVP, maybe just setting dxns on the current Activation would be enough? (and make a failing test for the more complex behavior)

@jarca0123 jarca0123 marked this pull request as draft July 18, 2025 15:08
@jarca0123 jarca0123 force-pushed the dxns branch 8 times, most recently from ff1ce9b to a44e385 Compare July 26, 2025 14:10
@jarca0123 jarca0123 marked this pull request as ready for review July 28, 2025 09:55
@jarca0123 jarca0123 force-pushed the dxns branch 2 times, most recently from dae00c7 to 5c03419 Compare July 31, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-avm2 Area: AVM2 (ActionScript 3) T-compat Type: Compatibility with Flash Player xml
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants