javascript - V8 crash when accessing persistent function -


can see why call persistent function pfunc_on_open crashes ?

locker lock(isolate); handlescope scope(isolate);  v8::local<v8::context> context = v8::local<v8::context>::new(isolate, p_context); context::scope context_scope(context); handle < v8::object > global = context->global();  handle < value > args[1]; if (event.compare(event_onopen) == 0) {      args[0] = v8::string::newfromutf8(isolate,message.c_str());      v8::local<v8::function> processonopen = v8::local<v8::function>::new(isolate, pfunc_on_open);      processonopen->call(global, 1, args); } 

the function associated javascript method via following code :

void websocket::exposewebsocket(handle<objecttemplate> globaltemplate) {  globaltemplate->set(string::newfromutf8(isolate,"websocket"), functiontemplate::new(isolate,websocketconstructor));} 

void websocketconstructor(const v8::functioncallbackinfo &args) {

logd(log_tag, "in websocketconstructor()");   locker lock(isolate);  handlescope scope(isolate);   handle<objecttemplate> websocket_templ= objecttemplate::new();  websocket_templ->setinternalfieldcount(1);   // object methods  websocket_templ->set(string::newfromutf8(isolate,"send"), functiontemplate::new(isolate,websocket::exposed_method_send));  websocket_templ->set(string::newfromutf8(isolate,"close"), functiontemplate::new(isolate,websocket::exposed_method_close));   // set properties event handlers  websocket_templ->setaccessor(string::newfromutf8(isolate,"onopen"), accessorgettercallback(websocket::getoncallback), accessorsettercallback(websocket::setonopen));  websocket_templ->setaccessor(string::newfromutf8(isolate,"onmessage"), accessorgettercallback(websocket::getoncallback), accessorsettercallback(websocket::setonmessage));  websocket_templ->setaccessor(string::newfromutf8(isolate,"onerror"), accessorgettercallback(websocket::getoncallback), accessorsettercallback(websocket::setonfail));  websocket_templ->setaccessor(string::newfromutf8(isolate,"onclose"), accessorgettercallback(websocket::getoncallback), accessorsettercallback(websocket::setonclose));   handle<object> ws_instance;   if (!args[0].isempty() && args[0]->isstring()) {          string::utf8value p1(args[0]->tostring());          logd(log_tag, "websocketconstructor() - url = %s", *p1);          // create c++ instance of type         websocket* wsobject = new websocket(*p1);          //handle<object> self = handle<object>::new(isolate, args.holder() );          ws_instance = websocket_templ->newinstance();           ws_instance->setinternalfield(0, v8::external::new(isolate, wsobject));          args.getreturnvalue().set(ws_instance);       } 

}

void websocket::setonopen(local<string> prop, local<value> value, const v8::propertycallbackinfo<void>& info) {

locker lock(isolate); handlescope scope(isolate);  string::utf8value str(prop);  logd(log_tag, "setonopen(): property = %s", *str);  // retrieve websocket instance associated callback // appropriate map object can used store callback address handle < object > self = info.holder(); handle < external > wrap = handle < external > ::cast(self->getinternalfield(0));  void* ptr = wrap->value();  websocket* ws = static_cast<websocket*>(ptr);  if (value->isfunction()) {      // store persistent function handle in callback map     handle<function> callback = handle<function>::cast(value);      ws->pfunc_on_open.reset(isolate, callback);      if(callback.isempty())     {          logd(log_tag, "callback null");     }      // may have connection error report     if (!ws->m_connection_error.empty() && std::string(*str).compare("onfail") == 0)     {         ws->calleventcallback(event_onfail, ws->m_connection_error);         ws->m_connection_error.clear();     } } else {     loge(log_tag, "setonopen(): invalid parameter type - value not function"); } 

}


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -