예제 #1
0
        /// <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));
        }
예제 #2
0
 public JsString CreateString(string str)
 {
     return(ValueFactory.CreateString(str));
 }