microsoft / Chakra-Samples

Repository for Chakra JavaScript engine related samples.
MIT License
216 stars 84 forks source link

Getting undefined when calling more than one function #31

Closed kinju4374 closed 8 years ago

kinju4374 commented 8 years ago

I am trying to use the following javascript and I am getting an undefined error. Can you please suggest what am I doing wrong.

function a(){ return 10; }; function b(){ return 20; }; function c(){ return 30; }; function abc(){ return a()*b()*c(); }

obastemur commented 8 years ago

Using ChakraCore ch from command line, I haven't get any error;

function a(){
return 10;
};
function b(){
return 20;
};
function c(){
return 30;
};
function abc(){
return a()*b()*c();
}

print(abc())
kinju4374 commented 8 years ago

When I am using print, I am getting, print is undefined. But when I add z=abc() then execute, it gives me 6000 which is correct output.

obastemur commented 8 years ago

Indeed print is defined by ch host. My guess is you use this script from your app that embeds ChakraCore?

In that case, you don't need z just abc() to the end should be enough.

kinju4374 commented 8 years ago

Yes, just abc() is also working.

I am just trying the ChakraHost Samples and trying different javascript in that.

obastemur commented 8 years ago

In that case; there is no issue here. If you want a particular script execution to return something, you may add that to the end.

closing this one. @kinju4374 Thanks for asking.

kinju4374 commented 8 years ago

Thanks for the help. I also have a query, when I use Debug.WriteLine() to check result of the javascript in c#, it doesn't display anything but when I use same in your sample, it gets displayed on TextBlock.

Can you please suggest how to debug javascript code when ChakraHost is used?

liminzhu commented 8 years ago

Here's a relevant thread for you @kinju4374 https://github.com/Microsoft/ChakraCore/issues/1274.

kinju4374 commented 8 years ago

@liminzhu thanks. This works fine for me. I have one more doubt that it will work in Release/ARM version(which we upload on store) without any issues right?

liminzhu commented 8 years ago

@kinju4374 no problem. Debugging should work on Release/ARM. I don't personally own an ARM device, but you can try it out.

kinju4374 commented 8 years ago

@liminzhu Yes, I will try. It works when Application Process is set as "Script", but I am asking that when I make app Live on the store, it will work without any problems right? When I change debug to Managed only, then the app starts giving Exception.

liminzhu commented 8 years ago

When I change debug to Managed only, then the app starts giving Exception.

@kinju4374 can you clarify that? What exceptions are you getting?

kinju4374 commented 8 years ago

@liminzhu I am getting Exception thrown: 'System.Exception' in ChakraBridge.winmd Exception thrown: 'System.Exception' in mscorlib.ni.dll

It is showing same with Release - ARM version which we used to deploy on store. Please suggest.

kinju4374 commented 8 years ago

@liminzhu @obastemur Do we have Nuget Package for this? I have added reference ChakraBridge.winmd from dist folder in my app. Please help me as I need this to load javascript in my c# project.

Exact Exception is Exception thrown: 'System.Exception' in ChakraBridge.winmd failed to start debugging.

liminzhu commented 8 years ago

ChakraBridge.winmd

Are you referring to this project? This sounds like an implementation issue specific to that project, rather than a Chakra/ChakraCore issue. I'd advise opening an issue on that project.

kinju4374 commented 8 years ago

I added this as reference to use ChakraHost API in my project but it gives exception when debug mode is changed

liminzhu commented 8 years ago

Close as the same issue is tracked at https://github.com/deltakosh/JsBridge/issues/15.