Index: src/d8.cc |
diff --git a/src/d8.cc b/src/d8.cc |
index 01b4939902e1b0373997dbbab460c427dd35e69a..9390c846d60055aef88431c04c70761dcfb00aac 100644 |
--- a/src/d8.cc |
+++ b/src/d8.cc |
@@ -295,8 +295,12 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
size_t length = 0; |
if (args[0]->IsUint32()) { |
length = args[0]->Uint32Value(); |
- } else if (args[0]->IsNumber()) { |
- double raw_length = args[0]->NumberValue(); |
+ } else { |
+ Local<Number> number = args[0]->ToNumber(); |
+ if (number.IsEmpty() || !number->IsNumber()) { |
+ return ThrowException(String::New("Array length must be a number.")); |
+ } |
+ double raw_length = number->NumberValue(); |
if (raw_length < 0) { |
return ThrowException(String::New("Array length must not be negative.")); |
} |
@@ -305,8 +309,6 @@ Handle<Value> Shell::CreateExternalArray(const Arguments& args, |
String::New("Array length exceeds maximum length.")); |
} |
length = static_cast<size_t>(raw_length); |
- } else { |
- return ThrowException(String::New("Array length must be a number.")); |
} |
if (length > static_cast<size_t>(kMaxLength)) { |
return ThrowException(String::New("Array length exceeds maximum length.")); |