| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (c) 2008, 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 "bindings/core/v8/ScriptCallStack.h" | |
| 32 | |
| 33 #include "bindings/core/v8/V8PerIsolateData.h" | |
| 34 #include "core/inspector/InspectorInstrumentation.h" | |
| 35 #include "core/inspector/ThreadDebugger.h" | |
| 36 #include "platform/ScriptForbiddenScope.h" | |
| 37 #include "platform/TracedValue.h" | |
| 38 #include "platform/v8_inspector/public/V8Debugger.h" | |
| 39 #include "platform/v8_inspector/public/V8StackTrace.h" | |
| 40 | |
| 41 namespace blink { | |
| 42 | |
| 43 PassRefPtr<ScriptCallStack> ScriptCallStack::capture(size_t maxStackSize) | |
| 44 { | |
| 45 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 46 if (!isolate->InContext()) | |
| 47 return nullptr; | |
| 48 V8PerIsolateData* data = V8PerIsolateData::from(isolate); | |
| 49 if (!data->threadDebugger()) | |
| 50 return nullptr; | |
| 51 ScriptForbiddenScope::AllowUserAgentScript allowScripting; | |
| 52 std::unique_ptr<V8StackTrace> stack = data->threadDebugger()->debugger()->ca
ptureStackTrace(maxStackSize); | |
| 53 return stack ? adoptRef(new ScriptCallStack(std::move(stack))) : nullptr; | |
| 54 } | |
| 55 | |
| 56 PassRefPtr<ScriptCallStack> ScriptCallStack::captureForConsole() | |
| 57 { | |
| 58 size_t stackSize = 1; | |
| 59 if (InspectorInstrumentation::hasFrontends()) { | |
| 60 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | |
| 61 if (!isolate->InContext()) | |
| 62 return nullptr; | |
| 63 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex
t(isolate))) | |
| 64 stackSize = V8StackTrace::maxCallStackSizeToCapture; | |
| 65 } | |
| 66 return ScriptCallStack::capture(stackSize); | |
| 67 } | |
| 68 | |
| 69 ScriptCallStack::ScriptCallStack(std::unique_ptr<V8StackTrace> stackTrace) | |
| 70 : m_stackTrace(std::move(stackTrace)) | |
| 71 { | |
| 72 } | |
| 73 | |
| 74 ScriptCallStack::~ScriptCallStack() | |
| 75 { | |
| 76 } | |
| 77 | |
| 78 bool ScriptCallStack::isEmpty() const | |
| 79 { | |
| 80 return m_stackTrace->isEmpty(); | |
| 81 } | |
| 82 | |
| 83 String ScriptCallStack::topSourceURL() const | |
| 84 { | |
| 85 return m_stackTrace->topSourceURL(); | |
| 86 } | |
| 87 | |
| 88 unsigned ScriptCallStack::topLineNumber() const | |
| 89 { | |
| 90 return m_stackTrace->topLineNumber(); | |
| 91 } | |
| 92 | |
| 93 unsigned ScriptCallStack::topColumnNumber() const | |
| 94 { | |
| 95 return m_stackTrace->topColumnNumber(); | |
| 96 } | |
| 97 | |
| 98 std::unique_ptr<protocol::Runtime::StackTrace> ScriptCallStack::buildInspectorOb
ject() const | |
| 99 { | |
| 100 return m_stackTrace->buildInspectorObject(); | |
| 101 } | |
| 102 | |
| 103 void ScriptCallStack::toTracedValue(TracedValue* value, const char* name) const | |
| 104 { | |
| 105 if (m_stackTrace->isEmpty()) | |
| 106 return; | |
| 107 value->beginArray(name); | |
| 108 value->beginDictionary(); | |
| 109 value->setString("functionName", m_stackTrace->topFunctionName()); | |
| 110 value->setString("scriptId", m_stackTrace->topScriptId()); | |
| 111 value->setString("url", m_stackTrace->topSourceURL()); | |
| 112 value->setInteger("lineNumber", m_stackTrace->topLineNumber()); | |
| 113 value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); | |
| 114 value->endDictionary(); | |
| 115 value->endArray(); | |
| 116 } | |
| 117 | |
| 118 String ScriptCallStack::toString() const | |
| 119 { | |
| 120 return m_stackTrace->toString(); | |
| 121 } | |
| 122 | |
| 123 std::unique_ptr<V8StackTrace> ScriptCallStack::copyStackTrace() const | |
| 124 { | |
| 125 return m_stackTrace ? m_stackTrace->clone() : nullptr; | |
| 126 } | |
| 127 | |
| 128 } // namespace blink | |
| OLD | NEW |