Skip to content

Commit

Permalink
Add ability to link to v8_libbase.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Jun 14, 2018
1 parent 168cc75 commit ec65717
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
10 changes: 10 additions & 0 deletions deno2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ executable("deno") {
":msg_proto",
"//third_party/protobuf:protoc_lib",
]
public_configs = [ ":public_v8_base_config" ]
}

executable("mock_runtime_test") {
Expand Down Expand Up @@ -52,6 +53,15 @@ source_set("deno_nosnapshot") {
"v8:v8_libplatform",
"v8:v8_libsampler",
]
public_configs = [ ":public_v8_base_config" ]
}

# This allows us to v8/src/base/ libraries.
config("public_v8_base_config") {
include_dirs = [
"v8",
"$target_gen_dir/v8",
]
}

executable("snapshot_creator") {
Expand Down
28 changes: 13 additions & 15 deletions deno2/deno.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,18 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

#include "v8/src/base/logging.h"
#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 {

// Extracts a C string from a v8::V8 Utf8Value.
Expand Down Expand Up @@ -92,15 +90,15 @@ void ExitOnPromiseRejectCallback(
v8::PromiseRejectMessage promise_reject_message) {
auto* isolate = v8::Isolate::GetCurrent();
Deno* d = static_cast<Deno*>(isolate->GetData(0));
assert(d->isolate == isolate);
DCHECK_EQ(d->isolate, isolate);
v8::HandleScope handle_scope(d->isolate);
auto exception = promise_reject_message.GetValue();
auto context = d->context.Get(d->isolate);
HandleException(context, exception);
}

void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
assert(args.Length() == 1);
CHECK_EQ(args.Length(), 1);
auto* isolate = args.GetIsolate();
v8::HandleScope handle_scope(isolate);
v8::String::Utf8Value str(isolate, args[0]);
Expand All @@ -113,7 +111,7 @@ void Print(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Sub(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
Deno* d = reinterpret_cast<Deno*>(isolate->GetData(0));
assert(d->isolate == isolate);
DCHECK_EQ(d->isolate, isolate);

v8::HandleScope handle_scope(isolate);

Expand All @@ -123,7 +121,7 @@ void Sub(const v8::FunctionCallbackInfo<v8::Value>& args) {
}

v8::Local<v8::Value> v = args[0];
assert(v->IsFunction());
CHECK(v->IsFunction());
v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(v);

d->sub.Reset(isolate, func);
Expand All @@ -132,19 +130,19 @@ void Sub(const v8::FunctionCallbackInfo<v8::Value>& args) {
void Pub(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::Isolate* isolate = args.GetIsolate();
Deno* d = static_cast<Deno*>(isolate->GetData(0));
assert(d->isolate == isolate);
DCHECK_EQ(d->isolate, isolate);

v8::Locker locker(d->isolate);
v8::EscapableHandleScope handle_scope(isolate);

assert(args.Length() == 2);
CHECK_EQ(args.Length(), 2);
v8::Local<v8::Value> channel_v = args[0];
assert(channel_v->IsString());
CHECK(channel_v->IsString());
v8::String::Utf8Value channel_vstr(isolate, channel_v);
const char* channel = *channel_vstr;

v8::Local<v8::Value> ab_v = args[1];
assert(ab_v->IsArrayBuffer());
CHECK(ab_v->IsArrayBuffer());

auto ab = v8::Local<v8::ArrayBuffer>::Cast(ab_v);
auto contents = ab->GetContents();
Expand All @@ -154,7 +152,7 @@ void Pub(const v8::FunctionCallbackInfo<v8::Value>& args) {
const_cast<const char*>(reinterpret_cast<char*>(contents.Data()));
deno_buf buf{data, contents.ByteLength()};

assert(d->currentArgs == nullptr);
DCHECK_EQ(d->currentArgs, nullptr);
d->currentArgs = &args;

d->cb(d, channel, buf);
Expand All @@ -180,15 +178,15 @@ bool Execute(v8::Local<v8::Context> context, const char* js_filename,
auto script = v8::Script::Compile(context, source, &origin);

if (script.IsEmpty()) {
assert(try_catch.HasCaught());
DCHECK(try_catch.HasCaught());
HandleException(context, try_catch.Exception());
return false;
}

auto result = script.ToLocalChecked()->Run(context);

if (result.IsEmpty()) {
assert(try_catch.HasCaught());
DCHECK(try_catch.HasCaught());
HandleException(context, try_catch.Exception());
return false;
}
Expand All @@ -198,7 +196,7 @@ bool Execute(v8::Local<v8::Context> context, const char* js_filename,

v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, int index,
void* data) {
assert(data == nullptr); // TODO(ry) pass Deno* object here.
DCHECK_EQ(data, nullptr); // TODO(ry) pass Deno* object here.
InternalFieldData* embedder_field = static_cast<InternalFieldData*>(
holder->GetAlignedPointerFromInternalField(index));
if (embedder_field == nullptr) return {nullptr, 0};
Expand Down
4 changes: 2 additions & 2 deletions deno2/main.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2018 Ryan Dahl <[email protected]>
// All rights reserved. MIT License.
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string>

#include "v8/src/base/logging.h"
#include "./msg.pb.h"
#include "include/deno.h"

Expand All @@ -20,7 +20,7 @@ void MessagesFromJS(Deno* d, const char* channel, deno_buf buf) {
response.set_start_cwd(cwd);

std::string output;
assert(response.SerializeToString(&output) == true);
CHECK(response.SerializeToString(&output));

auto bufout = deno_buf{output.c_str(), output.length()};
deno_set_response(d, bufout);
Expand Down

0 comments on commit ec65717

Please sign in to comment.