[v8-users] execution of eval() function returns empty value

21 views
Skip to first unread message

vlad

unread,
May 10, 2010, 4:22:12 PM5/10/10
to v8-users
Hi,
I'm confused why execution of eval() function returns empty value?

v8::Handle<v8::Function> eval_func =
v8::Handle<v8::Function>::Cast(global->Get(v8::String::New("eval")));

v8::Handle<v8::Value> args[] = { v8::String::New("/^a/i") };

v8::Handle<v8::Value> ret = eval_func->Call(eval_func, 1, args);

ret{val_ = 0x00000000} ?????


However if I do this:

V8RUN("function Foo(x) {return eval(x);}");

v8::Handle<v8::Function> eval_func =
v8::Handle<v8::Function>::Cast(global->Get(v8::String::New("Foo")));

v8::Handle<v8::Value> args[] = { v8::String::New("/^a/i") };

v8::Handle<v8::Value> ret = eval_func->Call(eval_func, 1, args);

ret is a valid RegExp object.

Thanks
Vlad




--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users

Stephan Beal

unread,
May 10, 2010, 4:43:29 PM5/10/10
to v8-u...@googlegroups.com
On Mon, May 10, 2010 at 10:22 PM, vlad <vla...@gmail.com> wrote:
>
> v8::Handle<v8::Value> ret = eval_func->Call(eval_func, 1, args);

i _think_ what you're looking for is:

v8::Handle<v8::Function> eval_func =
v8::Handle<v8::Function>::Cast(global->Get(v8::String::New("eval")));
...
v8::Handle<v8::Value> ret = eval_func->Call(global, 1, args);

Remember that the first argument to Call() is the "this" object, and
for eval() you want that to be the global.


PS: if you are only passing only one object as the args list then you
don't need the extra intermediary array. i.e.

Call(..., 1, &theArg)

will do.
--
----- stephan beal
http://wanderinghorse.net/home/stephan/

vlad

unread,
May 10, 2010, 6:33:38 PM5/10/10
to v8-users
Thank you!!! It works now.

On May 10, 1:43 pm, Stephan Beal <sgb...@googlemail.com> wrote:
> On Mon, May 10, 2010 at 10:22 PM, vlad <vlad...@gmail.com> wrote:
>
> > v8::Handle<v8::Value> ret = eval_func->Call(eval_func, 1, args);
>
> i _think_ what you're looking for is:
>
> v8::Handle<v8::Function> eval_func =
> v8::Handle<v8::Function>::Cast(global->Get(v8::String::New("eval")));
> ...
> v8::Handle<v8::Value> ret = eval_func->Call(global, 1, args);
>
> Remember that the first argument to Call() is the "this" object, and
> for eval() you want that to be the global.
>
> PS: if you are only passing only one object as the args list then you
> don't need the extra intermediary array. i.e.
>
> Call(..., 1, &theArg)
>
> will do.
> --
> ----- stephan bealhttp://wanderinghorse.net/home/stephan/
>
> --
> v8-users mailing list
> v8-users@googlegroups.comhttp://groups.google.com/group/v8-users
Reply all
Reply to author
Forward
0 new messages