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/module_system.h" | 5 #include "chrome/renderer/module_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedMicrotaskSup
pression.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 func->Call(global, 3, args); | 133 func->Call(global, 3, args); |
134 if (try_catch.HasCaught()) { | 134 if (try_catch.HasCaught()) { |
135 DumpException(try_catch); | 135 DumpException(try_catch); |
136 return v8::Undefined(); | 136 return v8::Undefined(); |
137 } | 137 } |
138 } | 138 } |
139 modules->Set(module_name, exports); | 139 modules->Set(module_name, exports); |
140 return handle_scope.Close(exports); | 140 return handle_scope.Close(exports); |
141 } | 141 } |
142 | 142 |
| 143 void ModuleSystem::CallModuleMethod(const std::string& module_name, |
| 144 const std::string& method_name) { |
| 145 v8::HandleScope handle_scope; |
| 146 v8::Local<v8::Value> module = |
| 147 v8::Local<v8::Value>::New( |
| 148 RequireForJsInner(v8::String::New(module_name.c_str()))); |
| 149 if (module.IsEmpty() || !module->IsObject()) |
| 150 return; |
| 151 v8::Local<v8::Value> value = |
| 152 v8::Handle<v8::Object>::Cast(module)->Get( |
| 153 v8::String::New(method_name.c_str())); |
| 154 if (value.IsEmpty() || !value->IsFunction()) |
| 155 return; |
| 156 v8::Handle<v8::Function> func = |
| 157 v8::Handle<v8::Function>::Cast(value); |
| 158 // TODO(jeremya/koz): refer to context_ here, not the current context. |
| 159 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
| 160 { |
| 161 WebKit::WebScopedMicrotaskSuppression suppression; |
| 162 v8::TryCatch try_catch; |
| 163 try_catch.SetCaptureMessage(true); |
| 164 func->Call(global, 0, NULL); |
| 165 if (try_catch.HasCaught()) |
| 166 DumpException(try_catch); |
| 167 } |
| 168 } |
| 169 |
143 void ModuleSystem::RegisterNativeHandler(const std::string& name, | 170 void ModuleSystem::RegisterNativeHandler(const std::string& name, |
144 scoped_ptr<NativeHandler> native_handler) { | 171 scoped_ptr<NativeHandler> native_handler) { |
145 native_handler_map_[name] = | 172 native_handler_map_[name] = |
146 linked_ptr<NativeHandler>(native_handler.release()); | 173 linked_ptr<NativeHandler>(native_handler.release()); |
147 } | 174 } |
148 | 175 |
149 void ModuleSystem::OverrideNativeHandler(const std::string& name) { | 176 void ModuleSystem::OverrideNativeHandler(const std::string& name) { |
150 overridden_native_handlers_.insert(name); | 177 overridden_native_handlers_.insert(name); |
151 } | 178 } |
152 | 179 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 v8::Handle<v8::String> left = | 278 v8::Handle<v8::String> left = |
252 v8::String::New("(function(require, requireNative, exports) {"); | 279 v8::String::New("(function(require, requireNative, exports) {"); |
253 v8::Handle<v8::String> right = v8::String::New("\n})"); | 280 v8::Handle<v8::String> right = v8::String::New("\n})"); |
254 return handle_scope.Close( | 281 return handle_scope.Close( |
255 v8::String::Concat(left, v8::String::Concat(source, right))); | 282 v8::String::Concat(left, v8::String::Concat(source, right))); |
256 } | 283 } |
257 | 284 |
258 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { | 285 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { |
259 return v8::ThrowException(v8::String::New(message.c_str())); | 286 return v8::ThrowException(v8::String::New(message.c_str())); |
260 } | 287 } |
OLD | NEW |