summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2017-11-29 12:52:16 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2017-12-28 03:08:25 +0800
commit9f122e3b5513fd354b3876d06ea322b676b7350d (patch)
treeb833d235a6f3137fda7cd578bdac5d383f3aaf3c /src
parent6ca10de9468ed027f5e0b45f721d441df5972bc9 (diff)
downloadandroid-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.tar.gz
android-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.tar.bz2
android-node-v8-9f122e3b5513fd354b3876d06ea322b676b7350d.zip
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 <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'src')
-rw-r--r--src/node_file.cc18
1 files changed, 13 insertions, 5 deletions
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<Value>& args) {
void Close(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
+ Local<Context> context = env->context();
+ int length = args.Length();
+ CHECK_GE(length, 2);
CHECK(args[0]->IsInt32());
- int fd = args[0]->Int32Value();
+ int fd = static_cast<int>(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<Object> 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);
}
}