fs: throw openSync errors in JS
PR-URL: https://github.com/nodejs/node/pull/18871 Refs: https://github.com/nodejs/node/issues/18106 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
d2c4f5082f
commit
fea5dda1d1
@ -521,8 +521,12 @@ fs.openSync = function(path, flags, mode) {
|
|||||||
validatePath(path);
|
validatePath(path);
|
||||||
validateUint32(mode, 'mode');
|
validateUint32(mode, 'mode');
|
||||||
|
|
||||||
return binding.open(pathModule.toNamespacedPath(path),
|
const ctx = { path };
|
||||||
stringToFlags(flags), mode);
|
const result = binding.open(pathModule.toNamespacedPath(path),
|
||||||
|
stringToFlags(flags), mode,
|
||||||
|
undefined, ctx);
|
||||||
|
handleErrorFromBinding(ctx);
|
||||||
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.read = function(fd, buffer, offset, length, position, callback) {
|
fs.read = function(fd, buffer, offset, length, position, callback) {
|
||||||
|
@ -1169,25 +1169,29 @@ static void ReadDir(const FunctionCallbackInfo<Value>& args) {
|
|||||||
|
|
||||||
static void Open(const FunctionCallbackInfo<Value>& args) {
|
static void Open(const FunctionCallbackInfo<Value>& args) {
|
||||||
Environment* env = Environment::GetCurrent(args);
|
Environment* env = Environment::GetCurrent(args);
|
||||||
Local<Context> context = env->context();
|
|
||||||
|
|
||||||
CHECK_GE(args.Length(), 3);
|
const int argc = args.Length();
|
||||||
CHECK(args[1]->IsInt32());
|
CHECK_GE(argc, 3);
|
||||||
CHECK(args[2]->IsInt32());
|
|
||||||
|
|
||||||
BufferValue path(env->isolate(), args[0]);
|
BufferValue path(env->isolate(), args[0]);
|
||||||
CHECK_NE(*path, nullptr);
|
CHECK_NE(*path, nullptr);
|
||||||
|
|
||||||
int flags = args[1]->Int32Value(context).ToChecked();
|
CHECK(args[1]->IsInt32());
|
||||||
int mode = args[2]->Int32Value(context).ToChecked();
|
const int flags = args[1].As<Int32>()->Value();
|
||||||
|
|
||||||
|
CHECK(args[2]->IsInt32());
|
||||||
|
const int mode = args[2].As<Int32>()->Value();
|
||||||
|
|
||||||
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
|
FSReqBase* req_wrap = GetReqWrap(env, args[3]);
|
||||||
if (req_wrap != nullptr) {
|
if (req_wrap != nullptr) { // open(path, flags, mode, req)
|
||||||
AsyncCall(env, req_wrap, args, "open", UTF8, AfterInteger,
|
AsyncCall(env, req_wrap, args, "open", UTF8, AfterInteger,
|
||||||
uv_fs_open, *path, flags, mode);
|
uv_fs_open, *path, flags, mode);
|
||||||
} else {
|
} else { // open(path, flags, mode, undefined, ctx)
|
||||||
SYNC_CALL(open, *path, *path, flags, mode)
|
CHECK_EQ(argc, 5);
|
||||||
args.GetReturnValue().Set(SYNC_RESULT);
|
fs_req_wrap req_wrap;
|
||||||
|
int result = SyncCall(env, args[4], &req_wrap, "open",
|
||||||
|
uv_fs_open, *path, flags, mode);
|
||||||
|
args.GetReturnValue().Set(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user