You never set the valueFromInterceptor property on any object.
Therefore, GetRealNamedPropertyInPrototypeChain can never find that
property and therefore the interceptor will do the same no matter how
many times you call it.

Cheers,    -- Mads

On Wed, Dec 2, 2009 at 4:57 AM, Xiang Zhong <[email protected]> wrote:
> Hi, All,
>
> When using Object:: GetRealNamedPropertyInPrototypeChain(), it seems it
> can't find already existed named property.
>
> There are two objects involved:
> o0   <--Define a named inteceptor for o0
>  ^
>  |  prototype
>  |
>  o1
> In the inteceptor of o0, I will check whether this property is defined
> already.
> When running script "o1.valueFromInteceptor; o1.valueFromInteceptor;", I
> expect
> When first try to
> resolve o1.valueFromInteceptor, GetRealNamedPropertyInPrototypeChain()
> should return empty
> But second try to resolve o1.valueFromInteceptor,
>  GetRealNamedPropertyInPrototypeChain() should not return empty.
> The sample is below:
> Expected behavior should be:
> property not defined before
> property defined before
>
> Now is:
> property not defined before
> property not defined before
>
>
> #include <v8.h>
> #include <iostream>
> using namespace v8;
> v8::Handle<v8::Value> Getter(v8::Local<v8::String> propertyName,const
> v8::AccessorInfo &info) {
>   v8::HandleScope handleScope;
> v8::Handle<v8::Value> v =
> info.This()->GetRealNamedPropertyInPrototypeChain(propertyName);
> if (!v.IsEmpty()) {
>         printf("property defined before\n");
> return v8::False();
> }
>     else
>     {
>         printf("property not defined before\n");
>         return v8::True();
>     }
> }
> int main()
> {
> HandleScope handleScope;
>
>   Persistent<Context> context = Context::New();
> Context::Scope contextScope(context);
>
>   Handle<FunctionTemplate> t0 = FunctionTemplate::New();
> t0->InstanceTemplate()->SetNamedPropertyHandler(Getter);
>   Handle<FunctionTemplate> t1 = FunctionTemplate::New();
>     Local<v8::Object> o0 = t0->GetFunction()->NewInstance();
>     Local<v8::Object> o1 = t1->GetFunction()->NewInstance();
>
>     o1->Set(v8::String::New("__proto__"), o0);
>     context->Global()->Set(v8::String::New("o0"), o0);
>     context->Global()->Set(v8::String::New("o1"), o1);
>
> Handle<Script> script =
> Script::Compile(v8::String::New("o1.valueFromInteceptor;
> o1.valueFromInteceptor;"));
> Handle<Value> result = script->Run();
> context.Dispose();
> return 0;
> }
>
>
> I am not sure whether I miss something or use it in wrong way.
> I appreciate if you can correct me.
>
>
> Cheers~
> Xiang
>
> --
> v8-dev mailing list
> [email protected]
> http://groups.google.com/group/v8-dev

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

Reply via email to