Hi All!

I have so many troubles using the global object thing. I am unable to
correctly attach an underlying object to it. I've seeked this group
for the first error that came up which was that eventhough when making
a SetInternalFieldCount(1) on the global object template, it'll be
lost when trying to access the global object instance. I've fixed this
in the api.cc where the global object is cloned, however now I have
updated to the latest trunk from version 0.4.9 to version 1.1.3 and
this error doesn't have been fixed so how is one supposed to attach a c
++ object instance to the global object at all?

Anyway, I can fix it again however I still have one big issue I can't
get resolved. I am accessing the c++ object class using the .Holder()
info. Works like a charm with functions but doing the same with a
property accessor, I get a fatal error that external::cast failed..
seems because the holder object is not a Proxy but why!?
Here's some code:

Handle<Value> TestAccessorGetter(Local<String> property,
                        const AccessorInfo &info) {
  Local<Object> self = info.Holder();
  Local<External> wrap = Local<External>::Cast(self->GetInternalField
(0));
  void* ptr = wrap->Value();

  return Integer::New(123);
}


Handle<Value> TestFunction(const Arguments& args)
{
  Local<Object> self = args.Holder();
  Local<External> wrap = Local<External>::Cast(self->GetInternalField
(0));
  void* ptr = wrap->Value();

  return Integer::New(123);
}


int main()
{
  // Create a stack-allocated handle scope.
  HandleScope handle_scope;

  TestClass* testClass = new TestClass();

  Handle<ObjectTemplate> global = ObjectTemplate::New();
  global->SetAccessor(String::New("TestAccessor"),
TestAccessorGetter);
  global->Set(String::New("TestFunc"), FunctionTemplate::New
(TestFunction));
  global->SetInternalFieldCount(1);

  // Create a new context.
  Persistent<Context> context = Context::New(NULL, global);

  // Enter the created context for compiling and
  // running the hello world script.
  Context::Scope context_scope(context);

  Handle<Object> globalObj = context->Global();
  globalObj->SetInternalField(0, External::New(testClass));

  // Create a string containing the JavaScript source code.
  Handle<String> source = String::New("TestFunc(); TestAccessor;");

  // Compile the source code.
  Handle<Script> script = Script::Compile(source);

  // Run the script to get the result.
  script->Run();

  // Dispose the persistent context.
  context.Dispose();
}

--> Call to TestFunction works perfectly. But the next call to
TestAccessor throws within Local<External> wrap = Local<External>::Cast
(self->GetInternalField(0));...

please, anyone?

thanks _a lot_ as I've been spending days now to get this figured :(

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

Reply via email to