tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WindowNamedPropertiesHandler.h (2683B)


      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/. */
      6 
      7 #ifndef mozilla_dom_WindowNamedPropertiesHandler_h
      8 #define mozilla_dom_WindowNamedPropertiesHandler_h
      9 
     10 #include "mozilla/dom/DOMJSProxyHandler.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 class WindowNamedPropertiesHandler : public BaseDOMProxyHandler {
     15 public:
     16  constexpr WindowNamedPropertiesHandler()
     17      : BaseDOMProxyHandler(nullptr, /* hasPrototype = */ true) {}
     18  virtual bool getOwnPropDescriptor(
     19      JSContext* aCx, JS::Handle<JSObject*> aProxy, JS::Handle<jsid> aId,
     20      bool /* unused */,
     21      JS::MutableHandle<Maybe<JS::PropertyDescriptor>> aDesc) const override;
     22  virtual bool defineProperty(JSContext* aCx, JS::Handle<JSObject*> aProxy,
     23                              JS::Handle<jsid> aId,
     24                              JS::Handle<JS::PropertyDescriptor> aDesc,
     25                              JS::ObjectOpResult& result) const override;
     26  virtual bool ownPropNames(
     27      JSContext* aCx, JS::Handle<JSObject*> aProxy, unsigned flags,
     28      JS::MutableHandleVector<jsid> aProps) const override;
     29  virtual bool delete_(JSContext* aCx, JS::Handle<JSObject*> aProxy,
     30                       JS::Handle<jsid> aId,
     31                       JS::ObjectOpResult& aResult) const override;
     32 
     33  // No need for getPrototypeIfOrdinary here: window named-properties objects
     34  // have static prototypes, so the version inherited from BaseDOMProxyHandler
     35  // will do the right thing.
     36 
     37  virtual bool preventExtensions(JSContext* aCx, JS::Handle<JSObject*> aProxy,
     38                                 JS::ObjectOpResult& aResult) const override {
     39    return aResult.failCantPreventExtensions();
     40  }
     41  virtual bool isExtensible(JSContext* aCx, JS::Handle<JSObject*> aProxy,
     42                            bool* aIsExtensible) const override {
     43    *aIsExtensible = true;
     44    return true;
     45  }
     46  virtual const char* className(JSContext* aCx,
     47                                JS::Handle<JSObject*> aProxy) const override {
     48    return "WindowProperties";
     49  }
     50 
     51  static const WindowNamedPropertiesHandler* getInstance() {
     52    static const WindowNamedPropertiesHandler instance;
     53    return &instance;
     54  }
     55 
     56  // For Create, aProto is the parent of the interface prototype object of the
     57  // Window we're associated with.
     58  static JSObject* Create(JSContext* aCx, JS::Handle<JSObject*> aProto);
     59 };
     60 
     61 }  // namespace mozilla::dom
     62 
     63 #endif /* mozilla_dom_WindowNamedPropertiesHandler_h */