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..bb6db9d5b7504e40f6d3f0192024d861d6e65105 100644 |
| --- a/extensions/renderer/module_system.cc |
| +++ b/extensions/renderer/module_system.cc |
| @@ -96,6 +96,20 @@ 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()); |
| + v8::Maybe<bool> result = |
| + obj->DefineOwnProperty(args.GetIsolate()->GetCallingContext(), |
|
jochen (gone - plz use gerrit)
2015/10/28 14:22:18
I know this is copy/paste, but this should really
Devlin
2015/10/28 20:38:17
Done. For my own edification, can you explain why
dcheng
2015/10/30 21:32:59
https://groups.google.com/a/chromium.org/forum/#!t
|
| + args[0]->ToString(), args[1], v8::ReadOnly); |
| + if (!result.IsJust() || !result.FromJust()) |
|
jochen (gone - plz use gerrit)
2015/10/28 14:22:18
if (!result.FromMaybe(false)) is shorter
Devlin
2015/10/28 20:38:18
Nifty, done.
|
| + LOG(ERROR) << "Failed to set private property on the export."; |
| +} |
| + |
| } // namespace |
| std::string ModuleSystem::ExceptionHandler::CreateExceptionString( |
| @@ -642,7 +656,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 |