mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-09 04:25:38 +00:00
Bug 921448 - Move ProxyObject::New to vm/ProxyObject.cpp. r=ejpbruel
This commit is contained in:
parent
197eaa4082
commit
78d1f83d78
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user