forked from chakra-core/ChakraCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCACore.cpp
More file actions
135 lines (117 loc) · 4.09 KB
/
Copy pathSCACore.cpp
File metadata and controls
135 lines (117 loc) · 4.09 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//-------------------------------------------------------------------------------------------------------
// 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
{
namespace SCACore
{
HRESULT ValidateTransferableVars(Var *vars, size_t count)
{
for (size_t i = 0; i < count; i++)
{
Js::TypeId typeId = Js::JavascriptOperators::GetTypeId(vars[i]);
if (typeId != TypeIds_ArrayBuffer)
{
AssertMsg(false, "These should have been filtered out by the host.");
return E_SCA_TRANSFERABLE_UNSUPPORTED;
}
if (Js::JavascriptOperators::IsObjectDetached(vars[i]))
{
return E_SCA_TRANSFERABLE_NEUTERED;
}
}
return S_OK;
}
HRESULT Serializer::SetTransferableVars(Var *vars, size_t count)
{
if (m_transferableVars != nullptr)
{
Assert(false);
return E_FAIL;
}
else if (count > 0)
{
HRESULT hr = ValidateTransferableVars(vars, count);
if (hr != S_OK)
{
return hr;
}
m_transferableVars = vars;
m_cTransferableVars = count;
}
return S_OK;
}
bool Serializer::WriteValue(Var rootObject)
{
ScriptContext *scriptContext = m_streamWriter.GetScriptContext();
BEGIN_JS_RUNTIME_CALL(scriptContext)
{
Js::SCASerializationEngine::Serialize(rootObject, &m_streamWriter, m_transferableVars, m_cTransferableVars, nullptr /*TBD*/);
}
END_JS_RUNTIME_CALL(scriptContext)
return true;
}
bool Serializer::DetachArrayBuffer()
{
Assert(false);
return true;
}
void Serializer::WriteRawBytes(const void* source, size_t length)
{
ScriptContext *scriptContext = m_streamWriter.GetScriptContext();
BEGIN_JS_RUNTIME_CALL(scriptContext)
{
m_streamWriter.Write(source, length);
}
END_JS_RUNTIME_CALL(scriptContext)
}
bool Serializer::Release(byte** data, size_t *dataLength)
{
*data = m_streamWriter.GetBuffer();
*dataLength = m_streamWriter.GetLength();
return true;
}
bool Deserializer::ReadRawBytes(size_t length, void **data)
{
m_streamReader.ReadRawBytes(data, length);
return true;
}
bool Deserializer::ReadBytes(size_t length, void **data)
{
m_streamReader.Read(*data, length);
return true;
}
Var Deserializer::ReadValue()
{
Var returnedValue = nullptr;
ScriptContext *scriptContext = m_streamReader.GetScriptContext();
BEGIN_JS_RUNTIME_CALL(scriptContext)
{
returnedValue = Js::SCADeserializationEngine::Deserialize(&m_streamReader, m_transferableVars, m_cTransferableVars);
}
END_JS_RUNTIME_CALL(scriptContext)
return returnedValue;
}
HRESULT Deserializer::SetTransferableVars(Var *vars, size_t count)
{
if (m_transferableVars != nullptr)
{
Assert(false);
return E_FAIL;
}
else if (count > 0)
{
HRESULT hr = ValidateTransferableVars(vars, count);
if (hr != S_OK)
{
return hr;
}
m_transferableVars = vars;
m_cTransferableVars = count;
}
return S_OK;
}
}
}