hey!
I…am stuck, again. This time however, I can’t find anything but posting here.
So, I have extended on my ph7 project now, and it has come to a point where it
is almost usable. But now I ran into an issue that is confusing me. So, within
my ObjectWrap class (ph7_wrapper : node::ObjectWrap) I have this declaration:
v8::Local<v8::Value> include_path;
v8::Local<v8::Value> $_SERVER;
v8::Local<v8::Value> $SGLOBALS;
v8::Local<v8::Value> $_ENV;
v8::Local<v8::Value> $_HEADERS;
v8::Local<v8::Value> $_GET;
v8::Local<v8::Value> $_POST;
v8::Local<v8::Value> $_COOKIE;
v8::Local<v8::Value> $_SESSION;
v8::Local<v8::Value> $argv;
v8::Local<v8::Value> $GLOBALS;
Its quite some, but I am not showing off everything, just the most important.
Now, I have a create method that returns a new instance with these variables.
The actual logic is this:
Handle<Value> ph7_wrapper::create(const Arguments& args) {
HandleScope scope;
// Create template
Local<ObjectTemplate> tpl = ObjectTemplate::New();
tpl->SetInternalFieldCount(2);
// Let's not forget the accessors.
tpl->SetAccessor(String::New("$SGLOBALS"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_SERVER"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_ENV"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_GET"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_POST"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_COOKIE"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_SESSION"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$_HEADERS"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$GLOBALS"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("$argv"),
ph7_wrapper::vm_getter, ph7_wrapper::vm_setter);
tpl->SetAccessor(String::New("include_path"),ph7_wrapper::vm_getter,
ph7_wrapper::vm_setter);
// Now, lets assign methods!
NODE_SET_METHOD(tpl, "config", ph7_wrapper::vm_config);
NODE_SET_METHOD(tpl, "prepair",
ph7_wrapper::vm_prepair);
NODE_SET_METHOD(tpl, "compile",
ph7_wrapper::vm_compile);
NODE_SET_METHOD(tpl, "compileFile", ph7_wrapper::vm_compileFile);
// Now the uber convinience :3
tpl->SetCallAsFunctionHandler(ph7_wrapper::vm_run);
// Wrap the nativeness.
Local<Object> obj = tpl->NewInstance();
ph7_wrapper *$self = new ph7_wrapper;
// Cast to void, store in object.
obj->SetPointerInInternalField(0, (void*)$self);
return scope.Close(obj);
}
So far so good. I can create my object, but when I use console.log to read if
everything is there, I run straight into a crash. Why? Well, the problem lies
in my getter function:
Handle<Value> ph7_wrapper::vm_getter(Local<String> property, const
AccessorInfo& info) {
NJS_UNWRAP_ACC($self, ph7_wrapper, info, 0);
HandleScope scope;
const char* cprop = **(new String::AsciiValue(property));
cout << "Getting: " << cprop << endl;
if (strcmp(cprop, "include_path") == 0) { return
scope.Close($self->include_path); }
else if (strcmp(cprop, "$_SERVER") == 0) { return
scope.Close($self->$_SERVER); }
else if (strcmp(cprop, "$_ENV") == 0) { return
scope.Close($self->$_ENV); }
else if (strcmp(cprop, "$_HEADERS") == 0) { return
scope.Close($self->$_HEADERS); }
else if (strcmp(cprop, "$_GET") == 0) { return
scope.Close($self->$_GET); }
else if (strcmp(cprop, "$_POST") == 0) { return
scope.Close($self->$_POST); }
else if (strcmp(cprop, "$_COOKIE") == 0) { return
scope.Close($self->$_COOKIE); }
else if (strcmp(cprop, "$_SESSION") == 0) { return
scope.Close($self->$_SESSION); }
else if (strcmp(cprop, "$argv") == 0) { return
scope.Close($self->$argv); }
else if (strcmp(cprop, "$GLOBALS") == 0) { return
scope.Close($self->$GLOBALS); }
else if (strcmp(cprop, "$SGLOBALS") == 0) { return
scope.Close($self->$SGLOBALS); }
else return scope.Close(Undefined());
}
The crash reports that „an invaild object was returned“, and due to my little
cout above the if’s, I know the variable, and that it happens right here, once
osmething is returned. When I just look up one variable, which does not crash,
and let nodejs display the type to me…it tells me that it is a string. Why, on
god’s earth, is something that was totally initialized as
this->$_SERVER = Array::New();
suddenly a frigin string?… I really ran out of ideas.
If anyone would be able to tell me, what I am doing wrong here, that’d be great.
The concept of the project is rather simple. It provides one method upon
require()ing, and a few cosntants. The one method is called to create a new
object as seen above, storing a new class isntance as a pointer into the
internal fields. Within other functions, that pointer is extracted and worked
with. So, to keep v8 arrays, I was thinking to just have them sit right inside
the class.
Please, any-dev, haaaaalp. x3
Kind regards, Ingwie
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" 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.