On Thursday, April 14, 2011 at 12:23:46 AM UTC-7, crtmpserver wrote:
>
> I would like to know if there is any API for getting the type of a 
> value but without calling IsXXXX() corresponding function. What I 
> would work very nice for me is to have an API which returns the type 
> as a numeric value. Example: 
>
> Handle<Value> value=.... 
>
> switch(value->GetType()) 
> { 
>     case NUMERIC: 
>         //do something 
>         break; 
>     case STRING: 
>         //do something 
>         break; 
>     case FUNCTION: 
>         //do something 
>         break; 
> } 
>
> Right now, to achieve the same result I have to do: 
> if(value->IsArray()) { 
> } else if(value->IsBoolean()) { 
> } else if(value->IsDate()) { 
> } .... 
>
> This is a performance overkill. 
>
> Bottom line: 
> Is there any API for actually *getting* the type instead of *guessing* it? 
>

Four years later, I have the same question.
It seems inconceivable that V8 wouldn't know the type of the value 
internally; I'm just trying to get at that type through V8's C++ API.

The two questions behind my question, in case anyone can help with these, 
are:

(1) I'm trying to stringize an arbitrary Javascript object — if it's 
JSONable I'd like to JSON.stringify it, but if that throws, I'd at least 
like to be able to say what type it was. For example, "unserializable 
object of type RegExp" or "unserializable object of type Bicycle" or 
whatever.

(2) I'm trying to expose a C++ function into Javascript. My callback is 
defined as

void foo(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    if (args.Length() != 1) throw "expected a single numeric argument";
    if (args[0]->IsNumber()) throw "expected a single numeric argument";
    // now do something with the numeric value we got
}

However, the above doesn't seem to accept values that aren't numeric 
literals, e.g.

    var x = 42;
    foo(x);  // throws because x apparently isn't IsNumber??

If there were a simple way to ask V8 "okay, so it's not IsNumber... what 
*is* it, then?", then I would have debugged this issue by now.

Thanks for any help anyone can provide,
–Arthur

-- 
-- 
v8-users mailing list
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to