Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/simulation2/serialization/StdDeserializer.cpp
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 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 152 Lines • ▼ Show 20 Lines | else // SCRIPT_TYPE_OBJECT_PROTOTYPE | ||||
String("proto name", prototypeName, 0, 256); | String("proto name", prototypeName, 0, 256); | ||||
// Get constructor object | // Get constructor object | ||||
JS::RootedObject proto(cx); | JS::RootedObject proto(cx); | ||||
GetSerializablePrototype(prototypeName, &proto); | GetSerializablePrototype(prototypeName, &proto); | ||||
if (!proto) | if (!proto) | ||||
throw PSERROR_Deserialize_ScriptError("Failed to find serializable prototype for object"); | throw PSERROR_Deserialize_ScriptError("Failed to find serializable prototype for object"); | ||||
JS::RootedObject parent(cx, JS_GetParent(proto)); | obj.set(JS_NewObjectWithGivenProto(cx, nullptr, proto)); | ||||
if (!proto || !parent) | |||||
throw PSERROR_Deserialize_ScriptError(); | |||||
// TODO: Remove support for parent since this is dropped upstream SpiderMonkey | |||||
obj.set(JS_NewObjectWithGivenProto(cx, nullptr, proto, parent)); | |||||
if (!obj) | if (!obj) | ||||
throw PSERROR_Deserialize_ScriptError("JS_NewObject failed"); | throw PSERROR_Deserialize_ScriptError("JS_NewObject failed"); | ||||
// Does it have custom Deserialize function? | // Does it have custom Deserialize function? | ||||
// if so, we let it handle the deserialized data, rather than adding properties directly | // if so, we let it handle the deserialized data, rather than adding properties directly | ||||
bool hasCustomDeserialize, hasCustomSerialize; | bool hasCustomDeserialize, hasCustomSerialize; | ||||
if (!JS_HasProperty(cx, obj, "Serialize", &hasCustomSerialize) || !JS_HasProperty(cx, obj, "Deserialize", &hasCustomDeserialize)) | if (!JS_HasProperty(cx, obj, "Serialize", &hasCustomSerialize) || !JS_HasProperty(cx, obj, "Deserialize", &hasCustomDeserialize)) | ||||
throw PSERROR_Serialize_ScriptError("JS_HasProperty failed"); | throw PSERROR_Serialize_ScriptError("JS_HasProperty failed"); | ||||
▲ Show 20 Lines • Show All 344 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator