Skip to content

Commit 668420d

Browse files
committed
src: clean up unused macros in node_file.cc
Remove a few unused or barely used macros from src/node_file.cc. PR-URL: #529 Reviewed-By: Trevor Norris <[email protected]>
1 parent 52f624e commit 668420d

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/node_file.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ using v8::Value;
4444

4545
#define THROW_BAD_ARGS TYPE_ERROR("Bad argument")
4646

47+
#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1)
48+
4749
class FSReqWrap: public ReqWrap<uv_fs_t> {
4850
public:
4951
void* operator new(size_t size) { return new char[size]; }
@@ -85,17 +87,6 @@ static void NewFSReqWrap(const FunctionCallbackInfo<Value>& args) {
8587
}
8688

8789

88-
#define ASSERT_OFFSET(a) \
89-
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
90-
return env->ThrowTypeError("Not an integer"); \
91-
}
92-
#define ASSERT_TRUNCATE_LENGTH(a) \
93-
if (!(a)->IsUndefined() && !(a)->IsNull() && !IsInt64((a)->NumberValue())) { \
94-
return env->ThrowTypeError("Not an integer"); \
95-
}
96-
#define GET_OFFSET(a) ((a)->IsNumber() ? (a)->IntegerValue() : -1)
97-
#define GET_TRUNCATE_LENGTH(a) ((a)->IntegerValue())
98-
9990
static inline bool IsInt64(double x) {
10091
return x == static_cast<double>(static_cast<int64_t>(x));
10192
}
@@ -599,8 +590,17 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
599590

600591
int fd = args[0]->Int32Value();
601592

602-
ASSERT_TRUNCATE_LENGTH(args[1]);
603-
int64_t len = GET_TRUNCATE_LENGTH(args[1]);
593+
// FIXME(bnoordhuis) It's questionable to reject non-ints here but still
594+
// allow implicit coercion from null or undefined to zero. Probably best
595+
// handled in lib/fs.js.
596+
Local<Value> len_v(args[1]);
597+
if (!len_v->IsUndefined() &&
598+
!len_v->IsNull() &&
599+
!IsInt64(len_v->NumberValue())) {
600+
return env->ThrowTypeError("Not an integer");
601+
}
602+
603+
const int64_t len = len_v->IntegerValue();
604604

605605
if (args[2]->IsObject()) {
606606
ASYNC_CALL(ftruncate, args[2], fd, len)

0 commit comments

Comments
 (0)