public static void ParseScript(JavaScriptModuleRecord module, string script, JavaScriptSourceContext sourceContext)
        {
            var buffer    = Encoding.UTF8.GetBytes(script);
            var length    = (uint)buffer.Length;
            var errorCode = Native.JsParseModuleSource(module, sourceContext, buffer, length, JavaScriptParseModuleSourceFlags.JsParseModuleSourceFlags_DataIsUTF8, out JavaScriptValue parseException);

            if (parseException.IsValid)
            {
                Native.JsGetPropertyIdFromName("message", out var propertyId);
                var    prop = parseException.GetProperty(propertyId);
                string ex   = prop.ToString();
                throw new InvalidOperationException($"Parse script failed with error = {ex}\n\n {script}");
            }

            Native.ThrowIfError(errorCode);
        }
Example #2
0
 public static extern JavaScriptErrorCode JsGetModuleNamespace(JavaScriptModuleRecord requestModule, out JavaScriptValue moduleNamespace);
Example #3
0
 public static extern JavaScriptErrorCode JsGetModuleHostInfo(
     JavaScriptModuleRecord requestModule,
     JavascriptModuleHostInfoKind moduleHostInfo,
     out JavaScriptValue hostInfo
     );
Example #4
0
 public static extern JavaScriptErrorCode JsFetchImportedModuleFromScriptyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, FetchImportedModuleFromScriptDelegate value);
Example #5
0
 public static extern JavaScriptErrorCode JsSetModuleNotifyModuleReadyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, NotifyModuleReadyCallbackDelegate value);
Example #6
0
 public static extern JavaScriptErrorCode JsSetModuleHostInfo(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, JavaScriptValue value);
Example #7
0
 public static extern JavaScriptErrorCode JsModuleEvaluation(JavaScriptModuleRecord module, out JavaScriptValue result);
Example #8
0
 public static extern JavaScriptErrorCode JsParseModuleSource(JavaScriptModuleRecord module, JavaScriptSourceContext sourceContext, byte[] script, uint scriptLength, JavaScriptParseModuleSourceFlags flags, out JavaScriptValue parseException);
Example #9
0
 public static extern JavaScriptErrorCode JsInitializeModuleRecord(JavaScriptModuleRecord parent, JavaScriptValue name, out JavaScriptModuleRecord result);
 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 SetHostUrl(JavaScriptModuleRecord module, string url)
        {
            var value = JavaScriptValue.FromString(url);

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