| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f5fd2f commit 37010cb
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -777,43 +777,6 @@ void AfterScanDir(uv_fs_t* req) { | |||
| 777 | 777 | FSReqBase* req_wrap = FSReqBase::from_req(req); | |
| 778 | 778 | FSReqAfterScope after(req_wrap, req); | |
| 779 | 779 | ||
| 780 | - if (!after.Proceed()) { | ||
| 781 | - return; | ||
| 782 | - } | ||
| 783 | - Environment* env = req_wrap->env(); | ||
| 784 | - Local<Value> error; | ||
| 785 | - int r; | ||
| 786 | - std::vector<Local<Value>> name_v; | ||
| 787 | - | ||
| 788 | - for (;;) { | ||
| 789 | - uv_dirent_t ent; | ||
| 790 | - | ||
| 791 | - r = uv_fs_scandir_next(req, &ent); | ||
| 792 | - if (r == UV_EOF) | ||
| 793 | - break; | ||
| 794 | - if (r != 0) { | ||
| 795 | - return req_wrap->Reject(UVException( | ||
| 796 | - env->isolate(), r, nullptr, req_wrap->syscall(), req->path)); | ||
| 797 | - } | ||
| 798 | - | ||
| 799 | - MaybeLocal<Value> filename = | ||
| 800 | - StringBytes::Encode(env->isolate(), | ||
| 801 | - ent.name, | ||
| 802 | - req_wrap->encoding(), | ||
| 803 | - &error); | ||
| 804 | - if (filename.IsEmpty()) | ||
| 805 | - return req_wrap->Reject(error); | ||
| 806 | - | ||
| 807 | - name_v.push_back(filename.ToLocalChecked()); | ||
| 808 | - } | ||
| 809 | - | ||
| 810 | - req_wrap->Resolve(Array::New(env->isolate(), name_v.data(), name_v.size())); | ||
| 811 | - } | ||
| 812 | - | ||
| 813 | - void AfterScanDirWithTypes(uv_fs_t* req) { | ||
| 814 | - FSReqBase* req_wrap = FSReqBase::from_req(req); | ||
| 815 | - FSReqAfterScope after(req_wrap, req); | ||
| 816 | - | ||
| 817 | 780 | if (!after.Proceed()) { | |
| 818 | 781 | return; | |
| 819 | 782 | } | |
@@ -826,6 +789,8 @@ void AfterScanDirWithTypes(uv_fs_t* req) { | |||
| 826 | 789 | std::vector<Local<Value>> name_v; | |
| 827 | 790 | std::vector<Local<Value>> type_v; | |
| 828 | 791 | ||
| 792 | + const bool with_file_types = req_wrap->with_file_types(); | ||
| 793 | + | ||
| 829 | 794 | for (;;) { | |
| 830 | 795 | uv_dirent_t ent; | |
| 831 | 796 | ||
@@ -837,23 +802,23 @@ void AfterScanDirWithTypes(uv_fs_t* req) { | |||
| 837 | 802 | UVException(isolate, r, nullptr, req_wrap->syscall(), req->path)); | |
| 838 | 803 | } | |
| 839 | 804 | ||
| 840 | - MaybeLocal<Value> filename = | ||
| 841 | - StringBytes::Encode(isolate, | ||
| 842 | - ent.name, | ||
| 843 | - req_wrap->encoding(), | ||
| 844 | - &error); | ||
| 845 | - if (filename.IsEmpty()) | ||
| 805 | + Local<Value> filename; | ||
| 806 | + if (!StringBytes::Encode(isolate, ent.name, req_wrap->encoding(), &error) | ||
| 807 | + .ToLocal(&filename)) { | ||
| 846 | 808 | return req_wrap->Reject(error); | |
| 809 | + } | ||
| 810 | + name_v.push_back(filename); | ||
| 847 | 811 | ||
| 848 | - name_v.push_back(filename.ToLocalChecked()); | ||
| 849 | - type_v.emplace_back(Integer::New(isolate, ent.type)); | ||
| 812 | + if (with_file_types) type_v.emplace_back(Integer::New(isolate, ent.type)); | ||
| 850 | 813 | } | |
| 851 | 814 | ||
| 852 | - Local<Value> result[] = { | ||
| 853 | - Array::New(isolate, name_v.data(), name_v.size()), | ||
| 854 | - Array::New(isolate, type_v.data(), type_v.size()) | ||
| 855 | - }; | ||
| 856 | - req_wrap->Resolve(Array::New(isolate, result, arraysize(result))); | ||
| 815 | + if (with_file_types) { | ||
| 816 | + Local<Value> result[] = {Array::New(isolate, name_v.data(), name_v.size()), | ||
| 817 | + Array::New(isolate, type_v.data(), type_v.size())}; | ||
| 818 | + req_wrap->Resolve(Array::New(isolate, result, arraysize(result))); | ||
| 819 | + } else { | ||
| 820 | + req_wrap->Resolve(Array::New(isolate, name_v.data(), name_v.size())); | ||
| 821 | + } | ||
| 857 | 822 | } | |
| 858 | 823 | ||
| 859 | 824 | void Access(const FunctionCallbackInfo<Value>& args) { | |
@@ -1650,13 +1615,16 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) { | |||
| 1650 | 1615 | ||
| 1651 | 1616 | FSReqBase* req_wrap_async = GetReqWrap(args, 3); | |
| 1652 | 1617 | if (req_wrap_async != nullptr) { // readdir(path, encoding, withTypes, req) | |
| 1653 | - if (with_types) { | ||
| 1654 | - AsyncCall(env, req_wrap_async, args, "scandir", encoding, | ||
| 1655 | - AfterScanDirWithTypes, uv_fs_scandir, *path, 0 /*flags*/); | ||
| 1656 | - } else { | ||
| 1657 | - AsyncCall(env, req_wrap_async, args, "scandir", encoding, | ||
| 1658 | - AfterScanDir, uv_fs_scandir, *path, 0 /*flags*/); | ||
| 1659 | - } | ||
| 1618 | + req_wrap_async->set_with_file_types(with_types); | ||
| 1619 | + AsyncCall(env, | ||
| 1620 | + req_wrap_async, | ||
| 1621 | + args, | ||
| 1622 | + "scandir", | ||
| 1623 | + encoding, | ||
| 1624 | + AfterScanDir, | ||
| 1625 | + uv_fs_scandir, | ||
| 1626 | + *path, | ||
| 1627 | + 0 /*flags*/); | ||
| 1660 | 1628 | } else { // readdir(path, encoding, withTypes, undefined, ctx) | |
| 1661 | 1629 | CHECK_EQ(argc, 5); | |
| 1662 | 1630 | FSReqWrapSync req_wrap_sync; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -89,8 +89,10 @@ class FSReqBase : public ReqWrap<uv_fs_t> { | |||
| 89 | 89 | enum encoding encoding() const { return encoding_; } | |
| 90 | 90 | bool use_bigint() const { return use_bigint_; } | |
| 91 | 91 | bool is_plain_open() const { return is_plain_open_; } | |
| 92 | + bool with_file_types() const { return with_file_types_; } | ||
| 92 | 93 | ||
| 93 | 94 | void set_is_plain_open(bool value) { is_plain_open_ = value; } | |
| 95 | + void set_with_file_types(bool value) { with_file_types_ = value; } | ||
| 94 | 96 | ||
| 95 | 97 | FSContinuationData* continuation_data() const { | |
| 96 | 98 | return continuation_data_.get(); | |
@@ -116,6 +118,7 @@ class FSReqBase : public ReqWrap<uv_fs_t> { | |||
| 116 | 118 | bool has_data_ = false; | |
| 117 | 119 | bool use_bigint_ = false; | |
| 118 | 120 | bool is_plain_open_ = false; | |
| 121 | + bool with_file_types_ = false; | ||
| 119 | 122 | const char* syscall_ = nullptr; | |
| 120 | 123 | ||
| 121 | 124 | BaseObjectPtr<BindingData> binding_data_; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments