in packages/flow-parser-bin/src/flow_parser_node.cc [62:101]
void Parse(const Nan::FunctionCallbackInfo<v8::Value>& info) {
if (info.Length() < 1) {
Nan::ThrowTypeError("Wrong number of arguments");
return;
}
if (!info[0]->IsString()) {
Nan::ThrowTypeError("First argument must be a string");
return;
}
Nan::HandleScope scope;
V8Translator converter;
Nan::Utf8String arg(info[0]);
std::string content(*arg);
options_t options;
if (info.Length() > 1) {
if (!info[1]->IsObject()) {
Nan::ThrowTypeError("Second argument must be an object");
return;
} else {
Local<Object> opts = Nan::To<Object>(info[1]).ToLocalChecked();
Nan::MaybeLocal<Array> maybe_props = Nan::GetPropertyNames(opts);
if (!maybe_props.IsEmpty()) {
Local<Array> props = maybe_props.ToLocalChecked();
for (uint32_t i = 0; i < props->Length(); i++) {
Local<Value> key = Nan::Get(props, i).ToLocalChecked();
Local<Value> value = Nan::Get(opts, key).ToLocalChecked();
Nan::Utf8String name(key);
options.insert(std::pair<std::string, int>(
std::string(*name), Nan::To<bool>(value).FromJust()));
}
}
}
}
Local<Value> result = converter.parse(content.c_str(), options);
info.GetReturnValue().Set(result);
}