Hi David,

I believe that "wrapping" is actually the right way to go.

Prepend your string with "function() {" and append "}"; compile, run and
convert the result to function. v8::Handle<v8::Function> has then the Call()
method, in which the first argument is your scope object....


Ondrej



2009/11/20 David <[email protected]>

>
> Hi. Given some JS in a string, I'd like to be able to evaluate it in a
> scope of my choice -- that is -- to set apparent global object for the
> JS to be something other than the context's actual global object. For
> example, if the JS is:
>
> var doggie = "laika";
>
> Then I'd like to be able to, when running that JS, have the "doggie"
> property of an arbitrary object of my choosing set to "laika".
>
> This would be the equivalent how, for JS_ExecuteScript() in the
> SpiderMonkey world (http://developer.mozilla.org/en/SpiderMonkey/
> JSAPI_Reference/JS_ExecuteScript<http://developer.mozilla.org/en/SpiderMonkey/%0AJSAPI_Reference/JS_ExecuteScript>),
> the second argument to the function
> is the apparent global object for the code to execute.
>
> I explored the "eval"-based solution described at
> http://markmail.org/message/3xw4eyrgunoiqobc but that doesn't work if
> the object-provided-as-alternative-global-object doesn't have an
> "eval" function attached to it. (Which objects generally don't.)
>
> The wrapExports mechanism that v8cgi uses I don't think is applicable
> for me since i don't know in advance the names of the variables that
> will be set inside the scope (as v8cgi does with "exports").
>
> Any help/thoughts? Have others encountered this need?
>
> Thanks,
> David
>
> >
>

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

Reply via email to