summaryrefslogtreecommitdiffstats
path: root/gin/modules/module_registry.cc
diff options
context:
space:
mode:
authorabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-24 19:10:11 +0000
committerabarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-24 19:10:11 +0000
commitec95fdfdde2c5c0ca1b953143dd6f4a9144025fa (patch)
tree112b98f4ca12105ce9c32376d9268bc03af6e723 /gin/modules/module_registry.cc
parent8b4e19b1b01a00c12d62a778a92981ef18d10073 (diff)
downloadchromium_src-ec95fdfdde2c5c0ca1b953143dd6f4a9144025fa.zip
chromium_src-ec95fdfdde2c5c0ca1b953143dd6f4a9144025fa.tar.gz
chromium_src-ec95fdfdde2c5c0ca1b953143dd6f4a9144025fa.tar.bz2
[Mojo] Improve JavaScript API for MojoReadMessage
Originally, I tried to make the JavaScript bindings for the core Mojo APIs a literal translation of the C APIs, but that makes MojoReadMessage a bit awkward because C needs to worry much more about buffer allocation than JavaScript. In building towards using the hello_world_service, I found that it was much easier to push the MojoReadMessage pattern from connector.cc into C++ and make the JavaScript API a bit more idiomatic by just returning an ArrayBuffer for the message and an Array of handles. BUG=317398 Review URL: https://codereview.chromium.org/83143002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@236999 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gin/modules/module_registry.cc')
-rw-r--r--gin/modules/module_registry.cc26
1 files changed, 10 insertions, 16 deletions
diff --git a/gin/modules/module_registry.cc b/gin/modules/module_registry.cc
index 8baa482..afb07d3 100644
--- a/gin/modules/module_registry.cc
+++ b/gin/modules/module_registry.cc
@@ -12,6 +12,7 @@
#include "gin/converter.h"
#include "gin/per_isolate_data.h"
#include "gin/public/wrapper_info.h"
+#include "gin/try_catch.h"
using v8::Context;
using v8::External;
@@ -91,19 +92,6 @@ Handle<String> GetHiddenValueKey(Isolate* isolate) {
return StringToSymbol(isolate, "::gin::ModuleRegistry");
}
-std::string GetImplicitModuleName(const std::string& explicit_name) {
- if (!explicit_name.empty())
- return explicit_name;
- std::string implicit_name;
- Handle<StackTrace> trace = StackTrace::CurrentStackTrace(1);
- if (!trace->GetFrameCount())
- return implicit_name;
- Handle<String> script_name = trace->GetFrame(0)->GetScriptName();
- if (!script_name.IsEmpty())
- ConvertFromV8(script_name, &implicit_name);
- return implicit_name;
-}
-
} // namespace
ModuleRegistry::ModuleRegistry(Isolate* isolate)
@@ -196,11 +184,17 @@ void ModuleRegistry::Load(Isolate* isolate, scoped_ptr<PendingModule> pending) {
Handle<Function> factory;
if (ConvertFromV8(module, &factory)) {
Handle<Object> global = isolate->GetCurrentContext()->Global();
- module = factory->Call(global, argc, argv.data());
- // TODO(abarth): What should we do with exceptions?
+ {
+ gin::TryCatch try_catch;
+ module = factory->Call(global, argc, argv.data());
+ if (try_catch.HasCaught())
+ return; // TODO(abarth): What should we do with the exception?
+ }
+ if (pending->id.empty())
+ ConvertFromV8(factory->GetScriptOrigin().ResourceName(), &pending->id);
}
- RegisterModule(isolate, GetImplicitModuleName(pending->id), module);
+ RegisterModule(isolate, pending->id, module);
}
bool ModuleRegistry::AttemptToLoad(Isolate* isolate,