public object InvokeProperty(JsObject obj, string name, object[] args)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");
            if (name == null)
                throw new ArgumentNullException("name");

            CheckDisposed();

            if (obj.Handle == IntPtr.Zero)
                throw new JsInteropException("wrapped V8 object is empty (IntPtr is Zero)");

            JsValue a = JsValue.Null; // Null value unless we're given args.
            if (args != null)
                a = _convert.ToJsValue(args);

            JsValue v = jscontext_invoke_property(_context, obj.Handle, name, a);
            object res = _convert.FromJsValue(v);
            jsvalue_dispose(v);
            jsvalue_dispose(a);

            Exception e = res as JsException;
            if (e != null)
                throw e;
            return res;
        }
Exemple #2
0
 internal JsException(string type, string resource, string message, int line, int col, JsObject error)
     : base(string.Format("{0}: {1} at line: {2} column: {3}.", resource, message, line, col))
 {
     _type = type;
     _resource = resource;
     _line = line;
     _column = col;
     _nativeException = error;
 }
        public object GetPropertyValue(JsObject obj, string name)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");
            if (name == null)
                throw new ArgumentNullException("name");

            CheckDisposed();

            if (obj.Handle == IntPtr.Zero)
                throw new JsInteropException("wrapped V8 object is empty (IntPtr is Zero)");

            JsValue v = jscontext_get_property_value(_context, obj.Handle, name);
            object res = _convert.FromJsValue(v);
            jsvalue_dispose(v);

            Exception e = res as JsException;
            if (e != null)
                throw e;
            return res;
        }
        public IEnumerable<string> GetMemberNames(JsObject obj)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");

            CheckDisposed();

            if (obj.Handle == IntPtr.Zero)
                throw new JsInteropException("wrapped V8 object is empty (IntPtr is Zero)");

            JsValue v = jscontext_get_property_names(_context, obj.Handle);
            object res = _convert.FromJsValue(v);
            jsvalue_dispose(v);

            Exception e = res as JsException;
            if (e != null)
                throw e;

            object[] arr = (object[])res;
            return arr.Cast<string>();
        }
Exemple #5
0
 // Native V8 exception objects are wrapped by special instances of JsException.
 public JsException(JsObject nativeException)
 {
     _nativeException = nativeException;
 }
Exemple #6
0
        public void SetPropertyValue(JsObject obj, string name, object value)
        {
            if (obj == null)
                throw new ArgumentNullException("obj");
            if (name == null)
                throw new ArgumentNullException("name");

            CheckDisposed();

            if (obj.Handle == IntPtr.Zero)
                throw new JsInteropException("wrapped V8 object is empty (IntPtr is Zero)");

            JsValue a = _convert.ToJsValue(value);
            JsValue v = jsengine_set_property_value(_engine, obj.Handle, name, a);
            object res = _convert.FromJsValue(v);
            jsvalue_dispose(v);
            jsvalue_dispose(a);

            Exception e = res as JsException;
            if (e != null)
                throw e;
        }
Exemple #7
0
 public void DisposeObject(JsObject obj)
 {
     // If the engine has already been explicitly disposed we pass Zero as
     // the first argument because we need to free the memory allocated by
     // "new" but not the object on the V8 heap: it has already been freed.
     if (_disposed)
         jsengine_dispose_object(new HandleRef(this, IntPtr.Zero), obj.Handle);
     else
         jsengine_dispose_object(_engine, obj.Handle);
 }
Exemple #8
0
        // Native V8 exception objects are wrapped by special instances of JsException.

        public JsException(JsObject nativeException)
        {
            _nativeException = nativeException;
        }
Exemple #9
0
 internal JsException(string type, string resource, string message, int line, int col, JsObject error)
     : base(string.Format("{0}: {1} at line: {2} column: {3}.", resource, message, line, col))
 {
     _type            = type;
     _resource        = resource;
     _line            = line;
     _column          = col;
     _nativeException = error;
 }
Exemple #10
0
 private JsObject JsDictionaryObject(JsValue v)
 {
     JsObject obj = new JsObject(this._context, v.Ptr);
     int len = v.Length * 2;
     for (int i = 0; i < len; i += 2)
     {
         var key = (JsValue)Marshal.PtrToStructure(new IntPtr(v.Ptr.ToInt64() + (16 * i)), typeof(JsValue));
         var value = (JsValue)Marshal.PtrToStructure(new IntPtr(v.Ptr.ToInt64() + (16 * (i + 1))), typeof(JsValue));
         obj[(string)FromJsValue(key)] = FromJsValue(value);
     }
     return obj;
 }