2020-03-04 07:18:22 +00:00
|
|
|
// Copyright (c) 2020 Slack Technologies, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
|
|
|
#define ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2021-02-08 20:30:25 +00:00
|
|
|
#include <unordered_map>
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2024-09-10 20:43:44 +00:00
|
|
|
#include "v8/include/v8-local-handle.h"
|
|
|
|
#include "v8/include/v8-object.h"
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api::context_bridge {
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2024-09-10 20:43:44 +00:00
|
|
|
/**
|
|
|
|
* NB: This is designed for context_bridge. Beware using it elsewhere!
|
|
|
|
* Since it's a v8::Local-to-v8::Local cache, be careful to destroy it
|
|
|
|
* before destroying the HandleScope that keeps the locals alive.
|
|
|
|
*/
|
2020-03-04 07:18:22 +00:00
|
|
|
class ObjectCache final {
|
|
|
|
public:
|
|
|
|
ObjectCache();
|
|
|
|
~ObjectCache();
|
|
|
|
|
|
|
|
void CacheProxiedObject(v8::Local<v8::Value> from,
|
|
|
|
v8::Local<v8::Value> proxy_value);
|
|
|
|
v8::MaybeLocal<v8::Value> GetCachedProxiedObject(
|
|
|
|
v8::Local<v8::Value> from) const;
|
|
|
|
|
|
|
|
private:
|
2024-09-10 20:43:44 +00:00
|
|
|
struct Hash {
|
|
|
|
std::size_t operator()(const v8::Local<v8::Object>& obj) const {
|
|
|
|
return obj->GetIdentityHash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// from_object ==> proxy_value
|
|
|
|
std::unordered_map<v8::Local<v8::Object>, v8::Local<v8::Value>, Hash>
|
|
|
|
proxy_map_;
|
2020-03-04 07:18:22 +00:00
|
|
|
};
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api::context_bridge
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_RENDERER_API_CONTEXT_BRIDGE_OBJECT_CACHE_H_
|