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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "gin/arguments.h" | 6 #include "gin/arguments.h" |
7 #include "gin/handle.h" | 7 #include "gin/handle.h" |
8 #include "gin/object_template_builder.h" | 8 #include "gin/object_template_builder.h" |
9 #include "gin/per_isolate_data.h" | 9 #include "gin/per_isolate_data.h" |
10 #include "gin/public/isolate_holder.h" | 10 #include "gin/public/isolate_holder.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 static gin::Handle<MyObject> Create(v8::Isolate* isolate) { | 34 static gin::Handle<MyObject> Create(v8::Isolate* isolate) { |
35 return CreateHandle(isolate, new MyObject()); | 35 return CreateHandle(isolate, new MyObject()); |
36 } | 36 } |
37 | 37 |
38 int value() const { return value_; } | 38 int value() const { return value_; } |
39 void set_value(int value) { value_ = value; } | 39 void set_value(int value) { value_ = value; } |
40 | 40 |
41 protected: | 41 protected: |
42 MyObject() : value_(0) {} | 42 MyObject() : value_(0) {} |
43 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( | 43 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( |
44 v8::Isolate* isolate) OVERRIDE; | 44 v8::Isolate* isolate) override; |
45 virtual ~MyObject() {} | 45 virtual ~MyObject() {} |
46 | 46 |
47 private: | 47 private: |
48 int value_; | 48 int value_; |
49 }; | 49 }; |
50 | 50 |
51 class MyObjectSubclass : public MyObject { | 51 class MyObjectSubclass : public MyObject { |
52 public: | 52 public: |
53 static gin::Handle<MyObjectSubclass> Create(v8::Isolate* isolate) { | 53 static gin::Handle<MyObjectSubclass> Create(v8::Isolate* isolate) { |
54 return CreateHandle(isolate, new MyObjectSubclass()); | 54 return CreateHandle(isolate, new MyObjectSubclass()); |
55 } | 55 } |
56 | 56 |
57 void SayHello(const std::string& name) { | 57 void SayHello(const std::string& name) { |
58 result = std::string("Hello, ") + name; | 58 result = std::string("Hello, ") + name; |
59 } | 59 } |
60 | 60 |
61 std::string result; | 61 std::string result; |
62 | 62 |
63 private: | 63 private: |
64 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( | 64 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( |
65 v8::Isolate* isolate) OVERRIDE { | 65 v8::Isolate* isolate) override { |
66 return MyObject::GetObjectTemplateBuilder(isolate) | 66 return MyObject::GetObjectTemplateBuilder(isolate) |
67 .SetMethod("sayHello", &MyObjectSubclass::SayHello); | 67 .SetMethod("sayHello", &MyObjectSubclass::SayHello); |
68 } | 68 } |
69 | 69 |
70 MyObjectSubclass() { | 70 MyObjectSubclass() { |
71 } | 71 } |
72 | 72 |
73 virtual ~MyObjectSubclass() { | 73 virtual ~MyObjectSubclass() { |
74 } | 74 } |
75 }; | 75 }; |
76 | 76 |
77 class MyCallableObject : public Wrappable<MyCallableObject> { | 77 class MyCallableObject : public Wrappable<MyCallableObject> { |
78 public: | 78 public: |
79 static WrapperInfo kWrapperInfo; | 79 static WrapperInfo kWrapperInfo; |
80 | 80 |
81 static gin::Handle<MyCallableObject> Create(v8::Isolate* isolate) { | 81 static gin::Handle<MyCallableObject> Create(v8::Isolate* isolate) { |
82 return CreateHandle(isolate, new MyCallableObject()); | 82 return CreateHandle(isolate, new MyCallableObject()); |
83 } | 83 } |
84 | 84 |
85 int result() { return result_; } | 85 int result() { return result_; } |
86 | 86 |
87 private: | 87 private: |
88 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( | 88 virtual ObjectTemplateBuilder GetObjectTemplateBuilder( |
89 v8::Isolate* isolate) OVERRIDE { | 89 v8::Isolate* isolate) override { |
90 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate) | 90 return Wrappable<MyCallableObject>::GetObjectTemplateBuilder(isolate) |
91 .SetCallAsFunctionHandler(&MyCallableObject::Call); | 91 .SetCallAsFunctionHandler(&MyCallableObject::Call); |
92 } | 92 } |
93 | 93 |
94 MyCallableObject() : result_(0) { | 94 MyCallableObject() : result_(0) { |
95 } | 95 } |
96 | 96 |
97 virtual ~MyCallableObject() { | 97 virtual ~MyCallableObject() { |
98 } | 98 } |
99 | 99 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 v8::Handle<v8::Function> func; | 264 v8::Handle<v8::Function> func; |
265 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); | 265 EXPECT_TRUE(ConvertFromV8(isolate, val, &func)); |
266 v8::Handle<v8::Value> argv[] = { | 266 v8::Handle<v8::Value> argv[] = { |
267 ConvertToV8(isolate, object.get()) | 267 ConvertToV8(isolate, object.get()) |
268 }; | 268 }; |
269 func->Call(v8::Undefined(isolate), 1, argv); | 269 func->Call(v8::Undefined(isolate), 1, argv); |
270 EXPECT_TRUE(try_catch.HasCaught()); | 270 EXPECT_TRUE(try_catch.HasCaught()); |
271 } | 271 } |
272 | 272 |
273 } // namespace gin | 273 } // namespace gin |
OLD | NEW |