@@ -44,6 +44,8 @@ using v8::Value;
44
44
45
45
#define THROW_BAD_ARGS TYPE_ERROR (" Bad argument" )
46
46
47
+ #define GET_OFFSET (a ) ((a)->IsNumber () ? (a)->IntegerValue() : -1)
48
+
47
49
class FSReqWrap: public ReqWrap<uv_fs_t> {
48
50
public:
49
51
void * operator new (size_t size) { return new char [size]; }
@@ -85,17 +87,6 @@ static void NewFSReqWrap(const FunctionCallbackInfo<Value>& args) {
85
87
}
86
88
87
89
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
-
99
90
static inline bool IsInt64 (double x) {
100
91
return x == static_cast <double >(static_cast <int64_t >(x));
101
92
}
@@ -599,8 +590,17 @@ static void FTruncate(const FunctionCallbackInfo<Value>& args) {
599
590
600
591
int fd = args[0 ]->Int32Value ();
601
592
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 ();
604
604
605
605
if (args[2 ]->IsObject ()) {
606
606
ASYNC_CALL (ftruncate , args[2 ], fd, len)
0 commit comments