pub struct Ssr<'s, 'i> { /* private fields */ }Expand description
This struct holds all the necessary v8 utilities to execute Javascript code. It cannot be shared across threads.
Implementations§
Source§impl<'s, 'i> Ssr<'s, 'i>where
's: 'i,
impl<'s, 'i> Ssr<'s, 'i>where
's: 'i,
Sourcepub fn create_platform()
pub fn create_platform()
Initialize a V8 js engine instance. It’s mandatory to call it before any call to V8. The Ssr module needs this function call before any other operation. It cannot be called more than once per process.
Sourcepub fn from(source: String, entry_point: &str) -> Result<Ssr<'s, 'i>, SsrError>
pub fn from(source: String, entry_point: &str) -> Result<Ssr<'s, 'i>, SsrError>
It creates a new SSR instance (multiple instances are allowed).
This function is expensive and it should be called as less as possible.
Even though V8 allows multiple threads the Ssr struct created with this call can be accessed by just the thread that created it.
Entry point is the JS element that the bundler exposes. It has to be an empty string in case the bundle is exported as IIFE.
Check the examples vite-react (for the IIFE example) and webpack-react (for the bundle exported as variable).
See the examples folder for more about using multiple parallel instances for multi-threaded execution.
Sourcepub fn add_global_fn(
&self,
name: &'static str,
callback: impl MapFnTo<extern "C" fn(_: *const FunctionCallbackInfo)>,
) -> Result<(), SsrError>
pub fn add_global_fn( &self, name: &'static str, callback: impl MapFnTo<extern "C" fn(_: *const FunctionCallbackInfo)>, ) -> Result<(), SsrError>
Add a global function to the V8 runtime. Any function defined here can be executed within any js scope