Bug 921454 - Add an option for explicitly forcing foreground finalization. r=jonco
authorBobby Holley <bobbyholley@gmail.com>
Fri, 04 Oct 2013 13:29:36 +0200
changeset 149901 7ea98711b26ce2b47b24df60cfa0b9519bfe0afa
parent 149900 6a194198c85da6772c32865cef1d507d75f44d1c
child 149902 fb163ed3947e45d7aa384893c1965c7d0bb6c7d4
push idunknown
push userunknown
push dateunknown
reviewersjonco
bugs921454
milestone27.0a1
Bug 921454 - Add an option for explicitly forcing foreground finalization. r=jonco
js/src/jsproxy.h
js/src/vm/ProxyObject.cpp
--- a/js/src/jsproxy.h
+++ b/js/src/jsproxy.h
@@ -348,34 +348,44 @@ SetProxyExtra(JSObject *obj, size_t n, c
     JS_ASSERT(IsProxy(obj));
     JS_ASSERT(n <= 1);
     SetReservedSlot(obj, PROXY_EXTRA_SLOT + n, extra);
 }
 
 class MOZ_STACK_CLASS ProxyOptions {
   public:
     ProxyOptions() : callable_(false),
-                     singleton_(false)
+                     singleton_(false),
+                     forceForegroundFinalization_(false)
     {}
 
     bool callable() const { return callable_; }
     ProxyOptions &setCallable(bool flag) {
         callable_ = flag;
         return *this;
     }
 
     bool singleton() const { return singleton_; }
     ProxyOptions &setSingleton(bool flag) {
         singleton_ = flag;
         return *this;
     }
 
+    bool forceForegroundFinalization() const {
+        return forceForegroundFinalization_;
+    }
+    ProxyOptions &setForceForegroundFinalization(bool flag) {
+        forceForegroundFinalization_ = true;
+        return *this;
+    }
+
   private:
     bool callable_;
     bool singleton_;
+    bool forceForegroundFinalization_;
 };
 
 JS_FRIEND_API(JSObject *)
 NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv,
                JSObject *proto, JSObject *parent, const ProxyOptions &options = ProxyOptions());
 
 JSObject *
 RenewProxyObject(JSContext *cx, JSObject *obj, BaseProxyHandler *handler, Value priv);
--- a/js/src/vm/ProxyObject.cpp
+++ b/js/src/vm/ProxyObject.cpp
@@ -38,17 +38,17 @@ ProxyObject::New(JSContext *cx, BaseProx
         RootedObject protoObj(cx, proto.toObject());
         if (!JSObject::setNewTypeUnknown(cx, clasp, protoObj))
             return NULL;
     }
 
     NewObjectKind newKind =
         (clasp == &OuterWindowProxyObject::class_ || options.singleton()) ? SingletonObject : GenericObject;
     gc::AllocKind allocKind = gc::GetGCObjectKind(clasp);
-    if (handler->finalizeInBackground(priv))
+    if (!options.forceForegroundFinalization() && handler->finalizeInBackground(priv))
         allocKind = GetBackgroundAllocKind(allocKind);
     RootedObject obj(cx, NewObjectWithGivenProto(cx, clasp, proto, parent, allocKind, newKind));
     if (!obj)
         return NULL;
 
     Rooted<ProxyObject*> proxy(cx, &obj->as<ProxyObject>());
     proxy->initHandler(handler);
     proxy->initCrossCompartmentPrivate(priv);