Thanks for the help, I almost got it to work
alert('bla') works, this.alert('blup') don't, as it should, I can
access stuf from the other contect directly,
but I have a problem when i write alert(this) than it fails, somehow
the toString function is not being invoked and an empty string
returned, when i use a function that is defined in the new context
than it works.
Whats the issue?
below my code
HandleScope scope;
Local<ObjectTemplate> LocalTemplate = ObjectTemplate::New();
LocalTemplate->SetInternalFieldCount(1);
CJSElement::SetupNode(pNode, this, LocalTemplate);
CJSContext Context(LocalTemplate);
Context::Scope contextScope(Context.GetContext());
Context.GetContext()->Global()->Set(String::New("context"), m_Context-
>GetContext()->Global()->GetPrototype());
Local<Object> prototype = Local<Object>::Cast(Context.GetContext()-
>Global()->GetPrototype());
prototype->SetInternalField(OBJECT_FIELD, External::New(pNode));
string Script = "(function () {" \
"with (this.context) {" \
"return (function(){";
Script.append(ScriptStr);
Script.append("\n}).call();}})");
Local<Value> Result = Context.RunScriptEx(Script);
if(!Result.IsEmpty())
{
Local<Function> EventFunction = Local<Function>::Cast(Result);
TryCatch tryCatch;
Local<Value> result = EventFunction->Call(Context.GetContext()-
>Global(), 0, NULL);
if(result.IsEmpty())
Context.ReportException(&tryCatch);
}
On 31 Mrz., 20:27, Anton Muhin <[email protected]> wrote:
> David,
>
> because this is something different. I don't remember details right
> now, but it should be something like the HTMLElement on which your
> inline listener is installed.
>
> yours,
> anton.
>
> On Thu, Mar 31, 2011 at 10:19 PM, David Xanatos
>
>
>
>
>
>
>
> <[email protected]> wrote:
> > So the global object is always window?
> > But why alert(window == this) tells me
> > false?
>
> > David
>
> > On 31 Mrz., 15:13, Anton Muhin <[email protected]> wrote:
> >> On Wed, Mar 30, 2011 at 11:39 PM, David Xanatos
>
> >> <[email protected]> wrote:
> >> > Cool, thanks for the answer,
>
> >> > So this with statement allows me to have inside the called function a
> >> > "this" made up of multiple objects.
>
> >> Not quite, it's a special chain of objects which are used to resolve
> >> identifiers. http://dmitrysoshnikov.com/ecmascript/chapter-4-scope-chain/
> >> is a good text about it.
>
> >> > But, how does it work with alert this is a function of window, but
> >> > windows is not been point in such with thing ?
>
> >> alert is defined on the global object (and window is just an alias to
> >> it), so it's always accessible unless shadowed.
>
> >> yours,
> >> anton.
>
> >> > David
>
> >> > On 29 Mrz., 20:43, Anton Muhin <[email protected]> wrote:
> >> >> David,
>
> >> >> As per the spec, DOM bindings build a special context chain for that,
> >> >> seehttp://codesearch.google.com./codesearch/p?hl=en#OAMlx_jo-ck/src/thir...
> >> >> for more details.
>
> >> >> hth and yours,
> >> >> anton.
>
> >> >> On Tue, Mar 29, 2011 at 10:34 PM, David Xanatos
>
> >> >> <[email protected]> wrote:
> >> >> > When I am in a event like onlaod="alert('bla'); this.alert('blup')"
> >> >> > the this is not longer 'window' but the html object the event is in.
> >> >> > But strangely I call call any alert and use document as if the global
> >> >> > object still would be the window, but alert(window == this) tells me
> >> >> > false :/
>
> >> >> > I would like to use this behavioure in a V8 C++ project, so i wanted
> >> >> > to ask how is this "superopsition" of the global object with an other
> >> >> > object achieved?
>
> >> >> > --
> >> >> > v8-users mailing list
> >> >> > [email protected]
> >> >> >http://groups.google.com/group/v8-users
>
> >> > --
> >> > v8-users mailing list
> >> > [email protected]
> >> >http://groups.google.com/group/v8-users
>
> > --
> > v8-users mailing list
> > [email protected]
> >http://groups.google.com/group/v8-users
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users