From 668420d1f7685f49843bbf81ee3b4733a1989852 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 20 Jan 2015 23:57:09 +0100 Subject: [PATCH] src: clean up unused macros in node_file.cc Remove a few unused or barely used macros from src/node_file.cc. PR-URL: https://github.com/iojs/io.js/pull/529 Reviewed-By: Trevor Norris --- src/node_file.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/node_file.cc b/src/node_file.cc index 972e0abb53e177..287d9a56ba116e 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -44,6 +44,8 @@ using v8::Value; #define THROW_BAD_ARGS TYPE_ERROR("Bad argument") +#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1) + class FSReqWrap: public ReqWrap { public: void* operator new(size_t size) { return new char[size]; } @@ -85,17 +87,6 @@ static void NewFSReqWrap(const FunctionCallbackInfo& args) { } -#define ASSERT_OFFSET(a) \ - if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \ - return env->ThrowTypeError("Not an integer"); \ - } -#define ASSERT_TRUNCATE_LENGTH(a) \ - if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \ - return env->ThrowTypeError("Not an integer"); \ - } -#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1) -#define GET_TRUNCATE_LENGTH(a) ((a)->IntegerValue()) - static inline bool IsInt64(double x) { return x == static_cast(static_cast(x)); } @@ -599,8 +590,17 @@ static void FTruncate(const FunctionCallbackInfo& args) { int fd = args[0]->Int32Value(); - ASSERT_TRUNCATE_LENGTH(args[1]); - int64_t len = GET_TRUNCATE_LENGTH(args[1]); + // 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 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(); if (args[2]->IsObject()) { ASYNC_CALL(ftruncate, args[2], fd, len)