aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames M Snell <jasnell@gmail.com>2017-11-26 14:06:50 -0800
committerJames M Snell <jasnell@gmail.com>2017-12-13 13:26:40 -0800
commitd453fac33b0769a12b8b926f0d77e1bbd834b397 (patch)
tree08b24c2a36e3ab2616cf83465b1ca14271d958a6 /src
parent8cb080c4867bb7b8eefbb2abf34bd97c31f647a1 (diff)
downloadandroid-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.tar.gz
android-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.tar.bz2
android-node-v8-d453fac33b0769a12b8b926f0d77e1bbd834b397.zip
fs: move type checking for fs.ftruncate to js
PR-URL: https://github.com/nodejs/node/pull/17334 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/node_file.cc19
1 files changed, 3 insertions, 16 deletions
diff --git a/src/node_file.cc b/src/node_file.cc
index 13155bedb1..c330c95fa6 100644
--- a/src/node_file.cc
+++ b/src/node_file.cc
@@ -763,24 +763,11 @@ static void Rename(const FunctionCallbackInfo<Value>& args) {
static void FTruncate(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
- if (args.Length() < 2)
- return TYPE_ERROR("fd and length are required");
- if (!args[0]->IsInt32())
- return TYPE_ERROR("fd must be a file descriptor");
+ CHECK(args[0]->IsInt32());
+ CHECK(args[1]->IsNumber());
int fd = args[0]->Int32Value();
-
- // FIXME(bnoordhuis) It's questionable to reject non-ints here but still
- // allow implicit coercion from null or undefined to zero. Probably best
- // handled in lib/fs.js.
- Local<Value> len_v(args[1]);
- if (!len_v->IsUndefined() &&
- !len_v->IsNull() &&
- !IsInt64(len_v->NumberValue())) {
- return env->ThrowTypeError("Not an integer");
- }
-
- const int64_t len = len_v->IntegerValue();
+ const int64_t len = args[1]->IntegerValue();
if (args[2]->IsObject()) {
ASYNC_CALL(ftruncate, args[2], UTF8, fd, len)