diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-01-30 17:21:31 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 17:21:31 -0500 |
commit | 00597ffde1ebb05a6c60ea7e09e6578c11f92820 (patch) | |
tree | 849b6b22c07ed38a4b424c363c06435ea2de4fa9 /libdeno/deno.h | |
parent | 7d278a0383ce634f4fa3dd792e9b202582a6fde1 (diff) |
Refactor libdeno ES module interface. (#1624)
Allows for future asynchronous module loading.
Add support for import.meta.url
Fixes #1496
Diffstat (limited to 'libdeno/deno.h')
-rw-r--r-- | libdeno/deno.h | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/libdeno/deno.h b/libdeno/deno.h index 7568002ae..42df80825 100644 --- a/libdeno/deno.h +++ b/libdeno/deno.h @@ -25,26 +25,15 @@ typedef struct deno_s Deno; typedef void (*deno_recv_cb)(void* user_data, int32_t req_id, deno_buf control_buf, deno_buf data_buf); -// A callback to implement ES Module imports. User must call deno_resolve_ok() -// at most once during deno_resolve_cb. If deno_resolve_ok() is not called, the -// specifier is considered invalid and will issue an error in JS. The reason -// deno_resolve_cb does not return deno_module is to avoid unnecessary heap -// allocations. -typedef void (*deno_resolve_cb)(void* user_data, const char* specifier, - const char* referrer); - -void deno_resolve_ok(Deno* d, const char* filename, const char* source); - void deno_init(); const char* deno_v8_version(); void deno_set_v8_flags(int* argc, char** argv); typedef struct { - 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. - deno_resolve_cb resolve_cb; // Each import calls this. + 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. } deno_config; // Create a new deno isolate. @@ -65,16 +54,6 @@ void deno_delete(Deno* d); int deno_execute(Deno* d, void* user_data, const char* js_filename, const char* js_source); -// Compile and execute an ES module. Caller must have provided a deno_resolve_cb -// when instantiating the Deno object. -// Return value: 0 = fail, 1 = success -// Get error text with deno_last_exception(). -// If resolve_only is 0, compile and evaluate the module. -// If resolve_only is 1, compile and collect dependencies of the module -// without running the code. -int deno_execute_mod(Deno* d, void* user_data, const char* js_filename, - const char* js_source, int resolve_only); - // 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 @@ -101,6 +80,26 @@ const char* deno_last_exception(Deno* d); void deno_terminate_execution(Deno* d); +// Module API + +typedef int deno_mod; + +// Returns zero on error - check deno_last_exception(). +deno_mod deno_mod_new(Deno* d, const char* name, const char* source); + +size_t deno_mod_imports_len(Deno* d, deno_mod id); + +// Returned pointer is valid for the lifetime of the Deno isolate "d". +const char* deno_mod_imports_get(Deno* d, deno_mod id, size_t index); + +typedef deno_mod (*deno_resolve_cb)(void* user_data, const char* specifier, + deno_mod referrer); + +void deno_mod_instantiate(Deno* d, void* user_data, deno_mod id, + deno_resolve_cb cb); + +void deno_mod_evaluate(Deno* d, void* user_data, deno_mod id); + #ifdef __cplusplus } // extern "C" #endif |