예제 #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;

            Native.ThrowIfError(Native.JsRun(JavaScriptValue.FromString(script), sourceContext, JavaScriptValue.FromString(sourceName), JavaScriptParseScriptAttributes.JsParseScriptAttributeNone, 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));
        }