#407 closed task (fixed)
Serialization of script class objects
Reported by: | Philip Taylor | Owned by: | historic_bruno |
---|---|---|---|
Priority: | Nice to Have | Milestone: | Alpha 14 |
Component: | UI & Simulation | Keywords: | |
Cc: | Patch: |
Description
It should be possible for scripts to create and use classes (function Thing(x) { this.x = x; }; Thing.prototype.foo = ...; y = new Thing(1);
etc), and have them correctly (de)serialized.
This is probably infeasible in the general case, but it would be useful to support the simple case: classes are defined as top-level functions (not defined or changed at run-time inside other functions), no prototype chains, etc, so the code can simply serialize the object like a plain Object plus a class name that gets looked up in the appropriate script's scope when deserializing.
Change History (7)
comment:1 by , 14 years ago
Type: | defect → task |
---|
comment:2 by , 14 years ago
Milestone: | Unclassified |
---|
comment:3 by , 14 years ago
Milestone: | → Backlog |
---|
comment:4 by , 11 years ago
Owner: | changed from | to
---|
comment:5 by , 11 years ago
Current idea is to have the script that defines the constructor/prototype call a new function Engine.RegisterSerializablePrototype("Thing", Thing.prototype)
which stores the name string and JSObject*
associated with the prototype in a std::map
or something. It is required that both the name and prototype be unique and only registered once (AIs have several script contexts, and each one might have an identically named but slightly different prototype definition).
The serializer uses the prototypes map to find if an arbitrary object's prototype matches a registered one, if so it gets marked as a class type object, the prototype name is stored, then its properties are enumerated like any other object. On deserialization, the reverse happens: it looks up the name and finds the prototype JSObject*
which is passed to JS_NewObject, then its properties are restored - though not preserving the original prototype chain.
comment:7 by , 11 years ago
Milestone: | Backlog → Alpha 14 |
---|
Milestone Unclassified deleted