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

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

Issue 1168003002: Revert "Oilpan: fix build after r196583." (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"
24 #include "core/events/EventTarget.h" 23 #include "core/events/EventTarget.h"
25 #include "core/inspector/EventListenerInfo.h" 24 #include "core/inspector/EventListenerInfo.h"
26 #include "core/inspector/InjectedScript.h" 25 #include "core/inspector/InjectedScript.h"
27 #include "core/inspector/InjectedScriptHost.h" 26 #include "core/inspector/InjectedScriptHost.h"
28 #include "core/inspector/JavaScriptCallFrame.h" 27 #include "core/inspector/JavaScriptCallFrame.h"
29 #include "platform/JSONValues.h" 28 #include "platform/JSONValues.h"
30 #include "wtf/RefPtr.h" 29 #include "wtf/RefPtr.h"
31 #include "wtf/StdLibExtras.h"
32 #include <algorithm>
33 30
34 namespace blink { 31 namespace blink {
35 32
36 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu e value) 33 Node* InjectedScriptHost::scriptValueAsNode(ScriptState* scriptState, ScriptValu e value)
37 { 34 {
38 ScriptState::Scope scope(scriptState); 35 ScriptState::Scope scope(scriptState);
39 if (!value.isObject() || value.isNull()) 36 if (!value.isObject() || value.isNull())
40 return 0; 37 return 0;
41 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value())); 38 return V8Node::toImpl(v8::Local<v8::Object>::Cast(value.v8Value()));
42 } 39 }
(...skipping 22 matching lines...) Expand all
65 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta te, ScriptValue value) 62 EventTarget* InjectedScriptHost::scriptValueAsEventTarget(ScriptState* scriptSta te, ScriptValue value)
66 { 63 {
67 ScriptState::Scope scope(scriptState); 64 ScriptState::Scope scope(scriptState);
68 if (value.isNull() || !value.isObject()) 65 if (value.isNull() || !value.isObject())
69 return nullptr; 66 return nullptr;
70 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value()); 67 return eventTargetFromScriptValue(scriptState->isolate(), value.v8Value());
71 } 68 }
72 69
73 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba ckInfo<v8::Value>& info) 70 void V8InjectedScriptHost::clearConsoleMessagesCallback(const v8::FunctionCallba ckInfo<v8::Value>& info)
74 { 71 {
75 InjectedScriptHost* impl = V8InjectedScriptHost::unwrap(info.Holder()); 72 InjectedScriptHost* impl = V8InjectedScriptHost::toImpl(info.Holder());
76 impl->clearConsoleMessages(); 73 impl->clearConsoleMessages();
77 } 74 }
78 75
79 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 76 void V8InjectedScriptHost::inspectedObjectCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
80 { 77 {
81 if (info.Length() < 1) 78 if (info.Length() < 1)
82 return; 79 return;
83 80
84 if (!info[0]->IsInt32()) { 81 if (!info[0]->IsInt32()) {
85 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be an integer"); 82 V8ThrowException::throwTypeError(info.GetIsolate(), "argument has to be an integer");
86 return; 83 return;
87 } 84 }
88 85
89 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 86 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
90 InjectedScriptHost::InspectableObject* object = host->inspectedObject(info[0 ].As<v8::Int32>()->Value()); 87 InjectedScriptHost::InspectableObject* object = host->inspectedObject(info[0 ].As<v8::Int32>()->Value());
91 v8SetReturnValue(info, object->get(ScriptState::current(info.GetIsolate())). v8Value()); 88 v8SetReturnValue(info, object->get(ScriptState::current(info.GetIsolate())). v8Value());
92 } 89 }
93 90
94 static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> functio n) 91 static v8::Local<v8::String> functionDisplayName(v8::Local<v8::Function> functio n)
95 { 92 {
96 v8::Local<v8::Value> value = function->GetDisplayName(); 93 v8::Local<v8::Value> value = function->GetDisplayName();
97 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length()) 94 if (value->IsString() && v8::Local<v8::String>::Cast(value)->Length())
98 return v8::Local<v8::String>::Cast(value); 95 return v8::Local<v8::String>::Cast(value);
99 96
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 location->Set(v8AtomicString(isolate, "scriptId"), v8::Integer::New(isolate, function->ScriptId())->ToString(isolate)); 227 location->Set(v8AtomicString(isolate, "scriptId"), v8::Integer::New(isolate, function->ScriptId())->ToString(isolate));
231 228
232 v8::Local<v8::Object> result = v8::Object::New(isolate); 229 v8::Local<v8::Object> result = v8::Object::New(isolate);
233 result->Set(v8AtomicString(isolate, "location"), location); 230 result->Set(v8AtomicString(isolate, "location"), location);
234 231
235 v8::Local<v8::String> name = functionDisplayName(function); 232 v8::Local<v8::String> name = functionDisplayName(function);
236 result->Set(v8AtomicString(isolate, "functionName"), name.IsEmpty() ? v8Atom icString(isolate, "") : name); 233 result->Set(v8AtomicString(isolate, "functionName"), name.IsEmpty() ? v8Atom icString(isolate, "") : name);
237 234
238 result->Set(v8AtomicString(isolate, "isGenerator"), v8::Boolean::New(isolate , function->IsGeneratorFunction())); 235 result->Set(v8AtomicString(isolate, "isGenerator"), v8::Boolean::New(isolate , function->IsGeneratorFunction()));
239 236
240 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 237 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
241 V8Debugger& debugger = host->debugger(); 238 V8Debugger& debugger = host->debugger();
242 v8::Local<v8::Value> scopes = debugger.functionScopes(function); 239 v8::Local<v8::Value> scopes = debugger.functionScopes(function);
243 if (!scopes.IsEmpty() && scopes->IsArray()) 240 if (!scopes.IsEmpty() && scopes->IsArray())
244 result->Set(v8AtomicString(isolate, "rawScopes"), scopes); 241 result->Set(v8AtomicString(isolate, "rawScopes"), scopes);
245 242
246 v8SetReturnValue(info, result); 243 v8SetReturnValue(info, result);
247 } 244 }
248 245
249 void V8InjectedScriptHost::generatorObjectDetailsCallback(const v8::FunctionCall backInfo<v8::Value>& info) 246 void V8InjectedScriptHost::generatorObjectDetailsCallback(const v8::FunctionCall backInfo<v8::Value>& info)
250 { 247 {
251 if (info.Length() < 1 || !info[0]->IsObject()) 248 if (info.Length() < 1 || !info[0]->IsObject())
252 return; 249 return;
253 250
254 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 251 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
255 252
256 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 253 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
257 V8Debugger& debugger = host->debugger(); 254 V8Debugger& debugger = host->debugger();
258 v8SetReturnValue(info, debugger.generatorObjectDetails(object)); 255 v8SetReturnValue(info, debugger.generatorObjectDetails(object));
259 } 256 }
260 257
261 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 258 void V8InjectedScriptHost::collectionEntriesCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
262 { 259 {
263 if (info.Length() < 1 || !info[0]->IsObject()) 260 if (info.Length() < 1 || !info[0]->IsObject())
264 return; 261 return;
265 262
266 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 263 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
267 264
268 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 265 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
269 V8Debugger& debugger = host->debugger(); 266 V8Debugger& debugger = host->debugger();
270 v8SetReturnValue(info, debugger.collectionEntries(object)); 267 v8SetReturnValue(info, debugger.collectionEntries(object));
271 } 268 }
272 269
273 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info) 270 void V8InjectedScriptHost::getInternalPropertiesCallback(const v8::FunctionCallb ackInfo<v8::Value>& info)
274 { 271 {
275 if (info.Length() < 1 || !info[0]->IsObject()) 272 if (info.Length() < 1 || !info[0]->IsObject())
276 return; 273 return;
277 274
278 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]); 275 v8::Local<v8::Object> object = v8::Local<v8::Object>::Cast(info[0]);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 } 310 }
314 311
315 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 312 void V8InjectedScriptHost::getEventListenersCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
316 { 313 {
317 if (info.Length() < 1) 314 if (info.Length() < 1)
318 return; 315 return;
319 316
320 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0]) ; 317 EventTarget* target = eventTargetFromScriptValue(info.GetIsolate(), info[0]) ;
321 if (!target) 318 if (!target)
322 return; 319 return;
323 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 320 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
324 Vector<EventListenerInfo> listenersArray; 321 Vector<EventListenerInfo> listenersArray;
325 host->getEventListenersImpl(target, listenersArray); 322 host->getEventListenersImpl(target, listenersArray);
326 323
327 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate()); 324 v8::Local<v8::Object> result = v8::Object::New(info.GetIsolate());
328 for (size_t i = 0; i < listenersArray.size(); ++i) { 325 for (size_t i = 0; i < listenersArray.size(); ++i) {
329 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate( ), target->executionContext(), listenersArray[i]); 326 v8::Local<v8::Array> listeners = getJSListenerFunctions(info.GetIsolate( ), target->executionContext(), listenersArray[i]);
330 if (!listeners->Length()) 327 if (!listeners->Length())
331 continue; 328 continue;
332 AtomicString eventType = listenersArray[i].eventType; 329 AtomicString eventType = listenersArray[i].eventType;
333 result->Set(v8String(info.GetIsolate(), eventType), listeners); 330 result->Set(v8String(info.GetIsolate(), eventType), listeners);
334 } 331 }
335 332
336 v8SetReturnValue(info, result); 333 v8SetReturnValue(info, result);
337 } 334 }
338 335
339 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info) 336 void V8InjectedScriptHost::inspectCallback(const v8::FunctionCallbackInfo<v8::Va lue>& info)
340 { 337 {
341 if (info.Length() < 2) 338 if (info.Length() < 2)
342 return; 339 return;
343 340
344 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 341 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
345 ScriptState* scriptState = ScriptState::current(info.GetIsolate()); 342 ScriptState* scriptState = ScriptState::current(info.GetIsolate());
346 ScriptValue object(scriptState, info[0]); 343 ScriptValue object(scriptState, info[0]);
347 ScriptValue hints(scriptState, info[1]); 344 ScriptValue hints(scriptState, info[1]);
348 host->inspectImpl(toJSONValue(object), toJSONValue(hints)); 345 host->inspectImpl(toJSONValue(object), toJSONValue(hints));
349 } 346 }
350 347
351 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value >& info) 348 void V8InjectedScriptHost::evalCallback(const v8::FunctionCallbackInfo<v8::Value >& info)
352 { 349 {
353 v8::Isolate* isolate = info.GetIsolate(); 350 v8::Isolate* isolate = info.GetIsolate();
354 if (info.Length() < 1) { 351 if (info.Length() < 1) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 void V8InjectedScriptHost::setFunctionVariableValueCallback(const v8::FunctionCa llbackInfo<v8::Value>& info) 415 void V8InjectedScriptHost::setFunctionVariableValueCallback(const v8::FunctionCa llbackInfo<v8::Value>& info)
419 { 416 {
420 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString()) 417 if (info.Length() < 4 || !info[0]->IsFunction() || !info[1]->IsInt32() || !i nfo[2]->IsString())
421 return; 418 return;
422 419
423 v8::Local<v8::Value> functionValue = info[0]; 420 v8::Local<v8::Value> functionValue = info[0];
424 int scopeIndex = info[1].As<v8::Int32>()->Value(); 421 int scopeIndex = info[1].As<v8::Int32>()->Value();
425 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]); 422 String variableName = toCoreStringWithUndefinedOrNullCheck(info[2]);
426 v8::Local<v8::Value> newValue = info[3]; 423 v8::Local<v8::Value> newValue = info[3];
427 424
428 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 425 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
429 V8Debugger& debugger = host->debugger(); 426 V8Debugger& debugger = host->debugger();
430 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop eIndex, variableName, newValue)); 427 v8SetReturnValue(info, debugger.setFunctionVariableValue(functionValue, scop eIndex, variableName, newValue));
431 } 428 }
432 429
433 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info, String* scriptId, int* lineNumber, int* columnNumber) 430 static bool getFunctionLocation(const v8::FunctionCallbackInfo<v8::Value>& info, String* scriptId, int* lineNumber, int* columnNumber)
434 { 431 {
435 if (info.Length() < 1 || !info[0]->IsFunction()) 432 if (info.Length() < 1 || !info[0]->IsFunction())
436 return false; 433 return false;
437 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]); 434 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0]);
438 *lineNumber = function->GetScriptLineNumber(); 435 *lineNumber = function->GetScriptLineNumber();
439 *columnNumber = function->GetScriptColumnNumber(); 436 *columnNumber = function->GetScriptColumnNumber();
440 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8: :Function::kLineOffsetNotFound) 437 if (*lineNumber == v8::Function::kLineOffsetNotFound || *columnNumber == v8: :Function::kLineOffsetNotFound)
441 return false; 438 return false;
442 *scriptId = String::number(function->ScriptId()); 439 *scriptId = String::number(function->ScriptId());
443 return true; 440 return true;
444 } 441 }
445 442
446 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value>& info) 443 void V8InjectedScriptHost::debugFunctionCallback(const v8::FunctionCallbackInfo< v8::Value>& info)
447 { 444 {
448 String scriptId; 445 String scriptId;
449 int lineNumber; 446 int lineNumber;
450 int columnNumber; 447 int columnNumber;
451 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 448 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
452 return; 449 return;
453 450
454 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 451 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
455 host->debugFunction(scriptId, lineNumber, columnNumber); 452 host->debugFunction(scriptId, lineNumber, columnNumber);
456 } 453 }
457 454
458 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 455 void V8InjectedScriptHost::undebugFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
459 { 456 {
460 String scriptId; 457 String scriptId;
461 int lineNumber; 458 int lineNumber;
462 int columnNumber; 459 int columnNumber;
463 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 460 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
464 return; 461 return;
465 462
466 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 463 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
467 host->undebugFunction(scriptId, lineNumber, columnNumber); 464 host->undebugFunction(scriptId, lineNumber, columnNumber);
468 } 465 }
469 466
470 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info) 467 void V8InjectedScriptHost::monitorFunctionCallback(const v8::FunctionCallbackInf o<v8::Value>& info)
471 { 468 {
472 String scriptId; 469 String scriptId;
473 int lineNumber; 470 int lineNumber;
474 int columnNumber; 471 int columnNumber;
475 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 472 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
476 return; 473 return;
477 474
478 v8::Local<v8::Value> name; 475 v8::Local<v8::Value> name;
479 if (info.Length() > 0 && info[0]->IsFunction()) { 476 if (info.Length() > 0 && info[0]->IsFunction()) {
480 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0] ); 477 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(info[0] );
481 name = function->GetName(); 478 name = function->GetName();
482 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length()) 479 if (!name->IsString() || !v8::Local<v8::String>::Cast(name)->Length())
483 name = function->GetInferredName(); 480 name = function->GetInferredName();
484 } 481 }
485 482
486 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 483 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
487 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn definedOrNullCheck(name)); 484 host->monitorFunction(scriptId, lineNumber, columnNumber, toCoreStringWithUn definedOrNullCheck(name));
488 } 485 }
489 486
490 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI nfo<v8::Value>& info) 487 void V8InjectedScriptHost::unmonitorFunctionCallback(const v8::FunctionCallbackI nfo<v8::Value>& info)
491 { 488 {
492 String scriptId; 489 String scriptId;
493 int lineNumber; 490 int lineNumber;
494 int columnNumber; 491 int columnNumber;
495 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber)) 492 if (!getFunctionLocation(info, &scriptId, &lineNumber, &columnNumber))
496 return; 493 return;
497 494
498 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 495 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
499 host->unmonitorFunction(scriptId, lineNumber, columnNumber); 496 host->unmonitorFunction(scriptId, lineNumber, columnNumber);
500 } 497 }
501 498
502 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v 8::Value>& info) 499 void V8InjectedScriptHost::callFunctionCallback(const v8::FunctionCallbackInfo<v 8::Value>& info)
503 { 500 {
504 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) { 501 if (info.Length() < 2 || info.Length() > 3 || !info[0]->IsFunction()) {
505 ASSERT_NOT_REACHED(); 502 ASSERT_NOT_REACHED();
506 return; 503 return;
507 } 504 }
508 505
(...skipping 18 matching lines...) Expand all
527 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer: :New(info.GetIsolate(), i)).ToLocal(&argv[i])) 524 if (!arguments->Get(info.GetIsolate()->GetCurrentContext(), v8::Integer: :New(info.GetIsolate(), i)).ToLocal(&argv[i]))
528 return; 525 return;
529 } 526 }
530 527
531 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get()); 528 v8::Local<v8::Value> result = function->Call(receiver, argc, argv.get());
532 v8SetReturnValue(info, result); 529 v8SetReturnValue(info, result);
533 } 530 }
534 531
535 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun ctionCallbackInfo<v8::Value>& info) 532 void V8InjectedScriptHost::suppressWarningsAndCallFunctionCallback(const v8::Fun ctionCallbackInfo<v8::Value>& info)
536 { 533 {
537 InjectedScriptHost* host = V8InjectedScriptHost::unwrap(info.Holder()); 534 InjectedScriptHost* host = V8InjectedScriptHost::toImpl(info.Holder());
538 host->client()->muteWarningsAndDeprecations(); 535 host->client()->muteWarningsAndDeprecations();
539 536
540 callFunctionCallback(info); 537 callFunctionCallback(info);
541 538
542 host->client()->unmuteWarningsAndDeprecations(); 539 host->client()->unmuteWarningsAndDeprecations();
543 } 540 }
544 541
545 void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallback Info<v8::Value>& info) 542 void V8InjectedScriptHost::setNonEnumPropertyCallback(const v8::FunctionCallback Info<v8::Value>& info)
546 { 543 {
547 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString()) 544 if (info.Length() < 3 || !info[0]->IsObject() || !info[1]->IsString())
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 if (!injectedScriptNative) 583 if (!injectedScriptNative)
587 return; 584 return;
588 int id = info[0].As<v8::Int32>()->Value(); 585 int id = info[0].As<v8::Int32>()->Value();
589 String groupName = injectedScriptNative->groupName(id); 586 String groupName = injectedScriptNative->groupName(id);
590 if (!groupName.isEmpty()) 587 if (!groupName.isEmpty())
591 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName)); 588 info.GetReturnValue().Set(v8String(info.GetIsolate(), groupName));
592 } 589 }
593 590
594 namespace { 591 namespace {
595 592
596 char hiddenPropertyName[] = "v8inspector::InjectedScriptHost"; 593 struct V8MethodConfiguration {
597 char className[] = "V8InjectedScriptHost"; 594 const char* name;
598 using InjectedScriptHostWrapper = InspectorWrapper<InjectedScriptHost, hiddenPro pertyName, className>; 595 v8::FunctionCallback callback;
596 };
599 597
600 const InjectedScriptHostWrapper::V8MethodConfiguration V8InjectedScriptHostMetho ds[] = { 598 const V8MethodConfiguration V8InjectedScriptHostMethods[] = {
601 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} , 599 {"clearConsoleMessages", V8InjectedScriptHost::clearConsoleMessagesCallback} ,
602 {"inspect", V8InjectedScriptHost::inspectCallback}, 600 {"inspect", V8InjectedScriptHost::inspectCallback},
603 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback}, 601 {"inspectedObject", V8InjectedScriptHost::inspectedObjectCallback},
604 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback}, 602 {"internalConstructorName", V8InjectedScriptHost::internalConstructorNameCal lback},
605 {"isDOMWrapper", V8InjectedScriptHost::isDOMWrapperCallback}, 603 {"isDOMWrapper", V8InjectedScriptHost::isDOMWrapperCallback},
606 {"isHTMLAllCollection", V8InjectedScriptHost::isHTMLAllCollectionCallback}, 604 {"isHTMLAllCollection", V8InjectedScriptHost::isHTMLAllCollectionCallback},
607 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback}, 605 {"isTypedArray", V8InjectedScriptHost::isTypedArrayCallback},
608 {"subtype", V8InjectedScriptHost::subtypeCallback}, 606 {"subtype", V8InjectedScriptHost::subtypeCallback},
609 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback}, 607 {"functionDetails", V8InjectedScriptHost::functionDetailsCallback},
610 {"generatorObjectDetails", V8InjectedScriptHost::generatorObjectDetailsCallb ack}, 608 {"generatorObjectDetails", V8InjectedScriptHost::generatorObjectDetailsCallb ack},
611 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback}, 609 {"collectionEntries", V8InjectedScriptHost::collectionEntriesCallback},
612 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k}, 610 {"getInternalProperties", V8InjectedScriptHost::getInternalPropertiesCallbac k},
613 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback}, 611 {"getEventListeners", V8InjectedScriptHost::getEventListenersCallback},
614 {"eval", V8InjectedScriptHost::evalCallback}, 612 {"eval", V8InjectedScriptHost::evalCallback},
615 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException DetailsCallback}, 613 {"evaluateWithExceptionDetails", V8InjectedScriptHost::evaluateWithException DetailsCallback},
616 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback}, 614 {"debugFunction", V8InjectedScriptHost::debugFunctionCallback},
617 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback}, 615 {"undebugFunction", V8InjectedScriptHost::undebugFunctionCallback},
618 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback}, 616 {"monitorFunction", V8InjectedScriptHost::monitorFunctionCallback},
619 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback}, 617 {"unmonitorFunction", V8InjectedScriptHost::unmonitorFunctionCallback},
620 {"callFunction", V8InjectedScriptHost::callFunctionCallback}, 618 {"callFunction", V8InjectedScriptHost::callFunctionCallback},
621 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback}, 619 {"suppressWarningsAndCallFunction", V8InjectedScriptHost::suppressWarningsAn dCallFunctionCallback},
622 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback}, 620 {"setNonEnumProperty", V8InjectedScriptHost::setNonEnumPropertyCallback},
623 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback}, 621 {"setFunctionVariableValue", V8InjectedScriptHost::setFunctionVariableValueC allback},
624 {"bind", V8InjectedScriptHost::bindCallback}, 622 {"bind", V8InjectedScriptHost::bindCallback},
625 {"objectForId", V8InjectedScriptHost::objectForIdCallback}, 623 {"objectForId", V8InjectedScriptHost::objectForIdCallback},
626 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback}, 624 {"idToObjectGroupName", V8InjectedScriptHost::idToObjectGroupNameCallback},
627 }; 625 };
628 626
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
629 } // namespace 651 } // namespace
630 652
631 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate) 653 v8::Local<v8::FunctionTemplate> V8InjectedScriptHost::createWrapperTemplate(v8:: Isolate* isolate)
632 { 654 {
633 Vector<InspectorWrapperBase::V8MethodConfiguration> methods(WTF_ARRAY_LENGTH (V8InjectedScriptHostMethods)); 655 v8::Local<v8::FunctionTemplate> functionTemplate = v8::FunctionTemplate::New (isolate);
634 std::copy(V8InjectedScriptHostMethods, V8InjectedScriptHostMethods + WTF_ARR AY_LENGTH(V8InjectedScriptHostMethods), methods.begin()); 656
635 Vector<InspectorWrapperBase::V8AttributeConfiguration> attributes; 657 functionTemplate->SetClassName(v8::String::NewFromUtf8(isolate, "InjectedScr iptHost", v8::NewStringType::kInternalized).ToLocalChecked());
636 return InjectedScriptHostWrapper::createWrapperTemplate(isolate, methods, at tributes); 658 v8::Local<v8::ObjectTemplate> instanceTemplate = functionTemplate->InstanceT emplate();
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;
637 } 668 }
638 669
639 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context, PassRefPtrWillBeRawPtr<Inj ectedScriptHost> host) 670 v8::Local<v8::Object> V8InjectedScriptHost::wrap(v8::Isolate* isolate, v8::Local <v8::FunctionTemplate> constructorTemplate, PassRefPtrWillBeRawPtr<InjectedScrip tHost> host)
640 { 671 {
641 return InjectedScriptHostWrapper::wrap(constructorTemplate, context, host); 672 RefPtrWillBeRawPtr<InjectedScriptHost> impl(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;
642 } 687 }
643 688
644 InjectedScriptHost* V8InjectedScriptHost::unwrap(v8::Local<v8::Object> object) 689 InjectedScriptHost* V8InjectedScriptHost::toImpl(v8::Local<v8::Object> object)
645 { 690 {
646 return InjectedScriptHostWrapper::unwrap(object); 691 v8::Isolate* isolate = object->GetIsolate();
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();
647 } 704 }
648 705
649 } // namespace blink 706 } // 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