microsoft / ClearScript

A library for adding scripting to .NET applications. Supports V8 (Windows, Linux, macOS) and JScript/VBScript (Windows).
https://microsoft.github.io/ClearScript/
MIT License
1.77k stars 148 forks source link

Bug 7.3.5 regression : Error t.ScriptableDispose is not a function when DisableTypeRestriction is enabled #463

Closed vbornand closed 1 year ago

vbornand commented 1 year ago

Hello,

When I try to execute a for .. of with the 7.3.5 version with DisableTypeRestriction = true, I get the following error:

TypeError: t.ScriptableDispose is not a function
    at V8ScriptEngine [internal]:1:1171 -> Object.defineProperty(this,'EngineInternal',{value:(t=>{let e=t=>t.bind();function o(){return new this(...arguments)}let r=t.isHostObjectKey;delete t.isHostObjectKey;let n=t=>!!t&&!0===t[r],i=Promise,c=Symbol(),a=t.toJson;return delete t.toJson,Object.freeze({commandHolder:{},getCommandResult:e(t=>null==t?t:'function'!=typeof t.hasOwnProperty?'Module'===t[Symbol.toStringTag]?'[module]':'[external]':!0===t[r]?t:'function'!=typeof t.toString?'['+typeof t+']':t.toString()),strictEquals:e((t,e)=>t===e),invokeConstructor:e((t,e)=>{if('function'!=typeof t)throw Error('Function expected');return o.apply(t,Array.from(e))}),invokeMethod:e((t,e,o)=>{if('function'!=typeof e)throw Error('Function expected');return e.apply(t,Array.from(o))}),createPromise:e(function(){return new i(...arguments)}),isPromise:e(t=>t instanceof i),isHostObject:e(n),completePromiseWithResult:e((t,e,o)=>{try{e(t())}catch(r){o(r)}}),completePromise:e((t,e,o)=>{try{t(),e()}catch(r){o(r)}}),throwValue:e(t=>{throw t}),getStackTrace:e(()=>{try{throw Error('[stack trace]')}catch(t){return t.stack}}),toIterator:e(function*(t){try{for(;t.ScriptableMoveNext();)yield t.ScriptableCurrent}finally{t.ScriptableDispose()}}),toAsyncIterator:e(async function*(t){try{for(;await t.ScriptableMoveNextAsync();)yield t.ScriptableCurrent}finally{await t.ScriptableDisposeAsync()}}),checkpoint:e(()=>{let e=t[c];if(e)throw e}),toJson:e((t,e)=>a?JSON.parse(a(t,e)):e)})})(this)});
    at Script:1:12
   at Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative.ThrowScheduledException()
   at Microsoft.ClearScript.V8.SplitProxy.V8SplitProxyNative.Invoke(Action`1 action)
   at Microsoft.ClearScript.V8.SplitProxy.V8ContextProxyImpl.InvokeWithLock(Action action)
   at Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.V8.V8ScriptEngine.Execute(UniqueDocumentInfo documentInfo, String code, Boolean evaluate)
   at Microsoft.ClearScript.ScriptEngine.Execute(DocumentInfo documentInfo, String code)
   at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, Boolean discard, String code)
   at Microsoft.ClearScript.ScriptEngine.Execute(String documentName, String code)
   at Microsoft.ClearScript.ScriptEngine.Execute(String code)
   at TestArray.Program.Main(String[] args)

There is no error with the version 7.3.4 and no error if DisableTypeRestriction is false.

Same behavior with .net 6 and .net 7.

Sample program: (In this case the DisableTypeRestriction is useless, but I need it in my real world software)

using Microsoft.ClearScript.V8;

namespace TestArray;

internal class Program
{
    static void Main(string[] args)
    {
        using (var engine = new V8ScriptEngine())
        {
            engine.DisableTypeRestriction = true;
            engine.AddHostObject("house", new House());
            engine.Execute("for (const vi of house.ValuesInt) { console.log(vi); }");
        }
     }
}

public class House
{
    public House() {
        this.ValuesInt = new List<int> { 1, 2 };
    }

    public List<int> ValuesInt { get; set; }

}

Thanks

ClearScriptLib commented 1 year ago

Hi @vbornand,

That's a bug; we'll have a fix in the next release, due very soon.

Thanks for reporting it!

ClearScriptLib commented 1 year ago

Fixed in Version 7.3.6.