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.
5 #include "gin/arguments.h"
7 #include "base/strings/stringprintf.h"
8 #include "gin/converter.h"
12 Arguments::Arguments()
16 insufficient_arguments_(false) {
19 Arguments::Arguments(const v8::FunctionCallbackInfo
<v8::Value
>& info
)
20 : isolate_(info
.GetIsolate()),
23 insufficient_arguments_(false) {
26 Arguments::~Arguments() {
29 v8::Handle
<v8::Value
> Arguments::PeekNext() const {
30 if (next_
>= info_
->Length())
31 return v8::Handle
<v8::Value
>();
32 return (*info_
)[next_
];
35 std::string
V8TypeAsString(v8::Handle
<v8::Value
> value
) {
37 return "<empty handle>";
38 if (value
->IsUndefined())
43 if (!ConvertFromV8(NULL
, value
, &result
))
48 void Arguments::ThrowError() const {
49 if (insufficient_arguments_
)
50 return ThrowTypeError("Insufficient number of arguments.");
52 return ThrowTypeError(base::StringPrintf(
53 "Error processing argument at index %d, conversion failure from %s",
54 next_
- 1, V8TypeAsString((*info_
)[next_
- 1]).c_str()));
57 void Arguments::ThrowTypeError(const std::string
& message
) const {
58 isolate_
->ThrowException(v8::Exception::TypeError(
59 StringToV8(isolate_
, message
)));
62 bool Arguments::IsConstructCall() const {
63 return info_
->IsConstructCall();