Ejemplo n.º 1
0
 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")];
 }
Ejemplo n.º 2
0
 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 ();
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
		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);
        }
Ejemplo n.º 6
0
		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();
			}
		}
Ejemplo n.º 7
0
        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));
            }
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
 internal JSException (JSContext context, IntPtr exception)
     : this (context, "JSON: " + new JSValue (context, exception).ToJsonString ())
 {
 }
Ejemplo n.º 10
0
 public static JSValue NewUndefined(JSContext ctx)
 {
     return(new JSValue(ctx, JSValueMakeUndefined(ctx.Raw)));
 }
Ejemplo n.º 11
0
 public JSValue (JSContext ctx, double value) : this (ctx, JSValueMakeNumber (ctx.Raw, value)) { }
Ejemplo n.º 12
0
 public JSValue (JSContext ctx, bool value) : this (ctx, JSValueMakeBoolean (ctx.Raw, value)) { }
Ejemplo n.º 13
0
 public JSValue (IntPtr context, IntPtr raw)
 {
     Raw = raw;
     Context = new JSContext (context);
 }
Ejemplo n.º 14
0
 public static JSValue FromJson (JSContext ctx, string json)
 {
     var json_native = JSString.New (json);
     try {
         return FromJson (ctx, json_native);
     } finally {
         json_native.Release ();
     }
 }
Ejemplo n.º 15
0
 public MyNativeBridge(JSContext newContext)
     : base()
 {
     jsContext = newContext;
 }
Ejemplo n.º 16
0
 public JSObject (JSContext context, JSClass jsClass)
     : base (context, JSObjectMake (context.Raw,
         jsClass == null ? IntPtr.Zero : jsClass.Raw, IntPtr.Zero))
 {
 }
Ejemplo n.º 17
0
 public JSObject (JSContext context) :
     base (context, JSObjectMake (context.Raw, IntPtr.Zero, IntPtr.Zero))
 {
 }
Ejemplo n.º 18
0
 public JSObject (JSContext context, IntPtr raw) : base (context, raw)
 {
 }
Ejemplo n.º 19
0
 public JSValue(JSContext ctx, ulong value) : this(ctx, JSValueMakeNumber(ctx.Raw, (double)value))
 {
 }
Ejemplo n.º 20
0
 public JSValue(JSContext ctx, bool value) : this(ctx, JSValueMakeBoolean(ctx.Raw, value))
 {
 }
Ejemplo n.º 21
0
 public JSValue(JSContext context, IntPtr raw)
 {
     Raw     = raw;
     Context = context;
 }
Ejemplo n.º 22
0
 public JSValue(JSContext ctx, double value) : this(ctx, JSValueMakeNumber(ctx.Raw, value))
 {
 }
Ejemplo n.º 23
0
 public JSValue(IntPtr context, IntPtr raw)
 {
     Raw     = raw;
     Context = new JSContext(context);
 }
Ejemplo n.º 24
0
 public static JSValue NewNull(JSContext ctx)
 {
     return(new JSValue(ctx, JSValueMakeNull(ctx.Raw)));
 }
Ejemplo n.º 25
0
 public JSValue (IntPtr raw)
 {
     Raw = raw;
     Context = null;
 }
Ejemplo n.º 26
0
 public JSErrorException(JSContext context, string name, string message)
 {
     Error = new JSError (context, name, message);
 }
Ejemplo n.º 27
0
 public JSValue (JSContext context, IntPtr raw)
 {
     Raw = raw;
     Context = context;
 }
Ejemplo n.º 28
0
 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;
 }
Ejemplo n.º 29
0
 public JSValue (JSContext ctx, float value) : this (ctx, JSValueMakeNumber (ctx.Raw, (double)value)) { }
Ejemplo n.º 30
0
 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));
 }
Ejemplo n.º 31
0
 public JSValue (JSContext ctx, string value) : this (ctx, JSValueMakeString (ctx.Raw, JSString.New (value))) { }
Ejemplo n.º 32
0
 public JSErrorException(JSContext context, string name, string message)
 {
     Error = new JSError(context, name, message);
 }
Ejemplo n.º 33
0
 public JSValue(JSContext ctx, string value) : this(ctx, JSValueMakeString(ctx.Raw, JSString.New(value)))
 {
 }
Ejemplo n.º 34
0
 public static JSValue NewUndefined (JSContext ctx)
 {
     return new JSValue (ctx, JSValueMakeUndefined (ctx.Raw));
 }
Ejemplo n.º 35
0
 internal JSException (JSContext context, string message)
     : base (message)
 {
     Context = context;
 }
Ejemplo n.º 36
0
 public static JSValue NewNull (JSContext ctx)
 {
     return new JSValue (ctx, JSValueMakeNull (ctx.Raw));
 }
Ejemplo n.º 37
0
 internal static void Proxy (JSContext ctx, IntPtr exception)
 {
     if (!exception.Equals (IntPtr.Zero)) {
         throw new JSException (ctx, exception);
     }
 }
Ejemplo n.º 38
0
        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) {
Ejemplo n.º 40
0
 public JSValue(IntPtr raw)
 {
     Raw     = raw;
     Context = null;
 }