Bug 968766 - Part d: Introduce HTMLAllCollection::Length; r=jst

This commit is contained in:
Ms2ger 2014-02-09 09:04:33 +01:00
parent 781b654612
commit b86cdb9379
2 changed files with 12 additions and 17 deletions

View File

@ -81,6 +81,12 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(HTMLAllCollection)
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mObject)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
uint32_t
HTMLAllCollection::Length()
{
return Collection()->Length(true);
}
JSObject*
HTMLAllCollection::GetObject(JSContext* aCx, ErrorResult& aRv)
{
@ -193,23 +199,8 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JS::Handle<JSObject*> ob
if (JSID_IS_STRING(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.
nsRefPtr<nsContentList> nodeList = doc->All()->Collection();
uint32_t length;
rv = nodeList->GetLength(&length);
if (NS_FAILED(rv)) {
xpc::Throw(cx, rv);
return false;
}
vp.set(INT_TO_JSVAL(length));
// Make sure <div id="length"> doesn't shadow document.all.length.
vp.setNumber(doc->All()->Length());
return true;
}

View File

@ -12,6 +12,8 @@
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include <stdint.h>
class nsContentList;
class nsHTMLDocument;
@ -29,6 +31,8 @@ public:
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(HTMLAllCollection)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(HTMLAllCollection)
uint32_t Length();
JSObject* GetObject(JSContext* aCx, ErrorResult& aRv);
nsContentList* Collection();