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

Side by Side Diff: gin/arguments.h

Issue 89723002: Convert the rest of the functions in core.cc to use CreateFunctionTemplate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase+comments Created 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | gin/arguments.cc » ('j') | no next file with comments »
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 #ifndef GIN_ARGUMENTS_H_ 5 #ifndef GIN_ARGUMENTS_H_
6 #define GIN_ARGUMENTS_H_ 6 #define GIN_ARGUMENTS_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "gin/converter.h" 9 #include "gin/converter.h"
10 10
11 namespace gin { 11 namespace gin {
12 12
13 class Arguments { 13 class Arguments {
14 public: 14 public:
15 Arguments();
15 explicit Arguments(const v8::FunctionCallbackInfo<v8::Value>& info); 16 explicit Arguments(const v8::FunctionCallbackInfo<v8::Value>& info);
16 ~Arguments(); 17 ~Arguments();
17 18
18 template<typename T> 19 template<typename T>
19 // TODO(aa): Rename GetHolder(). 20 // TODO(aa): Rename GetHolder().
20 bool Holder(T* out) { 21 bool Holder(T* out) {
21 return ConvertFromV8(info_.Holder(), out); 22 return ConvertFromV8(isolate_, info_->Holder(), out);
22 } 23 }
23 24
24 template<typename T> 25 template<typename T>
25 bool GetData(T* out) { 26 bool GetData(T* out) {
26 return ConvertFromV8(info_.Data(), out); 27 return ConvertFromV8(isolate_, info_->Data(), out);
27 } 28 }
28 29
29 template<typename T> 30 template<typename T>
30 bool GetNext(T* out) { 31 bool GetNext(T* out) {
31 if (next_ >= info_.Length()) { 32 if (next_ >= info_->Length()) {
32 insufficient_arguments_ = true; 33 insufficient_arguments_ = true;
33 return false; 34 return false;
34 } 35 }
35 v8::Handle<v8::Value> val = info_[next_++]; 36 v8::Handle<v8::Value> val = (*info_)[next_++];
36 return ConvertFromV8(val, out); 37 return ConvertFromV8(isolate_, val, out);
37 } 38 }
38 39
39 template<typename T> 40 template<typename T>
40 bool GetRemaining(std::vector<T>* out) { 41 bool GetRemaining(std::vector<T>* out) {
41 if (next_ >= info_.Length()) { 42 if (next_ >= info_->Length()) {
42 insufficient_arguments_ = true; 43 insufficient_arguments_ = true;
43 return false; 44 return false;
44 } 45 }
45 int remaining = info_.Length() - next_; 46 int remaining = info_->Length() - next_;
46 out->resize(remaining); 47 out->resize(remaining);
47 for (int i = 0; i < remaining; ++i) { 48 for (int i = 0; i < remaining; ++i) {
48 v8::Handle<v8::Value> val = info_[next_++]; 49 v8::Handle<v8::Value> val = (*info_)[next_++];
49 if (!ConvertFromV8(val, &out->at(i))) 50 if (!ConvertFromV8(isolate_, val, &out->at(i)))
50 return false; 51 return false;
51 } 52 }
52 return true; 53 return true;
53 } 54 }
54 55
55 template<typename T> 56 template<typename T>
56 void Return(T val) { 57 void Return(T val) {
57 info_.GetReturnValue().Set(ConvertToV8(isolate_, val)); 58 info_->GetReturnValue().Set(ConvertToV8(isolate_, val));
58 } 59 }
59 60
60 v8::Handle<v8::Value> PeekNext(); 61 v8::Handle<v8::Value> PeekNext();
61 62
62 void ThrowError(); 63 void ThrowError();
63 void ThrowTypeError(const std::string& message); 64 void ThrowTypeError(const std::string& message);
64 65
65 v8::Isolate* isolate() const { return isolate_; } 66 v8::Isolate* isolate() const { return isolate_; }
66 67
67 private: 68 private:
68 v8::Isolate* isolate_; 69 v8::Isolate* isolate_;
69 const v8::FunctionCallbackInfo<v8::Value>& info_; 70 const v8::FunctionCallbackInfo<v8::Value>* info_;
70 int next_; 71 int next_;
71 bool insufficient_arguments_; 72 bool insufficient_arguments_;
73 };
72 74
73 DISALLOW_COPY_AND_ASSIGN(Arguments); 75 template<>
74 }; 76 bool Arguments::GetNext<Arguments>(Arguments* out);
75 77
76 } // namespace gin 78 } // namespace gin
77 79
78 #endif // GIN_ARGUMENTS_H_ 80 #endif // GIN_ARGUMENTS_H_
OLDNEW
« no previous file with comments | « no previous file | gin/arguments.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698