On Tue, Sep 30, 2008 at 4:55 PM, ondras <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> (no IRC available as per my previous post, so I have to ask directly
> here)
>
> I would appreciate any help regarding these four issues:
>
> 1) how do I create (in C++) a JavaScript array, available in global
> context? I can do an object (global->Set(somestring,
> v8::ObjectTemplate::New()), a string, a number... but how about an
> array? And how can I then add its values? And what about more complex
> types, such as a Date() or RegExp() ?

Here is a fragement of my code that does just that:

        v8::Local<v8::Array> path = v8::Array::New(PathElems.size());
        for(int i = 0; i < PathElems.size(); ++i)
                path->Set(V8Int(i),V8Str(PathElems[i]));
        req->Set(V8Str("PathElems"),path);

I am not certain how to create the Date() or RegExp() objects from C++.

> 2) I fail to create a circular reference:
>
> global->Set(v8::String::New("window"), global);
>
> What am I doing wrong?

I am not sure what you are trying to do here.

> 3) Why does the 'ExecuteString' function (in shell.cc) need two
> arguments, the sourcecode and filename? Is this only used for caching
> purposes?

The source is the code to be executed.  The filename is context
information for error reports.

> 4) Imagine the following scenario:
>
> var A = function() {
>  this.name = "name";
>  load("printer.js");
> }
> this.name = "global";
> new A();
>
> and printer.js contains:
> print(this.name);
>
>
> This won't work as expected, because printer.js will be executed in
> global scope (so it will output "global"). Is it possible to load()
> the printer.js file while being in the correct scope (this instanceof
> A) ?

I don't know if that can be done.

-- 
Bryan White

--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to