Shaka Player Embedded
backing_object.h
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SHAKA_EMBEDDED_MAPPING_BACKING_OBJECT_H_
16 #define SHAKA_EMBEDDED_MAPPING_BACKING_OBJECT_H_
17 
18 #include <glog/logging.h>
19 
20 #include <string>
21 
24 #include "src/memory/heap_tracer.h"
25 
26 namespace shaka {
27 
28 namespace memory {
29 class HeapTracer;
30 class ObjectTracker;
31 } // namespace memory
32 
33 namespace js {
34 class Debug;
35 } // namespace js
36 
38 
39 #define DECLARE_TYPE_INFO(type) \
40  public: \
41  static std::string name() { \
42  return #type; \
43  } \
44  \
45  protected: \
46  ~type() override; \
47  \
48  public: \
49  ::shaka::BackingObjectFactoryBase* factory() const override
50 
57  public:
58  BackingObject();
59 
61  static constexpr const size_t kInternalFieldCount = 2;
62 
63  // In WebKit, it says that MSVC requires delete[] for exported classes.
64  // https://goo.gl/eXrvjn
65  // Disable new[] and delete[] since we use 'delete' in the ObjectTracker to
66  // delete objects and that does not work with arrays.
67  static void* operator new[](size_t size) = delete;
68  static void operator delete[](void*) = delete;
69 
70  void Trace(memory::HeapTracer* tracer) const override;
71  bool IsRootedAlive() const override;
72 
74  std::string name() const;
75 
77  virtual BackingObjectFactoryBase* factory() const = 0;
78 
80  bool DerivedFrom(const std::string& base);
81 
86  ReturnVal<JsValue> JsThis() const;
87 
89  void SetJsThis(Handle<JsObject> this_);
90 
91  protected:
92  friend class memory::ObjectTracker;
93  ~BackingObject() override;
94 
95  private:
96  WeakJsPtr<JsObject> js_this_;
97 };
98 
99 } // namespace shaka
100 
101 #endif // SHAKA_EMBEDDED_MAPPING_BACKING_OBJECT_H_
const char * name