OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/extensions/miscellaneous_bindings.h" | 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 extensions::ScopedPersistent<v8::Function> callback; | 157 extensions::ScopedPersistent<v8::Function> callback; |
158 | 158 |
159 private: | 159 private: |
160 DISALLOW_COPY_AND_ASSIGN(GCCallbackArgs); | 160 DISALLOW_COPY_AND_ASSIGN(GCCallbackArgs); |
161 }; | 161 }; |
162 | 162 |
163 static void GCCallback(v8::Isolate* isolate, | 163 static void GCCallback(v8::Isolate* isolate, |
164 v8::Persistent<v8::Value> object, | 164 v8::Persistent<v8::Value> object, |
165 void* parameter) { | 165 void* parameter) { |
166 v8::HandleScope handle_scope; | 166 v8::HandleScope handle_scope; |
167 GCCallbackArgs* args = reinterpret_cast<GCCallbackArgs*>(parameter); | 167 GCCallbackArgs* args = static_cast<GCCallbackArgs*>(parameter); |
| 168 v8::Handle<v8::Context> context = args->callback->CreationContext(); |
| 169 v8::Context::Scope context_scope(context); |
168 WebKit::WebScopedMicrotaskSuppression suppression; | 170 WebKit::WebScopedMicrotaskSuppression suppression; |
169 args->callback->Call(args->callback->CreationContext()->Global(), 0, NULL); | 171 // Wrap in try/catch here so that we don't call into any message/exception |
| 172 // handlers during GC. That is a recipe for pain. |
| 173 v8::TryCatch trycatch; |
| 174 args->callback->Call(context->Global(), 0, NULL); |
170 delete args; | 175 delete args; |
171 } | 176 } |
172 | 177 |
173 // Binds a callback to be invoked when the given object is garbage collected. | 178 // Binds a callback to be invoked when the given object is garbage collected. |
174 v8::Handle<v8::Value> BindToGC(const v8::Arguments& args) { | 179 v8::Handle<v8::Value> BindToGC(const v8::Arguments& args) { |
175 if (args.Length() == 2 && args[0]->IsObject() && args[1]->IsFunction()) { | 180 CHECK(args.Length() == 2 && args[0]->IsObject() && args[1]->IsFunction()); |
176 GCCallbackArgs* context = new GCCallbackArgs( | 181 GCCallbackArgs* context = new GCCallbackArgs( |
177 v8::Handle<v8::Object>::Cast(args[0]), | 182 v8::Handle<v8::Object>::Cast(args[0]), |
178 v8::Handle<v8::Function>::Cast(args[1])); | 183 v8::Handle<v8::Function>::Cast(args[1])); |
179 context->object.MakeWeak(context, GCCallback); | 184 context->object.MakeWeak(context, GCCallback); |
180 } else { | |
181 NOTREACHED(); | |
182 } | |
183 return v8::Undefined(); | 185 return v8::Undefined(); |
184 } | 186 } |
185 }; | 187 }; |
186 | 188 |
187 } // namespace | 189 } // namespace |
188 | 190 |
189 namespace extensions { | 191 namespace extensions { |
190 | 192 |
191 ChromeV8Extension* MiscellaneousBindings::Get( | 193 ChromeV8Extension* MiscellaneousBindings::Get( |
192 Dispatcher* dispatcher, | 194 Dispatcher* dispatcher, |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } else { | 324 } else { |
323 arguments.push_back(v8::Null()); | 325 arguments.push_back(v8::Null()); |
324 } | 326 } |
325 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", | 327 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", |
326 arguments.size(), &arguments[0], | 328 arguments.size(), &arguments[0], |
327 NULL); | 329 NULL); |
328 } | 330 } |
329 } | 331 } |
330 | 332 |
331 } // namespace extensions | 333 } // namespace extensions |
OLD | NEW |