| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/v8_context_native_handler.h" | 5 #include "extensions/renderer/v8_context_native_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "extensions/common/features/feature.h" | 8 #include "extensions/common/features/feature.h" |
| 9 #include "extensions/renderer/dispatcher.h" | 9 #include "extensions/renderer/dispatcher.h" |
| 10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 void V8ContextNativeHandler::GetModuleSystem( | 48 void V8ContextNativeHandler::GetModuleSystem( |
| 49 const v8::FunctionCallbackInfo<v8::Value>& args) { | 49 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 50 CHECK_EQ(args.Length(), 1); | 50 CHECK_EQ(args.Length(), 1); |
| 51 CHECK(args[0]->IsObject()); | 51 CHECK(args[0]->IsObject()); |
| 52 v8::Local<v8::Context> v8_context = | 52 v8::Local<v8::Context> v8_context = |
| 53 v8::Local<v8::Object>::Cast(args[0])->CreationContext(); | 53 v8::Local<v8::Object>::Cast(args[0])->CreationContext(); |
| 54 ScriptContext* context = | 54 ScriptContext* context = |
| 55 dispatcher_->script_context_set().GetByV8Context(v8_context); | 55 dispatcher_->script_context_set().GetByV8Context(v8_context); |
| 56 args.GetReturnValue().Set(context->module_system()->NewInstance()); | 56 v8::Local<v8::Value> instance; |
| 57 if (!context->module_system()->NewInstance().ToLocal(&instance)) |
| 58 NOTREACHED(); // This can happen if v8 has issues |
| 59 args.GetReturnValue().Set(instance); |
| 57 } | 60 } |
| 58 | 61 |
| 59 void V8ContextNativeHandler::RunWithNativesEnabledModuleSystem( | 62 void V8ContextNativeHandler::RunWithNativesEnabledModuleSystem( |
| 60 const v8::FunctionCallbackInfo<v8::Value>& args) { | 63 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 61 CHECK_EQ(args.Length(), 1); | 64 CHECK_EQ(args.Length(), 1); |
| 62 CHECK(args[0]->IsFunction()); | 65 CHECK(args[0]->IsFunction()); |
| 63 v8::Local<v8::Value> call_with_args[] = { | 66 v8::Local<v8::Value> instance; |
| 64 context()->module_system()->NewInstance()}; | 67 if (!context()->module_system()->NewInstance().ToLocal(&instance)) |
| 68 NOTREACHED(); // This can happen if v8 has issues |
| 69 v8::Local<v8::Value> call_with_args[] = {instance}; |
| 65 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); | 70 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); |
| 66 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 1, | 71 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0]), 1, |
| 67 call_with_args); | 72 call_with_args); |
| 68 } | 73 } |
| 69 | 74 |
| 70 } // namespace extensions | 75 } // namespace extensions |
| OLD | NEW |