From 3062039ffe5563cab1f80b2d7da2d9c7e468c462 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sun, 10 Jun 2018 04:55:31 +0200 Subject: First pass at libdeno. --- deno2/BUILD.gn | 24 ++++++++++++---------- deno2/deno.cc | 2 +- deno2/deno.h | 51 ----------------------------------------------- deno2/deno_test.cc | 2 +- deno2/include/deno.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++ deno2/main.cc | 2 +- deno2/snapshot_creator.cc | 2 +- deno2/tools/lint.sh | 2 +- 8 files changed, 70 insertions(+), 66 deletions(-) delete mode 100644 deno2/deno.h create mode 100644 deno2/include/deno.h diff --git a/deno2/BUILD.gn b/deno2/BUILD.gn index 777a29902..e044b29a0 100644 --- a/deno2/BUILD.gn +++ b/deno2/BUILD.gn @@ -88,31 +88,34 @@ create_snapshot("deno") { v8_executable("snapshot_creator") { sources = [ - "deno.cc", - "deno.h", "snapshot_creator.cc", ] configs = [ "v8:libplatform_config" ] deps = [ - "v8:v8", - "v8:v8_libbase", - "v8:v8_libplatform", - "v8:v8_libsampler", - "//build/config:exe_and_shlib_deps", - "//build/win:default_exe_manifest", + ":libdeno", ] } v8_executable("deno") { sources = [ - "deno.cc", - "deno.h", "main.cc", ] include_dirs = [ target_gen_dir ] configs = [ "v8:libplatform_config" ] deps = [ ":create_snapshot_deno", + ":libdeno", + ] +} + +v8_component("libdeno") { + sources = [ + "deno.cc", + "include/deno.h", + ] + include_dirs = [ "include/" ] + configs = [ "v8:libplatform_config" ] + deps = [ ":msg_proto", "v8:v8", "v8:v8_libbase", @@ -129,6 +132,7 @@ executable("deno_test") { "deno_test.cc", ] deps = [ + ":libdeno", "//testing/gtest:gtest", ] } diff --git a/deno2/deno.cc b/deno2/deno.cc index bf5dcc89f..4618b5480 100644 --- a/deno2/deno.cc +++ b/deno2/deno.cc @@ -28,7 +28,7 @@ IN THE SOFTWARE. #include "v8/include/libplatform/libplatform.h" #include "v8/include/v8.h" -#include "./deno.h" +#include "include/deno.h" #define CHECK(x) assert(x) // TODO(ry) use V8's CHECK. diff --git a/deno2/deno.h b/deno2/deno.h deleted file mode 100644 index 007c70884..000000000 --- a/deno2/deno.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2018 Ryan Dahl -// All rights reserved. MIT License. -#ifndef DENO_H_ -#define DENO_H_ - -#include -#include "v8/include/v8.h" - -namespace deno { - -// Data that gets transmitted. -struct buf_s { - void* data; - size_t len; -}; -typedef struct buf_s DenoBuf; - -struct deno_s; -typedef struct deno_s Deno; - -// The callback from V8 when data is sent. -typedef DenoBuf (*RecvCallback)(Deno* d, DenoBuf buf); - -void v8_init(); -const char* v8_version(); -void v8_set_flags(int* argc, char** argv); - -// Constructors: -Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb); - -v8::StartupData make_snapshot(v8::StartupData* prev_natives_blob, - v8::StartupData* prev_snapshot_blob, - const char* js_filename, const char* js_source); - -void* deno_get_data(); - -// Returns nonzero on error. -// Get error text with deno_last_exception(). -int deno_load(Deno* d, const char* name_s, const char* source_s); - -// Returns nonzero on error. -int deno_send(Deno* d, DenoBuf buf); - -const char* deno_last_exception(Deno* d); - -void deno_dispose(Deno* d); -void deno_terminate_execution(Deno* d); - -} // namespace deno - -#endif // DENO_H_ diff --git a/deno2/deno_test.cc b/deno2/deno_test.cc index 3656e1d1f..4d3d20d94 100644 --- a/deno2/deno_test.cc +++ b/deno2/deno_test.cc @@ -2,7 +2,7 @@ // All rights reserved. MIT License. #include "testing/gtest/include/gtest/gtest.h" -#include "./deno.h" +#include "include/deno.h" TEST(SnapshotTest, InitializesCorrectly) { EXPECT_TRUE(true); diff --git a/deno2/include/deno.h b/deno2/include/deno.h new file mode 100644 index 000000000..9c6a22d2e --- /dev/null +++ b/deno2/include/deno.h @@ -0,0 +1,51 @@ +// Copyright 2018 Ryan Dahl +// All rights reserved. MIT License. +#ifndef INCLUDE_DENO_H_ +#define INCLUDE_DENO_H_ + +#include +#include "v8/include/v8.h" + +namespace deno { + +// Data that gets transmitted. +struct buf_s { + void* data; + size_t len; +}; +typedef struct buf_s DenoBuf; + +struct deno_s; +typedef struct deno_s Deno; + +// The callback from V8 when data is sent. +typedef DenoBuf (*RecvCallback)(Deno* d, DenoBuf buf); + +void v8_init(); +const char* v8_version(); +void v8_set_flags(int* argc, char** argv); + +// Constructors: +Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb); + +v8::StartupData make_snapshot(v8::StartupData* prev_natives_blob, + v8::StartupData* prev_snapshot_blob, + const char* js_filename, const char* js_source); + +void* deno_get_data(); + +// Returns nonzero on error. +// Get error text with deno_last_exception(). +int deno_load(Deno* d, const char* name_s, const char* source_s); + +// Returns nonzero on error. +int deno_send(Deno* d, DenoBuf buf); + +const char* deno_last_exception(Deno* d); + +void deno_dispose(Deno* d); +void deno_terminate_execution(Deno* d); + +} // namespace deno + +#endif // INCLUDE_DENO_H_ diff --git a/deno2/main.cc b/deno2/main.cc index 5d8263d28..5139e01be 100644 --- a/deno2/main.cc +++ b/deno2/main.cc @@ -5,7 +5,7 @@ #include "v8/include/v8.h" -#include "./deno.h" +#include "include/deno.h" #include "natives_deno.cc" #include "snapshot_deno.cc" diff --git a/deno2/snapshot_creator.cc b/deno2/snapshot_creator.cc index 9ecfff11c..f1bbfb0ed 100644 --- a/deno2/snapshot_creator.cc +++ b/deno2/snapshot_creator.cc @@ -9,7 +9,7 @@ #include "v8/include/v8.h" -#include "./deno.h" +#include "include/deno.h" class StartupDataCppWriter { public: diff --git a/deno2/tools/lint.sh b/deno2/tools/lint.sh index c307d67d0..ed7831e29 100755 --- a/deno2/tools/lint.sh +++ b/deno2/tools/lint.sh @@ -1,4 +1,4 @@ #!/bin/sh cd `dirname "$0"`/.. set -e -v -cpplint --repository=. *.cc *.h +cpplint --repository=. *.cc *.h include/*.h -- cgit v1.2.3