HomePhabricator
Diffusion Comm eead12d31b69

[web] add `std::vector` (C++) <-> `Array` (JS) marshalling

Description

[web] add std::vector (C++) <-> Array (JS) marshalling

Summary:
Why it's .cpp file?

This code does not work when added to .h file (emscripten does not parse it then and has no reflection in generated module).

Why it's called SQLiteQueryExecutorBindings.cpp?
This code to work (for some reason) needs to be placed along with binding, in next diff I am adding SQLiteQueryExecutor bindings to this file.

Why this idea?
We can automate using JS array <-> std::vector marshalling. Without this will need to:

  • bind each vector type (for emscripten std::vector<int> and std::vector<std::string> are two different types.
  • passing data to .wasm module, we will have to create vector objects in JS, add data to it using put() method
  • parse data returned from .wasm module

This makes this process cleaner and easier for devs.

Inspiration
This issue: 11070

How it works?

  • It uses Template Specialization concept
  • it uses SFINAE to ensure it behaves properly for std::vector and ignores other types without an error

Sources:

Depends on D8551

Test Plan: Tested at the end of the stack - making sure that we can pass/retrieve array to .wasm module and works as a vector for both objects/classes and primitive variables as vector elements.

Reviewers: jon, michal, tomek

Reviewed By: michal, tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D8552

Details

Provenance
kamilAuthored on Jul 17 2023, 10:42 AM
Reviewer
michal
Differential Revision
D8552: [web] add `std::vector` (C++) <-> `Array` (JS) marshalling
Parents
rCOMM87e2ffdb590e: [native] overload `SQLiteQueryExecutor` constructor
Branches
Unknown
Tags
Unknown