Пример #1
0
        private Rooted(
            JSContext managedContext,
            JSContextPtr context,
            T value
            )
        {
            if (context.IsZero)
            {
                throw new ArgumentNullException("context");
            }

            // HACK: Attempt to locate a managed context for a raw pointer if that's all we have.
            // This lets us finalize safely.
            if (managedContext == null)
            {
                managedContext = JSContext.FromPointer(context);
            }

            if (managedContext != null)
            {
                ManagedContextReference = managedContext.WeakSelf;
            }
            else
            {
                ManagedContextReference = null;
            }

            Context = context;

            State = new _State(value);
            Pin   = GCHandle.Alloc(State, GCHandleType.Pinned);
            Root  = new JSRootPtr(Pin.AddrOfPinnedObject());

            if (!default(T).AddRoot(context, Root))
            {
                throw new Exception("Failed to add root");
            }
        }
Пример #2
0
 void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root)
 {
     JSAPI.RemoveObjectRoot(context, root);
 }
Пример #3
0
 // FIXME: I think this is right since JSFunction derives from JSObject
 bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root)
 {
     return(JSAPI.AddObjectRoot(context, root));
 }
Пример #4
0
 bool IRootable.AddRoot(JSContextPtr context, JSRootPtr root)
 {
     return(JSAPI.AddNamedScriptRoot(context, root, null));
 }
Пример #5
0
 void IRootable.RemoveRoot(JSContextPtr context, JSRootPtr root)
 {
     JSAPI.RemoveStringRoot(context, root);
 }