| OLD | NEW |
| 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 <sstream> | 7 #include <sstream> |
| 8 #include "gin/converter.h" | 8 #include "gin/converter.h" |
| 9 | 9 |
| 10 namespace gin { | 10 namespace gin { |
| 11 | 11 |
| 12 Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) | 12 Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 13 : isolate_(info.GetIsolate()), | 13 : isolate_(info.GetIsolate()), |
| 14 info_(info), | 14 info_(info), |
| 15 next_(0), | 15 next_(0), |
| 16 insufficient_arguments_(false) { | 16 insufficient_arguments_(false) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Arguments::~Arguments() { | 19 Arguments::~Arguments() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 v8::Handle<v8::Value> Arguments::PeekNext() { |
| 23 if (next_ >= info_.Length()) |
| 24 return v8::Handle<v8::Value>(); |
| 25 return info_[next_]; |
| 26 } |
| 27 |
| 22 void Arguments::ThrowError() { | 28 void Arguments::ThrowError() { |
| 23 if (insufficient_arguments_) | 29 if (insufficient_arguments_) |
| 24 return ThrowTypeError("Insufficient number of arguments."); | 30 return ThrowTypeError("Insufficient number of arguments."); |
| 25 | 31 |
| 26 std::stringstream stream; | 32 std::stringstream stream; |
| 27 stream << "Error processing argument " << next_ - 1 << "."; | 33 stream << "Error processing argument " << next_ - 1 << "."; |
| 28 ThrowTypeError(stream.str()); | 34 ThrowTypeError(stream.str()); |
| 29 } | 35 } |
| 30 | 36 |
| 31 void Arguments::ThrowTypeError(const std::string& message) { | 37 void Arguments::ThrowTypeError(const std::string& message) { |
| 32 isolate_->ThrowException(v8::Exception::TypeError( | 38 isolate_->ThrowException(v8::Exception::TypeError( |
| 33 StringToV8(isolate_, message))); | 39 StringToV8(isolate_, message))); |
| 34 } | 40 } |
| 35 | 41 |
| 36 } // namespace gin | 42 } // namespace gin |
| OLD | NEW |