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