This project has moved and is read-only. For the latest updates, please go here.

Add engine.Script dynamic object as a host object

Feb 13, 2013 at 2:24 PM
Is there any way to do something like this?
engine.AddHostObject("dynamicHost", engine.Script);
I am getting an InvalidOperationException("Invalid host item").

But if i skip check on line 317 in V8ScriptEngine (using debugger) - ScriptInvoke will pass without errors and i will have reference to Script dynamic object inside my dynamicHost.

Is there exist clever way to have reference to global scope?
What possible issues could be if i will use code above?

Feb 13, 2013 at 3:06 PM
Edited Aug 3, 2013 at 3:37 AM
Hello pro100sanya!

The Script property provides host-side access to the script engine's global object. Because the script engine already has access to its own global object, we're not sure what purpose is served by re-exposing it via AddHostObject().

That is, if ClearScript allowed your operation, then within the script engine, dynamicHost would simply be an alias for the global object. Is that what you're trying to set up? If so, you could simply do this:
engine.Execute("dynamicHost = this");
Or this:
engine.Script.dynamicHost = engine.Script;
Please let us know if we're missing something about your scenario. Thanks for your question!
Feb 14, 2013 at 9:04 AM
Yes, i need an alias to global object.

Feb 14, 2013 at 3:47 PM
No problem! Please let us know if the solutions proposed above don't work for you.