Exemplo n.º 1
0
 private Dictionary<string, JSValue> GetBag(JSObject obj)
 {
     Dictionary<string, JSValue> bag;
     if (!properties.TryGetValue (obj.Raw, out bag)) {
         properties.Add (obj.Raw, bag = new Dictionary<string, JSValue> ());
     }
     return bag;
 }
Exemplo n.º 2
0
 public JSValue EvaluateScript(JSString script, JSObject thisObject,
     JSString sourceUrl, int startingLineNumber)
 {
     var exception = IntPtr.Zero;
     var result = JSEvaluateScript (Raw, script,
         thisObject == null ? IntPtr.Zero : thisObject.Raw,
         sourceUrl, startingLineNumber, ref exception);
     JSException.Proxy (this, exception);
     return new JSValue (this, result);
 }
Exemplo n.º 3
0
        public JSValue EvaluateScript (string script, JSObject thisObject, string sourceUrl, int startingLineNumber)
        {
            var js_script = JSString.New (script);
            var js_source_url = JSString.New (sourceUrl);

            try {
                return EvaluateScript (js_script, thisObject, js_source_url, startingLineNumber);
            } finally {
                js_script.Release ();
                js_source_url.Release ();
            }
        }
Exemplo n.º 4
0
 protected virtual void OnJSInitialize (JSObject obj)
 {
 }
Exemplo n.º 5
0
 protected override bool OnJSSetProperty(JSObject obj, string propertyName, JSValue value)
 {
     GetBag (obj)[propertyName] = value;
     return true;
 }
Exemplo n.º 6
0
 protected override bool OnJSHasProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj).ContainsKey (propertyName);
 }
Exemplo n.º 7
0
 protected override void OnJSGetPropertyNames(JSObject obj, JSPropertyNameAccumulator propertyNames)
 {
     foreach (var name in GetBag (obj).Keys) {
         propertyNames.AddName (name);
     }
 }
Exemplo n.º 8
0
 protected override JSValue OnJSGetProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj)[propertyName];
 }
Exemplo n.º 9
0
 protected override void OnJSFinalize(JSObject obj)
 {
     properties.Remove (obj.Raw);
 }
Exemplo n.º 10
0
 protected override bool OnJSDeleteProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj).Remove (propertyName);
 }
Exemplo n.º 11
0
 protected virtual JSObject OnJSCallAsConstructor (JSObject constructor, JSValue [] args)
 {
     return null;
 }
Exemplo n.º 12
0
 public JSValue EvaluateScript(string script, JSObject thisObject)
 {
     return EvaluateScript (script, thisObject, null, 0);
 }
Exemplo n.º 13
0
 protected virtual void OnJSGetPropertyNames (JSObject obj, JSPropertyNameAccumulator propertyNames)
 {
 }
Exemplo n.º 14
0
 protected virtual bool OnJSDeleteProperty (JSObject obj, string propertyName)
 {
     return false;
 }
Exemplo n.º 15
0
 protected virtual bool OnJSSetProperty (JSObject obj, string propertyName, JSValue value)
 {
     return false;
 }
Exemplo n.º 16
0
 protected virtual JSValue OnJSGetProperty (JSObject obj, string propertyName)
 {
     return JSValue.NewUndefined (obj.Context);
 }
Exemplo n.º 17
0
 protected virtual void OnJSFinalize (JSObject obj)
 {
 }
Exemplo n.º 18
0
        public JSValue CallAsFunction (JSObject thisObject, JSValue [] args)
        {
            var exception = IntPtr.Zero;
            var args_native = new IntPtr[args.Length];

            for (int i = 0; i < args.Length; i++) {
                args_native[i] = args[i].Raw;
            }

            var result = new JSValue (Context.Raw, JSObjectCallAsFunction (Context.Raw, Raw,
                thisObject == null ? IntPtr.Zero : thisObject.Raw, new IntPtr (args.Length),
                args_native, ref exception));

            JSException.Proxy (Context, exception);

            return result;
        }
Exemplo n.º 19
0
 public bool IsInstanceOfConstructor (JSObject constructor)
 {
     var exception = IntPtr.Zero;
     var result = JSValueIsInstanceOfConstructor (Context.Raw, Raw, constructor.Raw, ref exception);
     JSException.Proxy (Context, exception);
     return result;
 }
Exemplo n.º 20
0
        private IntPtr OnStaticFunctionCallback (IntPtr ctx, IntPtr function, IntPtr thisObject,
            IntPtr argumentCount, IntPtr arguments, ref IntPtr exception)
        {
            var context = new JSContext (ctx);
            var fn = new JSObject (ctx, function);
            string fn_name = null;
            if (fn.HasProperty ("name")) {
                var prop = fn.GetProperty ("name");
                if (prop != null && prop.IsString) {
                    fn_name = prop.StringValue;
                }
            }

            MethodInfo method = null;
            if (fn_name == null || !static_methods.TryGetValue (fn_name, out method)) {
                return JSValue.NewUndefined (context).Raw;
            }

            var result = method.Invoke (null, new object [] {
                fn,
                new JSObject (context, thisObject),
                JSValue.MarshalArray (ctx, arguments, argumentCount)
            });

            return result == null
                ? JSValue.NewUndefined (context).Raw
                : ((JSValue)result).Raw;
        }