forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamWriter.cpp
More file actions
47 lines (42 loc) · 1.6 KB
/
StreamWriter.cpp
File metadata and controls
47 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "SCACorePch.h"
namespace Js
{
void StreamWriter::Write(const void* pv, size_t cb)
{
ScriptContext* scriptContext = GetScriptContext();
uint32 newSize = UInt32Math::Add((uint32)m_current, (uint32)cb);
if (newSize >= m_capacity)
{
size_t newCapacity = UInt32Math::Add(max(newSize, UInt32Math::Mul((uint32)m_capacity, 2)), 100);
BEGIN_LEAVE_SCRIPT(scriptContext)
{
m_buffer = m_stream->ExtendBuffer(m_buffer, newCapacity, &m_capacity);
}
END_LEAVE_SCRIPT(scriptContext);
}
Assert(m_buffer != nullptr);
js_memcpy_s(m_buffer + m_current, cb, pv, cb);
m_current += cb;
}
void StreamWriter::WriteHostObject(void* data)
{
ScriptContext* scriptContext = GetScriptContext();
BEGIN_LEAVE_SCRIPT(scriptContext)
{
m_stream->WriteHostObject(data);
}
END_LEAVE_SCRIPT(scriptContext);
}
//
// Overload to count for buffer position.
//
scaposition_t StreamWriter::GetPosition() const
{
// If this overflows, we will throw during Flush/RealWrite. So skip checking here.
return static_cast<scaposition_t>(m_current);
}
}