コード例 #1
0
        /// <summary>
        /// Registers a managed function as a property on the target object.
        /// The managed function is wrapped automatically by a marshalling proxy.
        /// </summary>
        /// <returns>
        /// The function's marshalling proxy that must be retained as long as the function is available to JS.
        /// </returns>
        public Managed.NativeToManagedProxy DefineFunction(
            JSContextPtr context, string name, Delegate @delegate, uint attrs = 0
            )
        {
            var wrapped = new Managed.NativeToManagedProxy(@delegate);

            JSAPI.DefineFunction(
                context, TransientSelf(), name, wrapped.WrappedMethod, wrapped.ArgumentCount, attrs
                );
            return(wrapped);
        }
コード例 #2
0
        public Rooted <JS.Value> Get()
        {
            var root = new Rooted <JS.Value>(Context, JS.Value.Undefined);

            if (JSAPI.GetPendingException(Context, root))
            {
                return(root);
            }

            root.Dispose();
            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Registers a managed JSNative as a property on the target object.
        /// The JSNative should return true on success and always set a result value.
        /// </summary>
        /// <returns>
        /// A pinning handle for the function that must be retained as long as the function is available to JS.
        /// </returns>
        public unsafe Managed.JSNativePin DefineFunction(
            JSContextPtr context, string name, JSNative call,
            uint nargs = 0, uint attrs = 0
            )
        {
            var wrapped = new Managed.JSNativePin(call);

            JSAPI.DefineFunction(
                context, TransientSelf(), name, wrapped.Target, nargs, attrs
                );
            return(wrapped);
        }
コード例 #4
0
        public Rooted <JS.Value> GetProperty(JSContextPtr context, string name)
        {
            var result = new Rooted <JS.Value>(context);

            if (JSAPI.GetProperty(context, TransientSelf(), name, result))
            {
                return(result);
            }

            result.Dispose();
            return(null);
        }
コード例 #5
0
        public unsafe JSObjectPtr InvokeConstructor(
            JSContextPtr context,
            params JS.Value[] arguments
            )
        {
            fixed(JSFunctionPtr *pThis = &this)
            fixed(JS.Value * pArgs = arguments)
            {
                var argsPtr = new JS.ValueArrayPtr((uint)arguments.Length, (IntPtr)pArgs);

                return(JSAPI.New(context, (JSObjectPtr *)pThis, ref argsPtr));
            }
        }
コード例 #6
0
        public Exception GetManaged()
        {
            var root = new Rooted <JS.Value>(Context, JS.Value.Undefined);

            if (!JSAPI.GetPendingException(Context, root))
            {
                return(null);
            }

            var error = new Spidermonkey.Managed.JSError(Context, root.Value.AsObject);

            return(error.ToException());
        }
コード例 #7
0
        // Creates a copy
        internal static unsafe string ToManagedString(JSContextPtr context, JSStringPtr ptr)
        {
            uint length;

            if (JSAPI.StringHasLatin1Chars(ptr))
            {
                var pChars = JSAPI.GetLatin1StringCharsAndLength(
                    context, ref JS.AutoCheckCannotGC.Instance,
                    ptr, out length
                    );

                var latin1 = Encoding.GetEncoding("ISO-8859-1");
                return(new String((sbyte *)pChars, 0, (int)length, latin1));
            }
            else
            {
                var pChars = JSAPI.GetTwoByteStringCharsAndLength(
                    context, ref JS.AutoCheckCannotGC.Instance,
                    ptr, out length
                    );

                return(new String((char *)pChars, 0, (int)length));
            }
        }
コード例 #8
0
 void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root)
 {
     JSAPI.RemoveObjectRoot(context, root);
 }
コード例 #9
0
 // FIXME: I think this is right since JSFunction derives from JSObject
 bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root)
 {
     return(JSAPI.AddObjectRoot(context, root));
 }
コード例 #10
0
 public void Clear()
 {
     JSAPI.ClearPendingException(Context);
 }
コード例 #11
0
 bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root)
 {
     return(JSAPI.AddNamedScriptRoot(context, root, null));
 }
コード例 #12
0
 void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root)
 {
     JSAPI.RemoveStringRoot(context, root);
 }
コード例 #13
0
 public bool SetProperty(JSContextPtr context, string name, JSHandleValue value)
 {
     return(JSAPI.SetProperty(context, TransientSelf(), name, value));
 }