I'm attempting to execute a tiny piece of JS via the following code (utilising the Native class from the Chakra Host example from MSDN):
var runtime = default(JavaScriptRuntime);
Native.ThrowIfError(Native.JsCreateRuntime(JavaScriptRuntimeAttributes.None, JavaScriptRuntimeVersion.VersionEdge, null, out runtime));
var context = default(JavaScriptContext);
Native.ThrowIfError(Native.JsCreateContext(runtime, (Native.IDebugApplication64)null, out context));
Native.ThrowIfError(Native.JsSetCurrentContext(context));
var script = @"var bob = 1;";
var result = default(JavaScriptValue);
var contextCookie = default(JavaScriptSourceContext);
Native.ThrowIfError(Native.JsRunScript(script, contextCookie, "source", out result));
The problem is that it returns a "ScriptCompile" error with no additional details that I'm able to spot.
Is anyone able to reveal what I've missed / done dumb / gotten confused over?
I doubt you're still wrestling with this... but I just did and figured out the answer.
If you look in jsrt.h you'll see that all the native functions use a wchar_t when using string parameters, however the DllImport attribute doesn't specify the charset, so it defaults to ANSI.
I did a find/replace in the Native.cs file and changed all the DllImport attributes to read...
[DllImport("jscript9.dll", CharSet = CharSet.Unicode)]
... and now my code works fine. I've sent a pull request to the sample owner on GitHub to get this fixed up. The update is currently in my fork at https://github.com/billti/chakra-host