Bug 855971 - Switch HTMLDocument to WebIDL bindings. r=bz.

This commit is contained in:
Peter Van der Beken 2012-12-11 21:45:36 -05:00
parent 93361c60c0
commit 01dccf283c
12 changed files with 65 additions and 38 deletions

View File

@ -190,18 +190,18 @@ function testFrameParameters()
.getAttribute("value"), '""',
"'formMethod' in buttonProtoNode should have the right value.");
is(documentProtoNode.get("baseURI").target.querySelector(".name")
.getAttribute("value"), "baseURI",
"Should have the right property name for 'baseURI' in documentProtoNode.");
is(documentProtoNode.get("baseURI").target.querySelector(".value")
.getAttribute("value"), '"' + TAB_URL + '"',
"'baseURI' in documentProtoNode should have the right value.");
is(documentProtoNode.get("URL").target.querySelector(".name")
.getAttribute("value"), "URL",
"Should have the right property name for 'URL' in documentProtoNode.");
is(documentProtoNode.get("URL").target.querySelector(".value")
.getAttribute("value"), '"' + TAB_URL + '"',
"'URL' in documentProtoNode should have the right value.");
is(documentProtoNode.get("domain").target.querySelector(".name")
.getAttribute("value"), "domain",
"Should have the right property name for 'domain' in documentProtoNode.");
is(documentProtoNode.get("domain").target.querySelector(".value")
.getAttribute("value"), '"example.com"',
"'domain' in documentProtoNode should have the right value.");
is(documentProtoNode.get("cookie").target.querySelector(".name")
.getAttribute("value"), "cookie",
"Should have the right property name for 'cookie' in documentProtoNode.");
is(documentProtoNode.get("cookie").target.querySelector(".value")
.getAttribute("value"), '""',
"'cookie' in documentProtoNode should have the right value.");
let buttonAsProtoProtoProtoNode = buttonAsProtoProtoNode.get("__proto__");

View File

@ -22,7 +22,7 @@ function consoleOpened(hud) {
function testConsoleDir(hud, ev, view) {
findVariableViewProperties(view, [
{ name: "__proto__.querySelectorAll", value: "[object Function]" },
{ name: "__proto__.__proto__.querySelectorAll", value: "[object Function]" },
{ name: "location", value: "[object Location]" },
{ name: "__proto__.write", value: "[object Function]" },
], { webconsole: hud }).then(finishTest);

View File

@ -69,9 +69,9 @@ function checkHasNoName(removed, test) {
is(i3_2.getAttribute("name"), attrValue, "i3_2 getAttribute " + test);
is(i3_3.getAttribute("name"), attrValue, "i3_3 getAttribute " + test);
todo_is(document.n1, undefined, "doc.n1 " + test);
todo_is(document.n2, undefined, "doc.n2 " + test);
todo_is(document.n3, undefined, "doc.n3 " + test);
is(document.n1, undefined, "doc.n1 " + test);
is(document.n2, undefined, "doc.n2 " + test);
is(document.n3, undefined, "doc.n3 " + test);
}
// Check that dynamic modifications of attribute work
@ -326,7 +326,7 @@ i3_1.addEventListener("DOMAttrModified", function(e) {
}, false);
i3_1.name = "n3";
ok(mutateFired, "mutation event fired");
todo_is(document.n3, undefined, "named was readded during mutation");
is(document.n3, undefined, "named was readded during mutation");
removeNode(i3_1);
SpecialPowers.gc();

View File

@ -217,7 +217,8 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
}
ImageDocument::ImageDocument()
: mOriginalZoomLevel(1.0)
: MediaDocument(true),
mOriginalZoomLevel(1.0)
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.

View File

@ -97,8 +97,9 @@ const char* const MediaDocument::sFormatNames[4] =
"" // eWithDimAndFile
};
MediaDocument::MediaDocument()
: mDocumentElementInserted(false)
MediaDocument::MediaDocument(bool aUseXPConnectToWrap)
: nsHTMLDocument(aUseXPConnectToWrap),
mDocumentElementInserted(false)
{
}
MediaDocument::~MediaDocument()

View File

