abetomo
null+****@clear*****
Fri Sep 22 16:20:39 JST 2017
abetomo 2017-09-22 16:20:39 +0900 (Fri, 22 Sep 2017) New Revision: 42d093dd482ed3ab9f64ffa8daf76261ba30959b https://github.com/nroonga/nroonga/commit/42d093dd482ed3ab9f64ffa8daf76261ba30959b Merged b325def: Merge pull request #31 from abetomo/fix_to_handle_on_addon Message: Add function to generate command string Modified files: src/nroonga.cc src/nroonga.h Modified: src/nroonga.cc (+38 -0) =================================================================== --- src/nroonga.cc 2017-09-22 16:09:50 +0900 (9d70f27) +++ src/nroonga.cc 2017-09-22 16:20:39 +0900 (1e1f6a8) @@ -4,6 +4,44 @@ namespace nroonga { Nan::Persistent<v8::Function> groonga_context_constructor; +v8::Local<v8::String> Database::optionsToCommandString( + const Nan::FunctionCallbackInfo<v8::Value>& info) { + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowTypeError("Bad parameter"); + return Nan::New("").ToLocalChecked(); + } + if (info.Length() == 1) { + return info[0]->ToString(); + } + if (info.Length() >= 2 && !info[1]->IsObject()) { + return info[0]->ToString(); + } + + v8::Local<v8::Object> options = info[1]->ToObject(); + v8::Local<v8::Array> props = + Nan::GetOwnPropertyNames(options).ToLocalChecked(); + + v8::Local<v8::String> commandString = info[0]->ToString(); + Nan::JSON NanJSON; + for (int i = 0, l = props->Length(); i < l; i++) { + v8::Local<v8::Value> key = props->Get(i); + v8::Local<v8::Value> value = Nan::Get(options, key).ToLocalChecked(); + if (value->IsNull()) { + continue; + } + + commandString = v8::String::Concat(commandString, + Nan::New(" --").ToLocalChecked()); + commandString = v8::String::Concat(commandString, key->ToString()); + commandString = v8::String::Concat(commandString, + Nan::New(" ").ToLocalChecked()); + commandString = v8::String::Concat( + commandString, + NanJSON.Stringify(value->ToObject()).ToLocalChecked()->ToString()); + } + return commandString; +} + void Database::Initialize(v8::Local<v8::Object> exports) { v8::Local<v8::FunctionTemplate> tpl = Nan::New<v8::FunctionTemplate>(New); Modified: src/nroonga.h (+2 -0) =================================================================== --- src/nroonga.h 2017-09-22 16:09:50 +0900 (f7da5fa) +++ src/nroonga.h 2017-09-22 16:20:39 +0900 (eb7c5ee) @@ -30,6 +30,8 @@ class Database : public Nan::ObjectWrap { static void CommandString(const Nan::FunctionCallbackInfo<v8::Value>& info); static void CommandSyncString(const Nan::FunctionCallbackInfo<v8::Value>& info); static void Close(const Nan::FunctionCallbackInfo<v8::Value>& info); + static v8::Local<v8::String> optionsToCommandString( + const Nan::FunctionCallbackInfo<v8::Value>& info); Database() : ObjectWrap() { } bool Cleanup(); -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20170922/9bd6fb95/attachment-0001.htm