1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_INTERCEPTOR_H_
6 #define GIN_INTERCEPTOR_H_
13 #include "base/memory/raw_ptr.h"
14 #include "gin/gin_export.h"
15 #include "v8/include/v8-forward.h"
21 // Base class for gin::Wrappable-derived classes that want to implement a
22 // property interceptor.
23 class GIN_EXPORT NamedPropertyInterceptor {
25 NamedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
26 NamedPropertyInterceptor(const NamedPropertyInterceptor&) = delete;
27 NamedPropertyInterceptor& operator=(const NamedPropertyInterceptor&) = delete;
28 virtual ~NamedPropertyInterceptor();
30 virtual v8::Local<v8::Value> GetNamedProperty(v8::Isolate* isolate,
31 const std::string& property);
32 // Return true if the set was interecepted.
33 virtual bool SetNamedProperty(v8::Isolate* isolate,
34 const std::string& property,
35 v8::Local<v8::Value> value);
36 virtual std::vector<std::string> EnumerateNamedProperties(
37 v8::Isolate* isolate);
40 raw_ptr<v8::Isolate, LeakedDanglingUntriaged> isolate_;
41 raw_ptr<WrappableBase> base_;
44 class GIN_EXPORT IndexedPropertyInterceptor {
46 IndexedPropertyInterceptor(v8::Isolate* isolate, WrappableBase* base);
47 IndexedPropertyInterceptor(const IndexedPropertyInterceptor&) = delete;
48 IndexedPropertyInterceptor& operator=(const IndexedPropertyInterceptor&) =
50 virtual ~IndexedPropertyInterceptor();
52 virtual v8::Local<v8::Value> GetIndexedProperty(v8::Isolate* isolate,
54 // Return true if the set was interecepted.
55 virtual bool SetIndexedProperty(v8::Isolate* isolate,
57 v8::Local<v8::Value> value);
58 virtual std::vector<uint32_t> EnumerateIndexedProperties(
59 v8::Isolate* isolate);
62 raw_ptr<v8::Isolate, LeakedDanglingUntriaged> isolate_;
63 raw_ptr<WrappableBase> base_;
68 #endif // GIN_INTERCEPTOR_H_