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

Microsoft.ClearScript.BindSignature already added? #541

Closed
flat-eric147 opened this issue Oct 4, 2023 · 3 comments
Closed

Microsoft.ClearScript.BindSignature already added? #541

flat-eric147 opened this issue Oct 4, 2023 · 3 comments
Assignees

Comments

@flat-eric147
Copy link

Hi, I'm running into a funny issue when some recursion from c# to Javascirpt happens.

My v8 script looks like this:

Global.OnParameterChanged = function (id)
{
   somecSharpObject.Value = Date.now() + ""
}

somecSharpObject is a C# object instance added through the AddHostObject method and its Value property looks more or less like this:

private string internalValue;
public string Value
{
    get
    {
        return internalValue;
    }
    set
    {
            if (value != internalValue)
            {
                internalValue = value;
                RaiseParameterEvent(); // this calls Global.OnParameterChanged script callback
            }
        }
    }
}

So as you can see this might lead to some recursions calling the set method which in turn calls the V8 method and so on.

The script engine fires a strange exception after the second time the script method is invoked:

An item with the same key has already been added. Key: Microsoft.ClearScript.BindSignature
at Global.OnParameterChanged (Module:4:27) -> somecSharpObject.Value = Date.now() + ""

I would expect a stack overflow exception in the worst case. I suspect everytime a method is invoked from C# to V8 there are some execution context's that get created adding built in host objects? Tried to build ClearScript from code to have a look but I am stuck in Windows 10 SDK madness.

The error is a little bit confusing. Any ideas on what is going on here? I will try to create a minimal project to reproduce the issue, but wanted to hear first if anybody has an opinion on that :-)

Thank you!

@ClearScriptLib ClearScriptLib self-assigned this Oct 5, 2023
@ClearScriptLib
Copy link
Collaborator

Hi @flat-eric147,

This is a bug in ClearScript. We'll have a fix in the next release. Thanks for reporting it!

Cheers!

ClearScriptLib added a commit that referenced this issue Oct 17, 2023
…added V8ScriptEngineFlags.UseSynchronizationContexts (GitHub Discussion #509); added ScriptEngine.CustomAttributeLoader (GitHub Discussion #540); fixed property accessor recursion bug (GitHub Issue #541); added ScriptEngine.HostData and CustomAttributeLoader.Default; updated API documentation. Tested with V8 11.8.172.15.
@ClearScriptLib
Copy link
Collaborator

Fixed in Version 7.4.4.

@flat-eric147
Copy link
Author

That was quick, much appreciated! Just tested it, and it works fine. Thank you!

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

No branches or pull requests

2 participants