Chromium Code Reviews| Index: extensions/renderer/module_system.cc |
| diff --git a/extensions/renderer/module_system.cc b/extensions/renderer/module_system.cc |
| index e760849602b9f8f4b768abcf519268289ccbb6d9..fd899328c47352639beb4d038d8cc1ef631e18b5 100644 |
| --- a/extensions/renderer/module_system.cc |
| +++ b/extensions/renderer/module_system.cc |
| @@ -96,6 +96,16 @@ class DefaultExceptionHandler : public ModuleSystem::ExceptionHandler { |
| } |
| }; |
| +// Sets a property on the "exports" object for bindings. Called by JS with |
| +// exports.$set(<key>, <value>). |
| +void SetExportsProperty( |
| + const v8::FunctionCallbackInfo<v8::Value>& args) { |
| + v8::Local<v8::Object> obj = args.This(); |
| + DCHECK_EQ(2, args.Length()); |
| + DCHECK(args[0]->IsString()); |
| + 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
|
| +} |
| + |
| } // namespace |
| std::string ModuleSystem::ExceptionHandler::CreateExceptionString( |
| @@ -642,7 +652,25 @@ v8::Local<v8::Value> ModuleSystem::LoadModule(const std::string& module_name) { |
| v8::Local<v8::Object> define_object = v8::Object::New(GetIsolate()); |
| gin::ModuleRegistry::InstallGlobals(GetIsolate(), define_object); |
| - v8::Local<v8::Value> exports = v8::Object::New(GetIsolate()); |
| + v8::Local<v8::Object> exports = v8::Object::New(GetIsolate()); |
| + |
| + v8::Local<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New( |
| + GetIsolate(), |
| + &SetExportsProperty); |
| + v8::Local<v8::String> v8_key; |
| + if (!v8_helpers::ToV8String(GetIsolate(), "$set", &v8_key)) { |
| + NOTREACHED(); |
| + return v8::Undefined(GetIsolate()); |
| + } |
| + |
| + v8::Local<v8::Function> function; |
| + if (!tmpl->GetFunction(v8_context).ToLocal(&function)) { |
| + NOTREACHED(); |
| + return v8::Undefined(GetIsolate()); |
| + } |
| + |
| + exports->ForceSet(v8_key, function, v8::ReadOnly); |
| + |
| v8::Local<v8::Object> natives(NewInstance()); |
| CHECK(!natives.IsEmpty()); // this can fail if v8 has issues |