@@ -609,16 +609,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) { |
609 | 609 | ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); |
610 | 610 | Mutex::ScopedLock lock(w->mutex_); |
611 | 611 |
|
612 | | - // The object now owns the created thread and should not be garbage collected |
613 | | - // until that finishes. |
614 | | - w->ClearWeak(); |
615 | | - |
616 | | - w->env()->add_sub_worker_context(w); |
617 | 612 | w->stopped_ = false; |
618 | | - w->thread_joined_ = false; |
619 | | - |
620 | | - if (w->has_ref_) |
621 | | - w->env()->add_refs(1); |
622 | 613 |
|
623 | 614 | uv_thread_options_t thread_options; |
624 | 615 | thread_options.flags = UV_THREAD_HAS_STACK_SIZE; |
@@ -645,21 +636,27 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) { |
645 | 636 | // implicitly delete w |
646 | 637 | }); |
647 | 638 | }, static_cast<void*>(w)); |
648 | | - if (ret != 0) { |
| 639 | + |
| 640 | + if (ret == 0) { |
| 641 | + // The object now owns the created thread and should not be garbage |
| 642 | + // collected until that finishes. |
| 643 | + w->ClearWeak(); |
| 644 | + w->thread_joined_ = false; |
| 645 | + |
| 646 | + if (w->has_ref_) |
| 647 | + w->env()->add_refs(1); |
| 648 | + |
| 649 | + w->env()->add_sub_worker_context(w); |
| 650 | + } else { |
| 651 | + w->stopped_ = true; |
| 652 | + |
649 | 653 | char err_buf[128]; |
650 | 654 | uv_err_name_r(ret, err_buf, sizeof(err_buf)); |
651 | | - w->custom_error_ = "ERR_WORKER_INIT_FAILED"; |
652 | | - w->custom_error_str_ = err_buf; |
653 | | - w->loop_init_failed_ = true; |
654 | | - w->thread_joined_ = true; |
655 | | - w->stopped_ = true; |
656 | | - w->env()->remove_sub_worker_context(w); |
657 | 655 | { |
658 | 656 | Isolate* isolate = w->env()->isolate(); |
659 | 657 | HandleScope handle_scope(isolate); |
660 | 658 | THROW_ERR_WORKER_INIT_FAILED(isolate, err_buf); |
661 | 659 | } |
662 | | - w->MakeWeak(); |
663 | 660 | } |
664 | 661 | } |
665 | 662 |
|
|