summaryrefslogtreecommitdiff
path: root/dom/base
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 07:07:09 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 07:07:09 -0400
commit5524318fe73a1123da10491a6a545b50af88ea60 (patch)
tree9712c640ba812c85594926f5f407f30a42d235a6 /dom/base
parent3a74795a56e92313c1b33a54500917794ba09b72 (diff)
downloaduxp-5524318fe73a1123da10491a6a545b50af88ea60.tar.gz
Bug 1416999 - Remove document.registerElement
Tag #1375
Diffstat (limited to 'dom/base')
-rw-r--r--dom/base/CustomElementRegistry.cpp19
-rw-r--r--dom/base/CustomElementRegistry.h10
-rw-r--r--dom/base/Element.cpp41
-rw-r--r--dom/base/nsContentUtils.cpp29
-rw-r--r--dom/base/nsContentUtils.h7
-rw-r--r--dom/base/nsDocument.cpp247
-rw-r--r--dom/base/nsDocument.h11
-rw-r--r--dom/base/nsIDocument.h9
-rw-r--r--dom/base/test/chrome/chrome.ini8
-rw-r--r--dom/base/test/chrome/registerElement_ep.js8
-rw-r--r--dom/base/test/chrome/test_registerElement_content.xul52
-rw-r--r--dom/base/test/chrome/test_registerElement_ep.xul44
-rw-r--r--dom/base/test/mochitest.ini2
-rw-r--r--dom/base/test/test_document_register.html6
14 files changed, 17 insertions, 476 deletions
diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp
index e4d4c0670f..67bd8e185d 100644
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -415,19 +415,6 @@ CustomElementRegistry::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType
}
void
-CustomElementRegistry::GetCustomPrototype(nsIAtom* aAtom,
- JS::MutableHandle<JSObject*> aPrototype)
-{
- mozilla::dom::CustomElementDefinition* definition =
- mCustomDefinitions.GetWeak(aAtom);
- if (definition) {
- aPrototype.set(definition->mPrototype);
- } else {
- aPrototype.set(nullptr);
- }
-}
-
-void
CustomElementRegistry::UpgradeCandidates(nsIAtom* aKey,
CustomElementDefinition* aDefinition,
ErrorResult& aRv)
@@ -624,9 +611,9 @@ CustomElementRegistry::Define(const nsAString& aName,
*/
JSAutoCompartment ac(cx, constructor);
JS::Rooted<JS::Value> prototypev(cx);
- // The .prototype on the constructor passed from document.registerElement
- // is the "expando" of a wrapper. So we should get it from wrapper instead
- // instead of underlying object.
+ // The .prototype on the constructor passed could be an "expando" of a
+ // wrapper. So we should get it from wrapper instead of the underlying
+ // object.
if (!JS_GetProperty(cx, constructor, "prototype", &prototypev)) {
aRv.StealExceptionFromJSContext(cx);
return;
diff --git a/dom/base/CustomElementRegistry.h b/dom/base/CustomElementRegistry.h
index c416e50439..a736e3019d 100644
--- a/dom/base/CustomElementRegistry.h
+++ b/dom/base/CustomElementRegistry.h
@@ -423,9 +423,6 @@ public:
LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs,
CustomElementDefinition* aDefinition);
- void GetCustomPrototype(nsIAtom* aAtom,
- JS::MutableHandle<JSObject*> aPrototype);
-
/**
* Upgrade an element.
* https://html.spec.whatwg.org/multipage/scripting.html#upgrades
@@ -434,8 +431,7 @@ public:
/**
* Registers an unresolved custom element that is a candidate for
- * upgrade when the definition is registered via registerElement.
- * |aTypeName| is the name of the custom element type, if it is not
+ * upgrade. |aTypeName| is the name of the custom element type, if it is not
* provided, then element name is used. |aTypeName| should be provided
* when registering a custom element that extends an existing
* element. e.g. <button is="x-button">.
@@ -472,8 +468,8 @@ private:
js::SystemAllocPolicy> ConstructorMap;
// Hashtable for custom element definitions in web components.
- // Custom prototypes are stored in the compartment where
- // registerElement was called.
+ // Custom prototypes are stored in the compartment where definition was
+ // defined.
DefinitionMap mCustomDefinitions;
// Hashtable for looking up definitions by using constructor as key.
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index cd803a60f9..f3c8a1129e 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -469,50 +469,11 @@ Element::GetBindingURL(nsIDocument *aDocument, css::URLValue **aResult)
JSObject*
Element::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
{
- JS::Rooted<JSObject*> givenProto(aCx, aGivenProto);
- JS::Rooted<JSObject*> customProto(aCx);
-
- if (!givenProto) {
- // Custom element prototype swizzling.
- CustomElementData* data = GetCustomElementData();
- if (data) {
- // If this is a registered custom element then fix the prototype.
- nsContentUtils::GetCustomPrototype(OwnerDoc(), NodeInfo()->NamespaceID(),
- data->GetCustomElementType(), &customProto);
- if (customProto &&
- NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(customProto))) {
- // The custom element prototype could be in different compartment.
- if (!JS_WrapObject(aCx, &customProto)) {
- return nullptr;
- }
- // Just go ahead and create with the right proto up front. Set
- // customProto to null to flag that we don't need to do any post-facto
- // proto fixups here.
- givenProto = customProto;
- customProto = nullptr;
- }
- }
- }
-
- JS::Rooted<JSObject*> obj(aCx, nsINode::WrapObject(aCx, givenProto));
+ JS::Rooted<JSObject*> obj(aCx, nsINode::WrapObject(aCx, aGivenProto));
if (!obj) {
return nullptr;
}
- if (customProto) {
- // We want to set the custom prototype in the compartment where it was
- // registered. In the case that |obj| and |prototype| are in different
- // compartments, this will set the prototype on the |obj|'s wrapper and
- // thus only visible in the wrapper's compartment, since we know obj's
- // principal does not subsume customProto's in this case.
- JSAutoCompartment ac(aCx, customProto);
- JS::Rooted<JSObject*> wrappedObj(aCx, obj);
- if (!JS_WrapObject(aCx, &wrappedObj) ||
- !JS_SetPrototype(aCx, wrappedObj, customProto)) {
- return nullptr;
- }
- }
-
nsIDocument* doc;
if (HasFlag(NODE_FORCE_XBL_BINDINGS)) {
doc = OwnerDoc();
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 96f9065803..3d23bedea5 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9673,35 +9673,6 @@ nsContentUtils::EnqueueLifecycleCallback(nsIDocument::ElementCallbackType aType,
aDefinition);
}
-/* static */ void
-nsContentUtils::GetCustomPrototype(nsIDocument* aDoc,
- int32_t aNamespaceID,
- nsIAtom* aAtom,
- JS::MutableHandle<JSObject*> aPrototype)
-{
- MOZ_ASSERT(aDoc);
-
- // To support imported document.
- nsCOMPtr<nsIDocument> doc = aDoc->MasterDocument();
-
- if (aNamespaceID != kNameSpaceID_XHTML ||
- !doc->GetDocShell()) {
- return;
- }
-
- nsCOMPtr<nsPIDOMWindowInner> window(doc->GetInnerWindow());
- if (!window) {
- return;
- }
-
- RefPtr<CustomElementRegistry> registry(window->CustomElements());
- if (!registry) {
- return;
- }
-
- return registry->GetCustomPrototype(aAtom, aPrototype);
-}
-
/* static */ bool
nsContentUtils::AttemptLargeAllocationLoad(nsIHttpChannel* aChannel)
{
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index c34f7e1026..fe076f0dc6 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -589,7 +589,7 @@ public:
/**
* Returns true if |aName| is a valid name to be registered via
- * document.registerElement.
+ * customElements.define.
*/
static bool IsCustomElementName(nsIAtom* aName);
@@ -2742,11 +2742,6 @@ public:
mozilla::dom::LifecycleAdoptedCallbackArgs* aAdoptedCallbackArgs = nullptr,
mozilla::dom::CustomElementDefinition* aDefinition = nullptr);
- static void GetCustomPrototype(nsIDocument* aDoc,
- int32_t aNamespaceID,
- nsIAtom* aAtom,
- JS::MutableHandle<JSObject*> prototype);
-
static bool AttemptLargeAllocationLoad(nsIHttpChannel* aChannel);
/**
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp
index 87d860c6ae..d69fff8637 100644
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -5352,31 +5352,6 @@ bool IsLowercaseASCII(const nsAString& aValue)
return true;
}
-already_AddRefed<mozilla::dom::CustomElementRegistry>
-nsDocument::GetCustomElementRegistry()
-{
- nsAutoString contentType;
- GetContentType(contentType);
- if (!IsHTMLDocument() &&
- !contentType.EqualsLiteral("application/xhtml+xml")) {
- return nullptr;
- }
-
- nsCOMPtr<nsPIDOMWindowInner> window(
- do_QueryInterface(mScriptGlobalObject ? mScriptGlobalObject
- : GetScopeObject()));
- if (!window) {
- return nullptr;
- }
-
- RefPtr<CustomElementRegistry> registry = window->CustomElements();
- if (!registry) {
- return nullptr;
- }
-
- return registry.forget();
-}
-
// We only support pseudo-elements with two colons in this function.
static CSSPseudoElementType
GetPseudoElementType(const nsString& aString, ErrorResult& aRv)
@@ -5693,103 +5668,6 @@ nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
}
bool
-nsDocument::CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp)
-{
- JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp);
-
- JS::Rooted<JSObject*> global(aCx,
- JS_GetGlobalForObject(aCx, &args.callee()));
- RefPtr<nsGlobalWindow> window;
- UNWRAP_OBJECT(Window, global, window);
- MOZ_ASSERT(window, "Should have a non-null window");
-
- nsDocument* document = static_cast<nsDocument*>(window->GetDoc());
-
- // Function name is the type of the custom element.
- JSString* jsFunName =
- JS_GetFunctionId(JS_ValueToFunction(aCx, args.calleev()));
- nsAutoJSString elemName;
- if (!elemName.init(aCx, jsFunName)) {
- return true;
- }
-
- RefPtr<mozilla::dom::CustomElementRegistry> registry = window->CustomElements();
- if (!registry) {
- return true;
- }
-
- nsCOMPtr<nsIAtom> typeAtom(NS_Atomize(elemName));
- CustomElementDefinition* definition =
- registry->mCustomDefinitions.GetWeak(typeAtom);
- if (!definition) {
- return true;
- }
-
- RefPtr<Element> element;
-
- // We integrate with construction stack and do prototype swizzling here, so
- // that old upgrade behavior could also share the new upgrade steps.
- // And this old upgrade will be remove at some point (when everything is
- // switched to latest custom element spec).
- nsTArray<RefPtr<nsGenericHTMLElement>>& constructionStack =
- definition->mConstructionStack;
- if (constructionStack.Length()) {
- element = constructionStack.LastElement();
- NS_ENSURE_TRUE(element != ALEADY_CONSTRUCTED_MARKER, false);
-
- // Do prototype swizzling if dom reflector exists.
- JS::Rooted<JSObject*> reflector(aCx, element->GetWrapper());
- if (reflector) {
- Maybe<JSAutoCompartment> ac;
- JS::Rooted<JSObject*> prototype(aCx, definition->mPrototype);
- if (element->NodePrincipal()->SubsumesConsideringDomain(nsContentUtils::ObjectPrincipal(prototype))) {
- ac.emplace(aCx, reflector);
- if (!JS_WrapObject(aCx, &prototype) ||
- !JS_SetPrototype(aCx, reflector, prototype)) {
- return false;
- }
- } else {
- // We want to set the custom prototype in the compartment where it was
- // registered. We store the prototype from define() without unwrapped,
- // hence the prototype's compartment is the compartment where it was
- // registered.
- // In the case that |reflector| and |prototype| are in different
- // compartments, this will set the prototype on the |reflector|'s wrapper
- // and thus only visible in the wrapper's compartment, since we know
- // reflector's principal does not subsume prototype's in this case.
- ac.emplace(aCx, prototype);
- if (!JS_WrapObject(aCx, &reflector) ||
- !JS_SetPrototype(aCx, reflector, prototype)) {
- return false;
- }
- }
-
- // Wrap into current context.
- if (!JS_WrapObject(aCx, &reflector)) {
- return false;
- }
-
- args.rval().setObject(*reflector);
- return true;
- }
- } else {
- nsDependentAtomString localName(definition->mLocalName);
- element =
- document->CreateElem(localName, nullptr, kNameSpaceID_XHTML,
- (definition->mLocalName != typeAtom) ? &elemName
- : nullptr);
- NS_ENSURE_TRUE(element, false);
- }
-
- // The prototype setup happens in Element::WrapObject().
-
- nsresult rv = nsContentUtils::WrapNative(aCx, element, element, args.rval());
- NS_ENSURE_SUCCESS(rv, true);
-
- return true;
-}
-
-bool
nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
{
JS::Rooted<JSObject*> obj(aCx, aObject);
@@ -5842,131 +5720,6 @@ nsDocument::IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow)
return false;
}
-void
-nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType,
- const ElementRegistrationOptions& aOptions,
- JS::MutableHandle<JSObject*> aRetval,
- ErrorResult& rv)
-{
- RefPtr<CustomElementRegistry> registry(GetCustomElementRegistry());
- if (!registry) {
- rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return;
- }
-
- AutoCEReaction ceReaction(this->GetDocGroup()->CustomElementReactionsStack(),
- aCx);
- // Unconditionally convert TYPE to lowercase.
- nsAutoString lcType;
- nsContentUtils::ASCIIToLower(aType, lcType);
-
- nsIGlobalObject* sgo = GetScopeObject();
- if (!sgo) {
- rv.Throw(NS_ERROR_UNEXPECTED);
- return;
- }
-
- JS::Rooted<JSObject*> global(aCx, sgo->GetGlobalJSObject());
- JS::Rooted<JSObject*> protoObject(aCx);
-
- if (!aOptions.mPrototype) {
- JS::Rooted<JSObject*> htmlProto(aCx);
- htmlProto = HTMLElementBinding::GetProtoObjectHandle(aCx);
- if (!htmlProto) {
- rv.Throw(NS_ERROR_OUT_OF_MEMORY);
- return;
- }
-
- protoObject = JS_NewObjectWithGivenProto(aCx, nullptr, htmlProto);
- if (!protoObject) {
- rv.Throw(NS_ERROR_UNEXPECTED);
- return;
- }
- } else {
- protoObject = aOptions.mPrototype;
-
- // Get the unwrapped prototype to do some checks.
- JS::Rooted<JSObject*> protoObjectUnwrapped(aCx, js::CheckedUnwrap(protoObject));
- if (!protoObjectUnwrapped) {
- // If the caller's compartment does not have permission to access the
- // unwrapped prototype then throw.
- rv.Throw(NS_ERROR_DOM_SECURITY_ERR);
- return;
- }
-
- // If PROTOTYPE is already an interface prototype object for any interface
- // object or PROTOTYPE has a non-configurable property named constructor,
- // throw a NotSupportedError and stop.
- const js::Class* clasp = js::GetObjectClass(protoObjectUnwrapped);
- if (IsDOMIfaceAndProtoClass(clasp)) {
- rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return;
- }
-
- JS::Rooted<JS::PropertyDescriptor> descRoot(aCx);
- JS::MutableHandle<JS::PropertyDescriptor> desc(&descRoot);
- // This check may go through a wrapper, but as we checked above
- // it should be transparent or an xray. This should be fine for now,
- // until the spec is sorted out.
- if (!JS_GetPropertyDescriptor(aCx, protoObject, "constructor", desc)) {
- rv.Throw(NS_ERROR_UNEXPECTED);
- return;
- }
-
- if (!desc.configurable()) {
- rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return;
- }
- }
-
- JS::Rooted<JSFunction*> constructor(aCx);
- {
- // Go into the document's global compartment when creating the constructor
- // function because we want to get the correct document (where the
- // definition is registered) when it is called.
- JSAutoCompartment ac(aCx, global);
-
- // Create constructor to return. Store the name of the custom element as the
- // name of the function.
- constructor = JS_NewFunction(aCx, nsDocument::CustomElementConstructor, 0,
- JSFUN_CONSTRUCTOR,
- NS_ConvertUTF16toUTF8(lcType).get());
- if (!constructor) {
- rv.Throw(NS_ERROR_OUT_OF_MEMORY);
- return;
- }
- }
-
- JS::Rooted<JSObject*> wrappedConstructor(aCx);
- wrappedConstructor = JS_GetFunctionObject(constructor);
- if (!JS_WrapObject(aCx, &wrappedConstructor)) {
- rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return;
- }
-
- if (!JS_LinkConstructorAndPrototype(aCx, wrappedConstructor, protoObject)) {
- rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return;
- }
-
- ElementDefinitionOptions options;
- if (!aOptions.mExtends.IsVoid()) {
- // Only convert NAME to lowercase in HTML documents.
- nsAutoString lcName;
- IsHTMLDocument() ? nsContentUtils::ASCIIToLower(aOptions.mExtends, lcName)
- : lcName.Assign(aOptions.mExtends);
-
- options.mExtends.Construct(lcName);
- }
-
- RootedCallback<OwningNonNull<binding_detail::FastFunction>> functionConstructor(aCx);
- functionConstructor = new binding_detail::FastFunction(aCx, wrappedConstructor, sgo);
-
- registry->Define(lcType, functionConstructor, options, rv);
-
- aRetval.set(wrappedConstructor);
-}
-
NS_IMETHODIMP
nsDocument::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h
index 79b7f18f4f..de2d19cdf9 100644
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1129,11 +1129,6 @@ public:
// WebIDL bits
virtual mozilla::dom::DOMImplementation*
GetImplementation(mozilla::ErrorResult& rv) override;
- virtual void
- RegisterElement(JSContext* aCx, const nsAString& aName,
- const mozilla::dom::ElementRegistrationOptions& aOptions,
- JS::MutableHandle<JSObject*> aRetval,
- mozilla::ErrorResult& rv) override;
virtual mozilla::dom::StyleSheetList* StyleSheets() override;
virtual void SetSelectedStyleSheetSet(const nsAString& aSheetSet) override;
virtual void GetLastStyleSheetSet(nsString& aSheetSet) override;
@@ -1385,13 +1380,7 @@ protected:
// non-null when this document is in fullscreen mode.
nsWeakPtr mFullscreenRoot;
-private:
- static bool CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp);
-
public:
- virtual already_AddRefed<mozilla::dom::CustomElementRegistry>
- GetCustomElementRegistry() override;
-
// Check whether web components are enabled for the global of aObject.
static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
// Check whether web components are enabled for the global of the document
diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h
index 125816c954..3088736bd2 100644
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -133,7 +133,6 @@ class DOMIntersectionObserver;
class DOMStringList;
class Element;
struct ElementCreationOptions;
-struct ElementRegistrationOptions;
class Event;
class EventTarget;
class FontFaceSet;
@@ -2587,14 +2586,6 @@ public:
nsIDocument* GetTopLevelContentDocument();
- virtual void
- RegisterElement(JSContext* aCx, const nsAString& aName,
- const mozilla::dom::ElementRegistrationOptions& aOptions,
- JS::MutableHandle<JSObject*> aRetval,
- mozilla::ErrorResult& rv) = 0;
- virtual already_AddRefed<mozilla::dom::CustomElementRegistry>
- GetCustomElementRegistry() = 0;
-
already_AddRefed<nsContentList>
GetElementsByTagName(const nsAString& aTagName)
{
diff --git a/dom/base/test/chrome/chrome.ini b/dom/base/test/chrome/chrome.ini
index 765bbd2dfb..c6ee423918 100644
--- a/dom/base/test/chrome/chrome.ini
+++ b/dom/base/test/chrome/chrome.ini
@@ -18,8 +18,8 @@ support-files =
file_bug1209621.xul
fileconstructor_file.png
frame_bug814638.xul
- frame_registerElement_content.html
- registerElement_ep.js
+ frame_custom_element_content.html
+ custom_element_ep.js
host_bug814638.xul
window_nsITextInputProcessor.xul
title_window.xul
@@ -62,8 +62,8 @@ support-files = ../file_bug357450.js
[test_bug1139964.xul]
[test_bug1209621.xul]
[test_cpows.xul]
-[test_registerElement_content.xul]
-[test_registerElement_ep.xul]
+[test_custom_element_content.xul]
+[test_custom_element_ep.xul]
[test_domparsing.xul]
[test_fileconstructor.xul]
[test_fileconstructor_tempfile.xul]
diff --git a/dom/base/test/chrome/registerElement_ep.js b/dom/base/test/chrome/registerElement_ep.js
deleted file mode 100644
index 9189593c0a..0000000000
--- a/dom/base/test/chrome/registerElement_ep.js
+++ /dev/null
@@ -1,8 +0,0 @@
-var proto = Object.create(HTMLElement.prototype);
-proto.magicNumber = 42;
-proto.connectedCallback = function() {
- finishTest(this.magicNumber === 42);
-};
-document.registerElement("x-foo", { prototype: proto });
-
-document.firstChild.appendChild(document.createElement("x-foo"));
diff --git a/dom/base/test/chrome/test_registerElement_content.xul b/dom/base/test/chrome/test_registerElement_content.xul
deleted file mode 100644
index bf00ed53d2..0000000000
--- a/dom/base/test/chrome/test_registerElement_content.xul
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
- type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=1130028
--->
-<window title="Mozilla Bug 1130028"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-
- <!-- test results are displayed in the html:body -->
- <body xmlns="http://www.w3.org/1999/xhtml">
- <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1130028"
- target="_blank">Mozilla Bug 1130028</a>
- <iframe onload="startTests()" id="frame" src="http://example.com/chrome/dom/base/test/chrome/frame_registerElement_content.html"></iframe>
- </body>
-
- <!-- test code goes here -->
- <script type="application/javascript"><![CDATA[
-
- /** Test for Bug 1130028 **/
- var connectedCallbackCount = 0;
-
- // Callback should be called only once by element created in content.
- function connectedCallbackCalled() {
- connectedCallbackCount++;
- is(connectedCallbackCount, 1, "Connected callback called, should be called once in test.");
- is(this.magicNumber, 42, "Callback should be able to see the custom prototype.");
- }
-
- function startTests() {
- var frame = $("frame");
-
- var c = frame.contentDocument.registerElement("x-foo");
- var elem = new c();
- is(elem.tagName, "X-FOO", "Constructor should create an x-foo element.");
-
- var proto = Object.create(frame.contentWindow.HTMLElement.prototype);
- proto.magicNumber = 42;
- proto.connectedCallback = connectedCallbackCalled;
-
- frame.contentDocument.registerElement("x-bar", { prototype: proto });
- is(connectedCallbackCount, 1, "Connected callback should be called by element created in content.");
-
- var element = frame.contentDocument.createElement("x-bar");
- is(element.magicNumber, 42, "Should be able to see the custom prototype on created element.");
- }
-
- ]]></script>
-</window>
diff --git a/dom/base/test/chrome/test_registerElement_ep.xul b/dom/base/test/chrome/test_registerElement_ep.xul
deleted file mode 100644
index b6a160c2e8..0000000000
--- a/dom/base/test/chrome/test_registerElement_ep.xul
+++ /dev/null
@@ -1,44 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
-<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
- type="text/css"?>
-<!--
-https://bugzilla.mozilla.org/show_bug.cgi?id=1130028
--->
-<window title="Mozilla Bug 1130028"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-
- <!-- test results are displayed in the html:body -->
- <body xmlns="http://www.w3.org/1999/xhtml">
- <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1130028"
- target="_blank">Mozilla Bug 1130028</a>
- <iframe onload="startTests()" id="frame" src="http://example.com/chrome/dom/base/test/chrome/frame_registerElement_content.html"></iframe>
- </body>
-
- <!-- test code goes here -->
- <script type="application/javascript"><![CDATA[
-
- Components.utils.import("resource://gre/modules/Services.jsm");
-
- /** Test for Bug 1130028 **/
- SimpleTest.waitForExplicitFinish();
-
- function finishTest(canSeePrototype) {
- ok(true, "connectedCallback called when reigsterElement was called with an extended principal.");
- ok(canSeePrototype, "connectedCallback should be able to see custom prototype.");
- SimpleTest.finish();
- }
-
- function startTests() {
- var frame = $("frame");
-
- // Create a sandbox with an extended principal then run a script that registers a custom element in the sandbox.
- var sandbox = Components.utils.Sandbox([frame.contentWindow], { sandboxPrototype: frame.contentWindow });
- sandbox.finishTest = finishTest;
- Services.scriptloader.loadSubScript("chrome://mochitests/content/chrome/dom/base/test/chrome/registerElement_ep.js", sandbox);
- }
-
- ]]></script>
-</window>
diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini
index 3dfd666f80..928727f81d 100644
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -630,7 +630,7 @@ skip-if = toolkit == 'android' #bug 904183
[test_document.all_unqualified.html]
[test_document_constructor.html]
[test_document_importNode_document.html]
-[test_document_register.html]
+[test_custom_element.html]
[test_domcursor.html]
[test_domparser_null_char.html]
[test_domparsing.html]
diff --git a/dom/base/test/test_document_register.html b/dom/base/test/test_document_register.html
index 6cf15a52f2..7de2351084 100644
--- a/dom/base/test/test_document_register.html
+++ b/dom/base/test/test_document_register.html
@@ -13,8 +13,10 @@
SimpleTest.waitForExplicitFinish();
function startTests() {
- var c = document.getElementById("fooframe").contentDocument.registerElement("x-foo");
- var elem = new c();
+ var frame = document.getElementById("fooframe");
+ class XFoo extends frame.contentWindow.HTMLElement {};
+ frame.contentWindow.customElements.define("x-foo", XFoo);
+ var elem = new XFoo();
is(elem.tagName, "X-FOO", "Constructor should create an x-foo element.");
var anotherElem = $("fooframe").contentDocument.createElement("x-foo");