diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-10-24 01:12:13 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-24 14:52:38 -0700 |
commit | 61cda728816b5916180f22d977ba741e2fadc8d9 (patch) | |
tree | 99e77029d5f3ffafff7c8ca0136169abcdaf8f7f /libdeno/api.cc | |
parent | 6afe94b3c855a8c486ce2a593cf2f8cac3b4d711 (diff) |
libdeno: Expose snapshot creation.
Diffstat (limited to 'libdeno/api.cc')
-rw-r--r-- | libdeno/api.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libdeno/api.cc b/libdeno/api.cc index e01f95e82..512252737 100644 --- a/libdeno/api.cc +++ b/libdeno/api.cc @@ -42,10 +42,39 @@ Deno* deno_new(deno_buf snapshot, deno_recv_cb cb) { return reinterpret_cast<Deno*>(d); } +Deno* deno_new_snapshotter(deno_recv_cb cb, const char* js_filename, + const char* js_source, const char* source_map) { + auto* creator = new v8::SnapshotCreator(deno::external_references); + auto* isolate = creator->GetIsolate(); + auto* d = new deno::DenoIsolate(deno::empty_buf, cb); + d->snapshot_creator_ = creator; + d->AddIsolate(isolate); + v8::Isolate::Scope isolate_scope(isolate); + { + v8::HandleScope handle_scope(isolate); + auto context = v8::Context::New(isolate); + creator->SetDefaultContext(context, + v8::SerializeInternalFieldsCallback( + deno::SerializeInternalFields, nullptr)); + deno::InitializeContext(isolate, context, js_filename, js_source, + source_map); + } + return reinterpret_cast<Deno*>(d); +} + deno::DenoIsolate* unwrap(Deno* d_) { return reinterpret_cast<deno::DenoIsolate*>(d_); } +deno_buf deno_get_snapshot(Deno* d_) { + auto* d = unwrap(d_); + CHECK_NE(d->snapshot_creator_, nullptr); + auto blob = d->snapshot_creator_->CreateBlob( + v8::SnapshotCreator::FunctionCodeHandling::kClear); + return {nullptr, 0, reinterpret_cast<uint8_t*>(const_cast<char*>(blob.data)), + blob.raw_size}; +} + void deno_init() { // v8::V8::InitializeICUDefaultLocation(argv[0]); // v8::V8::InitializeExternalStartupData(argv[0]); |