| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/module_system.h" | 5 #include "extensions/renderer/module_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 v8::Local<v8::Value> exports; | 278 v8::Local<v8::Value> exports; |
| 279 if (!GetPrivateProperty(v8_context, modules, module_name, &exports) || | 279 if (!GetPrivateProperty(v8_context, modules, module_name, &exports) || |
| 280 !exports->IsUndefined()) | 280 !exports->IsUndefined()) |
| 281 return handle_scope.Escape(exports); | 281 return handle_scope.Escape(exports); |
| 282 | 282 |
| 283 exports = LoadModule(*v8::String::Utf8Value(module_name)); | 283 exports = LoadModule(*v8::String::Utf8Value(module_name)); |
| 284 SetPrivateProperty(v8_context, modules, module_name, exports); | 284 SetPrivateProperty(v8_context, modules, module_name, exports); |
| 285 return handle_scope.Escape(exports); | 285 return handle_scope.Escape(exports); |
| 286 } | 286 } |
| 287 | 287 |
| 288 v8::Local<v8::Value> ModuleSystem::CallModuleMethod( | |
| 289 const std::string& module_name, | |
| 290 const std::string& method_name, | |
| 291 int argc, | |
| 292 v8::Local<v8::Value> argv[]) { | |
| 293 TRACE_EVENT2("v8", | |
| 294 "v8.callModuleMethod", | |
| 295 "module_name", | |
| 296 module_name, | |
| 297 "method_name", | |
| 298 method_name); | |
| 299 | |
| 300 v8::EscapableHandleScope handle_scope(GetIsolate()); | |
| 301 v8::Local<v8::Context> v8_context = context()->v8_context(); | |
| 302 v8::Context::Scope context_scope(v8_context); | |
| 303 | |
| 304 v8::Local<v8::Function> function = | |
| 305 GetModuleFunction(module_name, method_name); | |
| 306 if (function.IsEmpty()) { | |
| 307 NOTREACHED() << "GetModuleFunction() returns empty function handle"; | |
| 308 return handle_scope.Escape(v8::Undefined(GetIsolate())); | |
| 309 } | |
| 310 | |
| 311 v8::Local<v8::Value> result; | |
| 312 { | |
| 313 v8::TryCatch try_catch(GetIsolate()); | |
| 314 try_catch.SetCaptureMessage(true); | |
| 315 result = context_->CallFunction(function, argc, argv); | |
| 316 if (try_catch.HasCaught()) { | |
| 317 HandleException(try_catch); | |
| 318 result = v8::Undefined(GetIsolate()); | |
| 319 } | |
| 320 } | |
| 321 return handle_scope.Escape(result); | |
| 322 } | |
| 323 | |
| 324 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, | 288 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, |
| 325 const std::string& method_name) { | 289 const std::string& method_name) { |
| 326 v8::HandleScope handle_scope(GetIsolate()); | 290 v8::HandleScope handle_scope(GetIsolate()); |
| 327 v8::Local<v8::Value> no_args; | 291 v8::Local<v8::Value> no_args; |
| 328 CallModuleMethodSafe(module_name, method_name, 0, &no_args, | 292 CallModuleMethodSafe(module_name, method_name, 0, &no_args, |
| 329 ScriptInjectionCallback::CompleteCallback()); | 293 ScriptInjectionCallback::CompleteCallback()); |
| 330 } | 294 } |
| 331 | 295 |
| 332 void ModuleSystem::CallModuleMethodSafe( | 296 void ModuleSystem::CallModuleMethodSafe( |
| 333 const std::string& module_name, | 297 const std::string& module_name, |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 918 !value->IsFunction()) { | 882 !value->IsFunction()) { |
| 919 Fatal(context_, module_name + "." + method_name + " is not a function"); | 883 Fatal(context_, module_name + "." + method_name + " is not a function"); |
| 920 return function; | 884 return function; |
| 921 } | 885 } |
| 922 | 886 |
| 923 function = v8::Local<v8::Function>::Cast(value); | 887 function = v8::Local<v8::Function>::Cast(value); |
| 924 return function; | 888 return function; |
| 925 } | 889 } |
| 926 | 890 |
| 927 } // namespace extensions | 891 } // namespace extensions |
| OLD | NEW |