From 9f122e3b5513fd354b3876d06ea322b676b7350d Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 29 Nov 2017 12:52:16 +0800 Subject: fs: throw fs.close errors in JS * Collect the error context in both JS and C++, then throw the error in JS * Test that the errors thrown from fs.close and fs.closeSync includes the correct error code, error number and syscall properties PR-URL: https://github.com/nodejs/node/pull/17338 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- src/node_file.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/node_file.cc b/src/node_file.cc index 3373ad8707..3f680c14d6 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -429,15 +429,23 @@ void Access(const FunctionCallbackInfo& args) { void Close(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); + Local context = env->context(); + int length = args.Length(); + CHECK_GE(length, 2); CHECK(args[0]->IsInt32()); - int fd = args[0]->Int32Value(); + int fd = static_cast(args[0]->Int32Value(context).FromJust()); - if (args[1]->IsObject()) { - ASYNC_CALL(AfterNoArgs, close, args[1], UTF8, fd) - } else { - SYNC_CALL(close, 0, fd) + if (args[1]->IsObject()) { // close(fd, req) + Local req_obj = args[1]->ToObject(context).ToLocalChecked(); + FSReqWrap* req_wrap = AsyncCall( + env, req_obj, UTF8, "close", AfterNoArgs, uv_fs_close, fd); + if (req_wrap != nullptr) { + args.GetReturnValue().Set(req_wrap->persistent()); + } + } else { // close(fd, undefined, ctx) + SyncCall(env, args[2], "close", uv_fs_close, fd); } } -- cgit v1.2.3