Commit 257f036
Add ISerialization interface (#52624)
Summary:
Pull Request resolved: #52624
Add a new optional interface `ISerialization` to JSI. This interface
contains four APIs to clone objects from one runtime to another runtime.
Four methods are introduced in this interface:
* `serialize`: Takes in a JS value (represented by `jsi::Value`) and
serialize the value into an opaque `Serialized` object.
* `deserialize`: Takes in the `Serialized` object created by `serialize`
and deserialize it into the runtime, returning the created JS value.
* `serializeWithTransfer`: Takes in a JS value (represented by
`jsi::Value`) and a `transferList` (a `jsi::Array` of `jsi::Value`s).
This will serialize the `value` into an opaque `Serialize` object and
transfer the ownership of everything in `transferList` into the
`Serialized` object. If any non-transferable values is passed into the
transferList, this will throw. This `Serialized` object must only be
deserialized once.
* `deserializeWithTransfer`: Takes in the `Serialized` object created by
`serializeWithTransfer`. It will deserialize the object into the runtime
and any value owned by the `Serialized` object will now be owned by the
current runtime. It will return an `jsi::Array` where the first value is
the deserialized value passed into `serializeWithTransfer`, followed by
all transferred values.
The lifetime of the `Serialized` object created from the APIs is
independent of the original object and runtime.
Note that objects can only be copied into another runtime instance of
the same type. For example, a serialized object produced by the Hermes
runtime can only be deserialized by another Hermes runtime.
Changelog: [Internal]
Reviewed By: dannysu, fbmal7
Differential Revision: D76547681
fbshipit-source-id: 0c774f3f469c26d3894cac179f4ce5e32cf5ad7f1 parent 064a385 commit 257f036
2 files changed
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
287 | 291 | | |
288 | 292 | | |
289 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
260 | 326 | | |
261 | 327 | | |
262 | 328 | | |
| |||
0 commit comments