From b5b6ba0c74853e1f1a2da11ef88d2bb8daeaac37 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 28 Jul 2018 12:36:42 +0900 Subject: Deep-copy objects on MemoryStorage and add tests --- src/background/infrastructures/memory-storage.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/background/infrastructures') diff --git a/src/background/infrastructures/memory-storage.js b/src/background/infrastructures/memory-storage.js index 0a05928..234a9b8 100644 --- a/src/background/infrastructures/memory-storage.js +++ b/src/background/infrastructures/memory-storage.js @@ -2,10 +2,14 @@ const db = {}; export default class MemoryStorage { set(name, value) { - db[name] = value; + let data = JSON.stringify(value); + if (typeof data === 'undefined') { + throw new Error('value is not serializable'); + } + db[name] = data; } get(name) { - return db[name]; + return JSON.parse(db[name]); } } -- cgit v1.2.3