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

--HG--
extra : rebase_source : d5ec9a80442e5b9c8df29f6d5971b61cb9b05778
This commit is contained in:
Peter Van der Beken 2012-12-11 21:45:36 -05:00
parent 1a28e0e54a
commit 1c3055ed84
13 changed files with 84 additions and 65 deletions

View File

@ -64,7 +64,7 @@ function testFrameParameters()
is(globalNodes[3].querySelector(".name").getAttribute("value"), "document",
"Should have the right property name for |document|.");
is(globalNodes[3].querySelector(".value").getAttribute("value"), "[object HTMLDocument]",
is(globalNodes[3].querySelector(".value").getAttribute("value"), "[object Proxy]",
"Should have the right property value for |document|.");
let buttonNode = gVars.getItemForNode(anonymousNodes[1]);
@ -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

@ -89,11 +89,11 @@ function testVariablesFiltering()
"There should be 0 variables displayed in the test scope");
is(loadScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 0,
"There should be 0 variables displayed in the load scope");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 2,
"There should be 2 variables displayed in the global scope");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 1,
"There should be 1 variables displayed in the global scope");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match])").length, 8,
"There should be 8 properties displayed in the inner scope");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match])").length, 7,
"There should be 7 properties displayed in the inner scope");
is(mathScope.querySelectorAll(".variables-view-property:not([non-match])").length, 0,
"There should be 0 properties displayed in the math scope");
is(testScope.querySelectorAll(".variables-view-property:not([non-match])").length, 0,
@ -106,25 +106,21 @@ function testVariablesFiltering()
is(innerScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
"this", "The only inner variable displayed should be 'this'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[0].getAttribute("value"),
"document", "The first inner property displayed should be 'document'");
"window", "The first inner property displayed should be 'window'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[1].getAttribute("value"),
"window", "The second inner property displayed should be 'window'");
"document", "The second inner property displayed should be 'document'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[2].getAttribute("value"),
"document", "The third inner property displayed should be 'document'");
"location", "The third inner property displayed should be 'location'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[3].getAttribute("value"),
"location", "The fourth inner property displayed should be 'location'");
"__proto__", "The fourth inner property displayed should be '__proto__'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[4].getAttribute("value"),
"__proto__", "The fifth inner property displayed should be '__proto__'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[5].getAttribute("value"),
"__proto__", "The sixth inner property displayed should be '__proto__'");
"HTMLDocument", "The sixth inner property displayed should be 'HTMLDocument'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[6].getAttribute("value"),
"HTMLDocument", "The seventh inner property displayed should be 'HTMLDocument'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[7].getAttribute("value"),
"HTMLDocument", "The eight inner property displayed should be 'HTMLDocument'");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
"document", "The first global variable displayed should be 'document'");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[1].getAttribute("value"),
"HTMLDocument", "The first global variable displayed should be 'HTMLDocument'");
}
@ -183,11 +179,11 @@ function testVariablesFiltering()
"There should be 0 variables displayed in the test scope");
is(loadScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 0,
"There should be 0 variables displayed in the load scope");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 2,
"There should be 2 variables displayed in the global scope");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match])").length, 1,
"There should be 1 variables displayed in the global scope");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match])").length, 8,
"There should be 8 properties displayed in the inner scope");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match])").length, 7,
"There should be 7 properties displayed in the inner scope");
is(mathScope.querySelectorAll(".variables-view-property:not([non-match])").length, 0,
"There should be 0 properties displayed in the math scope");
is(testScope.querySelectorAll(".variables-view-property:not([non-match])").length, 0,
@ -200,25 +196,21 @@ function testVariablesFiltering()
is(innerScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
"this", "The only inner variable displayed should be 'this'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[0].getAttribute("value"),
"document", "The first inner property displayed should be 'document'");
"window", "The first inner property displayed should be 'window'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[1].getAttribute("value"),
"window", "The second inner property displayed should be 'window'");
"document", "The second inner property displayed should be 'document'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[2].getAttribute("value"),
"document", "The third inner property displayed should be 'document'");
"location", "The third inner property displayed should be 'location'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[3].getAttribute("value"),
"location", "The fourth inner property displayed should be 'location'");
"__proto__", "The fourth inner property displayed should be '__proto__'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[4].getAttribute("value"),
"__proto__", "The fifth inner property displayed should be '__proto__'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[5].getAttribute("value"),
"__proto__", "The sixth inner property displayed should be '__proto__'");
"HTMLDocument", "The sixth inner property displayed should be 'HTMLDocument'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[6].getAttribute("value"),
"HTMLDocument", "The seventh inner property displayed should be 'HTMLDocument'");
is(innerScope.querySelectorAll(".variables-view-property:not([non-match]) > .title > .name")[7].getAttribute("value"),
"HTMLDocument", "The eight inner property displayed should be 'HTMLDocument'");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[0].getAttribute("value"),
"document", "The first global variable displayed should be 'document'");
is(globalScope.querySelectorAll(".variables-view-variable:not([non-match]) > .title > .name")[1].getAttribute("value"),
"HTMLDocument", "The first global variable displayed should be 'HTMLDocument'");
}

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;