summaryrefslogtreecommitdiff
path: root/libdeno/internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'libdeno/internal.h')
-rw-r--r--libdeno/internal.h46
1 files changed, 32 insertions, 14 deletions
diff --git a/libdeno/internal.h b/libdeno/internal.h
index 58dae013c..022fd8f1e 100644
--- a/libdeno/internal.h
+++ b/libdeno/internal.h
@@ -5,12 +5,25 @@
#include <map>
#include <string>
#include <utility>
+#include <vector>
#include "deno.h"
#include "third_party/v8/include/v8.h"
#include "third_party/v8/src/base/logging.h"
namespace deno {
+struct ModuleInfo {
+ std::string name;
+ v8::Persistent<v8::Module> handle;
+ std::vector<std::string> import_specifiers;
+
+ ModuleInfo(v8::Isolate* isolate, v8::Local<v8::Module> module,
+ const char* name_, std::vector<std::string> import_specifiers_)
+ : name(name_), import_specifiers(import_specifiers_) {
+ handle.Reset(isolate, module);
+ }
+};
+
// deno_s = Wrapped Isolate.
class DenoIsolate {
public:
@@ -21,9 +34,9 @@ class DenoIsolate {
snapshot_creator_(nullptr),
global_import_buf_ptr_(nullptr),
recv_cb_(config.recv_cb),
- resolve_cb_(config.resolve_cb),
next_req_id_(0),
- user_data_(nullptr) {
+ user_data_(nullptr),
+ resolve_cb_(nullptr) {
array_buffer_allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
if (config.load_snapshot.data_ptr) {
snapshot_.data =
@@ -46,11 +59,22 @@ class DenoIsolate {
}
void AddIsolate(v8::Isolate* isolate);
- void RegisterModule(const char* filename, v8::Local<v8::Module> module);
- void ResolveOk(const char* filename, const char* source);
- void ClearModules();
+ deno_mod RegisterModule(const char* name, const char* source);
v8::Local<v8::Object> GetBuiltinModules();
+ void ClearModules();
+
+ ModuleInfo* GetModuleInfo(deno_mod id) {
+ if (id == 0) {
+ return nullptr;
+ }
+ auto it = mods_.find(id);
+ if (it != mods_.end()) {
+ return &it->second;
+ } else {
+ return nullptr;
+ }
+ }
v8::Isolate* isolate_;
v8::ArrayBuffer::Allocator* array_buffer_allocator_;
@@ -59,19 +83,13 @@ class DenoIsolate {
v8::SnapshotCreator* snapshot_creator_;
void* global_import_buf_ptr_;
deno_recv_cb recv_cb_;
- deno_resolve_cb resolve_cb_;
int32_t next_req_id_;
void* user_data_;
- // identity hash -> filename, module (avoid hash collision)
- std::multimap<int, std::pair<std::string, v8::Persistent<v8::Module>>>
- module_info_map_;
- // filename -> Module
- std::map<std::string, v8::Persistent<v8::Module>> module_map_;
- // Set by deno_resolve_ok
- v8::Persistent<v8::Module> resolve_module_;
-
v8::Persistent<v8::Object> builtin_modules_;
+ std::map<deno_mod, ModuleInfo> mods_;
+ std::map<std::string, deno_mod> mods_by_name_;
+ deno_resolve_cb resolve_cb_;
v8::Persistent<v8::Context> context_;
std::map<int32_t, v8::Persistent<v8::Value>> async_data_map_;