public static void ParseScript(JavaScriptModuleRecord module, string script, JavaScriptSourceContext sourceContext)
        {
            var  buffer = Encoding.UTF8.GetBytes(script);
            uint length = (uint)buffer.Length;

            Native.ThrowIfError(Native.JsParseModuleSource(module, sourceContext, buffer, length, JavaScriptParseModuleSourceFlags.JsParseModuleSourceFlags_DataIsUTF8, out JavaScriptValue parseException));
            if (parseException.IsValid)
            {
                string ex = parseException.ToString();
                throw new InvalidOperationException($"Parse script failed with error={ex}");
            }
        }
Example #2
0
 public static extern JavaScriptErrorCode JsFetchImportedModuleFromScriptyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, FetchImportedModuleFromScriptDelegate value);
Example #3
0
 public static extern JavaScriptErrorCode JsSetModuleNotifyModuleReadyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, NotifyModuleReadyCallbackDelegate value);
Example #4
0
 public static extern JavaScriptErrorCode JsSetModuleHostInfo(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, JavaScriptValue value);
Example #5
0
 public static extern JavaScriptErrorCode JsModuleEvaluation(JavaScriptModuleRecord moduel, out JavaScriptValue result);
Example #6
0
 public static extern JavaScriptErrorCode JsParseModuleSource(JavaScriptModuleRecord moduel, JavaScriptSourceContext sourceContext, byte[] script, uint scriptLength, JavaScriptParseModuleSourceFlags flags, out JavaScriptValue parseException);
Example #7
0
 public static extern JavaScriptErrorCode JsInitializeModuleRecord(JavaScriptModuleRecord parent, JavaScriptValue name, out JavaScriptModuleRecord result);
        public static void SetHostUrl(JavaScriptModuleRecord module, string url)
        {
            var value = JavaScriptValue.FromString(url);

            Native.ThrowIfError(Native.JsSetModuleHostInfo(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_Url, value));
        }
 public static JavaScriptValue RunModule(JavaScriptModuleRecord module)
 {
     Native.ThrowIfError(Native.JsModuleEvaluation(module, out JavaScriptValue result));
     return(result);
 }
 /// <summary>
 /// Set callback from chakracore to fetch module dynamically during runtime.
 /// While this call will come back directly from runtime script or module code, the additional
 /// task can be scheduled asynchronously that executed later.
 /// </summary>
 /// <param name="module"></param>
 /// <param name="callback"></param>
 public static void SetFetchModuleScriptCallback(JavaScriptModuleRecord module, FetchImportedModuleFromScriptDelegate callback)
 {
     Native.ThrowIfError(Native.JsFetchImportedModuleFromScriptyCallback(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_FetchImportedModuleFromScriptCallback, callback));
 }
 /// <summary>
 /// Set callback from chakraCore when the module resolution is finished, either successfuly or unsuccessfully.
 /// </summary>
 /// <param name="module"></param>
 /// <param name="callback"></param>
 public static void SetNotifyReady(JavaScriptModuleRecord module, NotifyModuleReadyCallbackDelegate callback)
 {
     Native.ThrowIfError(Native.JsSetModuleNotifyModuleReadyCallback(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_NotifyModuleReadyCallback, callback));
 }
 public static void SetHostInfo(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, object value)
 {
     Native.ThrowIfError(Native.JsSetModuleHostInfo(module, kind, value));
 }