public void JsSerializedScriptCanBeRun() { var script = "(()=>{return 6*7;})()"; string sourceUrl = "[eval code]"; using (var runtimeHandle = Engine.JsCreateRuntime(JavaScriptRuntimeAttributes.None, null)) { using (var contextHandle = Engine.JsCreateContext(runtimeHandle)) { Engine.JsSetCurrentContext(contextHandle); JavaScriptSerializedLoadScriptCallback callback = (JavaScriptSourceContext sourceContext, out IntPtr value, out JavaScriptParseScriptAttributes parseAttributes) => { value = Engine.JsCreateString(script, (ulong)script.Length).DangerousGetHandle(); parseAttributes = JavaScriptParseScriptAttributes.None; return(true); }; IntPtr ptrScript = Marshal.StringToHGlobalAnsi(script); try { var scriptHandle = Engine.JsCreateExternalArrayBuffer(ptrScript, (uint)script.Length, null, IntPtr.Zero); var bufferHandle = Engine.JsSerialize(scriptHandle, JavaScriptParseScriptAttributes.None); var sourceUrlHandle = Engine.JsCreateString(sourceUrl, (ulong)sourceUrl.Length); var resultHandle = Engine.JsRunSerialized(bufferHandle, callback, JavaScriptSourceContext.None, sourceUrlHandle); Assert.True(resultHandle != JavaScriptValueSafeHandle.Invalid); var handleType = Engine.JsGetValueType(resultHandle); Assert.True(handleType == JsValueType.Number); var resultValue = Engine.JsNumberToInt(resultHandle); Assert.True(resultValue == 42); sourceUrlHandle.Dispose(); resultHandle.Dispose(); scriptHandle.Dispose(); } finally { Marshal.FreeHGlobal(ptrScript); } } } }