summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--deno2/BUILD.gn26
-rw-r--r--deno2/deno.cc39
-rw-r--r--deno2/deno_internal.h32
-rw-r--r--deno2/from_snapshot.cc50
-rw-r--r--deno2/include/deno.h2
-rw-r--r--deno2/main.cc18
6 files changed, 106 insertions, 61 deletions
diff --git a/deno2/BUILD.gn b/deno2/BUILD.gn
index e044b29a0..a7a414ad0 100644
--- a/deno2/BUILD.gn
+++ b/deno2/BUILD.gn
@@ -92,7 +92,7 @@ v8_executable("snapshot_creator") {
]
configs = [ "v8:libplatform_config" ]
deps = [
- ":libdeno",
+ ":deno_nosnapshot",
]
}
@@ -100,17 +100,23 @@ v8_executable("deno") {
sources = [
"main.cc",
]
- include_dirs = [ target_gen_dir ]
configs = [ "v8:libplatform_config" ]
deps = [
- ":create_snapshot_deno",
":libdeno",
]
}
v8_component("libdeno") {
+ configs = [ "v8:libplatform_config" ]
+ deps = [
+ ":deno_snapshot",
+ ]
+}
+
+v8_source_set("deno_nosnapshot") {
sources = [
"deno.cc",
+ "deno_internal.h",
"include/deno.h",
]
include_dirs = [ "include/" ]
@@ -121,11 +127,21 @@ v8_component("libdeno") {
"v8:v8_libbase",
"v8:v8_libplatform",
"v8:v8_libsampler",
- "//build/config:exe_and_shlib_deps",
- "//build/win:default_exe_manifest",
]
}
+v8_source_set("deno_snapshot") {
+ sources = [
+ "from_snapshot.cc",
+ ]
+ deps = [
+ ":create_snapshot_deno",
+ ":deno_nosnapshot",
+ ]
+ include_dirs = [ target_gen_dir ]
+ configs = [ "v8:libplatform_config" ]
+}
+
executable("deno_test") {
testonly = true
sources = [
diff --git a/deno2/deno.cc b/deno2/deno.cc
index 4618b5480..eb9b05a7f 100644
--- a/deno2/deno.cc
+++ b/deno2/deno.cc
@@ -28,24 +28,13 @@ IN THE SOFTWARE.
#include "v8/include/libplatform/libplatform.h"
#include "v8/include/v8.h"
+#include "deno_internal.h"
#include "include/deno.h"
#define CHECK(x) assert(x) // TODO(ry) use V8's CHECK.
namespace deno {
-// deno_s = Wrapped Isolate.
-struct deno_s {
- v8::Isolate* isolate;
- std::string last_exception;
- v8::Persistent<v8::Function> recv;
- v8::Persistent<v8::Context> context;
- RecvCallback cb;
- void* data;
-};
-
-void deno_add_isolate(Deno* d, v8::Isolate* isolate);
-
// Extracts a C string from a v8::V8 Utf8Value.
const char* ToCString(const v8::String::Utf8Value& value) {
return *value ? *value : "<string conversion failed>";
@@ -170,10 +159,6 @@ void Send(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
}
-intptr_t external_references[] = {reinterpret_cast<intptr_t>(Print),
- reinterpret_cast<intptr_t>(Recv),
- reinterpret_cast<intptr_t>(Send), 0};
-
const char* v8_version() { return v8::V8::GetVersion(); }
void v8_set_flags(int* argc, char** argv) {
@@ -261,28 +246,6 @@ void v8_init() {
v8::V8::Initialize();
}
-Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb) {
- Deno* d = new Deno;
- d->cb = cb;
- d->data = data;
- v8::Isolate::CreateParams params;
- params.snapshot_blob = blob;
- params.array_buffer_allocator =
- v8::ArrayBuffer::Allocator::NewDefaultAllocator();
- params.external_references = external_references;
- v8::Isolate* isolate = v8::Isolate::New(params);
- deno_add_isolate(d, isolate);
-
- v8::Isolate::Scope isolate_scope(isolate);
- {
- v8::HandleScope handle_scope(isolate);
- auto context = v8::Context::New(isolate);
- d->context.Reset(d->isolate, context);
- }
-
- return d;
-}
-
void deno_add_isolate(Deno* d, v8::Isolate* isolate) {
d->isolate = isolate;
// Leaving this code here because it will probably be useful later on, but
diff --git a/deno2/deno_internal.h b/deno2/deno_internal.h
new file mode 100644
index 000000000..d125f39b1
--- /dev/null
+++ b/deno2/deno_internal.h
@@ -0,0 +1,32 @@
+// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
+// All rights reserved. MIT License.
+#ifndef DENO_INTERNAL_H_
+#define DENO_INTERNAL_H_
+
+#include <string>
+#include "include/deno.h"
+#include "v8/include/v8.h"
+
+namespace deno {
+
+void Print(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Recv(const v8::FunctionCallbackInfo<v8::Value>& args);
+void Send(const v8::FunctionCallbackInfo<v8::Value>& args);
+static intptr_t external_references[] = {reinterpret_cast<intptr_t>(Print),
+ reinterpret_cast<intptr_t>(Recv),
+ reinterpret_cast<intptr_t>(Send), 0};
+
+// deno_s = Wrapped Isolate.
+struct deno_s {
+ v8::Isolate* isolate;
+ std::string last_exception;
+ v8::Persistent<v8::Function> recv;
+ v8::Persistent<v8::Context> context;
+ RecvCallback cb;
+ void* data;
+};
+
+void deno_add_isolate(Deno* d, v8::Isolate* isolate);
+
+} // namespace deno
+#endif // DENO_INTERNAL_H_
diff --git a/deno2/from_snapshot.cc b/deno2/from_snapshot.cc
new file mode 100644
index 000000000..b743b441f
--- /dev/null
+++ b/deno2/from_snapshot.cc
@@ -0,0 +1,50 @@
+// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
+// All rights reserved. MIT License.
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <string>
+
+#include "v8/include/libplatform/libplatform.h"
+#include "v8/include/v8.h"
+
+#include "./deno_internal.h"
+#include "include/deno.h"
+
+namespace deno {
+
+#include "natives_deno.cc"
+#include "snapshot_deno.cc"
+
+Deno* from_snapshot(void* data, RecvCallback cb) {
+ auto natives_blob = *StartupBlob_natives();
+ printf("natives_blob %d bytes\n", natives_blob.raw_size);
+
+ auto snapshot_blob = *StartupBlob_snapshot();
+ printf("snapshot_blob %d bytes\n", snapshot_blob.raw_size);
+
+ v8::V8::SetNativesDataBlob(&natives_blob);
+ v8::V8::SetSnapshotDataBlob(&snapshot_blob);
+
+ Deno* d = new Deno;
+ d->cb = cb;
+ d->data = data;
+ v8::Isolate::CreateParams params;
+ params.array_buffer_allocator =
+ v8::ArrayBuffer::Allocator::NewDefaultAllocator();
+ params.external_references = external_references;
+ v8::Isolate* isolate = v8::Isolate::New(params);
+ deno_add_isolate(d, isolate);
+
+ v8::Isolate::Scope isolate_scope(isolate);
+ {
+ v8::HandleScope handle_scope(isolate);
+ auto context = v8::Context::New(isolate);
+ d->context.Reset(d->isolate, context);
+ }
+
+ return d;
+}
+
+} // namespace deno
diff --git a/deno2/include/deno.h b/deno2/include/deno.h
index 9c6a22d2e..e5a25f240 100644
--- a/deno2/include/deno.h
+++ b/deno2/include/deno.h
@@ -26,7 +26,7 @@ const char* v8_version();
void v8_set_flags(int* argc, char** argv);
// Constructors:
-Deno* deno_from_snapshot(v8::StartupData* blob, void* data, RecvCallback cb);
+Deno* from_snapshot(void* data, RecvCallback cb);
v8::StartupData make_snapshot(v8::StartupData* prev_natives_blob,
v8::StartupData* prev_snapshot_blob,
diff --git a/deno2/main.cc b/deno2/main.cc
index 5139e01be..29aacc4e6 100644
--- a/deno2/main.cc
+++ b/deno2/main.cc
@@ -3,31 +3,15 @@
#include <assert.h>
#include <stdio.h>
-#include "v8/include/v8.h"
-
#include "include/deno.h"
-#include "natives_deno.cc"
-#include "snapshot_deno.cc"
int main(int argc, char** argv) {
deno::v8_init();
- auto natives_blob = *StartupBlob_natives();
- printf("natives_blob %d bytes\n", natives_blob.raw_size);
-
- auto snapshot_blob = *StartupBlob_snapshot();
- printf("snapshot_blob %d bytes\n", snapshot_blob.raw_size);
-
- v8::V8::SetNativesDataBlob(&natives_blob);
- v8::V8::SetSnapshotDataBlob(&snapshot_blob);
-
- deno::Deno* d = deno::deno_from_snapshot(&snapshot_blob, NULL, NULL);
+ deno::Deno* d = deno::from_snapshot(NULL, NULL);
int r = deno::deno_load(d, "main2.js", "foo();");
if (r != 0) {
printf("Error! %s\n", deno::deno_last_exception(d));
exit(1);
}
-
- const char* v = v8::V8::GetVersion();
- printf("Hello World. V8 version %s\n", v);
}