diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2019-03-30 14:45:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-30 14:45:36 -0400 |
commit | c9614d86c190b98bd8f0df9e17272387c3bad1d5 (patch) | |
tree | 68d9054cabb8a829beac72024d48c37f0fce7321 /core/libdeno/snapshot_creator.cc | |
parent | ad3cbc50fb255f287a890a28f158f6842d335538 (diff) |
Move //libdeno to //core/libdeno (#2015)
Fixes some sed errors introduced in c43cfe.
Unfortunately moving libdeno required splitting build.rs into two parts,
one for cli and one for core.
I've also removed the arm64 build - it's complicating things at this
re-org and we're not even testing it. I need to swing back to it and get
tools/test.py running for it.
Diffstat (limited to 'core/libdeno/snapshot_creator.cc')
-rw-r--r-- | core/libdeno/snapshot_creator.cc | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/core/libdeno/snapshot_creator.cc b/core/libdeno/snapshot_creator.cc new file mode 100644 index 000000000..19098392d --- /dev/null +++ b/core/libdeno/snapshot_creator.cc @@ -0,0 +1,47 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +// Hint: --trace_serializer is a useful debugging flag. +#include <fstream> +#include <iostream> +#include "deno.h" +#include "file_util.h" +#include "internal.h" +#include "third_party/v8/include/v8.h" +#include "third_party/v8/src/base/logging.h" + +namespace deno {} // namespace deno + +int main(int argc, char** argv) { + const char* snapshot_out_bin = argv[1]; + const char* js_fn = argv[2]; + + deno_set_v8_flags(&argc, argv); + + CHECK_NOT_NULL(js_fn); + CHECK_NOT_NULL(snapshot_out_bin); + + std::string js_source; + CHECK(deno::ReadFileToString(js_fn, &js_source)); + + deno_init(); + deno_config config = {1, deno::empty_buf, deno::empty_buf, nullptr}; + Deno* d = deno_new(config); + + deno_execute(d, nullptr, js_fn, js_source.c_str()); + if (deno_last_exception(d) != nullptr) { + std::cerr << "Snapshot Exception " << std::endl; + std::cerr << deno_last_exception(d) << std::endl; + deno_delete(d); + return 1; + } + + auto snapshot = deno_get_snapshot(d); + + std::ofstream file_(snapshot_out_bin, std::ios::binary); + file_.write(reinterpret_cast<char*>(snapshot.data_ptr), snapshot.data_len); + file_.close(); + + delete[] snapshot.data_ptr; + deno_delete(d); + + return file_.bad(); +} |