protected override void InnerExecute(string code, string documentName) { string uniqueDocumentName = _documentNameManager.GetUniqueName(documentName); _dispatcher.Invoke(() => { using (CreateJsScope()) { try { JsParseScriptAttributes parseAttributes = JsParseScriptAttributes.None; JsContext.RunScript(code, _jsSourceContext++, uniqueDocumentName, ref parseAttributes); } catch (OriginalException e) { throw WrapJsException(e); } } }); }
/// <summary> /// Serializes a parsed script to a buffer than can be reused /// </summary> /// <remarks> /// <para> /// <c>SerializeScript</c> parses a script and then stores the parsed form of the script in a /// runtime-independent format. The serialized script then can be deserialized in any /// runtime without requiring the script to be re-parsed. /// </para> /// <para> /// Requires an active script context. /// </para> /// </remarks> /// <param name="script">The script to serialize</param> /// <param name="parseAttributes">Attribute mask for parsing the script</param> /// <returns>The buffer to put the serialized script into</returns> public static byte[] SerializeScript(string script, ref JsParseScriptAttributes parseAttributes) { JsValue scriptValue = JsValue.FromString(script); scriptValue.AddRef(); JsValue bufferValue; try { JsErrorCode errorCode = NativeMethods.JsSerialize(scriptValue, out bufferValue, parseAttributes); JsErrorHelpers.ThrowIfError(errorCode); } finally { scriptValue.Release(); } byte[] buffer = bufferValue.ArrayBufferBytes; return(buffer); }
protected override IPrecompiledScript InnerPrecompile(string code, string documentName) { string uniqueDocumentName = _documentNameManager.GetUniqueName(documentName); IPrecompiledScript precompiledScript = _dispatcher.Invoke(() => { using (CreateJsScope()) { try { JsParseScriptAttributes parseAttributes = JsParseScriptAttributes.None; byte[] cachedBytes = JsContext.SerializeScript(code, ref parseAttributes); return(new ChakraCorePrecompiledScript(code, parseAttributes, cachedBytes, uniqueDocumentName)); } catch (OriginalException e) { throw WrapJsException(e, uniqueDocumentName); } } }); return(precompiledScript); }
internal static extern JsErrorCode JsSerialize(JsValue script, out JsValue buffer, JsParseScriptAttributes parseAttributes);
internal static extern JsErrorCode JsRun(JsValue script, JsSourceContext sourceContext, JsValue sourceUrl, JsParseScriptAttributes parseAttributes, out JsValue result);
/// <summary> /// Executes a script. /// </summary> /// <remarks> /// Requires an active script context. /// </remarks> /// <param name="script">The script to run.</param> /// <param name="sourceContext"> /// A cookie identifying the script that can be used by script contexts that have debugging enabled. /// </param> /// <param name="sourceName">The location the script came from.</param> /// <returns>The result of the script, if any.</returns> public static JsValue Run(JsValue script, JsSourceContext sourceContext, JsValue sourceUrl, JsParseScriptAttributes parseAttributes) { Native.ThrowIfError(Native.JsRun(script, sourceContext, sourceUrl, parseAttributes, out JsValue result)); return(result); }
internal static extern JsErrorCode JsDiagEvaluate(JsValue expression, uint stackFrameIndex, JsParseScriptAttributes parseAttributes, bool forceSetValueProp, out JsValue eval);
internal static extern JavaScriptErrorCode JsParseScriptWithAttributes(String script, JavaScriptSourceContext sourceContext, String sourceUrl, JsParseScriptAttributes parseAttributes, out JavaScriptValue result);
public static extern JsErrorCode JsDeserializeParserState(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parserAttributes, JsValueRef parserState, out JsValueRef result);
public static extern JsErrorCode JsSerializeParserState(JsValueRef scriptVal, out JsValueRef bufferVal, JsParseScriptAttributes parseAttributes);
public static extern JsErrorCode JsParse(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, out JsValueRef result);
public static extern JsErrorCode JsExecuteBackgroundParse_Experimental(ulong dwBgParseCookie, JsValueRef script, JsSourceContext sourceContext, string url, JsParseScriptAttributes parseAttributes, JsValueRef parserState, out JsValueRef result);