@ -19,7 +19,7 @@ namespace dom {
class MediaDocument : public nsHTMLDocument
{
public:
MediaDocument();
MediaDocument(bool aUseXPConnectToWrap = false);
virtual ~MediaDocument();
virtual nsresult Init();

View File

@ -102,7 +102,9 @@
#include "nsHtml5Parser.h"
#include "nsIDOMJSWindow.h"
#include "nsSandboxFlags.h"
#include "nsIImageDocument.h"
#include "mozilla/dom/HTMLBodyElement.h"
#include "mozilla/dom/HTMLDocumentBinding.h"
#include "nsCharsetSource.h"
#include "nsIStringBundle.h"
#include "nsDOMClassInfo.h"
@ -195,7 +197,7 @@ NS_NewHTMLDocument(nsIDocument** aInstancePtrResult, bool aLoadedAsData)
// NOTE! nsDocument::operator new() zeroes out all members, so don't
// bother initializing members to 0.
nsHTMLDocument::nsHTMLDocument()
nsHTMLDocument::nsHTMLDocument(bool aUseXPConnectToWrap)
: nsDocument("text/html")
{
// NOTE! nsDocument::operator new() zeroes out all members, so don't
@ -204,6 +206,10 @@ nsHTMLDocument::nsHTMLDocument()
mIsRegularHTML = true;
mDefaultElementType = kNameSpaceID_XHTML;
mCompatMode = eCompatibility_NavQuirks;
if (!aUseXPConnectToWrap) {
SetIsDOMBinding();
}
}
@ -251,6 +257,21 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLDocument)
NS_INTERFACE_MAP_END_INHERITING(nsDocument)
JSObject*
nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
#ifdef DEBUG
// Don't do it yet for image documents
nsCOMPtr<nsIImageDocument> imgDoc = do_QueryObject(this);
MOZ_ASSERT(!imgDoc, "Who called SetIsDOMBinding()?");
#endif
JS::Rooted<JSObject*> obj(aCx, HTMLDocumentBinding::Wrap(aCx, aScope, this));
if (obj && !PostCreateWrapper(aCx, obj)) {
return nullptr;
}
return obj;
}
nsresult
nsHTMLDocument::Init()
@ -1660,14 +1681,13 @@ nsHTMLDocument::Open(JSContext* cx,
SetIsInitialDocument(false);
nsCOMPtr<nsIScriptGlobalObject> newScope(do_QueryReferent(mScopeObject));
if (oldScope && newScope != oldScope) {
nsIXPConnect *xpc = nsContentUtils::XPConnect();
rv = xpc->ReparentWrappedNativeIfFound(cx, oldScope->GetGlobalJSObject(),
newScope->GetGlobalJSObject(),
static_cast<nsINode*>(this));
JS::RootedObject wrapper(cx, GetWrapper());
if (oldScope && newScope != oldScope && wrapper) {
rv = mozilla::dom::ReparentWrapper(cx, wrapper);
if (rv.Failed()) {
return nullptr;
}
nsIXPConnect *xpc = nsContentUtils::XPConnect();
rv = xpc->RescueOrphansInScope(cx, oldScope->GetGlobalJSObject());
if (rv.Failed()) {
return nullptr;

View File

@ -42,7 +42,7 @@ public:
using nsDocument::SetDocumentURI;
using nsDocument::GetPlugins;
nsHTMLDocument();
nsHTMLDocument(bool aUseXPConnectToWrap = false);
virtual nsresult Init();
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
@ -180,6 +180,8 @@ public:
virtual bool WillIgnoreCharsetOverride();
// WebIDL API
virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aScope)
MOZ_OVERRIDE;
void GetDomain(nsAString& aDomain, mozilla::ErrorResult& rv);
void SetDomain(const nsAString& aDomain, mozilla::ErrorResult& rv);
void GetCookie(nsAString& aCookie, mozilla::ErrorResult& rv);

View File

@ -415,7 +415,6 @@ DOMInterfaces = {
'HTMLDocument': {
'nativeType': 'nsHTMLDocument',
'register': False,
'hasXPConnectImpls': True,
'resultNotAddRefed': [ 'body', 'head', 'images', 'embeds', 'plugins',
'links', 'forms', 'scripts', 'anchors', 'applets' ],

View File

@ -83,16 +83,18 @@ DOMProxyHandler::GetAndClearExpandoObject(JSObject* obj)
if (v.isObject()) {
js::SetProxyExtra(obj, JSPROXYSLOT_EXPANDO, UndefinedValue());
return &v.toObject();
} else {
js::ExpandoAndGeneration* expandoAndGeneration =
static_cast<js::ExpandoAndGeneration*>(v.toPrivate());
v = expandoAndGeneration->expando;
if (v.isUndefined()) {
return nullptr;
}
expandoAndGeneration->expando = UndefinedValue();
}
js::ExpandoAndGeneration* expandoAndGeneration =
static_cast<js::ExpandoAndGeneration*>(v.toPrivate());
v = expandoAndGeneration->expando;
if (v.isUndefined()) {
return nullptr;
}
expandoAndGeneration->expando = UndefinedValue();
xpc::GetObjectScope(obj)->RemoveDOMExpandoObject(obj);
return &v.toObject();
}

View File

@ -25,6 +25,7 @@
#include "mozilla/dom/HTMLElementBinding.h"
#include "mozilla/dom/DocumentBinding.h"
#include "mozilla/dom/SVGElementBinding.h"
#include "mozilla/dom/HTMLDocumentBinding.h"
template<class T>
struct ProtoIDAndDepth
@ -52,6 +53,7 @@ NEW_BINDING(mozilla::dom::Element, Element);
NEW_BINDING(nsGenericHTMLElement, HTMLElement);
NEW_BINDING(nsIDocument, Document);
NEW_BINDING(nsDocument, Document);
NEW_BINDING(nsHTMLDocument, HTMLDocument);
NEW_BINDING(nsSVGElement, SVGElement);
NEW_BINDING(nsDOMEvent, Event);
NEW_BINDING(nsDOMMouseEvent, MouseEvent);

View File

@ -33,7 +33,7 @@ ok(sawProp, "property should be enumerable");
is(getter.call(document), document.documentElement, "the getter actually works");
Object.getPrototypeOf(document).__defineSetter__('documentElement', function() {});
Document.prototype.__defineSetter__('documentElement', function() {});
is(getter.call(document), document.documentElement, "the getter works after defineSetter");
var oldTitle = document.title;