436
437 v8::TryCatch tc;
438 res = it->second.ch_hdl->Call(v8::Context::GetCurrent()->Global(),
439 argc, argv);
440 if (tc.HasCaught()) {
441 err = nvlist_add_v8_Value(rp, "err", tc.Exception());
442 tc.Reset();
443 if (err != 0) {
444 nvlist_free(rp);
445 return (v8plus_nverr(err, "err"));
446 }
447 } else if ((err = nvlist_add_v8_Value(rp, "res", res)) != 0) {
448 nvlist_free(rp);
449 return (v8plus_nverr(err, "res"));
450 }
451
452 return (rp);
453 }
454
455 extern "C" nvlist_t *
456 v8plus_method_call(void *cop, const char *name, const nvlist_t *lp)
457 {
458 v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
459 const int max_argc = nvlist_length(lp);
460 int argc, err;
461 v8::Handle<v8::Value> argv[max_argc];
462 v8::Handle<v8::Value> res;
463 nvlist_t *rp;
464
465 argc = max_argc;
466 nvlist_to_v8_argv(lp, &argc, argv);
467
468 if ((err = nvlist_alloc(&rp, NV_UNIQUE_NAME, 0)) != 0)
469 return (v8plus_nverr(err, NULL));
470
471 v8::TryCatch tc;
472 res = op->call(name, argc, argv);
473 if (tc.HasCaught()) {
474 err = nvlist_add_v8_Value(rp, "err", tc.Exception());
475 tc.Reset();
476 if (err != 0) {
477 nvlist_free(rp);
478 return (v8plus_nverr(err, "err"));
479 }
480 } else if ((err = nvlist_add_v8_Value(rp, "res", res)) != 0) {
481 nvlist_free(rp);
482 return (v8plus_nverr(err, "res"));
483 }
484
|
436
437 v8::TryCatch tc;
438 res = it->second.ch_hdl->Call(v8::Context::GetCurrent()->Global(),
439 argc, argv);
440 if (tc.HasCaught()) {
441 err = nvlist_add_v8_Value(rp, "err", tc.Exception());
442 tc.Reset();
443 if (err != 0) {
444 nvlist_free(rp);
445 return (v8plus_nverr(err, "err"));
446 }
447 } else if ((err = nvlist_add_v8_Value(rp, "res", res)) != 0) {
448 nvlist_free(rp);
449 return (v8plus_nverr(err, "res"));
450 }
451
452 return (rp);
453 }
454
455 extern "C" nvlist_t *
456 v8plus_method_call_direct(void *cop, const char *name, const nvlist_t *lp)
457 {
458 v8plus::ObjectWrap *op = v8plus::ObjectWrap::objlookup(cop);
459 const int max_argc = nvlist_length(lp);
460 int argc, err;
461 v8::Handle<v8::Value> argv[max_argc];
462 v8::Handle<v8::Value> res;
463 nvlist_t *rp;
464
465 if (v8plus_in_event_thread() != _B_TRUE)
466 v8plus_panic("direct method call outside of event loop");
467
468 argc = max_argc;
469 nvlist_to_v8_argv(lp, &argc, argv);
470
471 if ((err = nvlist_alloc(&rp, NV_UNIQUE_NAME, 0)) != 0)
472 return (v8plus_nverr(err, NULL));
473
474 v8::TryCatch tc;
475 res = op->call(name, argc, argv);
476 if (tc.HasCaught()) {
477 err = nvlist_add_v8_Value(rp, "err", tc.Exception());
478 tc.Reset();
479 if (err != 0) {
480 nvlist_free(rp);
481 return (v8plus_nverr(err, "err"));
482 }
483 } else if ((err = nvlist_add_v8_Value(rp, "res", res)) != 0) {
484 nvlist_free(rp);
485 return (v8plus_nverr(err, "res"));
486 }
487
|