Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: gin/arguments.cc

Issue 798163002: Add failure messages to gin and js mojom encoder (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gin/function_template.h » ('j') | mojo/public/js/codec.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/arguments.h" 5 #include "gin/arguments.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "gin/converter.h" 8 #include "gin/converter.h"
9 9
10 namespace gin { 10 namespace gin {
(...skipping 14 matching lines...) Expand all
25 25
26 Arguments::~Arguments() { 26 Arguments::~Arguments() {
27 } 27 }
28 28
29 v8::Handle<v8::Value> Arguments::PeekNext() const { 29 v8::Handle<v8::Value> Arguments::PeekNext() const {
30 if (next_ >= info_->Length()) 30 if (next_ >= info_->Length())
31 return v8::Handle<v8::Value>(); 31 return v8::Handle<v8::Value>();
32 return (*info_)[next_]; 32 return (*info_)[next_];
33 } 33 }
34 34
35 std::string V8TypeAsString(v8::Handle<v8::Value> value) {
36 if (value.IsEmpty())
37 return "<empty handle>";
38 if (value->IsUndefined())
39 return "undefined";
40 if (value->IsNull())
41 return "null";
42 std::string result;
43 if (!ConvertFromV8(NULL, value, &result))
44 return std::string();
45 return result;
46 }
47
35 void Arguments::ThrowError() const { 48 void Arguments::ThrowError() const {
36 if (insufficient_arguments_) 49 if (insufficient_arguments_)
37 return ThrowTypeError("Insufficient number of arguments."); 50 return ThrowTypeError("Insufficient number of arguments.");
38 51
39 ThrowTypeError(base::StringPrintf( 52 return ThrowTypeError(base::StringPrintf(
40 "Error processing argument %d.", next_ - 1)); 53 "Error processing argument at index %d, conversion failure from %s",
54 next_ - 1, V8TypeAsString((*info_)[next_ - 1]).c_str()));
41 } 55 }
42 56
43 void Arguments::ThrowTypeError(const std::string& message) const { 57 void Arguments::ThrowTypeError(const std::string& message) const {
44 isolate_->ThrowException(v8::Exception::TypeError( 58 isolate_->ThrowException(v8::Exception::TypeError(
45 StringToV8(isolate_, message))); 59 StringToV8(isolate_, message)));
46 } 60 }
47 61
48 bool Arguments::IsConstructCall() const { 62 bool Arguments::IsConstructCall() const {
49 return info_->IsConstructCall(); 63 return info_->IsConstructCall();
50 } 64 }
51 65
52 } // namespace gin 66 } // namespace gin
OLDNEW
« no previous file with comments | « no previous file | gin/function_template.h » ('j') | mojo/public/js/codec.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698