示例#1
0
        /// <summary>
        /// Returns a runtime-independent buffer of the the specified script 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[] SerializeScript(string script, bool isLibraryCode = false)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(nameof(BaristaContext));
            }

            var scriptBuffer            = ValueFactory.CreateArrayBufferUtf8(script);
            var parsedArrayBufferHandle = Engine.JsSerialize(scriptBuffer.Handle, isLibraryCode ? JavaScriptParseScriptAttributes.LibraryCode : JavaScriptParseScriptAttributes.None);
            var arrayBuffer             = ValueFactory.CreateValue <JsArrayBuffer>(parsedArrayBufferHandle);

            return(arrayBuffer.GetArrayBufferStorage());
        }
示例#2
0
 public JsArrayBuffer CreateArrayBufferUtf8(string data)
 {
     return(ValueFactory.CreateArrayBufferUtf8(data));
 }