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

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

Issue 10208001: Make functions being routed by NativeHandlers throw an exception if there is no ModuleSystem in the… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changed error message Created 8 years, 8 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
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 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 ModuleSystem* module_system) 52 ModuleSystem* module_system)
53 : module_system_(module_system) { 53 : module_system_(module_system) {
54 module_system_->natives_enabled_++; 54 module_system_->natives_enabled_++;
55 } 55 }
56 56
57 ModuleSystem::NativesEnabledScope::~NativesEnabledScope() { 57 ModuleSystem::NativesEnabledScope::~NativesEnabledScope() {
58 module_system_->natives_enabled_--; 58 module_system_->natives_enabled_--;
59 CHECK_GE(module_system_->natives_enabled_, 0); 59 CHECK_GE(module_system_->natives_enabled_, 0);
60 } 60 }
61 61
62 // static
63 bool ModuleSystem::IsPresentInCurrentContext() {
64 v8::Handle<v8::Object> global(v8::Context::GetCurrent()->Global());
65 return !global->GetHiddenValue(v8::String::New(kModuleSystem))->IsUndefined();
66 }
67
62 void ModuleSystem::Require(const std::string& module_name) { 68 void ModuleSystem::Require(const std::string& module_name) {
63 v8::HandleScope handle_scope; 69 v8::HandleScope handle_scope;
64 RequireForJsInner(v8::String::New(module_name.c_str())); 70 RequireForJsInner(v8::String::New(module_name.c_str()));
65 } 71 }
66 72
67 v8::Handle<v8::Value> ModuleSystem::RequireForJs(const v8::Arguments& args) { 73 v8::Handle<v8::Value> ModuleSystem::RequireForJs(const v8::Arguments& args) {
68 v8::HandleScope handle_scope; 74 v8::HandleScope handle_scope;
69 v8::Handle<v8::String> module_name = args[0]->ToString(); 75 v8::Handle<v8::String> module_name = args[0]->ToString();
70 return handle_scope.Close(RequireForJsInner(module_name)); 76 return handle_scope.Close(RequireForJsInner(module_name));
71 } 77 }
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 v8::Handle<v8::String> left = 216 v8::Handle<v8::String> left =
211 v8::String::New("(function(require, requireNative, exports) {"); 217 v8::String::New("(function(require, requireNative, exports) {");
212 v8::Handle<v8::String> right = v8::String::New("\n})"); 218 v8::Handle<v8::String> right = v8::String::New("\n})");
213 return handle_scope.Close( 219 return handle_scope.Close(
214 v8::String::Concat(left, v8::String::Concat(source, right))); 220 v8::String::Concat(left, v8::String::Concat(source, right)));
215 } 221 }
216 222
217 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { 223 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) {
218 return v8::ThrowException(v8::String::New(message.c_str())); 224 return v8::ThrowException(v8::String::New(message.c_str()));
219 } 225 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698