diff options
author | Faris Amali Alis <faris@starchild.my> | 2018-07-13 03:06:36 +0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-07-12 15:06:36 -0400 |
commit | 7e5f0a7a663de3fea0520e40a65872f7704ea262 (patch) | |
tree | 9896b437b017e78592abeee914b1f24790d42bcd /src | |
parent | 791357115c0aa1e4f87f70c57327bc66928b5019 (diff) |
Add nosnapshot executables for faster incremental builds (#359)
Fixes #311.
Diffstat (limited to 'src')
-rw-r--r-- | src/from_filesystem.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/from_filesystem.cc b/src/from_filesystem.cc new file mode 100644 index 000000000..b8854c6ff --- /dev/null +++ b/src/from_filesystem.cc @@ -0,0 +1,51 @@ +// Copyright 2018 Ryan Dahl <ry@tinyclouds.org> +// All rights reserved. MIT License. +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <string> + +#include "third_party/v8/include/v8.h" +#include "third_party/v8/src/base/logging.h" + +#include "deno.h" +#include "file_util.h" +#include "internal.h" + +namespace deno { + +Deno* NewFromFileSystem(void* data, deno_recv_cb cb) { + printf("Reading javascript runtime bundle from " BUNDLE_LOCATION "\n"); + + std::string js_source; + CHECK(deno::ReadFileToString(BUNDLE_LOCATION, &js_source)); + + Deno* d = new Deno; + d->currentArgs = nullptr; + d->cb = cb; + d->data = data; + v8::Isolate::CreateParams params; + params.array_buffer_allocator = + v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + v8::Isolate* isolate = v8::Isolate::New(params); + AddIsolate(d, isolate); + + v8::Locker locker(isolate); + v8::Isolate::Scope isolate_scope(isolate); + { + v8::HandleScope handle_scope(isolate); + auto context = v8::Context::New(isolate); + InitializeContext(isolate, context, BUNDLE_LOCATION, js_source.c_str()); + d->context.Reset(d->isolate, context); + } + + return d; +} + +} // namespace deno + +extern "C" { +Deno* deno_new(void* data, deno_recv_cb cb) { + return deno::NewFromFileSystem(data, cb); +} +} |