LCOV - code coverage report
Current view: top level - src/inspector - v8-function-call.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 36 40 90.0 %
Date: 2017-10-20 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 2009 Google Inc. All rights reserved.
       3             :  *
       4             :  * Redistribution and use in source and binary forms, with or without
       5             :  * modification, are permitted provided that the following conditions are
       6             :  * met:
       7             :  *
       8             :  *     * Redistributions of source code must retain the above copyright
       9             :  * notice, this list of conditions and the following disclaimer.
      10             :  *     * Redistributions in binary form must reproduce the above
      11             :  * copyright notice, this list of conditions and the following disclaimer
      12             :  * in the documentation and/or other materials provided with the
      13             :  * distribution.
      14             :  *     * Neither the name of Google Inc. nor the names of its
      15             :  * contributors may be used to endorse or promote products derived from
      16             :  * this software without specific prior written permission.
      17             :  *
      18             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
      19             :  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
      20             :  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
      21             :  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
      22             :  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      23             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
      24             :  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      25             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      26             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      27             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
      28             :  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      29             :  */
      30             : 
      31             : #include "src/inspector/v8-function-call.h"
      32             : 
      33             : #include "src/inspector/inspected-context.h"
      34             : #include "src/inspector/string-util.h"
      35             : #include "src/inspector/v8-debugger.h"
      36             : #include "src/inspector/v8-inspector-impl.h"
      37             : 
      38             : #include "include/v8-inspector.h"
      39             : 
      40             : namespace v8_inspector {
      41             : 
      42      550348 : V8FunctionCall::V8FunctionCall(V8InspectorImpl* inspector,
      43             :                                v8::Local<v8::Context> context,
      44             :                                v8::Local<v8::Value> value, const String16& name)
      45             :     : m_inspector(inspector),
      46             :       m_context(context),
      47      550348 :       m_name(toV8String(context->GetIsolate(), name)),
      48     1100696 :       m_value(value) {}
      49             : 
      50      550008 : void V8FunctionCall::appendArgument(v8::Local<v8::Value> value) {
      51      550008 :   m_arguments.push_back(value);
      52      550008 : }
      53             : 
      54      549898 : void V8FunctionCall::appendArgument(const String16& argument) {
      55     1649694 :   m_arguments.push_back(toV8String(m_context->GetIsolate(), argument));
      56      549898 : }
      57             : 
      58           0 : void V8FunctionCall::appendArgument(int argument) {
      59           0 :   m_arguments.push_back(v8::Number::New(m_context->GetIsolate(), argument));
      60           0 : }
      61             : 
      62     1167337 : void V8FunctionCall::appendArgument(bool argument) {
      63       68166 :   m_arguments.push_back(argument ? v8::True(m_context->GetIsolate())
      64     4601182 :                                  : v8::False(m_context->GetIsolate()));
      65     1167337 : }
      66             : 
      67      483252 : v8::Local<v8::Value> V8FunctionCall::call(bool& hadException,
      68             :                                           bool reportExceptions) {
      69      483252 :   v8::TryCatch tryCatch(m_context->GetIsolate());
      70      483252 :   tryCatch.SetVerbose(reportExceptions);
      71             : 
      72      483252 :   v8::Local<v8::Value> result = callWithoutExceptionHandling();
      73      483252 :   hadException = tryCatch.HasCaught();
      74      483252 :   return result;
      75             : }
      76             : 
      77      550348 : v8::Local<v8::Value> V8FunctionCall::callWithoutExceptionHandling() {
      78             :   v8::Context::Scope contextScope(m_context);
      79             : 
      80             :   v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value);
      81             :   v8::Local<v8::Value> value;
      82     1100696 :   if (!thisObject->Get(m_context, m_name).ToLocal(&value))
      83           0 :     return v8::Local<v8::Value>();
      84             : 
      85             :   DCHECK(value->IsFunction());
      86             : 
      87             :   v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value);
      88             :   std::unique_ptr<v8::Local<v8::Value>[]> info(
      89     6735878 :       new v8::Local<v8::Value>[m_arguments.size()]);
      90     5084834 :   for (size_t i = 0; i < m_arguments.size(); ++i) {
      91     2267243 :     info[i] = m_arguments[i];
      92             :     DCHECK(!info[i].IsEmpty());
      93             :   }
      94             : 
      95     1651044 :   int contextGroupId = m_inspector->contextGroupId(m_context);
      96      550348 :   if (contextGroupId) {
      97     1100696 :     m_inspector->client()->muteMetrics(contextGroupId);
      98      550348 :     m_inspector->muteExceptions(contextGroupId);
      99             :   }
     100             :   v8::MicrotasksScope microtasksScope(m_context->GetIsolate(),
     101     1100696 :                                       v8::MicrotasksScope::kDoNotRunMicrotasks);
     102      550348 :   v8::Isolate::AllowJavascriptExecutionScope(m_context->GetIsolate());
     103             :   v8::MaybeLocal<v8::Value> maybeResult = function->Call(
     104     1100696 :       m_context, thisObject, static_cast<int>(m_arguments.size()), info.get());
     105      550348 :   if (contextGroupId) {
     106     1100696 :     m_inspector->client()->unmuteMetrics(contextGroupId);
     107      550348 :     m_inspector->unmuteExceptions(contextGroupId);
     108             :   }
     109             : 
     110             :   v8::Local<v8::Value> result;
     111      550348 :   if (!maybeResult.ToLocal(&result)) return v8::Local<v8::Value>();
     112      550250 :   return result;
     113             : }
     114             : 
     115             : }  // namespace v8_inspector

Generated by: LCOV version 1.10