tor-browser

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

TemplateObject.h (2583B)


      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 jit_TemplateObject_h
      8 #define jit_TemplateObject_h
      9 
     10 #include "vm/NativeObject.h"
     11 #include "vm/Shape.h"
     12 
     13 namespace js {
     14 namespace jit {
     15 
     16 class TemplateNativeObject;
     17 
     18 // Wrapper for template objects. This should only expose methods that can be
     19 // safely called off-thread without racing with the main thread.
     20 class TemplateObject {
     21 protected:
     22  JSObject* obj_;
     23 
     24 public:
     25  explicit TemplateObject(JSObject* obj) : obj_(obj) {}
     26 
     27  inline gc::AllocKind getAllocKind() const;
     28 
     29  // The following methods rely on the object's group->clasp. This is safe
     30  // to read off-thread for template objects.
     31  inline bool isNativeObject() const;
     32  inline const TemplateNativeObject& asTemplateNativeObject() const;
     33  inline bool isArrayObject() const;
     34  inline bool isArgumentsObject() const;
     35  inline bool isTypedArrayObject() const;
     36  inline bool isRegExpObject() const;
     37  inline bool isCallObject() const;
     38  inline bool isBlockLexicalEnvironmentObject() const;
     39  inline bool isPlainObject() const;
     40 
     41  // The shape should not change. This is true for template objects because
     42  // they're never exposed to arbitrary script.
     43  inline gc::Cell* shape() const;
     44 };
     45 
     46 class TemplateNativeObject : public TemplateObject {
     47 protected:
     48  NativeObject& asNativeObject() const { return obj_->as<NativeObject>(); }
     49 
     50 public:
     51  // Reading slot counts and object slots is safe, as long as we don't touch
     52  // the BaseShape (it can change when we create a ShapeTable for the shape).
     53  inline bool hasDynamicSlots() const;
     54  inline uint32_t numDynamicSlots() const;
     55  inline uint32_t numUsedFixedSlots() const;
     56  inline uint32_t numFixedSlots() const;
     57  inline uint32_t slotSpan() const;
     58  inline Value getSlot(uint32_t i) const;
     59 
     60  // Reading ObjectElements fields is safe, except for the flags.
     61  // isSharedMemory is an exception: it's debug-only and not called on arrays.
     62 #ifdef DEBUG
     63  inline bool isSharedMemory() const;
     64 #endif
     65  inline uint32_t getDenseCapacity() const;
     66  inline uint32_t getDenseInitializedLength() const;
     67  inline uint32_t getArrayLength() const;
     68  inline bool hasDynamicElements() const;
     69  inline const Value* getDenseElements() const;
     70 
     71  inline gc::Cell* regExpShared() const;
     72 };
     73 
     74 }  // namespace jit
     75 }  // namespace js
     76 
     77 #endif /* jit_TemplateObject_h */