Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(402)

Side by Side Diff: Source/bindings/core/v8/inspector/V8InjectedScriptHost.cpp

Issue 1157313006: DevTools: extract common inspector bindigns code into InspectorWrapper (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "config.h" 5 #include "config.h"
6 #include "bindings/core/v8/inspector/V8InjectedScriptHost.h" 6 #include "bindings/core/v8/inspector/V8InjectedScriptHost.h"
7 7
8 #include "bindings/core/v8/BindingSecurity.h" 8 #include "bindings/core/v8/BindingSecurity.h"
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/ScriptValue.h" 10 #include "bindings/core/v8/ScriptValue.h"
11 #include "bindings/core/v8/V8AbstractEventListener.h" 11 #include "bindings/core/v8/V8AbstractEventListener.h"
12 #include "bindings/core/v8/V8Binding.h" 12 #include "bindings/core/v8/V8Binding.h"
13 #include "bindings/core/v8/V8DOMException.h" 13 #include "bindings/core/v8/V8DOMException.h"
14 #include "bindings/core/v8/V8DOMTokenList.h" 14 #include "bindings/core/v8/V8DOMTokenList.h"
15 #include "bindings/core/v8/V8Debugger.h" 15 #include "bindings/core/v8/V8Debugger.h"
16 #include "bindings/core/v8/V8Event.h" 16 #include "bindings/core/v8/V8Event.h"
17 #include "bindings/core/v8/V8EventTarget.h" 17 #include "bindings/core/v8/V8EventTarget.h"
18 #include "bindings/core/v8/V8HTMLAllCollection.h" 18 #include "bindings/core/v8/V8HTMLAllCollection.h"
19 #include "bindings/core/v8/V8HTMLCollection.h" 19 #include "bindings/core/v8/V8HTMLCollection.h"
20 #include "bindings/core/v8/V8Node.h" 20 #include "bindings/core/v8/V8Node.h"
21 #include "bindings/core/v8/V8NodeList.h" 21 #include "bindings/core/v8/V8NodeList.h"
22 #include "bindings/core/v8/V8ScriptRunner.h" 22 #include "bindings/core/v8/V8ScriptRunner.h"
23 #include "bindings/core/v8/inspector/InspectorWrapper.h"
23 #include "core/events/EventTarget.h" 24 #include "core/events/EventTarget.h"
24 #include "core/inspector/EventListenerInfo.h" 25 #include "core/inspector/EventListenerInfo.h"
25 #include "core/inspector/InjectedScript.h" 26 #include "core/inspector/InjectedScript.h"
26 #include "core/inspector/InjectedScriptHost.h" 27 #include "core/inspector/InjectedScriptHost.h"
27 #include "core/inspector/JavaScriptCallFrame.h" 28 #include "core/inspector/JavaScriptCallFrame.h"
28 #include "platform/JSONValues.h" 29 #include "platform/JSONValues.h"
29 #include "wtf/RefPtr.h" 30 #include "wtf/RefPtr.h"
31 #include "wtf/StdLibExtras.h"
32 #include <algorithm>
30 33
31 namespace blink { 34 namespace blink {
32 35
33 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu e value) 36 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu e value)
34 { 37 {
35 ScriptState::Scope scope(scriptState); 38 ScriptState::Scope scope(scriptState);
36 if (!value.isObject() || value.isNull()) 39 if (!value.isObject() || value.isNull())
37 return 0; 40 return 0;
38 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value())); 41 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value()));
39 } 42 }
(...skipping 22 matching lines...) Expand all
62 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta te, ScriptValue value) 65 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta te, ScriptValue value)
63 { 66 {
64 ScriptState::Scope scope(scriptState); 67 ScriptState::Scope scope(scriptState);
65 if (value.isNull() || !value.isObject()) 68 if (value.isNull() || !value.isObject())
66 return nullptr; 69 return nullptr;
67 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value()); 70 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value());
68 } 71 }
69 72
70 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba ckInfo<v8::Value>& info) 73 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba ckInfo<v8::Value>& info)
71 { 74 {
72 InjectedScriptHost* impl = V8InjectedScriptHost::toImpl(info.Holder()); 75 InjectedScriptHost* impl = V8InjectedScriptHost::unwrap(info.Holder());
73 impl->clearConsoleMessages(); 76 impl->clearConsoleMessages();
74 } 77 }
75 78
76 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 79 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
77 { 80 {
78 if (info.Length() < 1) 81 if (info.Length() < 1)
79 return; 82 return;
80 83
81 if (!info[0]->IsInt32()) { 84 if (!info[0]->IsInt32()) {
82 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be an integer"); 85 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be an integer");
83 return; 86 return;
84 } 87 }
85 88
86 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 89 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
87 InjectedScriptHost::InspectableObject* object = host->inspectedObject(info[0 ].As<v8::Int32>()->Value()); 90 InjectedScriptHost::InspectableObject* object = host->inspectedObject(info[0 ].As<v8::Int32>()->Value());
88 v8SetReturnValue(info, object->get(ScriptState::current(info.GetIsolate())). v8Value()); 91 v8SetReturnValue(info, object->get(ScriptState::current(info.GetIsolate())). v8Value());
89 } 92 }
90 93
91 static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> functio n) 94 static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> functio n)
92 { 95 {
93 v8::Local<v8::Value> value = function->GetDisplayName(); 96 v8::Local<v8::Value> value = function->GetDisplayName();
94 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) 97 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length())
95 return v8::Local<v8::String>::Cast(value); 98 return v8::Local<v8::String>::Cast(value);
96 99
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 location->Set(v8AtomicString(isolate, "scriptId"), v8::Integer::New(isolate, function->ScriptId())->ToString(isolate)); 230 location->Set(v8AtomicString(isolate, "scriptId"), v8::Integer::New(isolate, function->ScriptId())->ToString(isolate));
228 231
229 v8::Local<v8::Object> result = v8::Object::New(isolate); 232 v8::Local<v8::Object> result = v8::Object::New(isolate);
230 result->Set(v8AtomicString(isolate, "location"), location); 233 result->Set(v8AtomicString(isolate, "location"), location);
231 234
232 v8::Local<v8::String> name = functionDisplayName(function); 235 v8::Local<v8::String> name = functionDisplayName(function);
233 result->Set(v8AtomicString(isolate, "functionName"), name.IsEmpty() ? v8Atom icString(isolate, "") : name); 236 result->Set(v8AtomicString(isolate, "functionName"), name.IsEmpty() ? v8Atom icString(isolate, "") : name);
234 237
235 result->Set(v8AtomicString(isolate, "isGenerator"), v8::Boolean::New(isolate , function->IsGeneratorFunction())); 238 result->Set(v8AtomicString(isolate, "isGenerator"), v8::Boolean::New(isolate , function->IsGeneratorFunction()));
236 239
237 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 240 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
238 V8Debugger& debugger = host->debugger(); 241 V8Debugger& debugger = host->debugger();
239 v8::Local<v8::Value> scopes = debugger.functionScopes(function); 242 v8::Local<v8::Value> scopes = debugger.functionScopes(function);
240 if (!scopes.IsEmpty() && scopes->IsArray()) 243 if (!scopes.IsEmpty() && scopes->IsArray())
241 result->Set(v8AtomicString(isolate, "rawScopes"), scopes); 244 result->Set(v8AtomicString(isolate, "rawScopes"), scopes);
242 245
243 v8SetReturnValue(info, result); 246 v8SetReturnValue(info, result);
244 } 247 }
245 248
246 void V8InjectedScriptHost::generatorObjectDetailsCallback(const v8::FunctionCall backInfo<v8::Value>& info) 249 void V8InjectedScriptHost::generatorObjectDetailsCallback(const v8::FunctionCall backInfo<v8::Value>& info)
247 { 250 {
248 if (info.Length() < 1 || !info[0]->IsObject()) 251 if (info.Length() < 1 || !info[0]->IsObject())
249 return; 252 return;
250 253
251 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 254 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
252 255
253 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 256 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
254 V8Debugger& debugger = host->debugger(); 257 V8Debugger& debugger = host->debugger();
255 v8SetReturnValue(info, debugger.generatorObjectDetails(object)); 258 v8SetReturnValue(info, debugger.generatorObjectDetails(object));
256 } 259 }
257 260
258 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 261 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
259 { 262 {
260 if (info.Length() < 1 || !info[0]->IsObject()) 263 if (info.Length() < 1 || !info[0]->IsObject())
261 return; 264 return;
262 265
263 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 266 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
264 267
265 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 268 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
266 V8Debugger& debugger = host->debugger(); 269 V8Debugger& debugger = host->debugger();
267 v8SetReturnValue(info, debugger.collectionEntries(object)); 270 v8SetReturnValue(info, debugger.collectionEntries(object));
268 } 271 }
269 272
270 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info) 273 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info)
271 { 274 {
272 if (info.Length() < 1 || !info[0]->IsObject()) 275 if (info.Length() < 1 || !info[0]->IsObject())
273 return; 276 return;
274 277
275 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 278 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 313 }
311 314
312 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 315 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
313 { 316 {
314 if (info.Length() < 1) 317 if (info.Length() < 1)
315 return; 318 return;
316 319
317 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0]) ; 320 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0]) ;
318 if (!target) 321 if (!target)
319 return; 322 return;
320 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 323 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
321 Vector<EventListenerInfo> listenersArray; 324 Vector<EventListenerInfo> listenersArray;
322 host->getEventListenersImpl(target, listenersArray); 325 host->getEventListenersImpl(target, listenersArray);
323 326
324 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); 327 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate());
325 for (size_t i = 0; i < listenersArray.size(); ++i) { 328 for (size_t i = 0; i < listenersArray.size(); ++i) {
326 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate( ), target->executionContext(), listenersArray[i]); 329 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate( ), target->executionContext(), listenersArray[i]);
327 if (!listeners->Length()) 330 if (!listeners->Length())
328 continue; 331 continue;
329 AtomicString eventType = listenersArray[i].eventType; 332 AtomicString eventType = listenersArray[i].eventType;
330 result->Set(v8String(info.GetIsolate(), eventType), listeners); 333 result->Set(v8String(info.GetIsolate(), eventType), listeners);
331 } 334 }
332 335
333 v8SetReturnValue(info, result); 336 v8SetReturnValue(info, result);
334 } 337 }
335 338
336 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info) 339 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info)
337 { 340 {
338 if (info.Length() < 2) 341 if (info.Length() < 2)
339 return; 342 return;
340 343
341 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 344 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
342 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); 345 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
343 ScriptValue object(scriptState, info[0]); 346 ScriptValue object(scriptState, info[0]);
344 ScriptValue hints(scriptState, info[1]); 347 ScriptValue hints(scriptState, info[1]);
345 host->inspectImpl(toJSONValue(object), toJSONValue(hints)); 348 host->inspectImpl(toJSONValue(object), toJSONValue(hints));
346 } 349 }
347 350
348 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value >& info) 351 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value >& info)
349 { 352 {
350 v8::Isolate* isolate = info.GetIsolate(); 353 v8::Isolate* isolate = info.GetIsolate();
351 if (info.Length() < 1) { 354 if (info.Length() < 1) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 void V8InjectedScriptHost::setFunctionVariableValueCallback(const v8::FunctionCa llbackInfo<v8::Value>& info) 418 void V8InjectedScriptHost::setFunctionVariableValueCallback(const v8::FunctionCa llbackInfo<v8::Value>& info)
416 { 419 {
417 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString()) 420 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString())
418 return; 421 return;
419 422
420 v8::Local<v8::Value> functionValue = info[0]; 423 v8::Local<v8::Value> functionValue = info[0];
421 int scopeIndex = info[1].As<v8::Int32>()->Value(); 424 int scopeIndex = info[1].As<v8::Int32>()->Value();
422 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]); 425 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]);
423 v8::Local<v8::Value> newValue = info[3]; 426 v8::Local<v8::Value> newValue = info[3];
424 427
425 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 428 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
426 V8Debugger& debugger = host->debugger(); 429 V8Debugger& debugger = host->debugger();
427 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop eIndex, variableName, newValue)); 430 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop eIndex, variableName, newValue));
428 } 431 }
429 432
430 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info, String* scriptId, int* lineNumber, int* columnNumber) 433 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info, String* scriptId, int* lineNumber, int* columnNumber)
431 { 434 {
432 if (info.Length() < 1 || !info[0]->IsFunction()) 435 if (info.Length() < 1 || !info[0]->IsFunction())
433 return false; 436 return false;
434 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); 437 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]);
435 *lineNumber = function->GetScriptLineNumber(); 438 *lineNumber = function->GetScriptLineNumber();
436 *columnNumber = function->GetScriptColumnNumber(); 439 *columnNumber = function->GetScriptColumnNumber();
437 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8: :Function::kLineOffsetNotFound) 440 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8: :Function::kLineOffsetNotFound)
438 return false; 441 return false;
439 *scriptId = String::number(function->ScriptId()); 442 *scriptId = String::number(function->ScriptId());
440 return true; 443 return true;
441 } 444 }
442 445
443 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value>& info) 446 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value>& info)
444 { 447 {
445 String scriptId; 448 String scriptId;
446 int lineNumber; 449 int lineNumber;
447 int columnNumber; 450 int columnNumber;
448 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 451 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
449 return; 452 return;
450 453
451 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 454 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
452 host->debugFunction(scriptId, lineNumber, columnNumber); 455 host->debugFunction(scriptId, lineNumber, columnNumber);
453 } 456 }
454 457
455 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 458 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
456 { 459 {
457 String scriptId; 460 String scriptId;
458 int lineNumber; 461 int lineNumber;
459 int columnNumber; 462 int columnNumber;
460 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 463 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
461 return; 464 return;
462 465
463 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 466 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
464 host->undebugFunction(scriptId, lineNumber, columnNumber); 467 host->undebugFunction(scriptId, lineNumber, columnNumber);
465 } 468 }
466 469
467 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 470 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
468 { 471 {
469 String scriptId; 472 String scriptId;
470 int lineNumber; 473 int lineNumber;
471 int columnNumber; 474 int columnNumber;
472 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 475 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
473 return; 476 return;
474 477
475 v8::Local<v8::Value> name; 478 v8::Local<v8::Value> name;
476 if (info.Length() > 0 && info[0]->IsFunction()) { 479 if (info.Length() > 0 && info[0]->IsFunction()) {
477 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0] ); 480 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0] );
478 name = function->GetName(); 481 name = function->GetName();
479 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) 482 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
480 name = function->GetInferredName(); 483 name = function->GetInferredName();
481 } 484 }
482 485
483 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 486 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
484 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn definedOrNullCheck(name)); 487 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn definedOrNullCheck(name));
485 } 488 }
486 489
487 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 490 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
488 { 491 {
489 String scriptId; 492 String scriptId;
490 int lineNumber; 493 int lineNumber;
491 int columnNumber; 494 int columnNumber;
492 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 495 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
493 return; 496 return;
494 497
495 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 498 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
496 host->unmonitorFunction(scriptId, lineNumber, columnNumber); 499 host->unmonitorFunction(scriptId, lineNumber, columnNumber);
497 } 500 }
498 501
499 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v 8::Value>& info) 502 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v 8::Value>& info)
500 { 503 {
501 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { 504 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) {
502 ASSERT_NOT_REACHED(); 505 ASSERT_NOT_REACHED();
503 return; 506 return;
504 } 507 }
505 508
(...skipping 18 matching lines...) Expand all
524 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer: :New(info.GetIsolate(), i)).ToLocal(&argv[i])) 527 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer: :New(info.GetIsolate(), i)).ToLocal(&argv[i]))
525 return; 528 return;
526 } 529 }
527 530
528 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get()); 531 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get());
529 v8SetReturnValue(info, result); 532 v8SetReturnValue(info, result);
530 } 533 }
531 534
532 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun ctionCallbackInfo<v8::Value>& info) 535 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun ctionCallbackInfo<v8::Value>& info)
533 { 536 {
534 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder()); 537 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder());
535 host->client()->muteWarningsAndDeprecations(); 538 host->client()->muteWarningsAndDeprecations();
536 539
537 callFunctionCallback(info); 540 callFunctionCallback(info);
538 541
539 host->client()->unmuteWarningsAndDeprecations(); 542 host->client()->unmuteWarningsAndDeprecations();
540 } 543 }
541 544
542 void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallback Info<v8::Value>& info) 545 void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallback Info<v8::Value>& info)
543 { 546 {
544 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString()) 547 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 if (!injectedScriptNative) 586 if (!injectedScriptNative)
584 return; 587 return;
585 int id = info[0].As<v8::Int32>()->Value(); 588 int id = info[0].As<v8::Int32>()->Value();
586 String groupName = injectedScriptNative->groupName(id); 589 String groupName = injectedScriptNative->groupName(id);
587 if (!groupName.isEmpty()) 590 if (!groupName.isEmpty())
588 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); 591 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName));
589 } 592 }
590 593
591 namespace { 594 namespace {
592 595
593 struct V8MethodConfiguration { 596 char hiddenPropertyName[] = "v8inspector::InjectedScriptHost";
594 const char* name; 597 char className[] = "V8InjectedScriptHost";
595 v8::FunctionCallback callback; 598 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro pertyName, className>;
596 };
597 599
598 const V8MethodConfiguration V8InjectedScriptHostMethods[] = { 600 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho ds[] = {
599 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} , 601 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} ,
600 {"inspect", V8InjectedScriptHost::inspectCallback}, 602 {"inspect", V8InjectedScriptHost::inspectCallback},
601 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, 603 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback},
602 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback}, 604 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback},
603 {"isDOMWrapper", V8InjectedScriptHost::isDOMWrapperCallback}, 605 {"isDOMWrapper", V8InjectedScriptHost::isDOMWrapperCallback},
604 {"isHTMLAllCollection", V8InjectedScriptHost::isHTMLAllCollectionCallback}, 606 {"isHTMLAllCollection", V8InjectedScriptHost::isHTMLAllCollectionCallback},
605 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, 607 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback},
606 {"subtype", V8InjectedScriptHost::subtypeCallback}, 608 {"subtype", V8InjectedScriptHost::subtypeCallback},
607 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback}, 609 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback},
608 {"generatorObjectDetails", V8InjectedScriptHost::generatorObjectDetailsCallb ack}, 610 {"generatorObjectDetails", V8InjectedScriptHost::generatorObjectDetailsCallb ack},
609 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, 611 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback},
610 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k}, 612 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k},
611 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, 613 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback},
612 {"eval", V8InjectedScriptHost::evalCallback}, 614 {"eval", V8InjectedScriptHost::evalCallback},
613 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException DetailsCallback}, 615 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException DetailsCallback},
614 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, 616 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback},
615 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, 617 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback},
616 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, 618 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback},
617 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, 619 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback},
618 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, 620 {"callFunction", V8InjectedScriptHost::callFunctionCallback},
619 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback}, 621 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback},
620 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, 622 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback},
621 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback}, 623 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback},
622 {"bind", V8InjectedScriptHost::bindCallback}, 624 {"bind", V8InjectedScriptHost::bindCallback},
623 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, 625 {"objectForId", V8InjectedScriptHost::objectForIdCallback},
624 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, 626 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback},
625 }; 627 };
626 628
627 class WeakCallbackData final {
628 public:
629 WeakCallbackData(v8::Isolate* isolate, PassRefPtrWillBeRawPtr<InjectedScript Host> host, v8::Local<v8::Object> wrapper)
630 : m_host(host)
631 , m_persistent(isolate, wrapper)
632 {
633 m_persistent.SetWeak(this, &WeakCallbackData::weakCallback, v8::WeakCall backType::kParameter);
634 }
635
636 // If kept as a strong Persistent<>, this back reference causes an Oilpan le ak by
637 // way of v8. Sidestep by using a raw pointer; InjectedScriptHost is slated to
638 // become a non-Oilpan object.
639 GC_PLUGIN_IGNORE("466631")
640 RefPtrWillBeRawPtr<InjectedScriptHost> m_host;
641
642 private:
643 static void weakCallback(const v8::WeakCallbackInfo<WeakCallbackData>& info)
644 {
645 delete info.GetParameter();
646 }
647
648 v8::Global<v8::Object> m_persistent;
649 };
650
651 } // namespace 629 } // namespace
652 630
653 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate) 631 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate)
654 { 632 {
655 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate); 633 Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH (V8InjectedScriptHostMethods));
656 634 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin());
657 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "InjectedScr iptHost", v8::NewStringType::kInternalized).ToLocalChecked()); 635 Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes;
658 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT emplate(); 636 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes);
659
660 for (auto& config : V8InjectedScriptHostMethods) {
661 v8::Local<v8::Name> v8name = v8::String::NewFromUtf8(isolate, config.nam e, v8::NewStringType::kInternalized).ToLocalChecked();
662 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate: :New(isolate, config.callback);
663 functionTemplate->RemovePrototype();
664 instanceTemplate->Set(v8name, functionTemplate, static_cast<v8::Property Attribute>(v8::DontDelete | v8::DontEnum | v8::ReadOnly));
665 }
666
667 return functionTemplate;
668 } 637 }
669 638
670 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Isolate* isolate, v8::Local <v8::FunctionTemplate> constructorTemplate, PassRefPtrWillBeRawPtr<InjectedScrip tHost> host) 639 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, PassRefPtrWillBeRawPtr<Inj ectedScriptHost> host)
671 { 640 {
672 RefPtrWillBeRawPtr<InjectedScriptHost> impl(host); 641 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host);
673 v8::Local<v8::Function> function;
674 if (!constructorTemplate->GetFunction(isolate->GetCurrentContext()).ToLocal( &function))
675 return v8::Local<v8::Object>();
676
677 // FIXME: don't depend on V8ScriptRunner
678 v8::MaybeLocal<v8::Object> maybeResult = V8ScriptRunner::instantiateObject(i solate, function);
679 v8::Local<v8::Object> result;
680 if (!maybeResult.ToLocal(&result))
681 return v8::Local<v8::Object>();
682
683 v8::Local<v8::External> objectReference = v8::External::New(isolate, new Wea kCallbackData(isolate, impl, result));
684 result->SetHiddenValue(hiddenPropertyName(isolate), objectReference);
685
686 return result;
687 } 642 }
688 643
689 InjectedScriptHost* V8InjectedScriptHost::toImpl(v8::Local<v8::Object> object) 644 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Object> object)
690 { 645 {
691 v8::Isolate* isolate = object->GetIsolate(); 646 return InjectedScriptHostWrapper::unwrap(object);
692 v8::Local<v8::Value> value = object->GetHiddenValue(hiddenPropertyName(isola te));
693 if (value.IsEmpty())
694 return nullptr;
695 if (!value->IsExternal())
696 return nullptr;
697 void* data = value.As<v8::External>()->Value();
698 return reinterpret_cast<WeakCallbackData*>(data)->m_host.get();
699 }
700
701 v8::Local<v8::String> V8InjectedScriptHost::hiddenPropertyName(v8::Isolate* isol ate)
702 {
703 return v8::String::NewFromUtf8(isolate, "v8inspector::InjectedScriptHost", v 8::NewStringType::kInternalized).ToLocalChecked();
704 } 647 }
705 648
706 } // namespace blink 649 } // namespace blink
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/inspector/V8InjectedScriptHost.h ('k') | Source/bindings/core/v8/inspector/V8JavaScriptCallFrame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698