public MarkdownService() { _ctx = new JSContext(_vm); var script = System.IO.File.ReadAllText("WebResources/marked.js", System.Text.Encoding.UTF8); _ctx.EvaluateScript(script); _val = _ctx[new NSString("marked")]; }
public JSFunction (JSContext context, string name, JSFunctionHandler handler) : base (context, IntPtr.Zero) { this.handler = handler; var native_name = JSString.New (name); Raw = JSObjectMakeFunctionWithCallback (context.Raw, native_name, native_callback = new JSObject.CallAsFunctionCallback (JSCallback)); native_name.Release (); }
private IntPtr JSCallback (IntPtr ctx, IntPtr function, IntPtr thisObject, IntPtr argumentCount, IntPtr arguments, ref IntPtr exception) { var context = new JSContext (ctx); return handler == null ? JSValue.NewUndefined (context).Raw : handler (this, new JSObject (context, thisObject), JSValue.MarshalArray (ctx, arguments, argumentCount)).Raw; }
public MarkdownService() { var scriptPath = System.IO.Path.Combine(NSBundle.MainBundle.BundlePath, "WebResources", "marked.js"); var scriptContents = System.IO.File.ReadAllText(scriptPath); _ctx = new JSContext(_vm); _ctx.EvaluateScript(scriptContents); _val = _ctx[new NSString("marked")]; }
public void DidCreateJavascriptContext(WebView view, JSContext context, WebFrame frame) { jsContext = context; jsContext.ExceptionHandler = (JSContext contextException, JSValue exception) => { Console.WriteLine("JavaScript Exception: {0}", exception); }; nativeBridge = new MyNativeBridge(jsContext); jsContext[(NSString)"nativeBridge"] = JSValue.From(nativeBridge, jsContext); }
public string ConvertMarkdown(string c) { if (string.IsNullOrEmpty(c)) return string.Empty; using (var vm = new JSVirtualMachine()) { var ctx = new JSContext(vm); var script = System.IO.File.ReadAllText("Markdown/marked.js", System.Text.Encoding.UTF8); ctx.EvaluateScript(script); var val = ctx[new NSString("marked")]; return val.Call(JSValue.From(c, ctx)).ToString(); } }
public JSError (JSContext context, string name, string message) : base (context, IntPtr.Zero) { var exception = IntPtr.Zero; Raw = JSObjectMakeError (context.Raw, IntPtr.Zero, IntPtr.Zero, ref exception); JSException.Proxy (context, exception); if (name != null) { SetProperty ("name", new JSValue (context, name)); } if (message != null) { SetProperty ("message", new JSValue (context, message)); } }
private IntPtr JSCallback (IntPtr ctx, IntPtr function, IntPtr thisObject, IntPtr argumentCount, IntPtr arguments, ref IntPtr exception) { var context = new JSContext (ctx); if (handler == null) { return JSValue.NewUndefined (context).Raw; } var args = new JSValue[argumentCount.ToInt32 ()]; for (int i = 0; i < args.Length; i++) { args[i] = new JSValue (context, Marshal.ReadIntPtr (arguments, i * IntPtr.Size)); } return handler (this, new JSObject (context, thisObject), args).Raw; }
internal JSException (JSContext context, IntPtr exception) : this (context, "JSON: " + new JSValue (context, exception).ToJsonString ()) { }
public static JSValue NewUndefined(JSContext ctx) { return(new JSValue(ctx, JSValueMakeUndefined(ctx.Raw))); }
public JSValue (JSContext ctx, double value) : this (ctx, JSValueMakeNumber (ctx.Raw, value)) { }
public JSValue (JSContext ctx, bool value) : this (ctx, JSValueMakeBoolean (ctx.Raw, value)) { }
public JSValue (IntPtr context, IntPtr raw) { Raw = raw; Context = new JSContext (context); }
public static JSValue FromJson (JSContext ctx, string json) { var json_native = JSString.New (json); try { return FromJson (ctx, json_native); } finally { json_native.Release (); } }
public MyNativeBridge(JSContext newContext) : base() { jsContext = newContext; }
public JSObject (JSContext context, JSClass jsClass) : base (context, JSObjectMake (context.Raw, jsClass == null ? IntPtr.Zero : jsClass.Raw, IntPtr.Zero)) { }
public JSObject (JSContext context) : base (context, JSObjectMake (context.Raw, IntPtr.Zero, IntPtr.Zero)) { }
public JSObject (JSContext context, IntPtr raw) : base (context, raw) { }
public JSValue(JSContext ctx, ulong value) : this(ctx, JSValueMakeNumber(ctx.Raw, (double)value)) { }
public JSValue(JSContext ctx, bool value) : this(ctx, JSValueMakeBoolean(ctx.Raw, value)) { }
public JSValue(JSContext context, IntPtr raw) { Raw = raw; Context = context; }
public JSValue(JSContext ctx, double value) : this(ctx, JSValueMakeNumber(ctx.Raw, value)) { }
public JSValue(IntPtr context, IntPtr raw) { Raw = raw; Context = new JSContext(context); }
public static JSValue NewNull(JSContext ctx) { return(new JSValue(ctx, JSValueMakeNull(ctx.Raw))); }
public JSValue (IntPtr raw) { Raw = raw; Context = null; }
public JSErrorException(JSContext context, string name, string message) { Error = new JSError (context, name, message); }
public JSValue (JSContext context, IntPtr raw) { Raw = raw; Context = context; }
private IntPtr JSGetProperty (IntPtr ctx, IntPtr obj, JSString propertyName, ref IntPtr exception) { var context = new JSContext (ctx); return (OnJSGetProperty (new JSObject (context, obj), propertyName.Value) ?? JSValue.NewNull (context)).Raw; }
public JSValue (JSContext ctx, float value) : this (ctx, JSValueMakeNumber (ctx.Raw, (double)value)) { }
private bool JSSetProperty (IntPtr ctx, IntPtr obj, JSString propertyName, IntPtr value, ref IntPtr exception) { var context = new JSContext (ctx); return OnJSSetProperty (new JSObject (context, obj), propertyName.Value, new JSValue (context, value)); }
public JSValue (JSContext ctx, string value) : this (ctx, JSValueMakeString (ctx.Raw, JSString.New (value))) { }
public JSErrorException(JSContext context, string name, string message) { Error = new JSError(context, name, message); }
public JSValue(JSContext ctx, string value) : this(ctx, JSValueMakeString(ctx.Raw, JSString.New(value))) { }
public static JSValue NewUndefined (JSContext ctx) { return new JSValue (ctx, JSValueMakeUndefined (ctx.Raw)); }
internal JSException (JSContext context, string message) : base (message) { Context = context; }
public static JSValue NewNull (JSContext ctx) { return new JSValue (ctx, JSValueMakeNull (ctx.Raw)); }
internal static void Proxy (JSContext ctx, IntPtr exception) { if (!exception.Equals (IntPtr.Zero)) { throw new JSException (ctx, exception); } }
public static JSValue FromJson (JSContext ctx, JSString json) { var obj = JSValueMakeFromJSONString (ctx.Raw, json); if (obj.Equals (IntPtr.Zero)) { throw new JSException (ctx, "Invalid JSON"); } return new JSValue (ctx, obj); }
public void webView(WebView webView) didCreateJavaScriptContext(JSContext context) forFrame(WebFrame frame) {
public JSValue(IntPtr raw) { Raw = raw; Context = null; }