public static void ParseScript(JavaScriptModuleRecord module, string script) { var buffer = Encoding.UTF8.GetBytes(script); uint length = (uint)buffer.Length; Native.ThrowIfError(Native.JsParseModuleSource(module, JavaScriptSourceContext.None, buffer, length, JavaScriptParseModuleSourceFlags.JsParseModuleSourceFlags_DataIsUTF8, out JavaScriptValue parseException)); if (parseException.IsValid) { string ex = parseException.ToString(); throw new InvalidOperationException($"Parse script failed with error={ex}"); } }
public static extern JavaScriptErrorCode JsSetModuleHostName(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, JavaScriptValue value);
public static extern JavaScriptErrorCode JsSetFetchImportedModuleFromScriptyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, FetchImportedModuleFromScriptDelegate value);
public static extern JavaScriptErrorCode JsSetModuleNotifyModuleReadyCallback(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, NotifyModuleReadyCallbackDelegate value);
public static extern JavaScriptErrorCode JsSetModuleHostInfo(JavaScriptModuleRecord module, JavascriptModuleHostInfoKind kind, object value);
public static extern JavaScriptErrorCode JsModuleEvaluation(JavaScriptModuleRecord moduel, out JavaScriptValue result);
public static extern JavaScriptErrorCode JsParseModuleSource(JavaScriptModuleRecord moduel, JavaScriptSourceContext sourceContext, byte[] script, uint scriptLength, JavaScriptParseModuleSourceFlags flags, out JavaScriptValue parseException);
public static extern JavaScriptErrorCode JsInitializeModuleRecord(JavaScriptModuleRecord parent, JavaScriptValue name, out JavaScriptModuleRecord result);
public static void SetModuleName(JavaScriptModuleRecord module, string name) { JavaScriptValue value = JavaScriptValue.FromString(name); Native.ThrowIfError(Native.JsSetModuleHostName(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_HostDefined, value)); }
public static void SetFetchModuleScriptCallback(JavaScriptModuleRecord module, FetchImportedModuleFromScriptDelegate callback) { Native.ThrowIfError(Native.JsSetFetchImportedModuleFromScriptyCallback(module, JavascriptModuleHostInfoKind.JsModuleHostInfo_FetchImportedModuleFromScriptCallback, callback)); }
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)); }
public static JavaScriptValue RunModule(JavaScriptModuleRecord module) { Native.ThrowIfError(Native.JsModuleEvaluation(module, out JavaScriptValue result)); return(result); }