786fb948c23c57c1db45eab70cb1977e4983a890
[platform/framework/web/lwnode.git] /
1 /*
2  * Copyright (c) 2021-present Samsung Electronics Co., Ltd
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
17  *  USA
18  */
19
20 #if defined(ENABLE_THREADING)
21
22 #ifndef __EscargotSerializedSharedArrayBufferObjectValue__
23 #define __EscargotSerializedSharedArrayBufferObjectValue__
24
25 #include "runtime/serialization/SerializedValue.h"
26 #include "runtime/SharedArrayBufferObject.h"
27
28 namespace Escargot {
29
30 class SerializedSharedArrayBufferObjectValue : public SerializedValue {
31     friend class Serializer;
32
33 public:
34     virtual Type type() override
35     {
36         return SerializedValue::SharedArrayBufferObject;
37     }
38
39     virtual Value toValue(ExecutionState& state) override
40     {
41         return Value(new ::Escargot::SharedArrayBufferObject(state, state.context()->globalObject()->sharedArrayBufferPrototype(), m_bufferData));
42     }
43
44 protected:
45     virtual void serializeValueData(std::ostringstream& outputStream) override
46     {
47         size_t ptr = reinterpret_cast<size_t>(m_bufferData);
48         outputStream << ptr;
49         outputStream << std::endl;
50     }
51
52     static std::unique_ptr<SerializedValue> deserializeFrom(std::istringstream& inputStream)
53     {
54         size_t ptr;
55         inputStream >> ptr;
56         SharedArrayBufferObjectBackingStoreData* data = reinterpret_cast<SharedArrayBufferObjectBackingStoreData*>(ptr);
57         return std::unique_ptr<SerializedValue>(new SerializedSharedArrayBufferObjectValue(data));
58     }
59
60     SerializedSharedArrayBufferObjectValue(SharedArrayBufferObjectBackingStoreData* bufferData)
61         : m_bufferData(bufferData)
62     {
63         m_bufferData->ref();
64     }
65
66     ~SerializedSharedArrayBufferObjectValue()
67     {
68         m_bufferData->deref();
69     }
70
71     SharedArrayBufferObjectBackingStoreData* m_bufferData;
72 };
73
74 } // namespace Escargot
75
76 #endif
77 #endif