The following code seems pretty straight forward to me, but produces a
crash (OS X 10.6.4).
#include <v8.h>
using namespace v8;
Handle<Value>
Getter(Local<String> property, const AccessorInfo& info ) {
return String::New("42!");
}
Handle<Array>
Enumerator(const AccessorInfo& info) {
Handle<Array> result = Array::New();
result->Set(0, String::New("universalAnswer"));
return result;
}
Handle<Integer>
Query(Local<String> property, const AccessorInfo& info) {
return Integer::New(DontDelete | ReadOnly );
}
int main(int argc, char* argv[]) {
HandleScope handle_scope;
Persistent<Context> context = Context::New();
Context::Scope context_scope(context);
Handle<ObjectTemplate> tmpl = ObjectTemplate::New();
tmpl->SetNamedPropertyHandler(Getter, 0 ,Query, 0,Enumerator);
context->Global()->Set(String::New("test"), tmpl->NewInstance() );
Handle<String> source = String::New("JSON.stringify(test)");
Handle<Script> script = Script::Compile(source);
Handle<Value> result = script->Run();
context.Dispose();
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}
GDB isn't really helpful, this is the output
(gdb) run
Starting program: /Users/smorawietz/devel/test/cpp/v8test
Reading symbols for shared libraries ++. done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0xffffffffffffffff
0x00000001000f1150 in v8::internal::JSObject::LocalLookup ()
(gdb) bt
#0 0x00000001000f1150 in v8::internal::JSObject::LocalLookup ()
#1 0x00000001000f16fe in v8::internal::Object::Lookup ()
Previous frame inner to this frame (gdb could not unwind past this
frame)
(gdb)
What am I missing?
Greets
Sebastian
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users