From 7acbb85398eff84d7323ddedc2445e1cf2ced4d8 Mon Sep 17 00:00:00 2001 From: Ry Dahl Date: Wed, 18 Dec 2019 07:37:13 -0500 Subject: [PATCH] Move all cc code to binding.cc (#70) --- BUILD.gn | 22 +- src/V8.cc | 29 -- src/array_buffer.cc | 13 - src/binding.cc | 486 +++++++++++++++++++++++++++++++++ src/context.cc | 28 -- src/exception.cc | 42 --- src/function.cc | 55 ---- src/handle_scope.cc | 25 -- src/inspector/channel.cc | 58 ---- src/inspector/client.cc | 54 ---- src/inspector/string_buffer.cc | 17 -- src/isolate.cc | 45 --- src/json.cc | 14 - src/locker.cc | 15 - src/number.cc | 27 -- src/object.cc | 14 - src/platform/mod.cc | 20 -- src/platform/task.cc | 30 -- src/primitives.cc | 22 -- src/promise.cc | 57 ---- src/script.cc | 38 --- src/string.cc | 33 --- src/value.cc | 17 -- 23 files changed, 487 insertions(+), 674 deletions(-) delete mode 100644 src/V8.cc delete mode 100644 src/array_buffer.cc create mode 100644 src/binding.cc delete mode 100644 src/context.cc delete mode 100644 src/exception.cc delete mode 100644 src/function.cc delete mode 100644 src/handle_scope.cc delete mode 100644 src/inspector/channel.cc delete mode 100644 src/inspector/client.cc delete mode 100644 src/inspector/string_buffer.cc delete mode 100644 src/isolate.cc delete mode 100644 src/json.cc delete mode 100644 src/locker.cc delete mode 100644 src/number.cc delete mode 100644 src/object.cc delete mode 100644 src/platform/mod.cc delete mode 100644 src/platform/task.cc delete mode 100644 src/primitives.cc delete mode 100644 src/promise.cc delete mode 100644 src/script.cc delete mode 100644 src/string.cc delete mode 100644 src/value.cc diff --git a/BUILD.gn b/BUILD.gn index 971c3fa5..4fc19035 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3,27 +3,7 @@ import("//v8/gni/v8.gni") v8_static_library("rusty_v8") { sources = [ - "src/V8.cc", - "src/array_buffer.cc", - "src/context.cc", - "src/exception.cc", - "src/function.cc", - "src/handle_scope.cc", - "src/inspector/channel.cc", - "src/inspector/client.cc", - "src/inspector/string_buffer.cc", - "src/isolate.cc", - "src/json.cc", - "src/locker.cc", - "src/number.cc", - "src/object.cc", - "src/platform/mod.cc", - "src/platform/task.cc", - "src/primitives.cc", - "src/promise.cc", - "src/script.cc", - "src/string.cc", - "src/value.cc", + "src/binding.cc", ] deps = [ ":v8", diff --git a/src/V8.cc b/src/V8.cc deleted file mode 100644 index de161561..00000000 --- a/src/V8.cc +++ /dev/null @@ -1,29 +0,0 @@ -#include "v8/include/v8.h" - -using namespace v8; - -extern "C" { -void v8__V8__SetFlagsFromCommandLine(int* argc, char** argv) { - V8::SetFlagsFromCommandLine(argc, argv, true); -} - -const char* v8__V8__GetVersion() { - return V8::GetVersion(); -} - -void v8__V8__InitializePlatform(Platform& platform) { - V8::InitializePlatform(&platform); -} - -void v8__V8__Initialize() { - V8::Initialize(); -} - -bool v8__V8__Dispose() { - return V8::Dispose(); -} - -void v8__V8__ShutdownPlatform() { - V8::ShutdownPlatform(); -} -} diff --git a/src/array_buffer.cc b/src/array_buffer.cc deleted file mode 100644 index ec278412..00000000 --- a/src/array_buffer.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include "v8/include/v8.h" - -using namespace v8; - -extern "C" { -ArrayBuffer::Allocator* v8__ArrayBuffer__Allocator__NewDefaultAllocator() { - return ArrayBuffer::Allocator::NewDefaultAllocator(); -} - -void v8__ArrayBuffer__Allocator__DELETE(ArrayBuffer::Allocator& self) { - delete &self; -} -} // extern "C" diff --git a/src/binding.cc b/src/binding.cc new file mode 100644 index 00000000..a9668302 --- /dev/null +++ b/src/binding.cc @@ -0,0 +1,486 @@ +#include +#include +#include + +#include "support.h" +#include "v8/include/libplatform/libplatform.h" +#include "v8/include/v8-inspector.h" +#include "v8/include/v8-platform.h" +#include "v8/include/v8.h" + +// TODO(ry) do not use "using namespace" so the binding code is more explicit. +using namespace v8; +using namespace support; + +static_assert(sizeof(ScriptOrigin) == sizeof(size_t) * 7, + "ScriptOrigin size mismatch"); + +static_assert(sizeof(HandleScope) == sizeof(size_t) * 3, + "HandleScope size mismatch"); + +extern "C" { + +void v8__V8__SetFlagsFromCommandLine(int *argc, char **argv) { + V8::SetFlagsFromCommandLine(argc, argv, true); +} + +const char *v8__V8__GetVersion() { return V8::GetVersion(); } + +void v8__V8__InitializePlatform(Platform &platform) { + V8::InitializePlatform(&platform); +} + +void v8__V8__Initialize() { V8::Initialize(); } + +bool v8__V8__Dispose() { return V8::Dispose(); } + +void v8__V8__ShutdownPlatform() { V8::ShutdownPlatform(); } + +// This function consumes the Isolate::CreateParams object. The Isolate takes +// ownership of the ArrayBuffer::Allocator referenced by the params object. +Isolate *v8__Isolate__New(Isolate::CreateParams ¶ms) { + auto isolate = Isolate::New(params); + delete ¶ms; + return isolate; +} + +void v8__Isolate__Dispose(Isolate &isolate) { + auto allocator = isolate.GetArrayBufferAllocator(); + isolate.Dispose(); + delete allocator; +} + +void v8__Isolate__Enter(Isolate &isolate) { isolate.Enter(); } + +void v8__Isolate__Exit(Isolate &isolate) { isolate.Exit(); } + +Isolate::CreateParams *v8__Isolate__CreateParams__NEW() { + return new Isolate::CreateParams(); +} + +// This function is only called if the Isolate::CreateParams object is *not* +// consumed by Isolate::New(). +void v8__Isolate__CreateParams__DELETE(Isolate::CreateParams &self) { + delete self.array_buffer_allocator; + delete &self; +} + +// This function takes ownership of the ArrayBuffer::Allocator. +void v8__Isolate__CreateParams__SET__array_buffer_allocator( + Isolate::CreateParams &self, ArrayBuffer::Allocator *value) { + delete self.array_buffer_allocator; + self.array_buffer_allocator = value; +} + +void v8__HandleScope__CONSTRUCT(uninit_t &buf, Isolate *isolate) { + construct_in_place(buf, isolate); +} + +void v8__HandleScope__DESTRUCT(HandleScope &self) { self.~HandleScope(); } + +Isolate *v8__HandleScope__GetIsolate(const HandleScope &self) { + return self.GetIsolate(); +} + +void v8__Locker__CONSTRUCT(uninit_t &buf, Isolate *isolate) { + construct_in_place(buf, isolate); +} + +void v8__Locker__DESTRUCT(Locker &self) { self.~Locker(); } + +bool v8__Value__IsUndefined(const Value &self) { return self.IsUndefined(); } + +bool v8__Value__IsNull(const Value &self) { return self.IsNull(); } + +bool v8__Value__IsNullOrUndefined(const Value &self) { + return self.IsNullOrUndefined(); +} + +v8::Primitive *v8__Null(v8::Isolate *isolate) { + return local_to_ptr(v8::Null(isolate)); +} + +v8::Primitive *v8__Undefined(v8::Isolate *isolate) { + return local_to_ptr(v8::Undefined(isolate)); +} + +v8::Boolean *v8__True(v8::Isolate *isolate) { + return local_to_ptr(v8::True(isolate)); +} + +v8::Boolean *v8__False(v8::Isolate *isolate) { + return local_to_ptr(v8::False(isolate)); +} + +String *v8__String__NewFromUtf8(Isolate *isolate, const char *data, + NewStringType type, int length) { + return maybe_local_to_ptr(String::NewFromUtf8(isolate, data, type, length)); +} + +int v8__String__Length(const String &self) { return self.Length(); } + +int v8__String__Utf8Length(const String &self, Isolate *isolate) { + return self.Utf8Length(isolate); +} + +int v8__String__WriteUtf8(const String &self, Isolate *isolate, char *buffer, + int length, int *nchars_ref, int options) { + return self.WriteUtf8(isolate, buffer, length, nchars_ref, options); +} + +v8::Object *v8__Object__New(v8::Isolate *isolate, + v8::Local prototype_or_null, + v8::Local *names, + v8::Local *values, size_t length) { + return local_to_ptr( + v8::Object::New(isolate, prototype_or_null, names, values, length)); +} + +Number *v8__Number__New(Isolate *isolate, double value) { + return *Number::New(isolate, value); +} + +double v8__Number__Value(const Number &self) { return self.Value(); } + +Integer *v8__Integer__New(Isolate *isolate, int32_t value) { + return *Integer::New(isolate, value); +} + +Integer *v8__Integer__NewFromUnsigned(Isolate *isolate, uint32_t value) { + return *Integer::NewFromUnsigned(isolate, value); +} + +int64_t v8__Integer__Value(const Integer &self) { return self.Value(); } + +ArrayBuffer::Allocator *v8__ArrayBuffer__Allocator__NewDefaultAllocator() { + return ArrayBuffer::Allocator::NewDefaultAllocator(); +} + +void v8__ArrayBuffer__Allocator__DELETE(ArrayBuffer::Allocator &self) { + delete &self; +} + +Context *v8__Context__New(Isolate *isolate) { + // TODO: optional arguments. + return *Context::New(isolate); +} + +void v8__Context__Enter(Context &self) { self.Enter(); } + +void v8__Context__Exit(Context &self) { self.Exit(); } + +Isolate *v8__Context__GetIsolate(Context &self) { return self.GetIsolate(); } + +Object *v8__Context__Global(Context &self) { return *self.Global(); } + +v8::String *v8__Message__Get(v8::Message *self) { + return local_to_ptr(self->Get()); +} + +v8::Value *v8__Exception__RangeError(v8::Local message) { + return local_to_ptr(v8::Exception::RangeError(message)); +} + +v8::Value *v8__Exception__ReferenceError(v8::Local message) { + return local_to_ptr(v8::Exception::ReferenceError(message)); +} + +v8::Value *v8__Exception__SyntaxError(v8::Local message) { + return local_to_ptr(v8::Exception::SyntaxError(message)); +} + +v8::Value *v8__Exception__TypeError(v8::Local message) { + return local_to_ptr(v8::Exception::TypeError(message)); +} + +v8::Value *v8__Exception__Error(v8::Local message) { + return local_to_ptr(v8::Exception::Error(message)); +} + +v8::Message *v8__Exception__CreateMessage(v8::Isolate *isolate, + v8::Local exception) { + return local_to_ptr(v8::Exception::CreateMessage(isolate, exception)); +} + +v8::StackTrace *v8__Exception__GetStackTrace(v8::Local exception) { + return local_to_ptr(v8::Exception::GetStackTrace(exception)); +} + +v8::Function *v8__Function__New(v8::Local context, + v8::FunctionCallback callback) { + return maybe_local_to_ptr(v8::Function::New(context, callback)); +} + +v8::Value *v8__Function__Call(v8::Function *self, + v8::Local context, + v8::Local recv, int argc, + v8::Local argv[]) { + return maybe_local_to_ptr(self->Call(context, recv, argc, argv)); +} + +v8::FunctionTemplate * +v8__FunctionTemplate__New(v8::Isolate *isolate, + v8::FunctionCallback callback = nullptr) { + return local_to_ptr(v8::FunctionTemplate::New(isolate, callback)); +} + +v8::Function * +v8__FunctionTemplate__GetFunction(v8::Local self, + v8::Local context) { + return maybe_local_to_ptr(self->GetFunction(context)); +} +int v8__FunctionCallbackInfo__Length( + v8::FunctionCallbackInfo *self) { + return self->Length(); +} + +v8::Isolate *v8__FunctionCallbackInfo__GetIsolate( + v8::FunctionCallbackInfo *self) { + return self->GetIsolate(); +} + +v8::ReturnValue *v8__FunctionCallbackInfo__GetReturnValue( + v8::FunctionCallbackInfo *self) { + v8::ReturnValue *rv = + new v8::ReturnValue(self->GetReturnValue()); + return rv; +} + +void v8__ReturnValue__Set(v8::ReturnValue *self, + v8::Local value) { + self->Set(value); +} + +v8::Value *v8__ReturnValue__Get(v8::ReturnValue *self) { + return local_to_ptr(self->Get()); +} + +v8::Isolate *v8__ReturnValue__GetIsolate(v8::ReturnValue *self) { + return self->GetIsolate(); +} + +int v8__StackTrace__GetFrameCount(v8::StackTrace *self) { + return self->GetFrameCount(); +} + +Script *v8__Script__Compile(Context *context, String *source, + ScriptOrigin *origin) { + return maybe_local_to_ptr( + Script::Compile(ptr_to_local(context), ptr_to_local(source), origin)); +} + +Value *v8__Script__Run(Script &script, Context *context) { + return maybe_local_to_ptr(script.Run(ptr_to_local(context))); +} + +void v8__ScriptOrigin__CONSTRUCT(uninit_t &buf, + Value *resource_name, + Integer *resource_line_offset, + Integer *resource_column_offset, + Boolean *resource_is_shared_cross_origin, + Integer *script_id, Value *source_map_url, + Boolean *resource_is_opaque, Boolean *is_wasm, + Boolean *is_module) { + construct_in_place( + buf, ptr_to_local(resource_name), ptr_to_local(resource_line_offset), + ptr_to_local(resource_column_offset), + ptr_to_local(resource_is_shared_cross_origin), ptr_to_local(script_id), + ptr_to_local(source_map_url), ptr_to_local(resource_is_opaque), + ptr_to_local(is_wasm), ptr_to_local(is_module)); +} + +v8::Value *v8__JSON__Parse(v8::Local context, + v8::Local json_string) { + return maybe_local_to_ptr(v8::JSON::Parse(context, json_string)); +} + +v8::String *v8__JSON__Stringify(v8::Local context, + v8::Local json_object) { + return maybe_local_to_ptr(v8::JSON::Stringify(context, json_object)); +} + +v8::Promise::Resolver * +v8__Promise__Resolver__New(v8::Local context) { + return maybe_local_to_ptr(v8::Promise::Resolver::New(context)); +} + +v8::Promise *v8__Promise__Resolver__GetPromise(v8::Promise::Resolver *self) { + return local_to_ptr(self->GetPromise()); +} + +bool v8__Promise__Resolver__Resolve(v8::Promise::Resolver *self, + v8::Local context, + v8::Local value) { + return maybe_to_value(self->Resolve(context, value), false); +} + +bool v8__Promise__Resolver__Reject(v8::Promise::Resolver *self, + v8::Local context, + v8::Local value) { + return maybe_to_value(self->Reject(context, value), false); +} + +v8::Promise::PromiseState v8__Promise__State(v8::Promise *self) { + return self->State(); +} + +bool v8__Promise__HasHandler(v8::Promise *self) { return self->HasHandler(); } + +v8::Value *v8__Promise__Result(v8::Promise *self) { + return local_to_ptr(self->Result()); +} + +v8::Promise *v8__Promise__Catch(v8::Promise *self, + v8::Local context, + v8::Local handler) { + return maybe_local_to_ptr(self->Catch(context, handler)); +} + +v8::Promise *v8__Promise__Then(v8::Promise *self, + v8::Local context, + v8::Local handler) { + return maybe_local_to_ptr(self->Then(context, handler)); +} + +v8::Promise *v8__Promise__Then2(v8::Promise *self, + v8::Local context, + v8::Local on_fulfilled, + v8::Local on_rejected) { + return maybe_local_to_ptr(self->Then(context, on_fulfilled, on_rejected)); +} + +v8::Platform *v8__platform__NewDefaultPlatform() { + // TODO: support optional arguments. + return v8::platform::NewDefaultPlatform().release(); +} + +void v8__Platform__DELETE(v8::Platform &self) { delete &self; } +void v8__Task__BASE__DELETE(Task &self); +void v8__Task__BASE__Run(Task &self); + +struct v8__Task__BASE : public Task { + using Task::Task; + void operator delete(void *ptr) noexcept { + v8__Task__BASE__DELETE(*reinterpret_cast(ptr)); + } + void Run() override { v8__Task__BASE__Run(*this); } +}; + +void v8__Task__BASE__CONSTRUCT(uninit_t &buf) { + construct_in_place(buf); +} +void v8__Task__DELETE(Task &self) { delete &self; } +void v8__Task__Run(Task &self) { self.Run(); } + +void v8_inspector__V8Inspector__Channel__BASE__sendResponse( + v8_inspector::V8Inspector::Channel &self, int callId, + v8_inspector::StringBuffer *message); +void v8_inspector__V8Inspector__Channel__BASE__sendNotification( + v8_inspector::V8Inspector::Channel &self, + v8_inspector::StringBuffer *message); +void v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications( + v8_inspector::V8Inspector::Channel &self); +} // extern "C" + +struct v8_inspector__V8Inspector__Channel__BASE + : public v8_inspector::V8Inspector::Channel { + using v8_inspector::V8Inspector::Channel::Channel; + + void + sendResponse(int callId, + std::unique_ptr message) override { + v8_inspector__V8Inspector__Channel__BASE__sendResponse(*this, callId, + message.release()); + } + void sendNotification( + std::unique_ptr message) override { + v8_inspector__V8Inspector__Channel__BASE__sendNotification( + *this, message.release()); + } + void flushProtocolNotifications() override { + v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications(*this); + } +}; + +extern "C" { +void v8_inspector__V8Inspector__Channel__BASE__CONSTRUCT( + uninit_t &buf) { + construct_in_place(buf); +} + +void v8_inspector__V8Inspector__Channel__sendResponse( + v8_inspector::V8Inspector::Channel &self, int callId, + v8_inspector::StringBuffer *message) { + self.sendResponse( + callId, + static_cast>(message)); +} +void v8_inspector__V8Inspector__Channel__sendNotification( + v8_inspector::V8Inspector::Channel &self, + v8_inspector::StringBuffer *message) { + self.sendNotification( + static_cast>(message)); +} +void v8_inspector__V8Inspector__Channel__flushProtocolNotifications( + v8_inspector::V8Inspector::Channel &self) { + self.flushProtocolNotifications(); +} + +void v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause( + v8_inspector::V8InspectorClient &self, int contextGroupId); +void v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause( + v8_inspector::V8InspectorClient &self); +void v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger( + v8_inspector::V8InspectorClient &self, int contextGroupId); +} // extern "C" + +struct v8_inspector__V8InspectorClient__BASE + : public v8_inspector::V8InspectorClient { + using v8_inspector::V8InspectorClient::V8InspectorClient; + + void runMessageLoopOnPause(int contextGroupId) override { + v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause( + *this, contextGroupId); + } + void quitMessageLoopOnPause() override { + v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause(*this); + } + void runIfWaitingForDebugger(int contextGroupId) override { + v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger( + *this, contextGroupId); + } +}; + +extern "C" { +void v8_inspector__V8InspectorClient__BASE__CONSTRUCT( + uninit_t &buf) { + construct_in_place(buf); +} + +void v8_inspector__V8InspectorClient__runMessageLoopOnPause( + v8_inspector::V8InspectorClient &self, int contextGroupId) { + self.runMessageLoopOnPause(contextGroupId); +} +void v8_inspector__V8InspectorClient__quitMessageLoopOnPause( + v8_inspector::V8InspectorClient &self) { + self.quitMessageLoopOnPause(); +} +void v8_inspector__V8InspectorClient__runIfWaitingForDebugger( + v8_inspector::V8InspectorClient &self, int contextGroupId) { + self.runIfWaitingForDebugger(contextGroupId); +} + +void v8_inspector__StringBuffer__DELETE(v8_inspector::StringBuffer &self) { + delete &self; +} + +const v8_inspector::StringView * +v8_inspector__StringBuffer__string(v8_inspector::StringBuffer &self) { + return &self.string(); +} + +v8_inspector::StringBuffer * +v8_inspector__StringBuffer__create(const v8_inspector::StringView &source) { + return v8_inspector::StringBuffer::create(source).release(); +} +} // extern "C" diff --git a/src/context.cc b/src/context.cc deleted file mode 100644 index 3b9e5388..00000000 --- a/src/context.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include - -#include "v8/include/v8.h" - -using namespace v8; - -extern "C" { -Context* v8__Context__New(Isolate* isolate) { - // TODO: optional arguments. - return *Context::New(isolate); -} - -void v8__Context__Enter(Context& self) { - self.Enter(); -} - -void v8__Context__Exit(Context& self) { - self.Exit(); -} - -Isolate* v8__Context__GetIsolate(Context& self) { - return self.GetIsolate(); -} - -Object* v8__Context__Global(Context& self) { - return *self.Global(); -} -} diff --git a/src/exception.cc b/src/exception.cc deleted file mode 100644 index 8a11a57d..00000000 --- a/src/exception.cc +++ /dev/null @@ -1,42 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::String *v8__Message__Get(v8::Message* self) { - return local_to_ptr(self->Get()); -} - -v8::Value *v8__Exception__RangeError(v8::Local message) { - return local_to_ptr(v8::Exception::RangeError(message)); -} - -v8::Value *v8__Exception__ReferenceError(v8::Local message) { - return local_to_ptr(v8::Exception::ReferenceError(message)); -} - -v8::Value *v8__Exception__SyntaxError(v8::Local message) { - return local_to_ptr(v8::Exception::SyntaxError(message)); -} - -v8::Value *v8__Exception__TypeError(v8::Local message) { - return local_to_ptr(v8::Exception::TypeError(message)); -} - -v8::Value *v8__Exception__Error(v8::Local message) { - return local_to_ptr(v8::Exception::Error(message)); -} - -v8::Message *v8__Exception__CreateMessage(v8::Isolate* isolate, v8::Local exception) { - return local_to_ptr(v8::Exception::CreateMessage(isolate, exception)); -} - -v8::StackTrace *v8__Exception__GetStackTrace(v8::Local exception) { - return local_to_ptr(v8::Exception::GetStackTrace(exception)); -} - -int v8__StackTrace__GetFrameCount(v8::StackTrace* self) { - return self->GetFrameCount(); -} -} diff --git a/src/function.cc b/src/function.cc deleted file mode 100644 index 0d5fadbe..00000000 --- a/src/function.cc +++ /dev/null @@ -1,55 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::Function *v8__Function__New(v8::Local context, - v8::FunctionCallback callback) { - return maybe_local_to_ptr(v8::Function::New(context, callback)); -} - -v8::Value *v8__Function__Call(v8::Function *self, - v8::Local context, - v8::Local recv, - int argc, - v8::Local argv[]) { - return maybe_local_to_ptr(self->Call(context, recv, argc, argv)); -} - -v8::FunctionTemplate *v8__FunctionTemplate__New(v8::Isolate* isolate, - v8::FunctionCallback callback = nullptr) { - return local_to_ptr(v8::FunctionTemplate::New(isolate, callback)); -} - -v8::Function *v8__FunctionTemplate__GetFunction(v8::Local self, - v8::Local context) { - return maybe_local_to_ptr(self->GetFunction(context)); -} -int v8__FunctionCallbackInfo__Length(v8::FunctionCallbackInfo *self) { - return self->Length(); -} - -v8::Isolate *v8__FunctionCallbackInfo__GetIsolate(v8::FunctionCallbackInfo *self) { - return self->GetIsolate(); -} - -v8::ReturnValue *v8__FunctionCallbackInfo__GetReturnValue(v8::FunctionCallbackInfo *self) -{ - v8::ReturnValue *rv = new v8::ReturnValue(self->GetReturnValue()); - return rv; -} - -void v8__ReturnValue__Set(v8::ReturnValue *self, - v8::Local value) { - self->Set(value); -} - -v8::Value *v8__ReturnValue__Get(v8::ReturnValue *self) { - return local_to_ptr(self->Get()); -} - -v8::Isolate *v8__ReturnValue__GetIsolate(v8::ReturnValue *self) { - return self->GetIsolate(); -} -} diff --git a/src/handle_scope.cc b/src/handle_scope.cc deleted file mode 100644 index 8de90448..00000000 --- a/src/handle_scope.cc +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include - -#include "support.h" -#include "v8/include/v8.h" - -using namespace v8; -using namespace support; - -static_assert(sizeof(HandleScope) == sizeof(size_t) * 3, - "HandleScope size mismatch"); - -extern "C" { -void v8__HandleScope__CONSTRUCT(uninit_t& buf, Isolate* isolate) { - construct_in_place(buf, isolate); -} - -void v8__HandleScope__DESTRUCT(HandleScope& self) { - self.~HandleScope(); -} - -Isolate* v8__HandleScope__GetIsolate(const HandleScope& self) { - return self.GetIsolate(); -} -} diff --git a/src/inspector/channel.cc b/src/inspector/channel.cc deleted file mode 100644 index b17984fe..00000000 --- a/src/inspector/channel.cc +++ /dev/null @@ -1,58 +0,0 @@ -#include "v8/include/v8-inspector.h" -#include "../support.h" - -using namespace v8_inspector; -using namespace support; - -extern "C" { -void v8_inspector__V8Inspector__Channel__BASE__sendResponse( - V8Inspector::Channel& self, - int callId, - StringBuffer* message); -void v8_inspector__V8Inspector__Channel__BASE__sendNotification( - V8Inspector::Channel& self, - StringBuffer* message); -void v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications( - V8Inspector::Channel& self); -} // extern "C" - -struct v8_inspector__V8Inspector__Channel__BASE : public V8Inspector::Channel { - using V8Inspector::Channel::Channel; - - void sendResponse(int callId, - std::unique_ptr message) override { - v8_inspector__V8Inspector__Channel__BASE__sendResponse(*this, callId, - message.release()); - } - void sendNotification(std::unique_ptr message) override { - v8_inspector__V8Inspector__Channel__BASE__sendNotification( - *this, message.release()); - } - void flushProtocolNotifications() override { - v8_inspector__V8Inspector__Channel__BASE__flushProtocolNotifications(*this); - } -}; - -extern "C" { -void v8_inspector__V8Inspector__Channel__BASE__CONSTRUCT( - uninit_t& buf) { - construct_in_place(buf); -} - -void v8_inspector__V8Inspector__Channel__sendResponse( - V8Inspector::Channel& self, - int callId, - StringBuffer* message) { - self.sendResponse(callId, - static_cast>(message)); -} -void v8_inspector__V8Inspector__Channel__sendNotification( - V8Inspector::Channel& self, - StringBuffer* message) { - self.sendNotification(static_cast>(message)); -} -void v8_inspector__V8Inspector__Channel__flushProtocolNotifications( - V8Inspector::Channel& self) { - self.flushProtocolNotifications(); -} -} // extern "C" diff --git a/src/inspector/client.cc b/src/inspector/client.cc deleted file mode 100644 index 6848f139..00000000 --- a/src/inspector/client.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include "v8/include/v8-inspector.h" -#include "../support.h" - -using namespace v8_inspector; -using namespace support; - -extern "C" { -void v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause( - V8InspectorClient& self, - int contextGroupId); -void v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause( - V8InspectorClient& self); -void v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger( - V8InspectorClient& self, - int contextGroupId); -} // extern "C" - -struct v8_inspector__V8InspectorClient__BASE : public V8InspectorClient { - using V8InspectorClient::V8InspectorClient; - - void runMessageLoopOnPause(int contextGroupId) override { - v8_inspector__V8InspectorClient__BASE__runMessageLoopOnPause( - *this, contextGroupId); - } - void quitMessageLoopOnPause() override { - v8_inspector__V8InspectorClient__BASE__quitMessageLoopOnPause(*this); - } - void runIfWaitingForDebugger(int contextGroupId) override { - v8_inspector__V8InspectorClient__BASE__runIfWaitingForDebugger( - *this, contextGroupId); - } -}; - -extern "C" { -void v8_inspector__V8InspectorClient__BASE__CONSTRUCT( - uninit_t& buf) { - construct_in_place(buf); -} - -void v8_inspector__V8InspectorClient__runMessageLoopOnPause( - V8InspectorClient& self, - int contextGroupId) { - self.runMessageLoopOnPause(contextGroupId); -} -void v8_inspector__V8InspectorClient__quitMessageLoopOnPause( - V8InspectorClient& self) { - self.quitMessageLoopOnPause(); -} -void v8_inspector__V8InspectorClient__runIfWaitingForDebugger( - V8InspectorClient& self, - int contextGroupId) { - self.runIfWaitingForDebugger(contextGroupId); -} -} // extern "C" diff --git a/src/inspector/string_buffer.cc b/src/inspector/string_buffer.cc deleted file mode 100644 index 8673c9d1..00000000 --- a/src/inspector/string_buffer.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "v8/include/v8-inspector.h" - -using namespace v8_inspector; - -extern "C" { -void v8_inspector__StringBuffer__DELETE(StringBuffer& self) { - delete &self; -} - -const StringView* v8_inspector__StringBuffer__string(StringBuffer& self) { - return &self.string(); -} - -StringBuffer* v8_inspector__StringBuffer__create(const StringView& source) { - return StringBuffer::create(source).release(); -} -} diff --git a/src/isolate.cc b/src/isolate.cc deleted file mode 100644 index 6bce74a5..00000000 --- a/src/isolate.cc +++ /dev/null @@ -1,45 +0,0 @@ -#include "v8/include/v8.h" - -using namespace v8; - -extern "C" { -// This function consumes the Isolate::CreateParams object. The Isolate takes -// ownership of the ArrayBuffer::Allocator referenced by the params object. -Isolate* v8__Isolate__New(Isolate::CreateParams& params) { - auto isolate = Isolate::New(params); - delete ¶ms; - return isolate; -} - -void v8__Isolate__Dispose(Isolate& isolate) { - auto allocator = isolate.GetArrayBufferAllocator(); - isolate.Dispose(); - delete allocator; -} - -void v8__Isolate__Enter(Isolate& isolate) { - isolate.Enter(); -} - -void v8__Isolate__Exit(Isolate& isolate) { - isolate.Exit(); -} - -Isolate::CreateParams* v8__Isolate__CreateParams__NEW() { - return new Isolate::CreateParams(); -} - -// This function is only called if the Isolate::CreateParams object is *not* -// consumed by Isolate::New(). -void v8__Isolate__CreateParams__DELETE(Isolate::CreateParams& self) { - delete self.array_buffer_allocator; - delete &self; -} - -// This function takes ownership of the ArrayBuffer::Allocator. -void v8__Isolate__CreateParams__SET__array_buffer_allocator( - Isolate::CreateParams& self, ArrayBuffer::Allocator* value) { - delete self.array_buffer_allocator; - self.array_buffer_allocator = value; -} -} diff --git a/src/json.cc b/src/json.cc deleted file mode 100644 index 59f3f197..00000000 --- a/src/json.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::Value *v8__JSON__Parse(v8::Local context, v8::Local json_string) { - return maybe_local_to_ptr(v8::JSON::Parse(context, json_string)); -} - -v8::String *v8__JSON__Stringify(v8::Local context, v8::Local json_object) { - return maybe_local_to_ptr(v8::JSON::Stringify(context, json_object)); -} -} \ No newline at end of file diff --git a/src/locker.cc b/src/locker.cc deleted file mode 100644 index 7ba9d1f3..00000000 --- a/src/locker.cc +++ /dev/null @@ -1,15 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace v8; -using namespace support; - -extern "C" { -void v8__Locker__CONSTRUCT(uninit_t& buf, Isolate* isolate) { - construct_in_place(buf, isolate); -} - -void v8__Locker__DESTRUCT(Locker& self) { - self.~Locker(); -} -} diff --git a/src/number.cc b/src/number.cc deleted file mode 100644 index 7e2c1482..00000000 --- a/src/number.cc +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#include "v8/include/v8.h" - -using namespace v8; - -extern "C" { -Number* v8__Number__New(Isolate* isolate, double value) { - return *Number::New(isolate, value); -} - -double v8__Number__Value(const Number& self) { - return self.Value(); -} - -Integer* v8__Integer__New(Isolate* isolate, int32_t value) { - return *Integer::New(isolate, value); -} - -Integer* v8__Integer__NewFromUnsigned(Isolate* isolate, uint32_t value) { - return *Integer::NewFromUnsigned(isolate, value); -} - -int64_t v8__Integer__Value(const Integer& self) { - return self.Value(); -} -} diff --git a/src/object.cc b/src/object.cc deleted file mode 100644 index 228b05c2..00000000 --- a/src/object.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::Object *v8__Object__New(v8::Isolate *isolate, - v8::Local prototype_or_null, - v8::Local* names, - v8::Local* values, - size_t length) { - return local_to_ptr(v8::Object::New(isolate, prototype_or_null, names, values, length)); -} -} diff --git a/src/platform/mod.cc b/src/platform/mod.cc deleted file mode 100644 index 614c4eba..00000000 --- a/src/platform/mod.cc +++ /dev/null @@ -1,20 +0,0 @@ -#include "../support.h" -#include "v8/include/libplatform/libplatform.h" -#include "v8/include/v8-platform.h" - -#include - -using namespace v8; -using namespace v8::platform; -using namespace support; - -extern "C" { -Platform* v8__platform__NewDefaultPlatform() { - // TODO: support optional arguments. - return NewDefaultPlatform().release(); -} - -void v8__Platform__DELETE(Platform& self) { - delete &self; -} -} // extern "C" diff --git a/src/platform/task.cc b/src/platform/task.cc deleted file mode 100644 index 841dfc56..00000000 --- a/src/platform/task.cc +++ /dev/null @@ -1,30 +0,0 @@ -#include "../support.h" -#include "v8/include/v8-platform.h" - -using namespace v8; -using namespace support; - -extern "C" { -void v8__Task__BASE__DELETE(Task& self); -void v8__Task__BASE__Run(Task& self); -} // extern "C" - -struct v8__Task__BASE : public Task { - using Task::Task; - void operator delete(void* ptr) noexcept { - v8__Task__BASE__DELETE(*reinterpret_cast(ptr)); - } - void Run() override { v8__Task__BASE__Run(*this); } -}; - -extern "C" { -void v8__Task__BASE__CONSTRUCT(uninit_t& buf) { - construct_in_place(buf); -} -void v8__Task__DELETE(Task& self) { - delete &self; -} -void v8__Task__Run(Task& self) { - self.Run(); -} -} // extern "C" diff --git a/src/primitives.cc b/src/primitives.cc deleted file mode 100644 index bb628bd9..00000000 --- a/src/primitives.cc +++ /dev/null @@ -1,22 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::Primitive *v8__Null(v8::Isolate *isolate) { - return local_to_ptr(v8::Null(isolate)); -} - -v8::Primitive *v8__Undefined(v8::Isolate *isolate) { - return local_to_ptr(v8::Undefined(isolate)); -} - -v8::Boolean *v8__True(v8::Isolate *isolate) { - return local_to_ptr(v8::True(isolate)); -} - -v8::Boolean *v8__False(v8::Isolate *isolate) { - return local_to_ptr(v8::False(isolate)); -} -} diff --git a/src/promise.cc b/src/promise.cc deleted file mode 100644 index 82aa1522..00000000 --- a/src/promise.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include "support.h" -#include "v8/include/v8.h" - -using namespace support; - -extern "C" { -v8::Promise::Resolver *v8__Promise__Resolver__New(v8::Local context) { - return maybe_local_to_ptr(v8::Promise::Resolver::New(context)); -} - -v8::Promise *v8__Promise__Resolver__GetPromise(v8::Promise::Resolver *self) { - return local_to_ptr(self->GetPromise()); -} - -bool v8__Promise__Resolver__Resolve(v8::Promise::Resolver *self, - v8::Local context, - v8::Local value) { - return maybe_to_value(self->Resolve(context, value), false); -} - -bool v8__Promise__Resolver__Reject(v8::Promise::Resolver *self, - v8::Local context, - v8::Local value) { - return maybe_to_value(self->Reject(context, value), false); -} - -v8::Promise::PromiseState v8__Promise__State(v8::Promise *self) { - return self->State(); -} - -bool v8__Promise__HasHandler(v8::Promise *self) { - return self->HasHandler(); -} - -v8::Value *v8__Promise__Result(v8::Promise *self) { - return local_to_ptr(self->Result()); -} - -v8::Promise *v8__Promise__Catch(v8::Promise *self, - v8::Local context, - v8::Local handler) { - return maybe_local_to_ptr(self->Catch(context, handler)); -} - -v8::Promise *v8__Promise__Then(v8::Promise *self, - v8::Local context, - v8::Local handler) { - return maybe_local_to_ptr(self->Then(context, handler)); -} - -v8::Promise *v8__Promise__Then2(v8::Promise *self, - v8::Local context, - v8::Local on_fulfilled, - v8::Local on_rejected) { - return maybe_local_to_ptr(self->Then(context, on_fulfilled, on_rejected)); -} -} diff --git a/src/script.cc b/src/script.cc deleted file mode 100644 index cab26242..00000000 --- a/src/script.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "support.h" -#include "v8/include/v8.h" - -using namespace v8; -using namespace support; - -static_assert(sizeof(ScriptOrigin) == sizeof(size_t) * 7, - "ScriptOrigin size mismatch"); - -extern "C" { -Script *v8__Script__Compile(Context *context, String *source, - ScriptOrigin *origin) { - return maybe_local_to_ptr( - Script::Compile(ptr_to_local(context), ptr_to_local(source), origin)); -} - -Value *v8__Script__Run(Script &script, Context *context) { - return maybe_local_to_ptr(script.Run(ptr_to_local(context))); -} - -void v8__ScriptOrigin__CONSTRUCT(uninit_t &buf, - Value *resource_name, - Integer *resource_line_offset, - Integer *resource_column_offset, - Boolean *resource_is_shared_cross_origin, - Integer *script_id, Value *source_map_url, - Boolean *resource_is_opaque, Boolean *is_wasm, - Boolean *is_module) { - construct_in_place( - buf, ptr_to_local(resource_name), ptr_to_local(resource_line_offset), - ptr_to_local(resource_column_offset), - ptr_to_local(resource_is_shared_cross_origin), ptr_to_local(script_id), - ptr_to_local(source_map_url), ptr_to_local(resource_is_opaque), - ptr_to_local(is_wasm), ptr_to_local(is_module)); -} -} diff --git a/src/string.cc b/src/string.cc deleted file mode 100644 index c4b13c65..00000000 --- a/src/string.cc +++ /dev/null @@ -1,33 +0,0 @@ -#include - -#include "support.h" -#include "v8/include/v8.h" - -using namespace v8; -using namespace support; - -extern "C" { -String* v8__String__NewFromUtf8(Isolate* isolate, - const char* data, - NewStringType type, - int length) { - return maybe_local_to_ptr(String::NewFromUtf8(isolate, data, type, length)); -} - -int v8__String__Length(const String& self) { - return self.Length(); -} - -int v8__String__Utf8Length(const String& self, Isolate* isolate) { - return self.Utf8Length(isolate); -} - -int v8__String__WriteUtf8(const String& self, - Isolate* isolate, - char* buffer, - int length, - int* nchars_ref, - int options) { - return self.WriteUtf8(isolate, buffer, length, nchars_ref, options); -} -} diff --git a/src/value.cc b/src/value.cc deleted file mode 100644 index 28f4f71e..00000000 --- a/src/value.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include - -#include "support.h" -#include "v8/include/v8.h" - -using namespace v8; -using namespace support; - -extern "C" { -bool v8__Value__IsUndefined(const Value &self) { return self.IsUndefined(); } - -bool v8__Value__IsNull(const Value &self) { return self.IsNull(); } - -bool v8__Value__IsNullOrUndefined(const Value &self) { - return self.IsNullOrUndefined(); -} -}