Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interop of objects not working two-ways #206

Closed
doronguttman opened this issue Jul 3, 2015 · 6 comments
Closed

interop of objects not working two-ways #206

doronguttman opened this issue Jul 3, 2015 · 6 comments

Comments

@doronguttman
Copy link

I'm trying to save an object generating in a javascript code (obj below) into a value of a CLS object (nameValue.Value below) and later get it back from nameValue and get use a property of obj.
It looks like when you export the javascript object to the CLR it is converted to an ExpandoObject (which I have verified has all the properties set correctly), but when importing the ExpandoObject back to javascript, it is not usable in the same way as the original object (can't access it's properties).
Below is a way to verify the behavior.
Any suggestions?

Use this C# class:

namespace jintTester.TestClasses
{
    public class NameValue
    {
        private string _name;
        private object _value;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        public object Value
        {
            get { return _value; }
            set { _value = value; }
        }

        public override string ToString()
        {
            return string.Format("{{ Name: \"{0}\", Value: {1} }}", Name, Value);
        }
    }
}

Use this script:

(function () {
    log("** 2.interop.js: interop test");
    log("--> creating object");
    var obj = {
        s: "string",
        i: 10,
        d: 10.01,
        b: true,
        a: ["string1", "string2"],
        o: {
            s: "object"
        },
        f: function(a) { return a; }
    };
    assert(typeof obj !== "undefined" && obj !== null);             //True
    log("obj is: " + obj);                                          //obj is: [object Object]

    log("--> creating NameValue instance");
    var TestClasses = importNamespace('jintTester.TestClasses');
    var nameValue = new TestClasses.NameValue();
    assert(typeof nameValue !== "undefined" && nameValue !== null); //True
    log("nameValue is: " + nameValue.ToString());                   //nameValue is: { Name: "", Value:  }

    log("--> saving obj into nameValue");
    nameValue.Name = "Object Test";
    nameValue.Value = obj;
    log("nameValue is: " + nameValue.ToString());

    log("--> getting obj back out of nameValue");
    var rsltObj = nameValue.Value;
    //log("rslt is: " + rsltObj);                                   //TypeError
    log("rslt is: " + rsltObj.ToString());                          //rslt is: System.Dynamic.ExpandoObject
    assert(rsltObj.s === obj.s);                                    //False
    assert(rsltObj.i === obj.i);                                    //False
    assert(rsltObj.d === obj.d);                                    //False
    assert(rsltObj.b === obj.b);                                    //False
    assert(rsltObj.a === obj.a);                                    //False
    assert(rsltObj.o === obj.o);                                    //False
    assert(rsltObj.f === obj.f);                                    //False
})();
@doronguttman
Copy link
Author

Can someone please help with this?

@doronguttman
Copy link
Author

Guys, i could really use some help. I have no problem fixing this myself, but i need some guidance on where I should focus on.
I tried implementing an IObjectConverter and a ITypeConverter.
In any both cases I was not able to reach a working solution (by the way, it would be good if they would provide the Engine instance as a parameter).

Any ideas?

@sebastienros
Copy link
Owner

Can you provide a simpler unit test, it will save us some time. Is this what you have in mind:

var TestClasses = importNamespace('jintTester.TestClasses');
var nameValue = new TestClasses.NameValue();
assert(nameValue.toString() == "{ Name: "", Value:  }";
nameValue.Value = { "foo":"bar" };
assert(nameValue.Value.foo == "bar");

@doronguttman
Copy link
Author

That should do the trick.

Many thanks!

On 10 July 2015 at 14:00, Sébastien Ros notifications@github.com wrote:

Can you provide a simpler unit test, it will save us some time. Is this
what you have in mind:

var TestClasses = importNamespace('jintTester.TestClasses');
var nameValue = new TestClasses.NameValue();
assert(nameValue.toString() == "{ Name: "", Value: }";
nameValue.Value = { "foo":"bar" };
assert(nameValue.Value.foo == "bar");


Reply to this email directly or view it on GitHub
#206 (comment).

@doronguttman
Copy link
Author

Hello. any update on this (sorry to nag.. it is just that it is a blocker on my project)

@lahma
Copy link
Collaborator

lahma commented Oct 16, 2022

#1318 added a test to verify this case to be working nowadays.

@lahma lahma closed this as completed Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants