MCPcopy Index your code
hub / github.com/4ian/GDevelop / serializeToJSObject

Function serializeToJSObject

newIDE/app/src/Utils/Serializer.js:54–80  ·  view source on GitHub ↗
(
  serializable: gdSerializable,
  methodName: string = 'serializeTo',
  options: ?SerializationOptions = undefined
)

Source from the content-addressed store, hash-verified

52 * @param {*} options Optional serialization options (e.g. canonical mode)
53 */
54export function serializeToJSObject(
55 serializable: gdSerializable,
56 methodName: string = 'serializeTo',
57 options: ?SerializationOptions = undefined
58): any {
59 return withSerializationOptions(options, () => {
60 const serializedElement = new gd.SerializerElement();
61 serializable[methodName](serializedElement);
62
63 // JSON.parse + toJSON is 30% faster than gd.Serializer.toJSObject.
64 const json = gd.Serializer.toJSON(serializedElement);
65
66 try {
67 const object = JSON.parse(json);
68
69 serializedElement.delete();
70 return object;
71 } catch (error) {
72 serializedElement.delete();
73 console.error(
74 'Invalid JSON when serializing to JS object. toJSON should always return a valid JSON string.',
75 { json, error }
76 );
77 throw error;
78 }
79 });
80}
81
82export function serializeObjectWithCleanDefaultBehaviorFlags(
83 object: gdObject

Callers 15

index.jsFile · 0.90
ClipboardKind.jsFile · 0.90
getHistoryInitialStateFunction · 0.90
saveToHistoryFunction · 0.90
copyMethod · 0.90
copyMethod · 0.90
copyMethod · 0.90
VariablesList.jsFile · 0.90
serializeNamedPropertyFunction · 0.90
makeGenericFailureFunction · 0.90

Calls 5

withSerializationOptionsFunction · 0.85
toJSONMethod · 0.65
deleteMethod · 0.65
errorMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected