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;
 }
Beispiel #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);
 }
Beispiel #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 ();
            }
        }
 protected virtual void OnJSInitialize (JSObject obj)
 {
 }
 protected override bool OnJSSetProperty(JSObject obj, string propertyName, JSValue value)
 {
     GetBag (obj)[propertyName] = value;
     return true;
 }
 protected override bool OnJSHasProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj).ContainsKey (propertyName);
 }
 protected override void OnJSGetPropertyNames(JSObject obj, JSPropertyNameAccumulator propertyNames)
 {
     foreach (var name in GetBag (obj).Keys) {
         propertyNames.AddName (name);
     }
 }
 protected override JSValue OnJSGetProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj)[propertyName];
 }
 protected override void OnJSFinalize(JSObject obj)
 {
     properties.Remove (obj.Raw);
 }
 protected override bool OnJSDeleteProperty(JSObject obj, string propertyName)
 {
     return GetBag (obj).Remove (propertyName);
 }
Beispiel #11
0
 protected virtual JSObject OnJSCallAsConstructor (JSObject constructor, JSValue [] args)
 {
     return null;
 }
Beispiel #12
0
 public JSValue EvaluateScript(string script, JSObject thisObject)
 {
     return EvaluateScript (script, thisObject, null, 0);
 }
 protected virtual void OnJSGetPropertyNames (JSObject obj, JSPropertyNameAccumulator propertyNames)
 {
 }
 protected virtual bool OnJSDeleteProperty (JSObject obj, string propertyName)
 {
     return false;
 }
 protected virtual bool OnJSSetProperty (JSObject obj, string propertyName, JSValue value)
 {
     return false;
 }
 protected virtual JSValue OnJSGetProperty (JSObject obj, string propertyName)
 {
     return JSValue.NewUndefined (obj.Context);
 }
 protected virtual void OnJSFinalize (JSObject obj)
 {
 }
Beispiel #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;
        }
Beispiel #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;
 }
Beispiel #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;
        }