LCOV - code coverage report
Current view: top level - devtools/platform - nsJSInspector.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 0 54 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 15 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #include "nsJSInspector.h"
       7             : #include "nsIXPConnect.h"
       8             : #include "nsThreadUtils.h"
       9             : #include "jsfriendapi.h"
      10             : #include "mozilla/HoldDropJSObjects.h"
      11             : #include "mozilla/ModuleUtils.h"
      12             : #include "mozilla/dom/ScriptSettings.h"
      13             : #include "nsServiceManagerUtils.h"
      14             : #include "nsMemory.h"
      15             : #include "nsArray.h"
      16             : #include "nsTArray.h"
      17             : 
      18             : #define JSINSPECTOR_CONTRACTID \
      19             :   "@mozilla.org/jsinspector;1"
      20             : 
      21             : #define JSINSPECTOR_CID \
      22             : { 0xec5aa99c, 0x7abb, 0x4142, { 0xac, 0x5f, 0xaa, 0xb2, 0x41, 0x9e, 0x38, 0xe2 } }
      23             : 
      24             : namespace mozilla {
      25             : namespace jsinspector {
      26             : 
      27           0 : NS_GENERIC_FACTORY_CONSTRUCTOR(nsJSInspector)
      28             : 
      29           0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsJSInspector)
      30           0 :   NS_INTERFACE_MAP_ENTRY(nsISupports)
      31           0 :   NS_INTERFACE_MAP_ENTRY(nsIJSInspector)
      32           0 : NS_INTERFACE_MAP_END
      33             : 
      34             : NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSInspector)
      35             : 
      36           0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSInspector)
      37           0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSInspector)
      38             : 
      39           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSInspector)
      40           0 : NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
      41             : 
      42           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSInspector)
      43           0 :   tmp->mRequestors.Clear();
      44           0 :   tmp->mLastRequestor = JS::NullValue();
      45           0 : NS_IMPL_CYCLE_COLLECTION_UNLINK_END
      46             : 
      47           0 : NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsJSInspector)
      48           0 :   for (uint32_t i = 0; i < tmp->mRequestors.Length(); ++i) {
      49           0 :     NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mRequestors[i])
      50             :   }
      51           0 :   NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mLastRequestor)
      52           0 : NS_IMPL_CYCLE_COLLECTION_TRACE_END
      53             : 
      54           0 : nsJSInspector::nsJSInspector() : mNestedLoopLevel(0), mRequestors(1), mLastRequestor(JS::NullValue())
      55             : {
      56           0 : }
      57             : 
      58           0 : nsJSInspector::~nsJSInspector()
      59             : {
      60           0 :   MOZ_ASSERT(mRequestors.Length() == 0);
      61           0 :   MOZ_ASSERT(mLastRequestor.isNull());
      62           0 :   mozilla::DropJSObjects(this);
      63           0 : }
      64             : 
      65             : NS_IMETHODIMP
      66           0 : nsJSInspector::EnterNestedEventLoop(JS::Handle<JS::Value> requestor, uint32_t *out)
      67             : {
      68           0 :   nsresult rv = NS_OK;
      69             : 
      70           0 :   mLastRequestor = requestor;
      71           0 :   mRequestors.AppendElement(requestor);
      72           0 :   mozilla::HoldJSObjects(this);
      73             : 
      74           0 :   mozilla::dom::AutoNoJSAPI nojsapi;
      75             : 
      76           0 :   uint32_t nestLevel = ++mNestedLoopLevel;
      77           0 :   if (!SpinEventLoopUntil([&]() { return mNestedLoopLevel < nestLevel; })) {
      78           0 :     rv = NS_ERROR_UNEXPECTED;
      79             :   }
      80             : 
      81           0 :   NS_ASSERTION(mNestedLoopLevel <= nestLevel,
      82             :                "nested event didn't unwind properly");
      83             : 
      84           0 :   if (mNestedLoopLevel == nestLevel) {
      85           0 :     mLastRequestor = mRequestors.ElementAt(--mNestedLoopLevel);
      86             :   }
      87             : 
      88           0 :   *out = mNestedLoopLevel;
      89           0 :   return rv;
      90             : }
      91             : 
      92             : NS_IMETHODIMP
      93           0 : nsJSInspector::ExitNestedEventLoop(uint32_t *out)
      94             : {
      95           0 :   if (mNestedLoopLevel > 0) {
      96           0 :     mRequestors.RemoveElementAt(--mNestedLoopLevel);
      97           0 :     if (mNestedLoopLevel > 0)
      98           0 :       mLastRequestor = mRequestors.ElementAt(mNestedLoopLevel - 1);
      99             :     else
     100           0 :       mLastRequestor = JS::NullValue();
     101             :   } else {
     102           0 :     return NS_ERROR_FAILURE;
     103             :   }
     104             : 
     105           0 :   *out = mNestedLoopLevel;
     106             : 
     107           0 :   return NS_OK;
     108             : }
     109             : 
     110             : NS_IMETHODIMP
     111           0 : nsJSInspector::GetEventLoopNestLevel(uint32_t *out)
     112             : {
     113           0 :   *out = mNestedLoopLevel;
     114           0 :   return NS_OK;
     115             : }
     116             : 
     117             : NS_IMETHODIMP
     118           0 : nsJSInspector::GetLastNestRequestor(JS::MutableHandle<JS::Value> out)
     119             : {
     120           0 :   out.set(mLastRequestor);
     121           0 :   return NS_OK;
     122             : }
     123             : 
     124             : } // namespace jsinspector
     125             : } // namespace mozilla
     126             : 
     127             : NS_DEFINE_NAMED_CID(JSINSPECTOR_CID);
     128             : 
     129             : static const mozilla::Module::CIDEntry kJSInspectorCIDs[] = {
     130             :   { &kJSINSPECTOR_CID, false, nullptr, mozilla::jsinspector::nsJSInspectorConstructor },
     131             :   { nullptr }
     132             : };
     133             : 
     134             : static const mozilla::Module::ContractIDEntry kJSInspectorContracts[] = {
     135             :   { JSINSPECTOR_CONTRACTID, &kJSINSPECTOR_CID },
     136             :   { nullptr }
     137             : };
     138             : 
     139             : static const mozilla::Module kJSInspectorModule = {
     140             :   mozilla::Module::kVersion,
     141             :   kJSInspectorCIDs,
     142             :   kJSInspectorContracts
     143             : };
     144             : 
     145             : NSMODULE_DEFN(jsinspector) = &kJSInspectorModule;

Generated by: LCOV version 1.13