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

Creating objects using object literal syntax appears to create partial results #87

Open
cypren opened this issue Sep 6, 2011 · 1 comment

Comments

@cypren
Copy link

cypren commented Sep 6, 2011

After creating an object using literal evaluation syntax, a CommonObject with the appropriate members appears to be created but its members cannot be accessed through either dot or index notation. The following test code will demonstrate the problem:

using System;
using System.Linq;
using IronJS;
using IronJS.Hosting;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Test {
    [TestClass]
    public class UnitTest1 {
        [TestMethod]
        public void TestMethod1() {
            var context = new CSharp.Context();
            CommonObject foo = context.Environment.NewObject();
            CommonObject bar = context.Environment.NewObject();
            bar.Put("qux", "blah");
            foo.Put("bar", bar);
            foo.Put("baz", context.Execute("({ 'qux': 'blah' })"));
            context.Globals.Put("foo", foo);
            Console.WriteLine("foo: {0}\n"
                              + "foo.bar: {1}\n"
                              + "foo.bar.qux: {2}\n"
                              + "foo.bar['qux']: {3}\n"
                              + "foo.baz.qux: {4}\n"
                              + "foo.baz['qux']: {5}\n"
                              + "foo members: {6}\n"
                              + "foo.bar members: {7}\n"
                              + "foo.baz members: {8}",
                              context.Execute("foo"),
                              context.Execute("foo.bar"),
                              context.Execute("foo.bar.qux"),
                              context.Execute("foo.bar['qux']"),
                              context.Execute("foo.baz.qux"),
                              context.Execute("foo.baz['qux']"),
                              string.Join(", ", ((CommonObject) context.Execute("foo")).Members
                                                    .Select(m => String.Format("{{ {0}:{1} }}", m.Key, m.Value))),
                              string.Join(", ", ((CommonObject) context.Execute("foo.bar")).Members
                                                    .Select(m => String.Format("{{ {0}:{1} }}", m.Key, m.Value))),
                              string.Join(", ", ((CommonObject) context.Execute("foo.baz")).Members
                                                    .Select(m => String.Format("{{ {0}:{1} }}", m.Key, m.Value))));
        }
    }
}

The above code will produce the following output:

foo: IronJS.CommonObject
foo.bar: IronJS.CommonObject
foo.bar.qux: blah
foo.bar['qux']: blah
foo.baz.qux: IronJS.Undefined
foo.baz['qux']: IronJS.Undefined
foo members: { bar:IronJS.CommonObject }, { baz:IronJS.CommonObject }
foo.bar members: { qux:blah }
foo.baz members: { qux:blah }

The foo.bar field, created using Environment.NewObject, behaves as expected. The foo.baz field, created using literal syntax, appears to create a functional CommonObject, but its members cannot be referenced despite the object structure demonstrating that they are clearly present and have the correct values.

@otac0n
Copy link
Collaborator

otac0n commented Sep 6, 2011

We'll take a look.

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

2 participants