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

Value of the Interop.AllowGetType option can be set only once #1435

Closed
Taritsyn opened this issue Feb 17, 2023 · 2 comments · Fixed by #1436
Closed

Value of the Interop.AllowGetType option can be set only once #1435

Taritsyn opened this issue Feb 17, 2023 · 2 comments · Fixed by #1436
Labels

Comments

@Taritsyn
Copy link
Contributor

Hello!

Value of the Interop.AllowGetType option can be set only for the first instance of engine, then it will be cached and all other engine instances will use it. To reproduce this error, I created a example:

using System;

using Jint;
using Jint.Native;

namespace TestJint
{
    class Program
    {
        static void Main(string[] args)
        {
            // Displays the full type name
            TestAllowGetTypeOption(true);

            // Should throw an exception, but displays the full type name
            TestAllowGetTypeOption(false);
        }

        private static void TestAllowGetTypeOption(bool allowGetType)
        {
            var uri = new Uri("https://github.com/sebastienros/jint");
            string itemName = nameof(uri);
            string input = itemName + ".GetType();";

            Console.WriteLine("AllowGetType = {0}", allowGetType);

            using (var engine = new Engine(options => options.Interop.AllowGetType = allowGetType))
            {
                engine.SetValue(itemName, JsValue.FromObject(engine, uri));
                string result = engine.Evaluate(input).ToString();

                Console.WriteLine("Result = {0}", result);
            }

            Console.WriteLine();
        }
    }
}

Most likely, this error is caused by the default value of the Interop.TypeResolver option.

@lahma
Copy link
Collaborator

lahma commented Feb 17, 2023

Thank you @Taritsyn once again for a bug report with a great repro, should now be fixed in main!

@lahma lahma added the bug label Feb 17, 2023
@Taritsyn
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants