You could use v8::Object::GetOwnPropertyNames instead of trying each key
individually

On Tue, Dec 6, 2016 at 11:04 PM kent williams <chaircrus...@gmail.com>
wrote:

> 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!
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to