|
1 | 1 | #include "dom_storage_agent.h" |
| 2 | +#include <optional> |
2 | 3 | #include "env-inl.h" |
3 | 4 | #include "inspector/inspector_object_utils.h" |
| 5 | +#include "util.h" |
| 6 | +#include "v8-exception.h" |
4 | 7 | #include "v8-isolate.h" |
5 | 8 |
|
6 | 9 | namespace node { |
@@ -85,19 +88,19 @@ protocol::DispatchResponse DOMStorageAgent::getDOMStorageItems( |
85 | 88 | "DOMStorage domain is not enabled"); |
86 | 89 | } |
87 | 90 | bool is_local_storage = storageId->getIsLocalStorage(); |
88 | | - std::unique_ptr<std::unordered_map<std::string, std::string>> storage_map = |
| 91 | + std::optional<std::unordered_map<std::string, std::string>> storage_map = |
89 | 92 | is_local_storage |
90 | | - ? std::make_unique<std::unordered_map<std::string, std::string>>( |
| 93 | + ? std::make_optional<std::unordered_map<std::string, std::string>>( |
91 | 94 | local_storage_map_) |
92 | | - : std::make_unique<std::unordered_map<std::string, std::string>>( |
| 95 | + : std::make_optional<std::unordered_map<std::string, std::string>>( |
93 | 96 | session_storage_map_); |
94 | 97 | if (storage_map->empty()) { |
95 | 98 | auto web_storage_obj = getWebStorage(is_local_storage); |
96 | 99 | if (web_storage_obj) { |
97 | 100 | std::unordered_map<std::string, std::string> all_items = |
98 | 101 | web_storage_obj.value()->GetAll(); |
99 | 102 | storage_map = |
100 | | - std::make_unique<std::unordered_map<std::string, std::string>>( |
| 103 | + std::make_optional<std::unordered_map<std::string, std::string>>( |
101 | 104 | std::move(all_items)); |
102 | 105 | } |
103 | 106 | } |
@@ -258,17 +261,18 @@ void DOMStorageAgent::registerStorage(Local<Context> context, |
258 | 261 |
|
259 | 262 | std::optional<node::webstorage::Storage*> DOMStorageAgent::getWebStorage( |
260 | 263 | bool is_local_storage) { |
261 | | - std::string var_name = is_local_storage ? "localStorage" : "sessionStorage"; |
262 | 264 | v8::Isolate* isolate = env_->isolate(); |
263 | 265 | v8::HandleScope handle_scope(isolate); |
264 | 266 | v8::Local<v8::Object> global = env_->context()->Global(); |
265 | 267 | v8::Local<v8::Value> web_storage_val; |
| 268 | + v8::TryCatch try_catch(isolate); |
266 | 269 | if (!global |
267 | 270 | ->Get(env_->context(), |
268 | | - v8::String::NewFromUtf8(env_->isolate(), var_name.c_str()) |
269 | | - .ToLocalChecked()) |
| 271 | + is_local_storage |
| 272 | + ? FIXED_ONE_BYTE_STRING(isolate, "localStorage") |
| 273 | + : FIXED_ONE_BYTE_STRING(isolate, "sessionStorage")) |
270 | 274 | .ToLocal(&web_storage_val) || |
271 | | - !web_storage_val->IsObject()) { |
| 275 | + !web_storage_val->IsObject() || try_catch.HasCaught()) { |
272 | 276 | return std::nullopt; |
273 | 277 | } else { |
274 | 278 | node::webstorage::Storage* storage; |
|
0 commit comments