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.
|
|
|
|
|
|
|
|
#include "shell/renderer/api/context_bridge/object_cache.h"
|
|
|
|
|
2024-07-30 13:25:28 +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
|
|
|
|
2021-06-04 04:16:13 +00:00
|
|
|
ObjectCache::ObjectCache() = default;
|
2021-02-08 20:30:25 +00:00
|
|
|
ObjectCache::~ObjectCache() = default;
|
2020-03-04 07:18:22 +00:00
|
|
|
|
2024-09-05 08:08:42 +00:00
|
|
|
void ObjectCache::CacheProxiedObject(const v8::Local<v8::Value> from,
|
2020-03-04 07:18:22 +00:00
|
|
|
v8::Local<v8::Value> proxy_value) {
|
2024-09-05 08:08:42 +00:00
|
|
|
if (from->IsObject() && !from->IsNullOrUndefined())
|
|
|
|
proxy_map_.insert_or_assign(from.As<v8::Object>(), proxy_value);
|
2020-03-04 07:18:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v8::MaybeLocal<v8::Value> ObjectCache::GetCachedProxiedObject(
|
2024-09-05 08:08:42 +00:00
|
|
|
const v8::Local<v8::Value> from) const {
|
2020-03-04 07:18:22 +00:00
|
|
|
if (!from->IsObject() || from->IsNullOrUndefined())
|
2024-09-05 08:08:42 +00:00
|
|
|
return {};
|
|
|
|
|
|
|
|
const auto iter = proxy_map_.find(from.As<v8::Object>());
|
|
|
|
if (iter == proxy_map_.end() || iter->second.IsEmpty())
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return iter->second;
|
2020-03-04 07:18:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api::context_bridge
|