From 01dccf283c08149f1dd0a3a90981f72870e89258 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 11 Dec 2012 21:45:36 -0500 Subject: [PATCH] Bug 855971 - Switch HTMLDocument to WebIDL bindings. r=bz. --- .../test/browser_dbg_propertyview-11.js | 24 +++++++------- ...owser_webconsole_bug_659907_console_dir.js | 2 +- content/base/test/test_bug588990.html | 8 ++--- content/html/document/src/ImageDocument.cpp | 3 +- content/html/document/src/MediaDocument.cpp | 5 +-- content/html/document/src/MediaDocument.h | 2 +- content/html/document/src/nsHTMLDocument.cpp | 32 +++++++++++++++---- content/html/document/src/nsHTMLDocument.h | 4 ++- dom/bindings/Bindings.conf | 1 - dom/bindings/DOMJSProxyHandler.cpp | 18 ++++++----- js/xpconnect/src/nsDOMQS.h | 2 ++ .../tests/mochitest/test_bug462428.html | 2 +- 12 files changed, 65 insertions(+), 38 deletions(-) diff --git a/browser/devtools/debugger/test/browser_dbg_propertyview-11.js b/browser/devtools/debugger/test/browser_dbg_propertyview-11.js index 5c6ff682965..8811f041662 100644 --- a/browser/devtools/debugger/test/browser_dbg_propertyview-11.js +++ b/browser/devtools/debugger/test/browser_dbg_propertyview-11.js @@ -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__"); diff --git a/browser/devtools/webconsole/test/browser_webconsole_bug_659907_console_dir.js b/browser/devtools/webconsole/test/browser_webconsole_bug_659907_console_dir.js index e61b98513e1..50fc7ce77a0 100644 --- a/browser/devtools/webconsole/test/browser_webconsole_bug_659907_console_dir.js +++ b/browser/devtools/webconsole/test/browser_webconsole_bug_659907_console_dir.js @@ -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); diff --git a/content/base/test/test_bug588990.html b/content/base/test/test_bug588990.html index 3cb5dcef37f..087741a4de5 100644 --- a/content/base/test/test_bug588990.html +++ b/content/base/test/test_bug588990.html @@ -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(); diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp index 4e852c8108a..a64b464f552 100644 --- a/content/html/document/src/ImageDocument.cpp +++ b/content/html/document/src/ImageDocument.cpp @@ -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. diff --git a/content/html/document/src/MediaDocument.cpp b/content/html/document/src/MediaDocument.cpp index b232a5cf1e4..4bb7a309abc 100644 --- a/content/html/document/src/MediaDocument.cpp +++ b/content/html/document/src/MediaDocument.cpp @@ -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() diff --git a/content/html/document/src/MediaDocument.h b/content/html/document/src/MediaDocument.h index c319adc6f83..acd350d694a 100644 --- a/content/html/document/src/MediaDocument.h +++ b/content/html/document/src/MediaDocument.h @@ -19,7 +19,7 @@ namespace dom { class MediaDocument : public nsHTMLDocument { public: - MediaDocument(); + MediaDocument(bool aUseXPConnectToWrap = false); virtual ~MediaDocument(); virtual nsresult Init(); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 3231c63b979..ac9670b15bc 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -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 aScope) +{ +#ifdef DEBUG + // Don't do it yet for image documents + nsCOMPtr imgDoc = do_QueryObject(this); + MOZ_ASSERT(!imgDoc, "Who called SetIsDOMBinding()?"); +#endif + + JS::Rooted 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 newScope(do_QueryReferent(mScopeObject)); - if (oldScope && newScope != oldScope) { - nsIXPConnect *xpc = nsContentUtils::XPConnect(); - rv = xpc->ReparentWrappedNativeIfFound(cx, oldScope->GetGlobalJSObject(), - newScope->GetGlobalJSObject(), - static_cast(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; diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index e8828fe76cc..fdc8034fe1f 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -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 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); diff --git a/dom/bindings/Bindings.conf b/dom/bindings/Bindings.conf index 5c8df590bb9..e312c36448f 100644 --- a/dom/bindings/Bindings.conf +++ b/dom/bindings/Bindings.conf @@ -415,7 +415,6 @@ DOMInterfaces = { 'HTMLDocument': { 'nativeType': 'nsHTMLDocument', - 'register': False, 'hasXPConnectImpls': True, 'resultNotAddRefed': [ 'body', 'head', 'images', 'embeds', 'plugins', 'links', 'forms', 'scripts', 'anchors', 'applets' ], diff --git a/dom/bindings/DOMJSProxyHandler.cpp b/dom/bindings/DOMJSProxyHandler.cpp index 46ccef4301d..b687091d977 100644 --- a/dom/bindings/DOMJSProxyHandler.cpp +++ b/dom/bindings/DOMJSProxyHandler.cpp @@ -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(v.toPrivate()); + v = expandoAndGeneration->expando; + if (v.isUndefined()) { + return nullptr; + } + expandoAndGeneration->expando = UndefinedValue(); } - js::ExpandoAndGeneration* expandoAndGeneration = - static_cast(v.toPrivate()); - v = expandoAndGeneration->expando; - if (v.isUndefined()) { - return nullptr; - } - expandoAndGeneration->expando = UndefinedValue(); + xpc::GetObjectScope(obj)->RemoveDOMExpandoObject(obj); + return &v.toObject(); } diff --git a/js/xpconnect/src/nsDOMQS.h b/js/xpconnect/src/nsDOMQS.h index 0bff94b8b47..91b817c742f 100644 --- a/js/xpconnect/src/nsDOMQS.h +++ b/js/xpconnect/src/nsDOMQS.h @@ -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 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); diff --git a/js/xpconnect/tests/mochitest/test_bug462428.html b/js/xpconnect/tests/mochitest/test_bug462428.html index 0f6950e400b..8655bc359db 100644 --- a/js/xpconnect/tests/mochitest/test_bug462428.html +++ b/js/xpconnect/tests/mochitest/test_bug462428.html @@ -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;