[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #include "gin/arguments.h" | ||||
6 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 7 | #include "base/strings/stringprintf.h" |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 8 | #include "gin/converter.h" |
9 | |||||
10 | namespace gin { | ||||
11 | |||||
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 12 | Arguments::Arguments() |
13 | : isolate_(NULL), | ||||
14 | info_(NULL), | ||||
15 | next_(0), | ||||
16 | insufficient_arguments_(false) { | ||||
17 | } | ||||
18 | |||||
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 19 | Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) |
20 | : isolate_(info.GetIsolate()), | ||||
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 21 | info_(&info), |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 22 | next_(0), |
23 | insufficient_arguments_(false) { | ||||
24 | } | ||||
25 | |||||
26 | Arguments::~Arguments() { | ||||
27 | } | ||||
28 | |||||
[email protected] | 481d249 | 2013-12-13 23:55:25 | [diff] [blame] | 29 | v8::Handle<v8::Value> Arguments::PeekNext() const { |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 30 | if (next_ >= info_->Length()) |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 31 | return v8::Handle<v8::Value>(); |
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 32 | return (*info_)[next_]; |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 33 | } |
34 | |||||
[email protected] | 481d249 | 2013-12-13 23:55:25 | [diff] [blame] | 35 | void Arguments::ThrowError() const { |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 36 | if (insufficient_arguments_) |
37 | return ThrowTypeError("Insufficient number of arguments."); | ||||
38 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 39 | ThrowTypeError(base::StringPrintf( |
40 | "Error processing argument %d.", next_ - 1)); | ||||
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 41 | } |
42 | |||||
[email protected] | 481d249 | 2013-12-13 23:55:25 | [diff] [blame] | 43 | void Arguments::ThrowTypeError(const std::string& message) const { |
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 44 | isolate_->ThrowException(v8::Exception::TypeError( |
45 | StringToV8(isolate_, message))); | ||||
46 | } | ||||
47 | |||||
[email protected] | e87f312 | 2013-11-12 00:41:27 | [diff] [blame] | 48 | } // namespace gin |