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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 v8::String::Utf8Value stack_value(v8_stack_trace); | 89 v8::String::Utf8Value stack_value(v8_stack_trace); |
| 90 if (*stack_value) | 90 if (*stack_value) |
| 91 stack_trace.assign(*stack_value, stack_value.length()); | 91 stack_trace.assign(*stack_value, stack_value.length()); |
| 92 else | 92 else |
| 93 stack_trace = "<could not convert stack trace to string>"; | 93 stack_trace = "<could not convert stack trace to string>"; |
| 94 } | 94 } |
| 95 Fatal(context_, CreateExceptionString(try_catch) + "{" + stack_trace + "}"); | 95 Fatal(context_, CreateExceptionString(try_catch) + "{" + stack_trace + "}"); |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Sets a property on the "exports" object for bindings. Called by JS with | |
| 100 // exports.$set(<key>, <value>). | |
| 101 void SetExportsProperty( | |
| 102 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 103 v8::Local<v8::Object> obj = args.This(); | |
| 104 DCHECK_EQ(2, args.Length()); | |
| 105 DCHECK(args[0]->IsString()); | |
| 106 obj->ForceSet(args[0], args[1], v8::ReadOnly); | |
|
Devlin
2015/10/23 22:08:28
This works, but it looks like ForceSet() is deprec
jochen (gone - plz use gerrit)
2015/10/26 15:46:54
You'd use v8::Object::DefineOwnProperty()
Devlin
2015/10/27 23:08:54
Ah, for some reason I thought that would hit the a
| |
| 107 } | |
| 108 | |
| 99 } // namespace | 109 } // namespace |
| 100 | 110 |
| 101 std::string ModuleSystem::ExceptionHandler::CreateExceptionString( | 111 std::string ModuleSystem::ExceptionHandler::CreateExceptionString( |
| 102 const v8::TryCatch& try_catch) { | 112 const v8::TryCatch& try_catch) { |
| 103 v8::Local<v8::Message> message(try_catch.Message()); | 113 v8::Local<v8::Message> message(try_catch.Message()); |
| 104 if (message.IsEmpty()) { | 114 if (message.IsEmpty()) { |
| 105 return "try_catch has no message"; | 115 return "try_catch has no message"; |
| 106 } | 116 } |
| 107 | 117 |
| 108 std::string resource_name = "<unknown resource>"; | 118 std::string resource_name = "<unknown resource>"; |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) { | 645 if (func_as_value.IsEmpty() || func_as_value->IsUndefined()) { |
| 636 Fatal(context_, "Bad source for require(" + module_name + ")"); | 646 Fatal(context_, "Bad source for require(" + module_name + ")"); |
| 637 return v8::Undefined(GetIsolate()); | 647 return v8::Undefined(GetIsolate()); |
| 638 } | 648 } |
| 639 | 649 |
| 640 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(func_as_value); | 650 v8::Local<v8::Function> func = v8::Local<v8::Function>::Cast(func_as_value); |
| 641 | 651 |
| 642 v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate()); | 652 v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate()); |
| 643 gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); | 653 gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); |
| 644 | 654 |
| 645 v8::Local<v8::Value> exports = v8::Object::New(GetIsolate()); | 655 v8::Local<v8::Object> exports = v8::Object::New(GetIsolate()); |
| 656 | |
| 657 v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( | |
| 658 GetIsolate(), | |
| 659 &SetExportsProperty); | |
| 660 v8::Local<v8::String> v8_key; | |
| 661 if (!v8_helpers::ToV8String(GetIsolate(), "$set", &v8_key)) { | |
| 662 NOTREACHED(); | |
| 663 return v8::Undefined(GetIsolate()); | |
| 664 } | |
| 665 | |
| 666 v8::Local<v8::Function> function; | |
| 667 if (!tmpl->GetFunction(v8_context).ToLocal(&function)) { | |
| 668 NOTREACHED(); | |
| 669 return v8::Undefined(GetIsolate()); | |
| 670 } | |
| 671 | |
| 672 exports->ForceSet(v8_key, function, v8::ReadOnly); | |
| 673 | |
| 646 v8::Local<v8::Object> natives(NewInstance()); | 674 v8::Local<v8::Object> natives(NewInstance()); |
| 647 CHECK(!natives.IsEmpty()); // this can fail if v8 has issues | 675 CHECK(!natives.IsEmpty()); // this can fail if v8 has issues |
| 648 | 676 |
| 649 // These must match the argument order in WrapSource. | 677 // These must match the argument order in WrapSource. |
| 650 v8::Local<v8::Value> args[] = { | 678 v8::Local<v8::Value> args[] = { |
| 651 // AMD. | 679 // AMD. |
| 652 GetPropertyUnsafe(v8_context, define_object, "define"), | 680 GetPropertyUnsafe(v8_context, define_object, "define"), |
| 653 // CommonJS. | 681 // CommonJS. |
| 654 GetPropertyUnsafe(v8_context, natives, "require", | 682 GetPropertyUnsafe(v8_context, natives, "require", |
| 655 v8::NewStringType::kInternalized), | 683 v8::NewStringType::kInternalized), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 | 745 |
| 718 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { | 746 void ModuleSystem::ClobberExistingNativeHandler(const std::string& name) { |
| 719 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); | 747 NativeHandlerMap::iterator existing_handler = native_handler_map_.find(name); |
| 720 if (existing_handler != native_handler_map_.end()) { | 748 if (existing_handler != native_handler_map_.end()) { |
| 721 clobbered_native_handlers_.push_back(existing_handler->second); | 749 clobbered_native_handlers_.push_back(existing_handler->second); |
| 722 native_handler_map_.erase(existing_handler); | 750 native_handler_map_.erase(existing_handler); |
| 723 } | 751 } |
| 724 } | 752 } |
| 725 | 753 |
| 726 } // namespace extensions | 754 } // namespace extensions |
| OLD | NEW |