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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // static | 54 // static |
55 bool ModuleSystem::IsPresentInCurrentContext() { | 55 bool ModuleSystem::IsPresentInCurrentContext() { |
56 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); | 56 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); |
57 v8::Handle<v8::Value> module_system = | 57 v8::Handle<v8::Value> module_system = |
58 global->GetHiddenValue(v8::String::New(kModuleSystem)); | 58 global->GetHiddenValue(v8::String::New(kModuleSystem)); |
59 return !module_system.IsEmpty() && !module_system->IsUndefined(); | 59 return !module_system.IsEmpty() && !module_system->IsUndefined(); |
60 } | 60 } |
61 | 61 |
62 // static | 62 // static |
63 void ModuleSystem::DumpException(const v8::TryCatch& try_catch) { | 63 void ModuleSystem::DumpException(const v8::TryCatch& try_catch) { |
| 64 v8::HandleScope handle_scope; |
| 65 |
64 v8::Handle<v8::Message> message(try_catch.Message()); | 66 v8::Handle<v8::Message> message(try_catch.Message()); |
65 if (message.IsEmpty()) { | 67 if (message.IsEmpty()) { |
66 LOG(ERROR) << "try_catch has no message"; | 68 LOG(ERROR) << "try_catch has no message"; |
67 return; | 69 return; |
68 } | 70 } |
69 | 71 |
70 std::string resource_name = "<unknown resource>"; | 72 std::string resource_name = "<unknown resource>"; |
71 if (!message->GetScriptResourceName().IsEmpty()) { | 73 if (!message->GetScriptResourceName().IsEmpty()) { |
72 resource_name = | 74 resource_name = |
73 *v8::String::Utf8Value(message->GetScriptResourceName()->ToString()); | 75 *v8::String::Utf8Value(message->GetScriptResourceName()->ToString()); |
74 } | 76 } |
75 | 77 |
76 std::string error_message = "<no error message>"; | 78 std::string error_message = "<no error message>"; |
77 if (!message->Get().IsEmpty()) | 79 if (!message->Get().IsEmpty()) |
78 error_message = *v8::String::Utf8Value(message->Get()); | 80 error_message = *v8::String::Utf8Value(message->Get()); |
79 | 81 |
80 std::string stack_trace = "<stack trace unavailable>"; | 82 std::string stack_trace = "<stack trace unavailable>"; |
81 if (!try_catch.StackTrace().IsEmpty()) | 83 if (!try_catch.StackTrace().IsEmpty()) { |
82 stack_trace = *v8::String::Utf8Value(try_catch.StackTrace()); | 84 v8::String::Utf8Value stack_value(try_catch.StackTrace()); |
| 85 if (*stack_value) |
| 86 stack_trace.assign(*stack_value, stack_value.length()); |
| 87 else |
| 88 stack_trace = "<could not convert stack trace to string>"; |
| 89 } |
83 | 90 |
84 LOG(ERROR) << "[" << resource_name << "(" << message->GetLineNumber() << ")] " | 91 LOG(ERROR) << "[" << resource_name << "(" << message->GetLineNumber() << ")] " |
85 << error_message | 92 << error_message |
86 << "{" << stack_trace << "}"; | 93 << "{" << stack_trace << "}"; |
87 } | 94 } |
88 | 95 |
89 void ModuleSystem::Require(const std::string& module_name) { | 96 void ModuleSystem::Require(const std::string& module_name) { |
90 v8::HandleScope handle_scope; | 97 v8::HandleScope handle_scope; |
91 RequireForJsInner(v8::String::New(module_name.c_str())); | 98 RequireForJsInner(v8::String::New(module_name.c_str())); |
92 } | 99 } |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 v8::Handle<v8::String> left = | 258 v8::Handle<v8::String> left = |
252 v8::String::New("(function(require, requireNative, exports) {"); | 259 v8::String::New("(function(require, requireNative, exports) {"); |
253 v8::Handle<v8::String> right = v8::String::New("\n})"); | 260 v8::Handle<v8::String> right = v8::String::New("\n})"); |
254 return handle_scope.Close( | 261 return handle_scope.Close( |
255 v8::String::Concat(left, v8::String::Concat(source, right))); | 262 v8::String::Concat(left, v8::String::Concat(source, right))); |
256 } | 263 } |
257 | 264 |
258 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { | 265 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { |
259 return v8::ThrowException(v8::String::New(message.c_str())); | 266 return v8::ThrowException(v8::String::New(message.c_str())); |
260 } | 267 } |
OLD | NEW |