-
-
Save Qard/df47710286f90b17aaee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAN_METHOD(Context::createEvent) { | |
NanScope(); | |
Local<Object> obj = NanNew<Object>(); | |
NanSetInternalFieldPointer(obj, 1, Context::get()); | |
Handle<Value> argv[1] = { obj }; | |
// Handle<Value> argv[1] = { NanNew<External>((void *) Context::get()) }; | |
NanReturnValue(NanNew(Event::constructor)->NewInstance(1, argv)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I'm trying to approximate this; | |
Context.prototype.createEvent = function () { | |
return new Event(this) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NAN_METHOD(Event::New) { | |
NanScope(); | |
if (!args.IsConstructCall()) { | |
return NanThrowError("Event() must be called as a constructor"); | |
} | |
Event* event; | |
if (args.Length() == 1) { | |
void* ptr = NanGetInternalFieldPointer(args[0].As<Object>(), 1); | |
metadata_t* context = static_cast<metadata_t*>(ptr); | |
// ptr is a nullptr here.... | |
event = new Event(context, false); | |
} else { | |
event = new Event(); | |
} | |
event->Wrap(args.This()); | |
NanSetInternalFieldPointer(args.This(), 1, &event->event); | |
NanReturnValue(args.This()); | |
} | |
void Event::Init(Handle<Object> exports) { | |
NanScope(); | |
// Prepare constructor template | |
Handle<FunctionTemplate> ctor = NanNew<FunctionTemplate>(New); | |
ctor->InstanceTemplate()->SetInternalFieldCount(2); | |
ctor->SetClassName(NanNew<String>("Event")); | |
NanAssignPersistent(constructor, ctor->GetFunction()); | |
exports->Set(NanNew<String>("Event"), ctor->GetFunction()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment