Print this page
enable v8plus_call to be used in any thread


 399 
 400         if (fmt != NULL) {
 401                 va_start(ap, fmt);
 402                 len = vsnprintf(NULL, 0, fmt, ap);
 403                 va_end(ap);
 404                 msg = reinterpret_cast<char *>(alloca(len + 1));
 405 
 406                 va_start(ap, fmt);
 407                 (void) vsnprintf(msg, len + 1, fmt, ap);
 408                 va_end(ap);
 409         } else {
 410                 msg = _v8plus_errmsg;
 411         }
 412 
 413         exception = sexception(type, lp, msg);
 414 
 415         return (exception);
 416 }
 417 
 418 extern "C" nvlist_t *
 419 v8plus_call(v8plus_jsfunc_t f, const nvlist_t *lp)
 420 {
 421         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 422         const int max_argc = nvlist_length(lp);
 423         int argc, err;
 424         v8::Handle<v8::Value> argv[max_argc];
 425         v8::Handle<v8::Value> res;
 426         nvlist_t *rp;
 427 
 428         if ((it = cbhash.find(f)) == cbhash.end())
 429                 v8plus_panic("callback hash tag %llu not found", f);
 430 
 431         argc = max_argc;
 432         nvlist_to_v8_argv(lp, &argc, argv);
 433 
 434         if ((err = nvlist_alloc(&rp, NV_UNIQUE_NAME, 0)) != 0)
 435                 return (v8plus_nverr(err, NULL));
 436 
 437         v8::TryCatch tc;
 438         res = it->second.ch_hdl->Call(v8::Context::GetCurrent()->Global(),
 439             argc, argv);


 509 }
 510 
 511 extern "C" void
 512 v8plus_jsfunc_hold(v8plus_jsfunc_t f)
 513 {
 514         v8::Persistent<v8::Function> pfh;
 515         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 516 
 517         if ((it = cbhash.find(f)) == cbhash.end())
 518                 v8plus_panic("callback hash tag %llu not found", f);
 519 
 520         if (!it->second.ch_persist) {
 521                 pfh = v8::Persistent<v8::Function>::New(it->second.ch_hdl);
 522                 it->second.ch_hdl = pfh;
 523                 it->second.ch_persist = _B_TRUE;
 524         }
 525         ++it->second.ch_refs;
 526 }
 527 
 528 extern "C" void
 529 v8plus_jsfunc_rele(v8plus_jsfunc_t f)
 530 {
 531         v8::Local<v8::Function> lfh;
 532         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 533 
 534         if ((it = cbhash.find(f)) == cbhash.end())
 535                 v8plus_panic("callback hash tag %llu not found", f);
 536 
 537         if (it->second.ch_refs == 0)
 538                 v8plus_panic("releasing unheld callback hash tag %llu", f);
 539 
 540         if (--it->second.ch_refs == 0) {
 541                 if (it->second.ch_persist) {
 542                         v8::Persistent<v8::Function> pfh(it->second.ch_hdl);
 543                         pfh.Dispose();
 544                 }
 545                 cbhash.erase(it);
 546         }
 547 }
 548 
 549 static size_t


 623         uint64_t *lvp;
 624         uint_t nv;
 625         int err;
 626 
 627         if ((err = nvpair_value_uint64_array((nvpair_t *)pp, &lvp, &nv)) != 0)
 628                 return (err);
 629 
 630         *vp = *lvp;
 631 
 632         return (0);
 633 }
 634 
 635 extern "C" void
 636 v8plus_obj_hold(const void *cop)
 637 {
 638         v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
 639         op->public_Ref();
 640 }
 641 
 642 extern "C" void
 643 v8plus_obj_rele(const void *cop)
 644 {
 645         v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
 646         op->public_Unref();
 647 }


 399 
 400         if (fmt != NULL) {
 401                 va_start(ap, fmt);
 402                 len = vsnprintf(NULL, 0, fmt, ap);
 403                 va_end(ap);
 404                 msg = reinterpret_cast<char *>(alloca(len + 1));
 405 
 406                 va_start(ap, fmt);
 407                 (void) vsnprintf(msg, len + 1, fmt, ap);
 408                 va_end(ap);
 409         } else {
 410                 msg = _v8plus_errmsg;
 411         }
 412 
 413         exception = sexception(type, lp, msg);
 414 
 415         return (exception);
 416 }
 417 
 418 extern "C" nvlist_t *
 419 v8plus_call_direct(v8plus_jsfunc_t f, const nvlist_t *lp)
 420 {
 421         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 422         const int max_argc = nvlist_length(lp);
 423         int argc, err;
 424         v8::Handle<v8::Value> argv[max_argc];
 425         v8::Handle<v8::Value> res;
 426         nvlist_t *rp;
 427 
 428         if ((it = cbhash.find(f)) == cbhash.end())
 429                 v8plus_panic("callback hash tag %llu not found", f);
 430 
 431         argc = max_argc;
 432         nvlist_to_v8_argv(lp, &argc, argv);
 433 
 434         if ((err = nvlist_alloc(&rp, NV_UNIQUE_NAME, 0)) != 0)
 435                 return (v8plus_nverr(err, NULL));
 436 
 437         v8::TryCatch tc;
 438         res = it->second.ch_hdl->Call(v8::Context::GetCurrent()->Global(),
 439             argc, argv);


 509 }
 510 
 511 extern "C" void
 512 v8plus_jsfunc_hold(v8plus_jsfunc_t f)
 513 {
 514         v8::Persistent<v8::Function> pfh;
 515         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 516 
 517         if ((it = cbhash.find(f)) == cbhash.end())
 518                 v8plus_panic("callback hash tag %llu not found", f);
 519 
 520         if (!it->second.ch_persist) {
 521                 pfh = v8::Persistent<v8::Function>::New(it->second.ch_hdl);
 522                 it->second.ch_hdl = pfh;
 523                 it->second.ch_persist = _B_TRUE;
 524         }
 525         ++it->second.ch_refs;
 526 }
 527 
 528 extern "C" void
 529 v8plus_jsfunc_rele_direct(v8plus_jsfunc_t f)
 530 {
 531         v8::Local<v8::Function> lfh;
 532         std::unordered_map<uint64_t, cb_hdl_t>::iterator it;
 533 
 534         if ((it = cbhash.find(f)) == cbhash.end())
 535                 v8plus_panic("callback hash tag %llu not found", f);
 536 
 537         if (it->second.ch_refs == 0)
 538                 v8plus_panic("releasing unheld callback hash tag %llu", f);
 539 
 540         if (--it->second.ch_refs == 0) {
 541                 if (it->second.ch_persist) {
 542                         v8::Persistent<v8::Function> pfh(it->second.ch_hdl);
 543                         pfh.Dispose();
 544                 }
 545                 cbhash.erase(it);
 546         }
 547 }
 548 
 549 static size_t


 623         uint64_t *lvp;
 624         uint_t nv;
 625         int err;
 626 
 627         if ((err = nvpair_value_uint64_array((nvpair_t *)pp, &lvp, &nv)) != 0)
 628                 return (err);
 629 
 630         *vp = *lvp;
 631 
 632         return (0);
 633 }
 634 
 635 extern "C" void
 636 v8plus_obj_hold(const void *cop)
 637 {
 638         v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
 639         op->public_Ref();
 640 }
 641 
 642 extern "C" void
 643 v8plus_obj_rele_direct(const void *cop)
 644 {
 645         v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
 646         op->public_Unref();
 647 }