diff --git a/include/kth/js-native/chain/output_list.hpp b/include/kth/js-native/chain/output_list.hpp index a0359be..fd65f3e 100644 --- a/include/kth/js-native/chain/output_list.hpp +++ b/include/kth/js-native/chain/output_list.hpp @@ -9,7 +9,9 @@ namespace kth::js_native { +void chain_output_list_construct_default(v8::FunctionCallbackInfo const& args); void chain_output_list_push_back(v8::FunctionCallbackInfo const& args); +void chain_output_list_destruct(v8::FunctionCallbackInfo const& args); void chain_output_list_count(v8::FunctionCallbackInfo const& args); void chain_output_list_nth(v8::FunctionCallbackInfo const& args); diff --git a/src/chain/output_list.cpp b/src/chain/output_list.cpp index ed7b72d..fe77f97 100644 --- a/src/chain/output_list.cpp +++ b/src/chain/output_list.cpp @@ -17,7 +17,6 @@ using v8::FunctionCallbackInfo; using v8::Isolate; using v8::Local; using v8::Global; - using v8::Object; using v8::String; using v8::Boolean; @@ -30,51 +29,76 @@ using v8::Function; using v8::Uint8Array; using v8::ArrayBuffer; +void chain_output_list_construct_default(v8::FunctionCallbackInfo const& args) { + Isolate* isolate = args.GetIsolate(); + + if (args.Length() != 0) { + throw_exception(isolate, "Wrong number of arguments. chain_output_list_construct_default function requires 0 arguments."); + return; + } + + kth_output_list_t res = kth_chain_output_list_construct_default(); + args.GetReturnValue().Set(External::New(isolate, res)); +} void chain_output_list_push_back(v8::FunctionCallbackInfo const& args) { Isolate* isolate = args.GetIsolate(); if (args.Length() != 2) { - throw_exception(isolate, "Wrong number of arguments"); + throw_exception(isolate, "Wrong number of arguments. chain_output_list_push_back function requires 2 arguments."); return; } if ( ! args[0]->IsExternal()) { - throw_exception(isolate, "Wrong arguments"); + throw_exception(isolate, "Wrong argument type for argument list (#1). Required to be IsExternal."); return; } if ( ! args[1]->IsExternal()) { - throw_exception(isolate, "Wrong arguments"); + throw_exception(isolate, "Wrong argument type for argument elem (#2). Required to be IsExternal."); + return; + } + + kth_output_list_t list = (kth_output_list_t)v8::External::Cast(*args[0])->Value(); + kth_output_t elem = (kth_output_t)v8::External::Cast(*args[1])->Value(); + + kth_chain_output_list_push_back(list, elem); +} + +void chain_output_list_destruct(v8::FunctionCallbackInfo const& args) { + Isolate* isolate = args.GetIsolate(); + + if (args.Length() != 1) { + throw_exception(isolate, "Wrong number of arguments. chain_output_list_destruct function requires 1 arguments."); return; } - - void* vptr = v8::External::Cast(*args[0])->Value(); - kth_output_list_t output_list = (kth_output_list_t)vptr; - void* vptr2 = v8::External::Cast(*args[1])->Value(); - kth_output_t output = (kth_output_t)vptr2; + if ( ! args[0]->IsExternal()) { + throw_exception(isolate, "Wrong argument type for argument list (#1). Required to be IsExternal."); + return; + } - kth_chain_output_list_push_back(output_list, output); + kth_output_list_t list = (kth_output_list_t)v8::External::Cast(*args[0])->Value(); + + kth_chain_output_list_destruct(list); } void chain_output_list_count(v8::FunctionCallbackInfo const& args) { Isolate* isolate = args.GetIsolate(); if (args.Length() != 1) { - throw_exception(isolate, "Wrong number of arguments"); + throw_exception(isolate, "Wrong number of arguments. chain_output_list_count function requires 1 arguments."); return; } if ( ! args[0]->IsExternal()) { - throw_exception(isolate, "Wrong arguments"); + throw_exception(isolate, "Wrong argument type for argument list (#1). Required to be IsExternal."); return; } - - void* vptr = v8::External::Cast(*args[0])->Value(); - kth_output_list_t output_list = (kth_output_list_t)vptr; - uint64_t res = kth_chain_output_list_count(output_list); + kth_output_list_t list = (kth_output_list_t)v8::External::Cast(*args[0])->Value(); + + kth_size_t res = kth_chain_output_list_count(list); args.GetReturnValue().Set(Number::New(isolate, res)); } @@ -82,26 +106,24 @@ void chain_output_list_nth(v8::FunctionCallbackInfo const& args) { Isolate* isolate = args.GetIsolate(); if (args.Length() != 2) { - throw_exception(isolate, "Wrong number of arguments"); + throw_exception(isolate, "Wrong number of arguments. chain_output_list_nth function requires 2 arguments."); return; } if ( ! args[0]->IsExternal()) { - throw_exception(isolate, "Wrong arguments"); + throw_exception(isolate, "Wrong argument type for argument list (#1). Required to be IsExternal."); return; } if ( ! args[1]->IsNumber()) { - throw_exception(isolate, "Wrong arguments"); + throw_exception(isolate, "Wrong argument type for argument n (#2). Required to be IsNumber."); return; } - - void* vptr = v8::External::Cast(*args[0])->Value(); - kth_output_list_t output_list = (kth_output_list_t)vptr; - uint64_t n = args[1]->IntegerValue(isolate->GetCurrentContext()).ToChecked(); + kth_output_list_t list = (kth_output_list_t)v8::External::Cast(*args[0])->Value(); + kth_size_t n = args[1]->IntegerValue(isolate->GetCurrentContext()).ToChecked(); - kth_output_t res = kth_chain_output_list_nth(output_list, n); + kth_output_t res = kth_chain_output_list_nth(list, n); args.GetReturnValue().Set(External::New(isolate, res)); }