| 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 "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 { |
| 11 | 11 |
| 12 Arguments::Arguments() | 12 Arguments::Arguments() |
| 13 : isolate_(NULL), | 13 : isolate_(NULL), |
| 14 info_(NULL), | 14 info_(NULL), |
| 15 next_(0), | 15 next_(0), |
| 16 insufficient_arguments_(false) { | 16 insufficient_arguments_(false) { |
| 17 } | 17 } |
| 18 | 18 |
| 19 Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) | 19 Arguments::Arguments(const v8::FunctionCallbackInfo<v8::Value>& info) |
| 20 : isolate_(info.GetIsolate()), | 20 : isolate_(info.GetIsolate()), |
| 21 info_(&info), | 21 info_(&info), |
| 22 next_(0), | 22 next_(0), |
| 23 insufficient_arguments_(false) { | 23 insufficient_arguments_(false) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 Arguments::~Arguments() { | 26 Arguments::~Arguments() { |
| 27 } | 27 } |
| 28 | 28 |
| 29 v8::Handle<v8::Value> Arguments::PeekNext() const { | 29 v8::Local<v8::Value> Arguments::PeekNext() const { |
| 30 if (next_ >= info_->Length()) | 30 if (next_ >= info_->Length()) |
| 31 return v8::Handle<v8::Value>(); | 31 return v8::Local<v8::Value>(); |
| 32 return (*info_)[next_]; | 32 return (*info_)[next_]; |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::string V8TypeAsString(v8::Handle<v8::Value> value) { | 35 std::string V8TypeAsString(v8::Local<v8::Value> value) { |
| 36 if (value.IsEmpty()) | 36 if (value.IsEmpty()) |
| 37 return "<empty handle>"; | 37 return "<empty handle>"; |
| 38 if (value->IsUndefined()) | 38 if (value->IsUndefined()) |
| 39 return "undefined"; | 39 return "undefined"; |
| 40 if (value->IsNull()) | 40 if (value->IsNull()) |
| 41 return "null"; | 41 return "null"; |
| 42 std::string result; | 42 std::string result; |
| 43 if (!ConvertFromV8(NULL, value, &result)) | 43 if (!ConvertFromV8(NULL, value, &result)) |
| 44 return std::string(); | 44 return std::string(); |
| 45 return result; | 45 return result; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 57 void Arguments::ThrowTypeError(const std::string& message) const { | 57 void Arguments::ThrowTypeError(const std::string& message) const { |
| 58 isolate_->ThrowException(v8::Exception::TypeError( | 58 isolate_->ThrowException(v8::Exception::TypeError( |
| 59 StringToV8(isolate_, message))); | 59 StringToV8(isolate_, message))); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool Arguments::IsConstructCall() const { | 62 bool Arguments::IsConstructCall() const { |
| 63 return info_->IsConstructCall(); | 63 return info_->IsConstructCall(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 } // namespace gin | 66 } // namespace gin |
| OLD | NEW |