Merge pull request #5 from kevinsawicki/detail-string

Use ToDetailString for arguments error message
This commit is contained in:
Cheng Zhao 2016-08-11 17:22:39 +09:00 committed by GitHub
commit b5e5de626c

View file

@ -11,16 +11,13 @@ namespace mate {
namespace { namespace {
std::string V8TypeAsString(v8::Local<v8::Value> value) { std::string V8TypeAsString(v8::Isolate* isolate, v8::Local<v8::Value> value) {
if (value.IsEmpty()) if (value.IsEmpty())
return "<empty handle>"; return "<empty handle>";
if (value->IsUndefined()) v8::MaybeLocal<v8::String> details = value->ToDetailString(isolate);
return "undefined";
if (value->IsNull())
return "null";
std::string result; std::string result;
if (!ConvertFromV8(NULL, value, &result)) if (!details.IsEmpty())
return std::string(); ConvertFromV8(isolate, details.ToLocalChecked(), &result);
return result; return result;
} }
@ -55,7 +52,7 @@ v8::Local<v8::Value> Arguments::ThrowError() const {
return ThrowTypeError(base::StringPrintf( return ThrowTypeError(base::StringPrintf(
"Error processing argument at index %d, conversion failure from %s", "Error processing argument at index %d, conversion failure from %s",
next_, V8TypeAsString((*info_)[next_]).c_str())); next_, V8TypeAsString(isolate_, (*info_)[next_]).c_str()));
} }
v8::Local<v8::Value> Arguments::ThrowError(const std::string& message) const { v8::Local<v8::Value> Arguments::ThrowError(const std::string& message) const {