Beispiel #1
0
        /// <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 JavaScriptValue RunScript(string script, JavaScriptSourceContext sourceContext, string sourceName)
        {
            JavaScriptValue result;
            JavaScriptValue scriptValue = JavaScriptValue.FromString(script);
            JavaScriptValue name        = JavaScriptValue.FromString(sourceName);

            Native.ThrowIfError(Native.JsRun(scriptValue, sourceContext, name, JavaScriptParseScriptAttributes.JsParseScriptAttributeNone, out result));
            return(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 JavaScriptValue RunScript(string script, JavaScriptSourceContext sourceContext, string sourceName)
        {
            JavaScriptValue result;
            // windows only API
            //Native.ThrowIfError(Native.JsRunScript(script, sourceContext, sourceName, out result));

            JavaScriptValue jsScript    = JavaScriptValue.FromString(script);
            JavaScriptValue jsSourceUrl = JavaScriptValue.FromString(sourceName);

            Native.ThrowIfError(Native.JsRun(jsScript, sourceContext, jsSourceUrl, JavaScriptRuntimeAttributes.None, out result));
            return(result);
        }
        public static JavaScriptModuleRecord Create(JavaScriptModuleRecord?parent, string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = Guid.NewGuid().ToString();//root module has no name, give it a unique name
            }
            JavaScriptValue        moduleName = JavaScriptValue.FromString(name);
            JavaScriptModuleRecord result;

            if (parent.HasValue)
            {
                Native.ThrowIfError(Native.JsInitializeModuleRecord(parent.Value, moduleName, out result));
            }
            else
            {
                Native.ThrowIfError(Native.JsInitializeModuleRecord(NULLModuleRecord, moduleName, out result));
            }

            return(result);
        }
        public static void SetHostUrl(JavaScriptModuleRecord module, string url)
        {
            var value = JavaScriptValue.FromString(url);

            Native.ThrowIfError(Native.JsSetModuleHostInfo(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_Url, value));
        }