Chromium Code Reviews| 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/module_system.h" | 5 #include "extensions/renderer/module_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 return RequireForJsInner( | 556 return RequireForJsInner( |
| 557 ToV8StringUnsafe(GetIsolate(), native_name.c_str())); | 557 ToV8StringUnsafe(GetIsolate(), native_name.c_str())); |
| 558 } | 558 } |
| 559 | 559 |
| 560 NativeHandlerMap::iterator i = native_handler_map_.find(native_name); | 560 NativeHandlerMap::iterator i = native_handler_map_.find(native_name); |
| 561 if (i == native_handler_map_.end()) { | 561 if (i == native_handler_map_.end()) { |
| 562 Fatal(context_, | 562 Fatal(context_, |
| 563 "Couldn't find native for requireNative(" + native_name + ")"); | 563 "Couldn't find native for requireNative(" + native_name + ")"); |
| 564 return v8::Undefined(GetIsolate()); | 564 return v8::Undefined(GetIsolate()); |
| 565 } | 565 } |
| 566 return i->second->NewInstance(); | 566 v8::Local<v8::Value> instance; |
| 567 if (!i->second->NewInstance().ToLocal(&instance)) { | |
| 568 LOG(ERROR) << "Cannot instanciate native for requireNative(" + native_name + | |
|
not at google - send to devlin
2015/06/19 17:23:55
"instantiate", and NOTREACHED(), but might be moot
bashi
2015/06/23 00:10:49
Removed because NewInstance() returns Local now.
| |
| 569 ")"; | |
| 570 return v8::Undefined(GetIsolate()); | |
| 571 } | |
| 572 return instance; | |
| 567 } | 573 } |
| 568 | 574 |
| 569 void ModuleSystem::RequireAsync( | 575 void ModuleSystem::RequireAsync( |
| 570 const v8::FunctionCallbackInfo<v8::Value>& args) { | 576 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 571 CHECK_EQ(1, args.Length()); | 577 CHECK_EQ(1, args.Length()); |
| 572 std::string module_name = *v8::String::Utf8Value(args[0]); | 578 std::string module_name = *v8::String::Utf8Value(args[0]); |
| 573 v8::Local<v8::Context> v8_context = context_->v8_context(); | 579 v8::Local<v8::Context> v8_context = context_->v8_context(); |
| 574 v8::Local<v8::Promise::Resolver> resolver( | 580 v8::Local<v8::Promise::Resolver> resolver( |
| 575 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); | 581 v8::Promise::Resolver::New(v8_context).ToLocalChecked()); |
| 576 args.GetReturnValue().Set(resolver->GetPromise()); | 582 args.GetReturnValue().Set(resolver->GetPromise()); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 657 Fatal(context_, "Bad source for require(" + module_name + ")"); | 663 Fatal(context_, "Bad source for require(" + module_name + ")"); |
| 658 return v8::Undefined(GetIsolate()); | 664 return v8::Undefined(GetIsolate()); |
| 659 } | 665 } |
| 660 | 666 |
| 661 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(func_as_value); | 667 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(func_as_value); |
| 662 | 668 |
| 663 v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate()); | 669 v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate()); |
| 664 gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); | 670 gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); |
| 665 | 671 |
| 666 v8::Local<v8::Value> exports = v8::Object::New(GetIsolate()); | 672 v8::Local<v8::Value> exports = v8::Object::New(GetIsolate()); |
| 667 v8::Local<v8::Object> natives(NewInstance()); | 673 v8::Local<v8::Object> natives; |
| 668 CHECK(!natives.IsEmpty()); // this can fail if v8 has issues | 674 if (!NewInstance().ToLocal(&natives)) |
| 675 NOTREACHED(); // this can fail if v8 has issues | |
| 669 | 676 |
| 670 // These must match the argument order in WrapSource. | 677 // These must match the argument order in WrapSource. |
| 671 v8::Local<v8::Value> args[] = { | 678 v8::Local<v8::Value> args[] = { |
| 672 // AMD. | 679 // AMD. |
| 673 GetPropertyUnsafe(v8_context, define_object, "define"), | 680 GetPropertyUnsafe(v8_context, define_object, "define"), |
| 674 // CommonJS. | 681 // CommonJS. |
| 675 GetPropertyUnsafe(v8_context, natives, "require", | 682 GetPropertyUnsafe(v8_context, natives, "require", |
| 676 v8::NewStringType::kInternalized), | 683 v8::NewStringType::kInternalized), |
| 677 GetPropertyUnsafe(v8_context, natives, "requireNative", | 684 GetPropertyUnsafe(v8_context, natives, "requireNative", |
| 678 v8::NewStringType::kInternalized), | 685 v8::NewStringType::kInternalized), |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 | 745 |
| 739 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 746 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
| 740 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 747 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
| 741 if (existing_handler != native_handler_map_.end()) { | 748 if (existing_handler != native_handler_map_.end()) { |
| 742 clobbered_native_handlers_.push_back(existing_handler->second); | 749 clobbered_native_handlers_.push_back(existing_handler->second); |
| 743 native_handler_map_.erase(existing_handler); | 750 native_handler_map_.erase(existing_handler); |
| 744 } | 751 } |
| 745 } | 752 } |
| 746 | 753 |
| 747 } // namespace extensions | 754 } // namespace extensions |
| OLD | NEW |