Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLElement.cpp
blobe6dc290dbc336f0412744eda18bfdc18e0a190bf
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsGenericHTMLElement.h"
8 #include "mozilla/dom/HTMLElementBinding.h"
9 #include "nsContentUtils.h"
11 namespace mozilla {
12 namespace dom {
14 class HTMLElement final : public nsGenericHTMLElement {
15 public:
16 explicit HTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo);
17 virtual ~HTMLElement();
19 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
21 protected:
22 JSObject* WrapNode(JSContext* aCx,
23 JS::Handle<JSObject*> aGivenProto) override;
26 HTMLElement::HTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
27 : nsGenericHTMLElement(std::move(aNodeInfo)) {
28 if (NodeInfo()->Equals(nsGkAtoms::bdi)) {
29 AddStatesSilently(NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO);
33 HTMLElement::~HTMLElement() = default;
35 NS_IMPL_ELEMENT_CLONE(HTMLElement)
37 JSObject* HTMLElement::WrapNode(JSContext* aCx,
38 JS::Handle<JSObject*> aGivenProto) {
39 return dom::HTMLElement_Binding::Wrap(aCx, this, aGivenProto);
42 } // namespace dom
43 } // namespace mozilla
45 // Here, we expand 'NS_IMPL_NS_NEW_HTML_ELEMENT()' by hand.
46 // (Calling the macro directly (with no args) produces compiler warnings.)
47 nsGenericHTMLElement* NS_NewHTMLElement(
48 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
49 mozilla::dom::FromParser aFromParser) {
50 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
51 auto* nim = nodeInfo->NodeInfoManager();
52 return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget());
55 // Distinct from the above in order to have function pointer that compared
56 // unequal to a function pointer to the above.
57 nsGenericHTMLElement* NS_NewCustomElement(
58 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
59 mozilla::dom::FromParser aFromParser) {
60 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
61 auto* nim = nodeInfo->NodeInfoManager();
62 return new (nim) mozilla::dom::HTMLElement(nodeInfo.forget());