Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/renderer/module_system.cc

Issue 10383242: Expose DumpException() in ModuleSystem. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: respond to comments Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/module_system.h ('k') | chrome/test/base/module_system_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
11 11
12 const char* kModuleSystem = "module_system"; 12 const char* kModuleSystem = "module_system";
13 const char* kModuleName = "module_name"; 13 const char* kModuleName = "module_name";
14 const char* kModuleField = "module_field"; 14 const char* kModuleField = "module_field";
15 const char* kModulesField = "modules"; 15 const char* kModulesField = "modules";
16 16
17 void DumpException(v8::Handle<v8::Message> message) {
18 LOG(ERROR) << "["
19 << *v8::String::Utf8Value(
20 message->GetScriptResourceName()->ToString())
21 << "(" << message->GetLineNumber() << ")] "
22 << *v8::String::Utf8Value(message->Get());
23 }
24
25 } // namespace 17 } // namespace
26 18
27 ModuleSystem::ModuleSystem(v8::Handle<v8::Context> context, 19 ModuleSystem::ModuleSystem(v8::Handle<v8::Context> context,
28 SourceMap* source_map) 20 SourceMap* source_map)
29 : context_(v8::Persistent<v8::Context>::New(context)), 21 : context_(v8::Persistent<v8::Context>::New(context)),
30 source_map_(source_map), 22 source_map_(source_map),
31 natives_enabled_(0) { 23 natives_enabled_(0) {
32 RouteFunction("require", 24 RouteFunction("require",
33 base::Bind(&ModuleSystem::RequireForJs, base::Unretained(this))); 25 base::Bind(&ModuleSystem::RequireForJs, base::Unretained(this)));
34 RouteFunction("requireNative", 26 RouteFunction("requireNative",
(...skipping 23 matching lines...) Expand all
58 module_system_->natives_enabled_--; 50 module_system_->natives_enabled_--;
59 CHECK_GE(module_system_->natives_enabled_, 0); 51 CHECK_GE(module_system_->natives_enabled_, 0);
60 } 52 }
61 53
62 // static 54 // static
63 bool ModuleSystem::IsPresentInCurrentContext() { 55 bool ModuleSystem::IsPresentInCurrentContext() {
64 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global()); 56 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
65 return !global->GetHiddenValue(v8::String::New(kModuleSystem))->IsUndefined(); 57 return !global->GetHiddenValue(v8::String::New(kModuleSystem))->IsUndefined();
66 } 58 }
67 59
60 // static
61 void ModuleSystem::DumpException(v8::Handle<v8::Message> message) {
62 LOG(ERROR) << "["
63 << *v8::String::Utf8Value(
64 message->GetScriptResourceName()->ToString())
65 << "(" << message->GetLineNumber() << ")] "
66 << *v8::String::Utf8Value(message->Get());
67 }
68
68 void ModuleSystem::Require(const std::string& module_name) { 69 void ModuleSystem::Require(const std::string& module_name) {
69 v8::HandleScope handle_scope; 70 v8::HandleScope handle_scope;
70 RequireForJsInner(v8::String::New(module_name.c_str())); 71 RequireForJsInner(v8::String::New(module_name.c_str()));
71 } 72 }
72 73
73 v8::Handle<v8::Value> ModuleSystem::RequireForJs(const v8::Arguments& args) { 74 v8::Handle<v8::Value> ModuleSystem::RequireForJs(const v8::Arguments& args) {
74 v8::HandleScope handle_scope; 75 v8::HandleScope handle_scope;
75 v8::Handle<v8::String> module_name = args[0]->ToString(); 76 v8::Handle<v8::String> module_name = args[0]->ToString();
76 return handle_scope.Close(RequireForJsInner(module_name)); 77 return handle_scope.Close(RequireForJsInner(module_name));
77 } 78 }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 v8::Handle<v8::String> left = 223 v8::Handle<v8::String> left =
223 v8::String::New("(function(require, requireNative, exports) {"); 224 v8::String::New("(function(require, requireNative, exports) {");
224 v8::Handle<v8::String> right = v8::String::New("\n})"); 225 v8::Handle<v8::String> right = v8::String::New("\n})");
225 return handle_scope.Close( 226 return handle_scope.Close(
226 v8::String::Concat(left, v8::String::Concat(source, right))); 227 v8::String::Concat(left, v8::String::Concat(source, right)));
227 } 228 }
228 229
229 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { 230 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) {
230 return v8::ThrowException(v8::String::New(message.c_str())); 231 return v8::ThrowException(v8::String::New(message.c_str()));
231 } 232 }
OLDNEW
« no previous file with comments | « chrome/renderer/module_system.h ('k') | chrome/test/base/module_system_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698