Chromium Code Reviews| Index: extensions/renderer/binding_generating_native_handler.cc |
| diff --git a/extensions/renderer/binding_generating_native_handler.cc b/extensions/renderer/binding_generating_native_handler.cc |
| index 2f5dc6f442d48ee282e389dff302a45e69c92bd5..7beaeff28eedcce1b60b323786552c8f57c508db 100644 |
| --- a/extensions/renderer/binding_generating_native_handler.cc |
| +++ b/extensions/renderer/binding_generating_native_handler.cc |
| @@ -4,40 +4,87 @@ |
| #include "extensions/renderer/binding_generating_native_handler.h" |
| -#include "extensions/renderer/module_system.h" |
| +#include "extensions/renderer/script_context.h" |
| +#include "extensions/renderer/v8_helpers.h" |
| namespace extensions { |
| +using namespace v8_helpers; |
| + |
| BindingGeneratingNativeHandler::BindingGeneratingNativeHandler( |
| - ModuleSystem* module_system, |
| + ScriptContext* context, |
| const std::string& api_name, |
| const std::string& bind_to) |
| - : module_system_(module_system), api_name_(api_name), bind_to_(bind_to) {} |
| + : context_(context), api_name_(api_name), bind_to_(bind_to) {} |
| v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { |
|
not at google - send to devlin
2015/06/23 17:26:22
// This long sequence of commands effectively runs
bashi
2015/06/24 00:04:32
Done.
|
| - v8::Isolate* isolate = module_system_->GetIsolate(); |
| + v8::Isolate* isolate = context_->isolate(); |
| v8::EscapableHandleScope scope(isolate); |
| - v8::Local<v8::Object> binding_module = |
| - module_system_->Require("binding")->ToObject(isolate); |
| - v8::Local<v8::Object> binding = |
| - binding_module->Get(v8::String::NewFromUtf8(isolate, "Binding")) |
| - ->ToObject(isolate); |
| + |
| + v8::Local<v8::String> v8_api_name; |
|
not at google - send to devlin
2015/06/23 17:26:23
See above, I think these stages should be associat
bashi
2015/06/24 00:04:32
Done.
|
| + v8::Local<v8::String> v8_bind_to; |
| + if (!ToV8String(isolate, api_name_.c_str(), &v8_api_name) || |
| + !ToV8String(isolate, bind_to_.c_str(), &v8_bind_to)) { |
|
not at google - send to devlin
2015/06/23 17:26:23
Perhaps add a ToV8String() variation that takes a
bashi
2015/06/24 00:04:32
Done.
|
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + v8::Local<v8::Context> v8_context = context_->v8_context(); |
|
not at google - send to devlin
2015/06/23 17:26:23
// require('binding');
|
| + v8::Local<v8::Object> binding_module; |
| + if (!context_->module_system()->Require("binding") |
| + ->ToObject(v8_context) |
|
not at google - send to devlin
2015/06/23 17:26:22
Hm, Require() should really return a v8::Object be
bashi
2015/06/24 00:04:32
Hmm, ModuleSystem::Require() returns what ModuleSy
not at google - send to devlin
2015/06/24 00:34:56
I see... maybe because require can fail? A Maybe<O
bashi
2015/06/24 03:30:44
Done. I needed to change some other places. Requir
|
| + .ToLocal(&binding_module)) { |
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + v8::Local<v8::Value> binding_value; |
|
not at google - send to devlin
2015/06/23 17:26:22
// require('binding').Binding;
|
| + v8::Local<v8::Object> binding; |
| + if (!GetProperty(v8_context, binding_module, "Binding", &binding_value) || |
| + !binding_value->ToObject(v8_context).ToLocal(&binding)) { |
|
not at google - send to devlin
2015/06/23 17:26:23
Is |binding_value| guaranteed to be an Object? Wha
bashi
2015/06/24 00:04:32
It depends on what "require('binding').Binding" re
not at google - send to devlin
2015/06/24 00:34:56
ok, cool.
|
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + v8::Local<v8::Value> create_binding_value; |
|
not at google - send to devlin
2015/06/23 17:26:22
// require('Binding').Binding.create;
bashi
2015/06/24 00:04:32
Done.
|
| + if (!GetProperty(v8_context, binding, "create", &create_binding_value) || |
| + !create_binding_value->IsFunction()) { |
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| v8::Local<v8::Function> create_binding = |
| - binding->Get(v8::String::NewFromUtf8(isolate, "create")) |
| - .As<v8::Function>(); |
| - v8::Local<v8::Value> argv[] = { |
| - v8::String::NewFromUtf8(isolate, api_name_.c_str())}; |
| - v8::Local<v8::Object> binding_instance = |
| - create_binding->Call(binding, arraysize(argv), argv)->ToObject(isolate); |
| - v8::Local<v8::Function> generate = |
| - binding_instance->Get(v8::String::NewFromUtf8(isolate, "generate")) |
| - .As<v8::Function>(); |
| + create_binding_value.As<v8::Function>(); |
| + |
| + v8::Local<v8::Value> argv[] = {v8_api_name}; |
|
not at google - send to devlin
2015/06/23 17:26:22
// require('Binding').Binding.create(api_name);
bashi
2015/06/24 00:04:32
Done.
|
| + v8::Local<v8::Value> binding_instance_value; |
| + v8::Local<v8::Object> binding_instance; |
| + if (!CallFunction(v8_context, create_binding, binding, arraysize(argv), argv, |
| + &binding_instance_value) || |
| + !binding_instance_value->ToObject(v8_context) |
| + .ToLocal(&binding_instance)) { |
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + v8::Local<v8::Value> generate_value; |
|
not at google - send to devlin
2015/06/23 17:26:23
// require('Binding').Binding.create(api_name).gen
bashi
2015/06/24 00:04:32
Done.
|
| + if (!GetProperty(v8_context, binding_instance, "generate", &generate_value) || |
| + !generate_value->IsFunction()) { |
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + v8::Local<v8::Function> generate = generate_value.As<v8::Function>(); |
| + |
| v8::Local<v8::Object> object = v8::Object::New(isolate); |
|
not at google - send to devlin
2015/06/23 17:26:23
// require('Binding').Binding.create(api_name).gen
bashi
2015/06/24 00:04:32
Done.
|
| - v8::Local<v8::Value> compiled_schema = |
| - generate->Call(binding_instance, 0, NULL); |
| - if (!compiled_schema.IsEmpty()) { |
| - object->Set(v8::String::NewFromUtf8(isolate, bind_to_.c_str()), |
| - compiled_schema); |
| + v8::Local<v8::Value> compiled_schema; |
| + if (!CallFunction(v8_context, generate, binding_instance, 0, nullptr, |
| + &compiled_schema)) { |
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| + } |
| + |
| + if (!SetProperty(v8_context, object, v8_bind_to, compiled_schema)) { |
|
not at google - send to devlin
2015/06/23 17:26:23
// var result = {};
// result[bind_to] = ...;
bashi
2015/06/24 00:04:32
Done.
|
| + NOTREACHED(); |
| + return v8::Local<v8::Object>(); |
| } |
| return scope.Escape(object); |
|
not at google - send to devlin
2015/06/23 17:26:22
// var result = {};
// result[bind_to] = ...;
// r
bashi
2015/06/24 00:04:32
Done.
|
| } |