Bug 766447 - Teach TI about the new DOM bindings. (r=bhackett)

This commit is contained in:
Eric Faust 2012-07-11 20:55:19 -07:00
parent 55c4b6acdf
commit 8cc5a05403
9 changed files with 45 additions and 24 deletions

View File

@ -21,8 +21,7 @@
#define DOM_PROTOTYPE_SLOT (JSCLASS_GLOBAL_SLOT_COUNT + 1)
// We use these flag bits for the new bindings.
#define JSCLASS_IS_DOMJSCLASS JSCLASS_USERBIT1
#define JSCLASS_DOM_GLOBAL JSCLASS_USERBIT2
#define JSCLASS_DOM_GLOBAL JSCLASS_USERBIT1
namespace mozilla {
namespace dom {

View File

@ -3369,15 +3369,11 @@ JS_NewObject(JSContext *cx, JSClass *jsclasp, JSObject *proto_, JSObject *parent
JS_ASSERT(clasp != &FunctionClass);
JS_ASSERT(!(clasp->flags & JSCLASS_IS_GLOBAL));
if (proto && !proto->setNewTypeUnknown(cx))
return NULL;
JSObject *obj = NewObjectWithClassProto(cx, clasp, proto, parent);
AssertRootingUnnecessary safe(cx);
if (obj) {
if (clasp->ext.equality)
MarkTypeObjectFlags(cx, obj, OBJECT_FLAG_SPECIAL_EQUALITY);
MarkTypeObjectUnknownProperties(cx, obj->type());
}
JS_ASSERT_IF(obj, obj->getParent());

View File

@ -3892,7 +3892,7 @@ struct JSClass {
#define JSCLASS_NEW_ENUMERATE (1<<1) /* has JSNewEnumerateOp hook */
#define JSCLASS_NEW_RESOLVE (1<<2) /* has JSNewResolveOp hook */
#define JSCLASS_PRIVATE_IS_NSISUPPORTS (1<<3) /* private is (nsISupports *) */
/* (1<<4) is unused */
#define JSCLASS_IS_DOMJSCLASS (1<<4) /* objects are DOM */
#define JSCLASS_IMPLEMENTS_BARRIERS (1<<5) /* Correctly implements GC read
and write barriers */
#define JSCLASS_DOCUMENT_OBSERVER (1<<6) /* DOM document observer */

View File

@ -1830,7 +1830,8 @@ TypeCompartment::init(JSContext *cx)
TypeObject *
TypeCompartment::newTypeObject(JSContext *cx, JSScript *script,
JSProtoKey key, JSObject *proto_, bool unknown)
JSProtoKey key, JSObject *proto_, bool unknown,
bool isDOM)
{
RootedObject proto(cx, proto_);
TypeObject *object = gc::NewGCThing<TypeObject>(cx, gc::FINALIZE_TYPE_OBJECT, sizeof(TypeObject));
@ -1838,10 +1839,17 @@ TypeCompartment::newTypeObject(JSContext *cx, JSScript *script,
return NULL;
new(object) TypeObject(proto, key == JSProto_Function, unknown);
if (!cx->typeInferenceEnabled())
if (!cx->typeInferenceEnabled()) {
object->flags |= OBJECT_FLAG_UNKNOWN_MASK;
else
object->setFlagsFromKey(cx, key);
} else {
if (isDOM) {
object->setFlags(cx, OBJECT_FLAG_NON_DENSE_ARRAY
| OBJECT_FLAG_NON_TYPED_ARRAY
| OBJECT_FLAG_NON_PACKED_ARRAY);
} else {
object->setFlagsFromKey(cx, key);
}
}
return object;
}
@ -5261,7 +5269,7 @@ JSObject::setNewTypeUnknown(JSContext *cx)
}
TypeObject *
JSObject::getNewType(JSContext *cx, JSFunction *fun_)
JSObject::getNewType(JSContext *cx, JSFunction *fun_, bool isDOM)
{
TypeObjectSet &table = cx->compartment->newTypeObjects;
@ -5286,6 +5294,9 @@ JSObject::getNewType(JSContext *cx, JSFunction *fun_)
if (type->newScript && type->newScript->fun != fun_)
type->clearNewScript(cx);
if (!isDOM && !type->hasAnyFlags(OBJECT_FLAG_NON_DOM))
type->setFlags(cx, OBJECT_FLAG_NON_DOM);
return type;
}
@ -5298,7 +5309,8 @@ JSObject::getNewType(JSContext *cx, JSFunction *fun_)
bool markUnknown = self->lastProperty()->hasObjectFlag(BaseShape::NEW_TYPE_UNKNOWN);
RootedTypeObject type(cx);
type = cx->compartment->types.newTypeObject(cx, NULL, JSProto_Object, self, markUnknown);
type = cx->compartment->types.newTypeObject(cx, NULL, JSProto_Object, self,
markUnknown, isDOM);
if (!type)
return NULL;

View File

@ -277,20 +277,23 @@ enum {
/* Whether any objects this represents are not typed arrays. */
OBJECT_FLAG_NON_TYPED_ARRAY = 0x00040000,
/* Whether any objects this represents are not DOM objects. */
OBJECT_FLAG_NON_DOM = 0x00080000,
/* Whether any represented script is considered uninlineable. */
OBJECT_FLAG_UNINLINEABLE = 0x00080000,
OBJECT_FLAG_UNINLINEABLE = 0x00100000,
/* Whether any objects have an equality hook. */
OBJECT_FLAG_SPECIAL_EQUALITY = 0x00100000,
OBJECT_FLAG_SPECIAL_EQUALITY = 0x00200000,
/* Whether any objects have been iterated over. */
OBJECT_FLAG_ITERATED = 0x00200000,
OBJECT_FLAG_ITERATED = 0x00400000,
/* For a global object, whether flags were set on the RegExpStatics. */
OBJECT_FLAG_REGEXP_FLAGS_SET = 0x00400000,
OBJECT_FLAG_REGEXP_FLAGS_SET = 0x00800000,
/* Flags which indicate dynamic properties of represented objects. */
OBJECT_FLAG_DYNAMIC_MASK = 0x007f0000,
OBJECT_FLAG_DYNAMIC_MASK = 0x00ff0000,
/*
* Whether all properties of this object are considered unknown.
@ -1098,7 +1101,8 @@ struct TypeCompartment
* js_ObjectClass).
*/
TypeObject *newTypeObject(JSContext *cx, JSScript *script,
JSProtoKey kind, JSObject *proto, bool unknown = false);
JSProtoKey kind, JSObject *proto,
bool unknown = false, bool isDOM = false);
/* Make an object for an allocation site. */
TypeObject *newAllocationSiteTypeObject(JSContext *cx, AllocationSiteKey key);

View File

@ -1323,7 +1323,8 @@ TypeObject::setFlagsFromKey(JSContext *cx, JSProtoKey key)
switch (key) {
case JSProto_Array:
flags = OBJECT_FLAG_NON_TYPED_ARRAY;
flags = OBJECT_FLAG_NON_TYPED_ARRAY
| OBJECT_FLAG_NON_DOM;
break;
case JSProto_Int8Array:
@ -1337,13 +1338,15 @@ TypeObject::setFlagsFromKey(JSContext *cx, JSProtoKey key)
case JSProto_Uint8ClampedArray:
case JSProto_DataView:
flags = OBJECT_FLAG_NON_DENSE_ARRAY
| OBJECT_FLAG_NON_PACKED_ARRAY;
| OBJECT_FLAG_NON_PACKED_ARRAY
| OBJECT_FLAG_NON_DOM;
break;
default:
flags = OBJECT_FLAG_NON_DENSE_ARRAY
| OBJECT_FLAG_NON_PACKED_ARRAY
| OBJECT_FLAG_NON_TYPED_ARRAY;
| OBJECT_FLAG_NON_TYPED_ARRAY
| OBJECT_FLAG_NON_DOM;
break;
}

View File

@ -2400,7 +2400,9 @@ js::NewObjectWithGivenProto(JSContext *cx, js::Class *clasp, JSObject *proto_, J
}
}
types::TypeObject *type = proto ? proto->getNewType(cx) : cx->compartment->getEmptyType(cx);
bool isDOM = (clasp->flags & JSCLASS_IS_DOMJSCLASS);
types::TypeObject *type = proto ? proto->getNewType(cx, NULL, isDOM)
: cx->compartment->getEmptyType(cx);
if (!type)
return NULL;

View File

@ -442,7 +442,8 @@ struct JSObject : public js::ObjectImpl
inline void setType(js::types::TypeObject *newType);
js::types::TypeObject *getNewType(JSContext *cx, JSFunction *fun = NULL);
js::types::TypeObject *getNewType(JSContext *cx, JSFunction *fun = NULL,
bool isDOM = false);
#ifdef DEBUG
bool hasNewType(js::types::TypeObject *newType);

View File

@ -1768,6 +1768,10 @@ js::NewProxyObject(JSContext *cx, BaseProxyHandler *handler, const Value &priv_,
/* Don't track types of properties of proxies. */
MarkTypeObjectUnknownProperties(cx, obj->type());
/* Mark the new proxy as having singleton type. */
if (clasp == &OuterWindowProxyClass && !obj->setSingletonType(cx))
return NULL;
return obj;
}