Commit dc3d06e0 authored by marja@chromium.org's avatar marja@chromium.org

Remove more calls to HandleScope default ctor.

It's replaced by a version which takes an isolate. The default ctor will be
removed soon.

BUG=NONE

Review URL: https://chromiumcodereview.appspot.com/23679004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221689 0039d316-1c4b-4281-b951-d872f2087c98
parent c93c9c32
......@@ -207,7 +207,7 @@ bool AppBindings::OnMessageReceived(const IPC::Message& message) {
void AppBindings::OnAppInstallStateResponse(
const std::string& state, int callback_id) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context()->isolate());
v8::Context::Scope context_scope(context()->v8_context());
v8::Handle<v8::Value> argv[] = {
v8::String::New(state.c_str()),
......
......@@ -38,7 +38,7 @@ class DidCreateDocumentElementObserver : public content::RenderViewObserver {
// Don't attempt to inject the titlebar into iframes.
if (frame->parent())
return;
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
ChromeV8Context* v8_context =
dispatcher_->v8_context_set().GetByV8Context(
frame->mainWorldScriptContext());
......
......@@ -18,7 +18,7 @@ BindingGeneratingNativeHandler::BindingGeneratingNativeHandler(
}
v8::Handle<v8::Object> BindingGeneratingNativeHandler::NewInstance() {
v8::HandleScope scope;
v8::HandleScope scope(module_system_->GetIsolate());
v8::Handle<v8::Object> binding_module =
module_system_->Require("binding")->ToObject();
v8::Handle<v8::Object> binding =
......
......@@ -34,7 +34,8 @@ ChromeV8Context::ChromeV8Context(v8::Handle<v8::Context> v8_context,
web_frame_(web_frame),
extension_(extension),
context_type_(context_type),
safe_builtins_(this) {
safe_builtins_(this),
isolate_(v8_context->GetIsolate()) {
VLOG(1) << "Created context:\n"
<< " extension id: " << GetExtensionID() << "\n"
<< " frame: " << web_frame_ << "\n"
......@@ -76,7 +77,7 @@ v8::Local<v8::Value> ChromeV8Context::CallFunction(
v8::Handle<v8::Function> function,
int argc,
v8::Handle<v8::Value> argv[]) const {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(isolate());
v8::Context::Scope scope(v8_context());
WebKit::WebScopedMicrotaskSuppression suppression;
......@@ -135,7 +136,7 @@ void ChromeV8Context::OnResponseReceived(const std::string& name,
bool success,
const base::ListValue& response,
const std::string& error) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(isolate());
scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
v8::Handle<v8::Value> argv[] = {
......
......@@ -116,6 +116,10 @@ class ChromeV8Context : public RequestSender::Source {
const base::ListValue& response,
const std::string& error) OVERRIDE;
v8::Isolate* isolate() const {
return isolate_;
}
private:
// The v8 context the bindings are accessible to.
ScopedPersistent<v8::Context> v8_context_;
......@@ -137,6 +141,8 @@ class ChromeV8Context : public RequestSender::Source {
// Contains safe copies of builtin objects like Function.prototype.
SafeBuiltins safe_builtins_;
v8::Isolate* isolate_;
DISALLOW_COPY_AND_ASSIGN(ChromeV8Context);
};
......
......@@ -172,7 +172,7 @@ void AddMessage(v8::Handle<v8::Context> context,
}
v8::Local<v8::Object> AsV8Object() {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Local<v8::Object> console_object = v8::Object::New();
BindLogMethod(console_object, "debug", &Debug);
BindLogMethod(console_object, "log", &Log);
......
......@@ -98,7 +98,7 @@ void ContentWatcher::DidCreateDocumentElement(WebKit::WebFrame* frame) {
}
void ContentWatcher::EnsureWatchingMutations(WebKit::WebFrame* frame) {
v8::HandleScope scope;
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Context::Scope context_scope(frame->mainWorldScriptContext());
if (ModuleSystem* module_system = GetModuleSystem(frame)) {
ModuleSystem::NativesEnabledScope scope(module_system);
......
......@@ -379,7 +379,7 @@ void CallModuleMethod(const std::string& module_name,
const std::string& method_name,
const base::ListValue* args,
ChromeV8Context* context) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context->isolate());
v8::Context::Scope context_scope(context->v8_context());
scoped_ptr<content::V8ValueConverter> converter(
......@@ -646,7 +646,7 @@ v8::Handle<v8::Object> Dispatcher::GetOrCreateObject(
}
void Dispatcher::AddOrRemoveBindingsForContext(ChromeV8Context* context) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context->isolate());
v8::Context::Scope context_scope(context->v8_context());
// TODO(kalman): Make the bindings registration have zero overhead then run
......
......@@ -353,7 +353,7 @@ void ExtensionHelper::OnAddMessageToConsole(ConsoleMessageLevel level,
}
void ExtensionHelper::OnAppWindowClosed() {
v8::HandleScope scope;
v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Context> script_context =
render_view()->GetWebView()->mainFrame()->mainWorldScriptContext();
ChromeV8Context* chrome_v8_context =
......
......@@ -168,8 +168,9 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
class GCCallback {
public:
static void Bind(v8::Handle<v8::Object> object,
v8::Handle<v8::Function> callback) {
GCCallback* cb = new GCCallback(object, callback);
v8::Handle<v8::Function> callback,
v8::Isolate* isolate) {
GCCallback* cb = new GCCallback(object, callback, isolate);
cb->object_.MakeWeak(cb, NearDeathCallback);
}
......@@ -184,12 +185,13 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
base::Bind(&GCCallback::RunCallback, base::Owned(self)));
}
GCCallback(v8::Handle<v8::Object> object, v8::Handle<v8::Function> callback)
: object_(object), callback_(callback) {
}
GCCallback(v8::Handle<v8::Object> object,
v8::Handle<v8::Function> callback,
v8::Isolate* isolate)
: object_(object), callback_(callback), isolate_(isolate) {}
void RunCallback() {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(isolate_);
v8::Handle<v8::Context> context = callback_->CreationContext();
if (context.IsEmpty())
return;
......@@ -200,6 +202,7 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
extensions::ScopedPersistent<v8::Object> object_;
extensions::ScopedPersistent<v8::Function> callback_;
v8::Isolate* isolate_;
DISALLOW_COPY_AND_ASSIGN(GCCallback);
};
......@@ -211,7 +214,9 @@ class ExtensionImpl : public extensions::ChromeV8Extension {
// JS in some bizarro undefined mid-GC state.
void BindToGC(const v8::FunctionCallbackInfo<v8::Value>& args) {
CHECK(args.Length() == 2 && args[0]->IsObject() && args[1]->IsFunction());
GCCallback::Bind(args[0].As<v8::Object>(), args[1].As<v8::Function>());
GCCallback::Bind(args[0].As<v8::Object>(),
args[1].As<v8::Function>(),
args.GetIsolate());
}
};
......@@ -235,7 +240,7 @@ void MessagingBindings::DispatchOnConnect(
const std::string& target_extension_id,
const GURL& source_url,
content::RenderView* restrict_to_render_view) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
......@@ -296,7 +301,7 @@ void MessagingBindings::DeliverMessage(
int target_port_id,
const std::string& message,
content::RenderView* restrict_to_render_view) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
// TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach.
for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin();
......@@ -337,7 +342,7 @@ void MessagingBindings::DispatchOnDisconnect(
int port_id,
const std::string& error_message,
content::RenderView* restrict_to_render_view) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
// TODO(kalman): pass in the full ChromeV8ContextSet; call ForEach.
for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin();
......
......@@ -74,7 +74,7 @@ class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler {
// Make sure this is never used for exceptions that originate in external
// code!
virtual void HandleUncaughtException(const v8::TryCatch& try_catch) OVERRIDE {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context_->isolate());
std::string stack_trace = "<stack trace unavailable>";
if (!try_catch.StackTrace().IsEmpty()) {
v8::String::Utf8Value stack_value(try_catch.StackTrace());
......@@ -146,7 +146,7 @@ void ModuleSystem::Invalidate() {
// Clear the module system properties from the global context. It's polite,
// and we use this as a signal in lazy handlers that we no longer exist.
{
v8::HandleScope scope;
v8::HandleScope scope(GetIsolate());
v8::Handle<v8::Object> global = context()->v8_context()->Global();
global->DeleteHiddenValue(v8::String::New(kModulesField));
global->DeleteHiddenValue(v8::String::New(kModuleSystem));
......@@ -177,7 +177,7 @@ void ModuleSystem::HandleException(const v8::TryCatch& try_catch) {
}
v8::Handle<v8::Value> ModuleSystem::Require(const std::string& module_name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
return handle_scope.Close(
RequireForJsInner(v8::String::New(module_name.c_str())));
}
......@@ -190,7 +190,7 @@ void ModuleSystem::RequireForJs(
v8::Handle<v8::Value> ModuleSystem::RequireForJsInner(
v8::Handle<v8::String> module_name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
v8::Context::Scope context_scope(context()->v8_context());
v8::Handle<v8::Object> global(context()->v8_context()->Global());
......@@ -263,7 +263,7 @@ v8::Handle<v8::Value> ModuleSystem::RequireForJsInner(
v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
const std::string& module_name,
const std::string& method_name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
v8::Handle<v8::Value> no_args;
return CallModuleMethod(module_name, method_name, 0, &no_args);
}
......@@ -285,7 +285,7 @@ v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
"module_name", module_name,
"method_name", method_name);
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
v8::Context::Scope context_scope(context()->v8_context());
v8::Local<v8::Value> module;
......@@ -332,7 +332,7 @@ void ModuleSystem::OverrideNativeHandlerForTest(const std::string& name) {
}
void ModuleSystem::RunString(const std::string& code, const std::string& name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
RunString(v8::String::New(code.c_str()), v8::String::New(name.c_str()));
}
......@@ -359,7 +359,7 @@ void ModuleSystem::LazyFieldGetterInner(
RequireFunction require_function) {
CHECK(!info.Data().IsEmpty());
CHECK(info.Data()->IsObject());
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(info.GetIsolate());
v8::Handle<v8::Object> parameters = v8::Handle<v8::Object>::Cast(info.Data());
// This context should be the same as context()->v8_context().
v8::Handle<v8::Context> context = parameters->CreationContext();
......@@ -438,7 +438,7 @@ void ModuleSystem::SetLazyField(v8::Handle<v8::Object> object,
const std::string& module_name,
const std::string& module_field,
v8::AccessorGetterCallback getter) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
v8::Handle<v8::Object> parameters = v8::Object::New();
parameters->Set(v8::String::New(kModuleName),
v8::String::New(module_name.c_str()));
......@@ -458,9 +458,14 @@ void ModuleSystem::SetNativeLazyField(v8::Handle<v8::Object> object,
&ModuleSystem::NativeLazyFieldGetter);
}
v8::Isolate* ModuleSystem::GetIsolate() const {
return context_->isolate();
}
v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
v8::Handle<v8::String> name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
v8::Context::Scope context_scope(context()->v8_context());
WebKit::WebScopedMicrotaskSuppression suppression;
......@@ -482,7 +487,7 @@ v8::Handle<v8::Value> ModuleSystem::RunString(v8::Handle<v8::String> code,
}
v8::Handle<v8::Value> ModuleSystem::GetSource(const std::string& module_name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
if (!source_map_->Contains(module_name))
return v8::Undefined();
return handle_scope.Close(source_map_->GetSource(module_name));
......@@ -520,7 +525,7 @@ v8::Handle<v8::Value> ModuleSystem::RequireNativeFromString(
}
v8::Handle<v8::String> ModuleSystem::WrapSource(v8::Handle<v8::String> source) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(GetIsolate());
// Keep in order with the arguments in RequireForJsInner.
v8::Handle<v8::String> left = v8::String::New(
"(function(require, requireNative, exports, "
......
......@@ -134,6 +134,8 @@ class ModuleSystem : public ObjectBackedNativeHandler {
exception_handler_ = handler.Pass();
}
v8::Isolate* GetIsolate() const;
protected:
friend class ChromeV8Context;
virtual void Invalidate() OVERRIDE;
......
......@@ -38,7 +38,7 @@ v8::Handle<v8::Object> ObjectBackedNativeHandler::NewInstance() {
// static
void ObjectBackedNativeHandler::Router(
const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(args.GetIsolate());
v8::Handle<v8::Object> data = args.Data().As<v8::Object>();
v8::Handle<v8::Value> handler_function_value =
......
......@@ -38,7 +38,7 @@ class LoadWatcher : public content::RenderViewObserver {
private:
void CallbackAndDie(bool succeeded) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context_->isolate());
v8::Handle<v8::Value> args[] = { v8::Boolean::New(succeeded) };
context_->CallFunction(callback_.get(), 1, args);
delete this;
......
......@@ -200,7 +200,7 @@ void UserScriptScheduler::ExecuteCodeImpl(
}
WebScriptSource source(WebString::fromUTF8(params.code));
v8::HandleScope scope;
v8::HandleScope scope(v8::Isolate::GetCurrent());
scoped_ptr<content::V8ValueConverter> v8_converter(
content::V8ValueConverter::create());
......
......@@ -211,7 +211,7 @@ void WebstoreBindings::OnInlineWebstoreInstallResponse(
int install_id,
bool success,
const std::string& error) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(context()->isolate());
v8::Context::Scope context_scope(context()->v8_context());
v8::Handle<v8::Value> argv[] = {
v8::Integer::New(install_id),
......
......@@ -76,7 +76,7 @@ extensions::ChromeV8Context* PepperExtensionsCommonHost::GetContext() {
return NULL;
WebKit::WebFrame* frame = container->element().document().frame();
v8::HandleScope scope;
v8::HandleScope scope(v8::Isolate::GetCurrent());
return dispatcher_->v8_context_set().GetByV8Context(
frame->mainWorldScriptContext());
}
......@@ -132,4 +132,3 @@ int32_t PepperExtensionsCommonHost::OnCall(
}
} // namespace chrome
......@@ -421,7 +421,7 @@ v8::Extension* SearchBoxExtension::Get() {
// static
bool SearchBoxExtension::PageSupportsInstant(WebKit::WebFrame* frame) {
if (!frame) return false;
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Value> v = frame->executeScriptAndReturnValue(
WebKit::WebScriptSource(kSupportsInstantScript));
return !v.IsEmpty() && v->BooleanValue();
......
......@@ -195,7 +195,7 @@ bool TranslateHelper::ExecuteScriptAndGetBoolResult(const std::string& script,
if (!main_frame)
return fallback;
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
WebVector<v8::Local<v8::Value> > results;
WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
main_frame->executeScriptInIsolatedWorld(
......@@ -218,7 +218,7 @@ std::string TranslateHelper::ExecuteScriptAndGetStringResult(
if (!main_frame)
return std::string();
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
WebVector<v8::Local<v8::Value> > results;
WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
main_frame->executeScriptInIsolatedWorld(
......@@ -245,7 +245,7 @@ double TranslateHelper::ExecuteScriptAndGetDoubleResult(
if (!main_frame)
return 0.0;
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
WebVector<v8::Local<v8::Value> > results;
WebScriptSource source = WebScriptSource(ASCIIToUTF16(script));
main_frame->executeScriptInIsolatedWorld(
......
......@@ -188,7 +188,7 @@ void ModuleSystemTest::ExpectNoAssertionsMade() {
}
v8::Handle<v8::Object> ModuleSystemTest::CreateGlobal(const std::string& name) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Object> object = v8::Object::New();
v8::Context::GetCurrent()->Global()->Set(v8::String::New(name.c_str()),
object);
......
......@@ -19,7 +19,7 @@ std::string LogArgs2String(const v8::FunctionCallbackInfo<v8::Value>& args) {
std::string message;
bool first = true;
for (int i = 0; i < args.Length(); i++) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
if (first)
first = false;
else
......@@ -212,7 +212,7 @@ void V8UnitTest::ExecuteScriptInContext(const base::StringPiece& script_source,
std::string V8UnitTest::ExceptionToString(const v8::TryCatch& try_catch) {
std::string str;
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::String::Utf8Value exception(try_catch.Exception());
v8::Local<v8::Message> message(try_catch.Message());
if (message.IsEmpty()) {
......@@ -260,7 +260,7 @@ void V8UnitTest::Error(const v8::FunctionCallbackInfo<v8::Value>& args) {
}
void V8UnitTest::ChromeSend(const v8::FunctionCallbackInfo<v8::Value>& args) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
// We expect to receive 2 args: ("testResult", [ok, message]). However,
// chrome.send may pass only one. Therefore we need to ensure we have at least
// 1, then ensure that the first is "testResult" before checking again for 2.
......
......@@ -112,7 +112,7 @@ void BrowserPluginTest::TearDown() {
std::string BrowserPluginTest::ExecuteScriptAndReturnString(
const std::string& script) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue(
WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str())));
if (value.IsEmpty() || !value->IsString())
......@@ -127,7 +127,7 @@ std::string BrowserPluginTest::ExecuteScriptAndReturnString(
int BrowserPluginTest::ExecuteScriptAndReturnInt(
const std::string& script) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue(
WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str())));
if (value.IsEmpty() || !value->IsInt32())
......@@ -140,7 +140,7 @@ int BrowserPluginTest::ExecuteScriptAndReturnInt(
// of the script is stored in |result|
bool BrowserPluginTest::ExecuteScriptAndReturnBool(
const std::string& script, bool* result) {
v8::HandleScope handle_scope;
v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue(
WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str())));
if (value.IsEmpty() || !value->IsBoolean())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment