Hello there,
I have a piece of native C++ code that creates "special" objects. Objects,
that behave differently under certain conditions.
My question is, how to make these special objects resume their normal
functionality. I need something that says (in pseudo-code)
Getter() {
if (my condition) {
return a specially calculated value */ I know how to do this /*
} else
return the regular JS value */ How do I do this? /*
}
}
Setter() {
if (my condition) {
cause a special side effect */ I know how to do this /*
} else
set the regular JS value */ How do I do this? /*
}
}
Here is a sample code I've written to investigate this issue (based on
"hello world").
1 #include <v8.h>
2 #include <stdio.h>
3 using namespace v8;
4
5 void GetAlfa(Local<String> property, const PropertyCallbackInfo<Value>&
info)
6 {
7 }
8 void SetAlfa(Local<String> property, Local<Value> value, const
PropertyCallbackInfo<void>& info)
9 {
10 }
11
12 int main(int argc, char* argv[]) {
13 Isolate* isolate = Isolate::GetCurrent();
14 HandleScope handle_scope(isolate);
15 Handle<Context> context = Context::New(isolate);
16 Context::Scope context_scope(context);
*17 Handle<ObjectTemplate> specific_templ = ObjectTemplate::New();*
* 18 specific_templ->SetAccessor(String::New("alfa"), GetAlfa, SetAlfa);*
* 19 Handle<Object> specific_obj = specific_templ->NewInstance();*
* 20 context->Global()->Set(String::New("specific"), specific_obj);*
* 21 Handle<String> source = String::New("specific.alfa=7;
specific.alfa");*
22 Handle<Script> script = Script::Compile(source);
23 Handle<Value> result = script->Run();
24 String::AsciiValue ascii(result);
25 printf("%s\n", *ascii);
26 return 0;
27 }
Currently the code returns "undefined". Is there a way to make it return
"7" *without* removing the getter and setter, and *without* going to
External or static storage?
I did some primitive testing, and ended up in infinite get- or set-loops.
Regards,
Danny
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.