From ec65717c59082c98c93c0ce2ded265861e20b48d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Thu, 14 Jun 2018 00:55:40 +0200 Subject: [PATCH] Add ability to link to v8_libbase. --- deno2/BUILD.gn | 10 ++++++++++ deno2/deno.cc | 28 +++++++++++++--------------- deno2/main.cc | 4 ++-- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/deno2/BUILD.gn b/deno2/BUILD.gn index 564d8f8fb6..d90cd9de13 100644 --- a/deno2/BUILD.gn +++ b/deno2/BUILD.gn @@ -11,6 +11,7 @@ executable("deno") { ":msg_proto", "//third_party/protobuf:protoc_lib", ] + public_configs = [ ":public_v8_base_config" ] } executable("mock_runtime_test") { @@ -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") { diff --git a/deno2/deno.cc b/deno2/deno.cc index d59f490655..c344629b9f 100644 --- a/deno2/deno.cc +++ b/deno2/deno.cc @@ -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 #include #include #include #include +#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. @@ -92,7 +90,7 @@ void ExitOnPromiseRejectCallback( v8::PromiseRejectMessage promise_reject_message) { auto* isolate = v8::Isolate::GetCurrent(); Deno* d = static_cast(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); @@ -100,7 +98,7 @@ void ExitOnPromiseRejectCallback( } void Print(const v8::FunctionCallbackInfo& 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]); @@ -113,7 +111,7 @@ void Print(const v8::FunctionCallbackInfo& args) { void Sub(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); Deno* d = reinterpret_cast(isolate->GetData(0)); - assert(d->isolate == isolate); + DCHECK_EQ(d->isolate, isolate); v8::HandleScope handle_scope(isolate); @@ -123,7 +121,7 @@ void Sub(const v8::FunctionCallbackInfo& args) { } v8::Local v = args[0]; - assert(v->IsFunction()); + CHECK(v->IsFunction()); v8::Local func = v8::Local::Cast(v); d->sub.Reset(isolate, func); @@ -132,19 +130,19 @@ void Sub(const v8::FunctionCallbackInfo& args) { void Pub(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); Deno* d = static_cast(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 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 ab_v = args[1]; - assert(ab_v->IsArrayBuffer()); + CHECK(ab_v->IsArrayBuffer()); auto ab = v8::Local::Cast(ab_v); auto contents = ab->GetContents(); @@ -154,7 +152,7 @@ void Pub(const v8::FunctionCallbackInfo& args) { const_cast(reinterpret_cast(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); @@ -180,7 +178,7 @@ bool Execute(v8::Local 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; } @@ -188,7 +186,7 @@ bool Execute(v8::Local context, const char* js_filename, auto result = script.ToLocalChecked()->Run(context); if (result.IsEmpty()) { - assert(try_catch.HasCaught()); + DCHECK(try_catch.HasCaught()); HandleException(context, try_catch.Exception()); return false; } @@ -198,7 +196,7 @@ bool Execute(v8::Local context, const char* js_filename, v8::StartupData SerializeInternalFields(v8::Local 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( holder->GetAlignedPointerFromInternalField(index)); if (embedder_field == nullptr) return {nullptr, 0}; diff --git a/deno2/main.cc b/deno2/main.cc index 506469dfa1..37e2719519 100644 --- a/deno2/main.cc +++ b/deno2/main.cc @@ -1,11 +1,11 @@ // Copyright 2018 Ryan Dahl // All rights reserved. MIT License. -#include #include #include #include #include +#include "v8/src/base/logging.h" #include "./msg.pb.h" #include "include/deno.h" @@ -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);