From 5524318fe73a1123da10491a6a545b50af88ea60 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:07:09 -0400 Subject: Bug 1416999 - Remove document.registerElement Tag #1375 --- dom/base/nsDocument.cpp | 247 ------------------------------------------------ 1 file changed, 247 deletions(-) (limited to 'dom/base/nsDocument.cpp') diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 87d860c6a..d69fff863 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -5352,31 +5352,6 @@ bool IsLowercaseASCII(const nsAString& aValue) return true; } -already_AddRefed -nsDocument::GetCustomElementRegistry() -{ - nsAutoString contentType; - GetContentType(contentType); - if (!IsHTMLDocument() && - !contentType.EqualsLiteral("application/xhtml+xml")) { - return nullptr; - } - - nsCOMPtr window( - do_QueryInterface(mScriptGlobalObject ? mScriptGlobalObject - : GetScopeObject())); - if (!window) { - return nullptr; - } - - RefPtr 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) @@ -5692,103 +5667,6 @@ nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI, return attribute.forget(); } -bool -nsDocument::CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value* aVp) -{ - JS::CallArgs args = JS::CallArgsFromVp(aArgc, aVp); - - JS::Rooted global(aCx, - JS_GetGlobalForObject(aCx, &args.callee())); - RefPtr window; - UNWRAP_OBJECT(Window, global, window); - MOZ_ASSERT(window, "Should have a non-null window"); - - nsDocument* document = static_cast(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 registry = window->CustomElements(); - if (!registry) { - return true; - } - - nsCOMPtr typeAtom(NS_Atomize(elemName)); - CustomElementDefinition* definition = - registry->mCustomDefinitions.GetWeak(typeAtom); - if (!definition) { - return true; - } - - RefPtr 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>& 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 reflector(aCx, element->GetWrapper()); - if (reflector) { - Maybe ac; - JS::Rooted 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) { @@ -5842,131 +5720,6 @@ nsDocument::IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow) return false; } -void -nsDocument::RegisterElement(JSContext* aCx, const nsAString& aType, - const ElementRegistrationOptions& aOptions, - JS::MutableHandle aRetval, - ErrorResult& rv) -{ - RefPtr 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 global(aCx, sgo->GetGlobalJSObject()); - JS::Rooted protoObject(aCx); - - if (!aOptions.mPrototype) { - JS::Rooted 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 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 descRoot(aCx); - JS::MutableHandle 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 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 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> 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) -- cgit v1.2.3