Bug 871189 - Remove Document classinfo r=bz

This commit is contained in:
David Zbarsky 2013-05-16 11:06:21 -07:00
parent 50fd518a07
commit c8f4001a0a
6 changed files with 10 additions and 309 deletions

View File

@ -233,9 +233,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument)
DOMCI_NODE_DATA(HTMLDocument, nsHTMLDocument)
// QueryInterface implementation for nsHTMLDocument
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
NS_DOCUMENT_INTERFACE_TABLE_BEGIN(nsHTMLDocument)
@ -243,7 +240,6 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
NS_INTERFACE_TABLE_ENTRY(nsHTMLDocument, nsIDOMHTMLDocument)
NS_OFFSET_AND_INTERFACE_TABLE_END
NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLDocument)
NS_INTERFACE_MAP_END_INHERITING(nsDocument)
JSObject*

View File

@ -167,8 +167,6 @@ public:
return nsDocument::GetElementById(aElementId);
}
virtual nsXPCClassInfo* GetClassInfo();
virtual void DocSizeOfExcludingThis(nsWindowSizes* aWindowSizes) const;
// DocSizeOfIncludingThis is inherited from nsIDocument.

View File

@ -372,11 +372,6 @@ static const char kDOMStringBundleURL[] =
((NODE_SCRIPTABLE_FLAGS & ~nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY) | \
nsIXPCScriptable::WANT_POSTCREATE)
#define DOCUMENT_SCRIPTABLE_FLAGS \
(NODE_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_POSTCREATE | \
nsIXPCScriptable::WANT_ENUMERATE)
#define ARRAY_SCRIPTABLE_FLAGS \
(DOM_DEFAULT_SCRIPTABLE_FLAGS | \
nsIXPCScriptable::WANT_GETPROPERTY | \
@ -591,10 +586,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(DeviceRotationRate, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
// Misc HTML classes
NS_DEFINE_CLASSINFO_DATA(HTMLDocument, nsHTMLDocumentSH,
DOCUMENT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_GETPROPERTY)
// HTML element classes
NS_DEFINE_CLASSINFO_DATA(HTMLFormElement, nsHTMLFormElementSH,
ELEMENT_SCRIPTABLE_FLAGS |
@ -1034,7 +1025,6 @@ jsid nsDOMClassInfo::sFrames_id = JSID_VOID;
jsid nsDOMClassInfo::sSelf_id = JSID_VOID;
jsid nsDOMClassInfo::sAll_id = JSID_VOID;
jsid nsDOMClassInfo::sTags_id = JSID_VOID;
jsid nsDOMClassInfo::sDocumentURIObject_id=JSID_VOID;
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
jsid nsDOMClassInfo::sURL_id = JSID_VOID;
jsid nsDOMClassInfo::sOnload_id = JSID_VOID;
@ -1295,7 +1285,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
SET_JSID_TO_STRING(sSelf_id, cx, "self");
SET_JSID_TO_STRING(sAll_id, cx, "all");
SET_JSID_TO_STRING(sTags_id, cx, "tags");
SET_JSID_TO_STRING(sDocumentURIObject_id,cx,"documentURIObject");
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
SET_JSID_TO_STRING(sURL_id, cx, "URL");
SET_JSID_TO_STRING(sOnload_id, cx, "onload");
@ -1771,13 +1760,6 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_EVENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(HTMLDocument, nsIDOMHTMLDocument)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLDocument)
DOM_CLASSINFO_MAP_CONDITIONAL_ENTRY(nsIDocumentRegister,
nsDocument::RegisterEnabled())
DOM_CLASSINFO_DOCUMENT_MAP_ENTRIES
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(HTMLFormElement, nsIDOMHTMLFormElement)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMHTMLFormElement)
DOM_CLASSINFO_GENERIC_HTML_MAP_ENTRIES
@ -3014,7 +2996,6 @@ nsDOMClassInfo::ShutDown()
sSelf_id = JSID_VOID;
sAll_id = JSID_VOID;
sTags_id = JSID_VOID;
sDocumentURIObject_id=JSID_VOID;
sWrappedJSObject_id = JSID_VOID;
sOnload_id = JSID_VOID;
sOnerror_id = JSID_VOID;
@ -6067,134 +6048,8 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
}
NS_IMETHODIMP
nsDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *aObj, jsid aId, uint32_t flags,
JSObject **objp, bool *_retval)
{
JS::Rooted<JSObject*> obj(cx, aObj);
JS::Rooted<jsid> id(cx, aId);
nsresult rv;
if (id == sLocation_id) {
// Define the location property on the document object itself so
// that we can intercept getting and setting of document.location.
nsCOMPtr<nsIDOMDocument> doc = do_QueryWrappedNative(wrapper, obj);
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIDOMLocation> location;
rv = doc->GetLocation(getter_AddRefs(location));
NS_ENSURE_SUCCESS(rv, rv);
JS::Rooted<JS::Value> v(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx), location,
&NS_GET_IID(nsIDOMLocation), true, v.address(),
getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
JSBool ok = ::JS_DefinePropertyById(cx, obj, id, v, JS_PropertyStub,
LocationSetter<nsIDOMDocument>,
JSPROP_PERMANENT | JSPROP_ENUMERATE);
if (!ok) {
return NS_ERROR_FAILURE;
}
*objp = obj;
return NS_OK;
}
return nsNodeSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
}
NS_IMETHODIMP
nsDocumentSH::GetFlags(uint32_t* aFlags)
{
*aFlags = DOMCLASSINFO_STANDARD_FLAGS;
return NS_OK;
}
NS_IMETHODIMP
nsDocumentSH::PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *aObj)
{
JS::Rooted<JSObject*> obj(cx, aObj);
// If this is the current document for the window that's the script global
// object of this document, then define this document object on the window.
// That will make sure that the document is referenced (via window.document)
// and prevent it from going away in GC.
nsCOMPtr<nsIDocument> doc = do_QueryWrappedNative(wrapper);
if (!doc) {
return NS_ERROR_UNEXPECTED;
}
nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(sgo);
if (!win) {
// No window, nothing else to do here
return NS_OK;
}
nsIDocument* currentDoc = win->GetExtantDoc();
if (SameCOMIdentity(doc, currentDoc)) {
JS::Rooted<JS::Value> winVal(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, obj, win, &NS_GET_IID(nsIDOMWindow), false,
winVal.address(), getter_AddRefs(holder));
NS_ENSURE_SUCCESS(rv, rv);
NS_NAMED_LITERAL_STRING(doc_str, "document");
if (!::JS_DefineUCProperty(cx, JSVAL_TO_OBJECT(winVal),
reinterpret_cast<const jschar *>
(doc_str.get()),
doc_str.Length(), OBJECT_TO_JSVAL(obj),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_READONLY | JSPROP_ENUMERATE)) {
return NS_ERROR_FAILURE;
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDocumentSH::PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj)
{
// Nothing to do here.
return NS_OK;
}
// HTMLDocument helper
static nsresult
ResolveImpl(JSContext *cx, nsIXPConnectWrappedNative *wrapper, jsid id,
nsISupports **result, nsWrapperCache **aCache)
{
nsHTMLDocument *doc =
static_cast<nsHTMLDocument*>(static_cast<nsINode*>(wrapper->Native()));
// 'id' is not always a string, it can be a number since document.1
// should map to <input name="1">. Thus we can't use
// JSVAL_TO_STRING() here.
JSString *str = IdToString(cx, id);
NS_ENSURE_TRUE(str, NS_ERROR_UNEXPECTED);
nsDependentJSString depStr;
NS_ENSURE_TRUE(depStr.init(cx, str), NS_ERROR_UNEXPECTED);
NS_IF_ADDREF(*result = doc->ResolveName(depStr, aCache));
return NS_OK;
}
static JSClass sHTMLDocumentAllClass = {
"HTML document.all class",
JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_NEW_RESOLVE |
@ -6266,7 +6121,7 @@ nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx,
NS_ADDREF(*nodeList = static_cast<nsContentList*>(htmlCollection));
}
else {
nsISupports *native = sXPConnect->GetNativeOfWrapper(cx, obj);
nsISupports *native = nsDOMClassInfo::XPConnect()->GetNativeOfWrapper(cx, obj);
if (native) {
NS_ADDREF(*nodeList = nsContentList::FromSupports(native));
rv = NS_OK;
@ -6317,7 +6172,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
// newResolve hook, so nothing to do for those properties here. And
// we need to return early to prevent <div id="item"> from shadowing
// document.all.item(), etc.
if (sItem_id == id || sNamedItem_id == id) {
if (nsDOMClassInfo::sItem_id == id || nsDOMClassInfo::sNamedItem_id == id) {
return JS_TRUE;
}
@ -6341,7 +6196,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
nsresult rv = NS_OK;
if (JSID_IS_STRING(id)) {
if (sLength_id == id) {
if (nsDOMClassInfo::sLength_id == id) {
// Map document.all.length to the length of the collection
// document.getElementsByTagName("*"), and make sure <div
// id="length"> doesn't shadow document.all.length.
@ -6363,7 +6218,7 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
vp.set(INT_TO_JSVAL(length));
return JS_TRUE;
} else if (sTags_id != id) {
} else if (nsDOMClassInfo::sTags_id != id) {
// For all other strings, look for an element by id or name.
nsDependentJSString str(id);
@ -6416,7 +6271,7 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSHandleObject obj, JSHan
{
JS::RootedValue v(cx);
if (sItem_id == id || sNamedItem_id == id) {
if (nsDOMClassInfo::sItem_id == id || nsDOMClassInfo::sNamedItem_id == id) {
// Define the item() or namedItem() method.
JSFunction *fnc = ::JS_DefineFunctionById(cx, obj, id, CallToGetPropMapper,
@ -6426,14 +6281,14 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSHandleObject obj, JSHan
return fnc != nullptr;
}
if (sLength_id == id) {
if (nsDOMClassInfo::sLength_id == id) {
// document.all.length. Any jsval other than undefined would do
// here, all we need is to get into the code below that defines
// this propery on obj, the rest happens in
// DocumentAllGetProperty().
v = JSVAL_ONE;
} else if (sTags_id == id) {
} else if (nsDOMClassInfo::sTags_id == id) {
nsHTMLDocument *doc = GetDocument(obj);
JSObject *tags = ::JS_NewObject(cx, &sHTMLDocumentAllTagsClass, nullptr,
@ -6720,87 +6575,13 @@ nsresult
nsHTMLDocumentSH::TryResolveAll(JSContext* cx, nsHTMLDocument* doc,
JS::Handle<JSObject*> obj)
{
if (sDisableDocumentAllSupport) {
if (nsDOMClassInfo::sDisableDocumentAllSupport) {
return NS_OK;
}
JSAutoCompartment ac(cx, obj);
return ResolveAll(cx, doc, obj);
}
NS_IMETHODIMP
nsHTMLDocumentSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *aObj, jsid aId, uint32_t flags,
JSObject **objp, bool *_retval)
{
JS::Rooted<JSObject*> obj(cx, aObj);
JS::Rooted<jsid> id(cx, aId);
// nsDocumentSH::NewResolve() does a security check that we'd kinda
// want to do here too before doing anything else. But given that we
// only define dynamic properties here before the call to
// nsDocumentSH::NewResolve() we're ok, since once those properties
// are accessed, we'll do the necessary security check.
if (!(flags & JSRESOLVE_ASSIGNING)) {
// For native wrappers, do not resolve random names on document
JSAutoRequest ar(cx);
if (!ObjectIsNativeWrapper(cx, obj) ||
xpc::WrapperFactory::XrayWrapperNotShadowing(obj, id)) {
nsCOMPtr<nsISupports> result;
nsWrapperCache *cache;
nsresult rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result),
&cache);
NS_ENSURE_SUCCESS(rv, rv);
if (result) {
JSBool ok = *_retval =
::JS_DefinePropertyById(cx, obj, id, JSVAL_VOID, nullptr, nullptr, 0);
*objp = obj;
return ok ? NS_OK : NS_ERROR_FAILURE;
}
}
if (id == sAll_id && !sDisableDocumentAllSupport &&
!ObjectIsNativeWrapper(cx, obj)) {
nsIDocument *doc = static_cast<nsIDocument*>(wrapper->Native());
if (doc->GetCompatibilityMode() != eCompatibility_NavQuirks) {
return NS_OK;
}
return ResolveAll(cx, doc, obj);
}
}
return nsDocumentSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
}
NS_IMETHODIMP
nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
JSContext *cx, JSObject *aObj, jsid aId,
jsval *vp, bool *_retval)
{
JS::Rooted<JSObject*> obj(cx, aObj);
JS::Rooted<jsid> id(cx, aId);
nsCOMPtr<nsISupports> result;
JSAutoRequest ar(cx);
nsWrapperCache *cache;
nsresult rv = ResolveImpl(cx, wrapper, id, getter_AddRefs(result), &cache);
NS_ENSURE_SUCCESS(rv, rv);
if (result) {
rv = WrapNative(cx, obj, result, cache, true, vp);
if (NS_SUCCEEDED(rv)) {
rv = NS_SUCCESS_I_DID_SOMETHING;
}
return rv;
}
return NS_OK;
}
// HTMLFormElement helper
NS_IMETHODIMP

View File

@ -25,7 +25,6 @@ class nsContentList;
class nsGlobalWindow;
class nsIDOMWindow;
class nsIForm;
class nsIHTMLDocument;
class nsNPAPIPluginInstance;
class nsObjectLoadingContent;
class nsIObjectLoadingContent;
@ -81,6 +80,7 @@ struct nsExternalDOMClassInfoData : public nsDOMClassInfoData
class nsDOMClassInfo : public nsXPCClassInfo
{
friend class nsHTMLDocumentSH;
public:
nsDOMClassInfo(nsDOMClassInfoData* aData);
virtual ~nsDOMClassInfo();
@ -219,7 +219,6 @@ public:
static jsid sSelf_id;
static jsid sAll_id;
static jsid sTags_id;
static jsid sDocumentURIObject_id;
static jsid sJava_id;
static jsid sPackages_id;
static jsid sWrappedJSObject_id;
@ -593,53 +592,14 @@ private:
};
// Document helper, for document.location and document.on*
class nsDocumentSH : public nsNodeSH
{
public:
nsDocumentSH(nsDOMClassInfoData* aData) : nsNodeSH(aData)
{
}
virtual ~nsDocumentSH()
{
}
public:
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval);
NS_IMETHOD GetFlags(uint32_t* aFlags);
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
NS_IMETHOD PostTransplant(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsDocumentSH(aData);
}
};
// HTMLDocument helper
class nsHTMLDocumentSH : public nsDocumentSH
class nsHTMLDocumentSH
{
protected:
nsHTMLDocumentSH(nsDOMClassInfoData* aData) : nsDocumentSH(aData)
{
}
virtual ~nsHTMLDocumentSH()
{
}
static JSBool GetDocumentAllNodeList(JSContext *cx, JS::Handle<JSObject*> obj,
nsDocument *doc,
nsContentList **nodeList);
public:
static JSBool DocumentAllGetProperty(JSContext *cx, JSHandleObject obj, JSHandleId id,
JSMutableHandleValue vp);
@ -656,19 +616,8 @@ public:
JSHandleId id, unsigned flags,
JS::MutableHandle<JSObject*> objp);
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, uint32_t flags,
JSObject **objp, bool *_retval);
NS_IMETHOD GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsid id, jsval *vp, bool *_retval);
static nsresult TryResolveAll(JSContext* cx, nsHTMLDocument* doc,
JS::Handle<JSObject*> obj);
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsHTMLDocumentSH(aData);
}
};

View File

@ -38,9 +38,6 @@ DOMCI_CLASS(DeviceMotionEvent)
DOMCI_CLASS(DeviceAcceleration)
DOMCI_CLASS(DeviceRotationRate)
// HTML classes
DOMCI_CLASS(HTMLDocument)
// HTML element classes
DOMCI_CLASS(HTMLFormElement)

View File

@ -879,24 +879,6 @@ WrapURI(JSContext *cx, nsIURI *uri, MutableHandleValue vp)
return true;
}
static JSBool
documentURIObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
{
nsCOMPtr<nsIDocument> native = do_QueryInterfaceNative(cx, wrapper);
if (!native) {
JS_ReportError(cx, "Unexpected object");
return false;
}
nsCOMPtr<nsIURI> uri = native->GetDocumentURI();
if (!uri) {
JS_ReportOutOfMemory(cx);
return false;
}
return WrapURI(cx, uri, vp);
}
static JSBool
baseURIObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp)
{
@ -1012,8 +994,6 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper
desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED;
if (id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT))
desc->getter = baseURIObject_getter;
else if (id == rt->GetStringID(XPCJSRuntime::IDX_DOCUMENTURIOBJECT))
desc->getter = documentURIObject_getter;
else
desc->getter = nodePrincipal_getter;
desc->setter = NULL;