2018-07-23 14:46:30 -04:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-07-06 03:19:19 -04:00
|
|
|
#ifndef DENO_H_
|
|
|
|
#define DENO_H_
|
2018-07-06 15:00:45 -04:00
|
|
|
#include <stddef.h>
|
2018-07-08 21:35:34 -04:00
|
|
|
#include <stdint.h>
|
2018-06-10 08:18:15 -04:00
|
|
|
// Neither Rust nor Go support calling directly into C++ functions, therefore
|
|
|
|
// the public interface to libdeno is done in C.
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2018-06-09 20:24:34 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
// Data that gets transmitted.
|
2018-06-10 08:18:15 -04:00
|
|
|
typedef struct {
|
2018-07-08 21:35:34 -04:00
|
|
|
uint8_t* alloc_ptr; // Start of memory allocation (returned from `malloc()`).
|
|
|
|
size_t alloc_len; // Length of the memory allocation.
|
|
|
|
uint8_t* data_ptr; // Start of logical contents (within the allocation).
|
|
|
|
size_t data_len; // Length of logical contents.
|
2018-06-10 08:18:15 -04:00
|
|
|
} deno_buf;
|
2018-06-09 21:44:56 -04:00
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
typedef struct deno_s Deno;
|
2018-06-09 21:44:56 -04:00
|
|
|
|
2018-09-27 17:33:10 -04:00
|
|
|
// A callback to receive a message from a libdeno.send() javascript call.
|
|
|
|
// control_buf is valid for only for the lifetime of this callback.
|
|
|
|
// data_buf is valid until deno_respond() is called.
|
2018-10-08 05:04:33 -04:00
|
|
|
typedef void (*deno_recv_cb)(void* user_data, int32_t req_id,
|
|
|
|
deno_buf control_buf, deno_buf data_buf);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-06-10 08:18:15 -04:00
|
|
|
void deno_init();
|
2018-06-10 08:34:59 -04:00
|
|
|
const char* deno_v8_version();
|
2018-09-22 08:47:44 -04:00
|
|
|
void deno_set_v8_flags(int* argc, char** argv);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-12-04 18:06:20 -05:00
|
|
|
typedef struct {
|
2018-12-13 16:25:42 -05:00
|
|
|
int will_snapshot; // Default 0. If calling deno_get_snapshot 1.
|
|
|
|
deno_buf load_snapshot; // Optionally: A deno_buf from deno_get_snapshot.
|
|
|
|
deno_buf shared; // Shared buffer to be mapped to libdeno.shared
|
|
|
|
deno_recv_cb recv_cb; // Maps to libdeno.send() calls.
|
2018-12-04 18:06:20 -05:00
|
|
|
} deno_config;
|
|
|
|
|
2018-12-17 20:05:18 -05:00
|
|
|
// Create a new deno isolate.
|
|
|
|
// Warning: If config.will_snapshot is set, deno_get_snapshot() must be called
|
|
|
|
// or an error will result.
|
2018-12-13 16:25:42 -05:00
|
|
|
Deno* deno_new(deno_config config);
|
2018-10-24 01:12:13 -04:00
|
|
|
|
2018-12-03 14:22:26 -05:00
|
|
|
// Generate a snapshot. The resulting buf can be used with deno_new.
|
|
|
|
// The caller must free the returned data by calling delete[] buf.data_ptr.
|
2018-10-24 01:12:13 -04:00
|
|
|
deno_buf deno_get_snapshot(Deno* d);
|
|
|
|
|
2018-06-11 16:36:14 -04:00
|
|
|
void deno_delete(Deno* d);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-06-11 11:01:35 -04:00
|
|
|
// Returns false on error.
|
2018-06-09 18:32:04 -04:00
|
|
|
// Get error text with deno_last_exception().
|
2018-06-15 09:12:32 -04:00
|
|
|
// 0 = fail, 1 = success
|
2018-12-06 23:05:36 -05:00
|
|
|
//
|
|
|
|
// TODO change return value to be const char*. On success the return
|
|
|
|
// value is nullptr, on failure it is the JSON exception text that
|
|
|
|
// is returned by deno_last_exception(). Remove deno_last_exception().
|
|
|
|
// The return string is valid until the next execution of deno_execute or
|
|
|
|
// deno_respond (as deno_last_exception is now).
|
2018-10-07 17:48:06 -04:00
|
|
|
int deno_execute(Deno* d, void* user_data, const char* js_filename,
|
|
|
|
const char* js_source);
|
2018-06-09 18:32:04 -04:00
|
|
|
|
2018-09-27 17:33:10 -04:00
|
|
|
// deno_respond sends up to one message back for every deno_recv_cb made.
|
|
|
|
//
|
|
|
|
// If this is called during deno_recv_cb, the issuing libdeno.send() in
|
|
|
|
// javascript will synchronously return the specified buf as an ArrayBuffer (or
|
|
|
|
// null if buf is empty).
|
|
|
|
//
|
|
|
|
// If this is called after deno_recv_cb has returned, the deno_respond
|
|
|
|
// will call into the JS callback specified by libdeno.recv().
|
|
|
|
//
|
|
|
|
// (Ideally, but not currently: After calling deno_respond(), the caller no
|
|
|
|
// longer owns `buf` and must not use it; deno_respond() is responsible for
|
|
|
|
// releasing its memory.)
|
|
|
|
//
|
|
|
|
// Calling this function more than once with the same req_id will result in
|
|
|
|
// an error.
|
|
|
|
//
|
|
|
|
// A non-zero return value, means a JS exception was encountered during the
|
|
|
|
// libdeno.recv() callback. Check deno_last_exception() for exception text.
|
2018-12-06 23:05:36 -05:00
|
|
|
//
|
|
|
|
// TODO change return value to be const char*. On success the return
|
|
|
|
// value is nullptr, on failure it is the JSON exception text that
|
|
|
|
// is returned by deno_last_exception(). Remove deno_last_exception().
|
|
|
|
// The return string is valid until the next execution of deno_execute or
|
|
|
|
// deno_respond (as deno_last_exception is now).
|
2018-10-07 17:48:06 -04:00
|
|
|
int deno_respond(Deno* d, void* user_data, int32_t req_id, deno_buf buf);
|
2018-06-13 13:38:22 -04:00
|
|
|
|
2018-10-12 14:22:52 -04:00
|
|
|
void deno_check_promise_errors(Deno* d);
|
|
|
|
|
2018-06-09 18:32:04 -04:00
|
|
|
const char* deno_last_exception(Deno* d);
|
|
|
|
|
|
|
|
void deno_terminate_execution(Deno* d);
|
|
|
|
|
2018-06-10 08:18:15 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
2018-07-06 03:19:19 -04:00
|
|
|
#endif // DENO_H_
|