interceptor.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef GIN_INTERCEPTOR_H_
  5. #define GIN_INTERCEPTOR_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/memory/raw_ptr.h"
  10. #include "gin/gin_export.h"
  11. #include "v8/include/v8-forward.h"
  12. namespace gin {
  13. class WrappableBase;
  14. // Base class for gin::Wrappable-derived classes that want to implement a
  15. // property interceptor.
  16. class GIN_EXPORT NamedPropertyInterceptor {
  17. public:
  18. NamedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
  19. NamedPropertyInterceptor(const NamedPropertyInterceptor&) = delete;
  20. NamedPropertyInterceptor& operator=(const NamedPropertyInterceptor&) = delete;
  21. virtual ~NamedPropertyInterceptor();
  22. virtual v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate,
  23. const std::string& property);
  24. // Return true if the set was interecepted.
  25. virtual bool SetNamedProperty(v8::Isolate* isolate,
  26. const std::string& property,
  27. v8::Local<v8::Value> value);
  28. virtual std::vector<std::string> EnumerateNamedProperties(
  29. v8::Isolate* isolate);
  30. private:
  31. raw_ptr<v8::Isolate> isolate_;
  32. raw_ptr<WrappableBase> base_;
  33. };
  34. class GIN_EXPORT IndexedPropertyInterceptor {
  35. public:
  36. IndexedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
  37. IndexedPropertyInterceptor(const IndexedPropertyInterceptor&) = delete;
  38. IndexedPropertyInterceptor& operator=(const IndexedPropertyInterceptor&) =
  39. delete;
  40. virtual ~IndexedPropertyInterceptor();
  41. virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
  42. uint32_t index);
  43. // Return true if the set was interecepted.
  44. virtual bool SetIndexedProperty(v8::Isolate* isolate,
  45. uint32_t index,
  46. v8::Local<v8::Value> value);
  47. virtual std::vector<uint32_t> EnumerateIndexedProperties(
  48. v8::Isolate* isolate);
  49. private:
  50. raw_ptr<v8::Isolate> isolate_;
  51. raw_ptr<WrappableBase> base_;
  52. };
  53. } // namespace gin
  54. #endif // GIN_INTERCEPTOR_H_