Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/serialization/BinarySerializer.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | default: | ||||
LOGERROR("Cannot serialize unrecognized typed array view: %d", arrayType); | LOGERROR("Cannot serialize unrecognized typed array view: %d", arrayType); | ||||
throw PSERROR_Serialize_InvalidScriptValue(); | throw PSERROR_Serialize_InvalidScriptValue(); | ||||
} | } | ||||
} | } | ||||
CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer) : | CBinarySerializerScriptImpl::CBinarySerializerScriptImpl(const ScriptInterface& scriptInterface, ISerializer& serializer) : | ||||
m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_ScriptBackrefsNext(0) | m_ScriptInterface(scriptInterface), m_Serializer(serializer), m_ScriptBackrefsNext(0) | ||||
{ | { | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
m_ScriptBackrefSymbol.init(rq.cx, JS::NewSymbol(rq.cx, nullptr)); | m_ScriptBackrefSymbol.init(rq.cx, JS::NewSymbol(rq.cx, nullptr)); | ||||
} | } | ||||
void CBinarySerializerScriptImpl::HandleScriptVal(JS::HandleValue val) | void CBinarySerializerScriptImpl::HandleScriptVal(JS::HandleValue val) | ||||
{ | { | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
switch (JS_TypeOfValue(rq.cx, val)) | switch (JS_TypeOfValue(rq.cx, val)) | ||||
{ | { | ||||
case JSTYPE_VOID: | case JSTYPE_VOID: | ||||
{ | { | ||||
m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_VOID); | m_Serializer.NumberU8_Unbounded("type", SCRIPT_TYPE_VOID); | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | default: | ||||
debug_warn(L"Invalid TypeOfValue"); | debug_warn(L"Invalid TypeOfValue"); | ||||
throw PSERROR_Serialize_InvalidScriptValue(); | throw PSERROR_Serialize_InvalidScriptValue(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CBinarySerializerScriptImpl::ScriptString(const char* name, JS::HandleString string) | void CBinarySerializerScriptImpl::ScriptString(const char* name, JS::HandleString string) | ||||
{ | { | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
#if BYTE_ORDER != LITTLE_ENDIAN | #if BYTE_ORDER != LITTLE_ENDIAN | ||||
#error TODO: probably need to convert JS strings to little-endian | #error TODO: probably need to convert JS strings to little-endian | ||||
#endif | #endif | ||||
size_t length; | size_t length; | ||||
JS::AutoCheckCannotGC nogc; | JS::AutoCheckCannotGC nogc; | ||||
// Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions | // Serialize strings directly as UTF-16 or Latin1, to avoid expensive encoding conversions | ||||
Show All 23 Lines | i32 CBinarySerializerScriptImpl::GetScriptBackrefTag(JS::HandleObject obj) | ||||
// To support non-tree structures (e.g. "var x = []; var y = [x, x];"), we need a way | // To support non-tree structures (e.g. "var x = []; var y = [x, x];"), we need a way | ||||
// to indicate multiple references to one object(/array). So every time we serialize a | // to indicate multiple references to one object(/array). So every time we serialize a | ||||
// new object, we give it a new tag; when we serialize it a second time we just refer | // new object, we give it a new tag; when we serialize it a second time we just refer | ||||
// to that tag. | // to that tag. | ||||
// | // | ||||
// Tags are stored on the object. To avoid overwriting any existing property, | // Tags are stored on the object. To avoid overwriting any existing property, | ||||
// they are saved as a uniquely-named, non-enumerable property (the serializer's unique symbol). | // they are saved as a uniquely-named, non-enumerable property (the serializer's unique symbol). | ||||
ScriptInterface::Request rq(m_ScriptInterface); | ScriptRequest rq(m_ScriptInterface); | ||||
JS::RootedValue symbolValue(rq.cx, JS::SymbolValue(m_ScriptBackrefSymbol)); | JS::RootedValue symbolValue(rq.cx, JS::SymbolValue(m_ScriptBackrefSymbol)); | ||||
JS::RootedId symbolId(rq.cx); | JS::RootedId symbolId(rq.cx); | ||||
ENSURE(JS_ValueToId(rq.cx, symbolValue, &symbolId)); | ENSURE(JS_ValueToId(rq.cx, symbolValue, &symbolId)); | ||||
JS::RootedValue tagValue(rq.cx); | JS::RootedValue tagValue(rq.cx); | ||||
// If it was already there, return the tag | // If it was already there, return the tag | ||||
Show All 16 Lines |
Wildfire Games · Phabricator