Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/serialization/StdDeserializer.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 263 Lines • ▼ Show 20 Lines | // TODO: Should ask upstream about getting a variant of JS_SetProperty with a length param. | ||||
{ | { | ||||
double value; | double value; | ||||
NumberDouble_Unbounded("value", value); | NumberDouble_Unbounded("value", value); | ||||
JS::RootedValue val(rq.cx, JS::NumberValue(value)); | JS::RootedValue val(rq.cx, JS::NumberValue(value)); | ||||
JS::RootedObject ctorobj(rq.cx); | JS::RootedObject ctorobj(rq.cx); | ||||
if (!JS_GetClassObject(rq.cx, JSProto_Number, &ctorobj)) | if (!JS_GetClassObject(rq.cx, JSProto_Number, &ctorobj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | ||||
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj)); | |||||
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val))); | JS::RootedObject obj(rq.cx); | ||||
if (!obj) | if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_New failed"); | throw PSERROR_Deserialize_ScriptError("JS_New failed"); | ||||
AddScriptBackref(obj); | AddScriptBackref(obj); | ||||
return JS::ObjectValue(*obj); | return JS::ObjectValue(*obj); | ||||
} | } | ||||
case SCRIPT_TYPE_OBJECT_STRING: | case SCRIPT_TYPE_OBJECT_STRING: | ||||
{ | { | ||||
JS::RootedString str(rq.cx); | JS::RootedString str(rq.cx); | ||||
ScriptString("value", &str); | ScriptString("value", &str); | ||||
if (!str) | if (!str) | ||||
throw PSERROR_Deserialize_ScriptError(); | throw PSERROR_Deserialize_ScriptError(); | ||||
JS::RootedValue val(rq.cx, JS::StringValue(str)); | JS::RootedValue val(rq.cx, JS::StringValue(str)); | ||||
JS::RootedObject ctorobj(rq.cx); | JS::RootedObject ctorobj(rq.cx); | ||||
if (!JS_GetClassObject(rq.cx, JSProto_String, &ctorobj)) | if (!JS_GetClassObject(rq.cx, JSProto_String, &ctorobj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | ||||
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj)); | |||||
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val))); | JS::RootedObject obj(rq.cx); | ||||
if (!obj) | if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_New failed"); | throw PSERROR_Deserialize_ScriptError("JS_New failed"); | ||||
AddScriptBackref(obj); | AddScriptBackref(obj); | ||||
return JS::ObjectValue(*obj); | return JS::ObjectValue(*obj); | ||||
} | } | ||||
case SCRIPT_TYPE_OBJECT_BOOLEAN: | case SCRIPT_TYPE_OBJECT_BOOLEAN: | ||||
{ | { | ||||
bool value; | bool value; | ||||
Bool("value", value); | Bool("value", value); | ||||
JS::RootedValue val(rq.cx, JS::BooleanValue(value)); | JS::RootedValue val(rq.cx, JS::BooleanValue(value)); | ||||
JS::RootedObject ctorobj(rq.cx); | JS::RootedObject ctorobj(rq.cx); | ||||
if (!JS_GetClassObject(rq.cx, JSProto_Boolean, &ctorobj)) | if (!JS_GetClassObject(rq.cx, JSProto_Boolean, &ctorobj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | throw PSERROR_Deserialize_ScriptError("JS_GetClassObject failed"); | ||||
JS::RootedValue protoval(rq.cx, JS::ObjectOrNullValue(ctorobj)); | |||||
JS::RootedObject obj(rq.cx, JS_New(rq.cx, ctorobj, JS::HandleValueArray(val))); | JS::RootedObject obj(rq.cx); | ||||
if (!obj) | if (!JS::Construct(rq.cx, protoval, JS::HandleValueArray(val), &obj)) | ||||
throw PSERROR_Deserialize_ScriptError("JS_New failed"); | throw PSERROR_Deserialize_ScriptError("JS_New failed"); | ||||
AddScriptBackref(obj); | AddScriptBackref(obj); | ||||
return JS::ObjectValue(*obj); | return JS::ObjectValue(*obj); | ||||
} | } | ||||
case SCRIPT_TYPE_TYPED_ARRAY: | case SCRIPT_TYPE_TYPED_ARRAY: | ||||
{ | { | ||||
u8 arrayType; | u8 arrayType; | ||||
u32 byteOffset, length; | u32 byteOffset, length; | ||||
▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator