There's a convention that we use for our C++ native functions called from C++, where required arguments are followed (optionally) by an object whose properties are additional flags. EG
var num = convertNumber(x);
var num2 = convertNumber(x, { base: 8 });
Is there a streamlined way to extract properties from this optional object?
I end up doing this:
v8::Local<v8::Object> argsObj;
argsObj.Clear();
if(args.Length() >=2)
argsObj = args[1];
const char *cvval = 0;
if(!argsObj.IsEmpty()) {
v8::Local<v8::String> cvt = v8::String::NewFromUtf8(isolate,
"convert", v8::NewStringType::kNormal).ToLocalChecked();
v8::MaybeLocal<v8::Value> convertval = argsObj->Get(context,cvt);
if(!convertval.IsEmpty()) {
v8::Local<v8::Value> cv = convertval.ToLocalChecked();
v8::String::Utf8Value val2 = cv->ToString();
cvval = *val2 ? *val2 : 0;
}
}
This seems like a whole lot of work -- way more than Spidermonkey, for example.
Are there some convenience functions that make this less painful, or do I have to write my own?
Thanks!