#406 closed task (fixed)
Serialization of standard JS object types
Reported by: | Philip Taylor | Owned by: | historic_bruno |
---|---|---|---|
Priority: | Nice to Have | Milestone: | Alpha 14 |
Component: | UI & Simulation | Keywords: | |
Cc: | Patch: |
Description
To avoid unnecessarily restricting script code, it should be possible for script components to use new Number(42)
, new String("foo")
, etc, and have them correctly (de)serialized with no information loss. MDC has a list of the standard classes, and the simple common ones should be supported.
The code for this is currently in CBinarySerializer::HandleScriptVal
Change History (6)
comment:1 by , 14 years ago
Milestone: | Unclassified |
---|
comment:2 by , 14 years ago
Milestone: | → Backlog |
---|
comment:3 by , 11 years ago
Owner: | changed from | to
---|
comment:4 by , 11 years ago
My current idea for implementing this is to call JS_GetClass on objects in the serializer, then check the returned class name string for e.g. "Object", "Number", "String". The primitive value for special classes can be retrieved by calling valueOf()
or the way I"m testing which is using JS_ValueTo...
directly on the object itself. It's straightforward to reconstruct the objects in the deserializer using JS_New with the appropriate constructor and passing in the (de)serialized primitive value.
I'd be interested to know if there's a better/more efficient way of checking for standard classes than testing the class name strings. Otherwise, I have a WIP patch that fixes this for Number, String, and Boolean - which I think are the only important ones needing serialization support (other types will be easy to add though).
Typed arrays are a case not mentioned in this ticket, and require some special handling, but it's not too difficult once you discover the "hidden" API for them. They will also be supported in the patch, both raw buffer objects and arbitrary "data views" should work.
comment:6 by , 11 years ago
Milestone: | Backlog → Alpha 14 |
---|
Milestone Unclassified deleted