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

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

Issue 9865015: Make renderer calls into script declare there "type" (internal or author). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: pre-review 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
« no previous file with comments | « chrome/renderer/extensions/miscellaneous_bindings.cc ('k') | no next file » | 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 9
9 namespace { 10 namespace {
10 11
11 const char* kModuleSystem = "module_system"; 12 const char* kModuleSystem = "module_system";
12 const char* kModuleName = "module_name"; 13 const char* kModuleName = "module_name";
13 const char* kModuleField = "module_field"; 14 const char* kModuleField = "module_field";
14 15
15 } // namespace 16 } // namespace
16 17
17 ModuleSystem::ModuleSystem(SourceMap* source_map) 18 ModuleSystem::ModuleSystem(SourceMap* source_map)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 v8::Handle<v8::String>::Cast(source))); 68 v8::Handle<v8::String>::Cast(source)));
68 v8::Handle<v8::Function> func = 69 v8::Handle<v8::Function> func =
69 v8::Handle<v8::Function>::Cast(RunString(wrapped_source, module_name)); 70 v8::Handle<v8::Function>::Cast(RunString(wrapped_source, module_name));
70 exports = v8::Object::New(); 71 exports = v8::Object::New();
71 v8::Handle<v8::Object> natives(NewInstance()); 72 v8::Handle<v8::Object> natives(NewInstance());
72 v8::Handle<v8::Value> args[] = { 73 v8::Handle<v8::Value> args[] = {
73 natives->Get(v8::String::NewSymbol("require")), 74 natives->Get(v8::String::NewSymbol("require")),
74 natives->Get(v8::String::NewSymbol("requireNative")), 75 natives->Get(v8::String::NewSymbol("requireNative")),
75 exports, 76 exports,
76 }; 77 };
77 func->Call(global, 3, args); 78 {
79 WebKit::WebScopedMicrotaskSuppression suppression;
80 func->Call(global, 3, args);
81 }
78 modules->Set(module_name, exports); 82 modules->Set(module_name, exports);
79 return handle_scope.Close(exports); 83 return handle_scope.Close(exports);
80 } 84 }
81 85
82 void ModuleSystem::RegisterNativeHandler(const std::string& name, 86 void ModuleSystem::RegisterNativeHandler(const std::string& name,
83 scoped_ptr<NativeHandler> native_handler) { 87 scoped_ptr<NativeHandler> native_handler) {
84 native_handler_map_[name] = 88 native_handler_map_[name] =
85 linked_ptr<NativeHandler>(native_handler.release()); 89 linked_ptr<NativeHandler>(native_handler.release());
86 } 90 }
87 91
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 133
130 object->SetAccessor(v8::String::New(field.c_str()), 134 object->SetAccessor(v8::String::New(field.c_str()),
131 &ModuleSystem::LazyFieldGetter, 135 &ModuleSystem::LazyFieldGetter,
132 NULL, 136 NULL,
133 parameters); 137 parameters);
134 } 138 }
135 139
136 v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code, 140 v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
137 v8::Handle<v8::String> name) { 141 v8::Handle<v8::String> name) {
138 v8::HandleScope handle_scope; 142 v8::HandleScope handle_scope;
143 WebKit::WebScopedMicrotaskSuppression suppression;
139 return handle_scope.Close(v8::Script::New(code, name)->Run()); 144 return handle_scope.Close(v8::Script::New(code, name)->Run());
140 } 145 }
141 146
142 v8::Handle<v8::Value> ModuleSystem::GetSource( 147 v8::Handle<v8::Value> ModuleSystem::GetSource(
143 v8::Handle<v8::String> source_name) { 148 v8::Handle<v8::String> source_name) {
144 v8::HandleScope handle_scope; 149 v8::HandleScope handle_scope;
145 std::string module_name = *v8::String::AsciiValue(source_name); 150 std::string module_name = *v8::String::AsciiValue(source_name);
146 if (!source_map_->Contains(module_name)) 151 if (!source_map_->Contains(module_name))
147 return v8::Undefined(); 152 return v8::Undefined();
148 return handle_scope.Close(source_map_->GetSource(module_name)); 153 return handle_scope.Close(source_map_->GetSource(module_name));
(...skipping 15 matching lines...) Expand all
164 v8::Handle<v8::String> left = 169 v8::Handle<v8::String> left =
165 v8::String::New("(function(require, requireNative, exports) {"); 170 v8::String::New("(function(require, requireNative, exports) {");
166 v8::Handle<v8::String> right = v8::String::New("\n})"); 171 v8::Handle<v8::String> right = v8::String::New("\n})");
167 return handle_scope.Close( 172 return handle_scope.Close(
168 v8::String::Concat(left, v8::String::Concat(source, right))); 173 v8::String::Concat(left, v8::String::Concat(source, right)));
169 } 174 }
170 175
171 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) { 176 v8::Handle<v8::Value> ModuleSystem::ThrowException(const std::string& message) {
172 return v8::ThrowException(v8::String::New(message.c_str())); 177 return v8::ThrowException(v8::String::New(message.c_str()));
173 } 178 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/miscellaneous_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698