Index: third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp |
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp |
index 342df6fbe2e0faf912006eadc6a07c88562eb20c..0cfbbd5681b3531de74d4540050637a4770c44f5 100644 |
--- a/third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp |
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8Console.cpp |
@@ -702,25 +702,13 @@ v8::Local<v8::Object> V8Console::createCommandLineAPI(InspectedContext* inspecte |
return commandLineAPI; |
} |
-void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, v8::Local<v8::Object> console) |
-{ |
- v8::Isolate* isolate = context->GetIsolate(); |
- console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::External::New(isolate, nullptr)); |
-} |
- |
-bool V8Debugger::isCommandLineAPIMethod(const String16& name) |
+static void setterCallback(const v8::FunctionCallbackInfo<v8::Value>& info) |
dgozman
2016/06/01 01:25:40
Why do we need this indirection?
kozy
2016/06/01 18:49:22
We'd like to make CommandLineAPI methods replaceab
|
{ |
- DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, methods, ()); |
- if (methods.size() == 0) { |
- const char* members[] = { "dir", "dirxml", "keys", "values", "profile", "profileEnd", "inspect", |
- "copy", "clear", "debug", "undebug", "monitor", "unmonitor", "table" }; |
- for (size_t i = 0; i < WTF_ARRAY_LENGTH(members); ++i) |
- methods.add(members[i]); |
- } |
- return methods.find(name) != methods.end(); |
+ if (!info.Holder()->CreateDataProperty(info.GetIsolate()->GetCurrentContext(), v8::Local<v8::Name>::Cast(info.Data()), info[0]).FromMaybe(false)) |
+ return; |
} |
-bool V8Debugger::isCommandLineAPIGetter(const String16& name) |
+static bool isCommandLineAPIGetter(const String16& name) |
{ |
DEFINE_STATIC_LOCAL(protocol::HashSet<String16>, getters, ()); |
if (getters.size() == 0) { |
@@ -731,4 +719,71 @@ bool V8Debugger::isCommandLineAPIGetter(const String16& name) |
return getters.find(name) != getters.end(); |
} |
+v8::Local<v8::Object> V8Console::installCommandLineAPI(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v8::Local<v8::Object> commandLineAPI) |
+{ |
+ v8::Local<v8::Object> installedMethods = v8::Object::New(context->GetIsolate()); |
+ v8::Local<v8::Array> commandLineAPIMethodNames; |
+ if (!commandLineAPI->GetOwnPropertyNames(context).ToLocal(&commandLineAPIMethodNames)) |
dgozman
2016/06/01 01:25:40
Perhaps, it makes sense to migrate command line ap
kozy
2016/06/01 18:49:22
I'll make it in follow up.
|
+ return installedMethods; |
+ for (size_t i = 0; i < commandLineAPIMethodNames->Length(); ++i) { |
+ v8::Local<v8::Value> methodName; |
+ if (!commandLineAPIMethodNames->Get(context, i).ToLocal(&methodName) || !methodName->IsName()) |
+ continue; |
+ if (object->Has(context, methodName).FromMaybe(true)) |
+ continue; |
+ v8::Local<v8::Value> method; |
+ if (!commandLineAPI->Get(context, methodName).ToLocal(&method) || !method->IsFunction()) |
+ continue; |
+ if (!installedMethods->Set(context, methodName, method).FromMaybe(false)) |
+ continue; |
+ if (isCommandLineAPIGetter(toProtocolStringWithTypeCheck(methodName))) { |
+ v8::Local<v8::Function> setter; |
+ if (!v8::Function::New(context, setterCallback, methodName).ToLocal(&setter)) |
+ continue; |
+ object->SetAccessorProperty(v8::Local<v8::Name>::Cast(methodName), v8::Local<v8::Function>::Cast(method), setter, v8::DontEnum); |
+ } else if (!object->DefineOwnProperty(context, v8::Local<v8::Name>::Cast(methodName), method, v8::DontEnum).FromMaybe(false)) { |
+ continue; |
+ } |
+ } |
+ return installedMethods; |
+} |
+ |
+void V8Console::clearCommandLineAPI(v8::Local<v8::Context> context, v8::Local<v8::Object> object, v8::Local<v8::Object> installedMethods) |
+{ |
+ v8::Local<v8::Array> installedMethodNames; |
+ if (!installedMethods->GetOwnPropertyNames(context).ToLocal(&installedMethodNames)) |
+ return; |
+ for (size_t i = 0; i < installedMethodNames->Length(); ++i) { |
+ v8::Local<v8::Value> methodName; |
+ if (!installedMethodNames->Get(context, i).ToLocal(&methodName) || !methodName->IsName()) |
+ continue; |
+ if (!object->Has(context, methodName).FromMaybe(false)) |
+ continue; |
+ v8::Local<v8::Value> commandLineAPIValue; |
+ if (!installedMethods->Get(context, methodName).ToLocal(&commandLineAPIValue)) |
+ continue; |
+ v8::Local<v8::Value> objectMethodValue; |
+ if (isCommandLineAPIGetter(toProtocolStringWithTypeCheck(methodName))) { |
+ v8::Local<v8::Value> propertyDescriptor; |
+ if (!object->GetOwnPropertyDescriptor(context, v8::Local<v8::String>::Cast(methodName)).ToLocal(&propertyDescriptor) || !propertyDescriptor->IsObject()) |
+ continue; |
+ if (!propertyDescriptor.As<v8::Object>()->Get(context, toV8StringInternalized(context->GetIsolate(), "get")).ToLocal(&objectMethodValue)) |
+ continue; |
+ } else { |
+ if (!object->Get(context, methodName).ToLocal(&objectMethodValue)) |
+ continue; |
+ } |
+ if (!commandLineAPIValue->Equals(context, objectMethodValue).FromMaybe(false)) |
dgozman
2016/06/01 01:25:40
This is kind of scary. What about having a setter
kozy
2016/06/01 18:49:22
Done.
|
+ continue; |
+ if (!object->Delete(context, methodName).FromMaybe(false)) |
+ continue; |
+ } |
+} |
+ |
+void V8Console::clearInspectedContextIfNeeded(v8::Local<v8::Context> context, v8::Local<v8::Object> console) |
+{ |
+ v8::Isolate* isolate = context->GetIsolate(); |
+ console->SetPrivate(context, inspectedContextPrivateKey(isolate), v8::External::New(isolate, nullptr)); |
+} |
+ |
} // namespace blink |