/// <summary> /// Returns a runtime-independent buffer of the the specified script, which contains unicode characters, that can be reused without requiring the script to be re-parsed. /// </summary> /// <param name="script"></param> /// <param name="isLibraryCode"></param> /// <returns></returns> public byte[] SerializeUnicodeScript(string unicodeScript, bool isLibraryCode = false) { if (IsDisposed) { throw new ObjectDisposedException(nameof(BaristaContext)); } var scriptBuffer = ValueFactory.CreateArrayBuffer(unicodeScript); var parsedArrayBufferHandle = Engine.JsSerialize(scriptBuffer.Handle, JavaScriptParseScriptAttributes.ArrayBufferIsUtf16Encoded); var arrayBuffer = ValueFactory.CreateValue <JsArrayBuffer>(parsedArrayBufferHandle); return(arrayBuffer.GetArrayBufferStorage()); }
/// <summary> /// Returns a function representing the specified, previously-serialized, script. /// </summary> /// <param name="serializedScript"></param> /// <param name="sourceUrl"></param> /// <returns></returns> public JsFunction ParseSerializedScript(byte[] serializedScript, Func <string> scriptLoadCallback, string sourceUrl = "[eval code]") { var buffer = ValueFactory.CreateArrayBuffer(serializedScript); var jsSourceUrl = ValueFactory.CreateString(sourceUrl); var callback = new JavaScriptSerializedLoadScriptCallback((JavaScriptSourceContext sourceContext, out IntPtr value, out JavaScriptParseScriptAttributes parseAttributes) => { var script = scriptLoadCallback(); value = Engine.JsCreateString(script, (ulong)script.Length).DangerousGetHandle(); parseAttributes = JavaScriptParseScriptAttributes.None; return(true); }); var fnScript = Engine.JsParseSerialized(buffer.Handle, callback, JavaScriptSourceContext.None, jsSourceUrl.Handle); return(ValueFactory.CreateValue <JsFunction>(fnScript)); }
public JsArrayBuffer CreateArrayBuffer(byte[] data) { return(ValueFactory.CreateArrayBuffer(data)); }
public JsArrayBuffer CreateArrayBuffer(string data) { return(ValueFactory.CreateArrayBuffer(data)); }