yantrajs / yantra

JavaScript Engine for .NET Standard
https://yantrajs.com
Apache License 2.0
222 stars 7 forks source link

Xamarin Error #61

Closed adiamante closed 1 year ago

adiamante commented 2 years ago

Hi I'm not sure if this library supports Xamarin but I tried the sample code

var context = new JSContext();

// create global function
context["add"] = new JSFunction((in Arguments a) => {
    return new JSNumber(
         (a[0]?.IntValue ?? 0) + (a[1]?.IntValue ?? 0)
    );
});

var result = context.Eval("add(4,5)", "script.js");

and got the following error

System.InvalidProgramException: 'Invalid IL code in (wrapper dynamic-method) YantraJS.Closures:body-:0,0 (YantraJS.Closures,YantraJS.Core.Arguments&): IL_00d0: pop       
ackava commented 2 years ago

Is it Android or iOS? I doubt it will work on iOS as there are execution restrictions, though mono interpreter should work correctly. But we haven't tried it. Android also has different variants, some of the IL code in x86 emulators don't work but they work correctly on ARM devices.

adiamante commented 2 years ago

I was using nox emulator with a Google Pixel 2 instance. Would that be x86?

ackava commented 2 years ago

@adiamante Can you try the solution mentioned on https://github.com/mono/mono/issues/21385 ?

ackava commented 1 year ago

@adiamante We have recently upgraded YantraJS to .NET 6 and some Bad IL code bugs were fixed, please use latest version and let us know if you are facing any issue.

adiamante commented 1 year ago

@ackava Will give it a shot over the weekend.

adiamante commented 1 year ago

HI @ackava I tried again and got the same error. Used the version 1.2.71 NuGet package.

cyraid commented 1 year ago

Believe it or not, was just evaluating if I should use YantrajS instead of V8, but my project is on android with Xamarin. Any update on this?

ackava commented 1 year ago

Believe it or not, was just evaluating if I should use YantrajS instead of V8, but my project is on android with Xamarin. Any update on this?

Can you please provide GitHub repo to reproduce the error?

We have been able to successfully run YantraJS on Android on actual device. But we have only tested on 64bit emulators.

Can you confirm if it fails on actual device as well?

cyraid commented 1 year ago

Sorry for the late reply. Got it working on an actual device. Thanks @ackava

adiamante commented 1 year ago

I've moved on to .NET MAUI and tried the same example with the same emulator (Nox). Worrking fine now.