Bug 921448 - Move ProxyObject::New to vm/ProxyObject.cpp. r=ejpbruel

This commit is contained in:
Bobby Holley 2013-10-04 13:29:35 +02:00
parent 197eaa4082
commit 78d1f83d78
2 changed files with 49 additions and 47 deletions

View File

@ -3141,53 +3141,6 @@ const Class js::OuterWindowProxyObject::class_ = {
const Class* const js::OuterWindowProxyClassPtr = &OuterWindowProxyObject::class_;
/* static */ ProxyObject *
ProxyObject::New(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, TaggedProto proto_,
JSObject *parent_, ProxyCallable callable, bool singleton)
{
Rooted<TaggedProto> proto(cx, proto_);
RootedObject parent(cx, parent_);
JS_ASSERT_IF(proto.isObject(), cx->compartment() == proto.toObject()->compartment());
JS_ASSERT_IF(parent, cx->compartment() == parent->compartment());
const Class *clasp;
if (handler->isOuterWindow())
clasp = &OuterWindowProxyObject::class_;
else
clasp = callable ? &ProxyObject::callableClass_
: &ProxyObject::uncallableClass_;
/*
* Eagerly mark properties unknown for proxies, so we don't try to track
* their properties and so that we don't need to walk the compartment if
* their prototype changes later.
*/
if (proto.isObject() && !singleton) {
RootedObject protoObj(cx, proto.toObject());
if (!JSObject::setNewTypeUnknown(cx, clasp, protoObj))
return NULL;
}
NewObjectKind newKind =
(clasp == &OuterWindowProxyObject::class_ || singleton) ? SingletonObject : GenericObject;
gc::AllocKind allocKind = gc::GetGCObjectKind(clasp);
if (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);
/* Don't track types of properties of proxies. */
if (newKind != SingletonObject)
MarkTypeObjectUnknownProperties(cx, proxy->type());
return proxy;
}
JS_FRIEND_API(JSObject *)
js::NewProxyObject(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, JSObject *proto_,
JSObject *parent_, ProxyCallable callable, bool singleton)

View File

@ -8,9 +8,58 @@
#include "jscompartment.h"
#include "jsgcinlines.h"
#include "jsinferinlines.h"
#include "jsobjinlines.h"
using namespace js;
/* static */ ProxyObject *
ProxyObject::New(JSContext *cx, BaseProxyHandler *handler, HandleValue priv, TaggedProto proto_,
JSObject *parent_, ProxyCallable callable, bool singleton)
{
Rooted<TaggedProto> proto(cx, proto_);
RootedObject parent(cx, parent_);
JS_ASSERT_IF(proto.isObject(), cx->compartment() == proto.toObject()->compartment());
JS_ASSERT_IF(parent, cx->compartment() == parent->compartment());
const Class *clasp;
if (handler->isOuterWindow())
clasp = &OuterWindowProxyObject::class_;
else
clasp = callable ? &ProxyObject::callableClass_
: &ProxyObject::uncallableClass_;
/*
* Eagerly mark properties unknown for proxies, so we don't try to track
* their properties and so that we don't need to walk the compartment if
* their prototype changes later.
*/
if (proto.isObject() && !singleton) {
RootedObject protoObj(cx, proto.toObject());
if (!JSObject::setNewTypeUnknown(cx, clasp, protoObj))
return NULL;
}
NewObjectKind newKind =
(clasp == &OuterWindowProxyObject::class_ || singleton) ? SingletonObject : GenericObject;
gc::AllocKind allocKind = gc::GetGCObjectKind(clasp);
if (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);
/* Don't track types of properties of proxies. */
if (newKind != SingletonObject)
MarkTypeObjectUnknownProperties(cx, proxy->type());
return proxy;
}
void
ProxyObject::initCrossCompartmentPrivate(HandleValue priv)
{