OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 Google Inc. All rights reserved. | 2 * Copyright (c) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "core/inspector/ScriptCallStack.h" | 39 #include "core/inspector/ScriptCallStack.h" |
40 #include "platform/JSONValues.h" | 40 #include "platform/JSONValues.h" |
41 #include "wtf/text/StringBuilder.h" | 41 #include "wtf/text/StringBuilder.h" |
42 | 42 |
43 #include <v8-debug.h> | 43 #include <v8-debug.h> |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 class ExecutionContext; | 47 class ExecutionContext; |
48 | 48 |
49 static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame) | 49 static ScriptCallFrame toScriptCallFrame(v8::Local<v8::StackFrame> frame) |
50 { | 50 { |
51 StringBuilder stringBuilder; | 51 StringBuilder stringBuilder; |
52 stringBuilder.appendNumber(frame->GetScriptId()); | 52 stringBuilder.appendNumber(frame->GetScriptId()); |
53 String scriptId = stringBuilder.toString(); | 53 String scriptId = stringBuilder.toString(); |
54 String sourceName; | 54 String sourceName; |
55 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); | 55 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); |
56 if (!sourceNameValue.IsEmpty()) | 56 if (!sourceNameValue.IsEmpty()) |
57 sourceName = toCoreString(sourceNameValue); | 57 sourceName = toCoreString(sourceNameValue); |
58 | 58 |
59 String functionName; | 59 String functionName; |
60 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 60 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
61 if (!functionNameValue.IsEmpty()) | 61 if (!functionNameValue.IsEmpty()) |
62 functionName = toCoreString(functionNameValue); | 62 functionName = toCoreString(functionNameValue); |
63 | 63 |
64 int sourceLineNumber = frame->GetLineNumber(); | 64 int sourceLineNumber = frame->GetLineNumber(); |
65 int sourceColumn = frame->GetColumn(); | 65 int sourceColumn = frame->GetColumn(); |
66 return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber,
sourceColumn); | 66 return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber,
sourceColumn); |
67 } | 67 } |
68 | 68 |
69 static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vect
or<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAll
owed, v8::Isolate* isolate) | 69 static void toScriptCallFramesVector(v8::Local<v8::StackTrace> stackTrace, Vecto
r<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAllo
wed, v8::Isolate* isolate) |
70 { | 70 { |
71 ASSERT(isolate->InContext()); | 71 ASSERT(isolate->InContext()); |
72 int frameCount = stackTrace->GetFrameCount(); | 72 int frameCount = stackTrace->GetFrameCount(); |
73 if (frameCount > static_cast<int>(maxStackSize)) | 73 if (frameCount > static_cast<int>(maxStackSize)) |
74 frameCount = maxStackSize; | 74 frameCount = maxStackSize; |
75 for (int i = 0; i < frameCount; i++) { | 75 for (int i = 0; i < frameCount; i++) { |
76 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 76 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
77 scriptCallFrames.append(toScriptCallFrame(stackFrame)); | 77 scriptCallFrames.append(toScriptCallFrame(stackFrame)); |
78 } | 78 } |
79 if (!frameCount && !emptyStackIsAllowed) { | 79 if (!frameCount && !emptyStackIsAllowed) { |
80 // Successfully grabbed stack trace, but there are no frames. It may hap
pen in case | 80 // Successfully grabbed stack trace, but there are no frames. It may hap
pen in case |
81 // when a bound function is called from native code for example. | 81 // when a bound function is called from native code for example. |
82 // Fallback to setting lineNumber to 0, and source and function name to
"undefined". | 82 // Fallback to setting lineNumber to 0, and source and function name to
"undefined". |
83 scriptCallFrames.append(ScriptCallFrame()); | 83 scriptCallFrames.append(ScriptCallFrame()); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 static PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(v8::Isolate
* isolate, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize, bool empt
yStackIsAllowed) | 87 static PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(v8::Isolate
* isolate, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, bool empty
StackIsAllowed) |
88 { | 88 { |
89 ASSERT(isolate->InContext()); | 89 ASSERT(isolate->InContext()); |
90 ASSERT(!stackTrace.IsEmpty()); | 90 ASSERT(!stackTrace.IsEmpty()); |
91 v8::HandleScope scope(isolate); | 91 v8::HandleScope scope(isolate); |
92 Vector<ScriptCallFrame> scriptCallFrames; | 92 Vector<ScriptCallFrame> scriptCallFrames; |
93 toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptySt
ackIsAllowed, isolate); | 93 toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptySt
ackIsAllowed, isolate); |
94 RefPtrWillBeRawPtr<ScriptCallStack> callStack = ScriptCallStack::create(scri
ptCallFrames); | 94 RefPtrWillBeRawPtr<ScriptCallStack> callStack = ScriptCallStack::create(scri
ptCallFrames); |
95 if (InspectorInstrumentation::hasFrontends() && maxStackSize > 1) | 95 if (InspectorInstrumentation::hasFrontends() && maxStackSize > 1) |
96 InspectorInstrumentation::appendAsyncCallStack(currentExecutionContext(i
solate), callStack.get()); | 96 InspectorInstrumentation::appendAsyncCallStack(currentExecutionContext(i
solate), callStack.get()); |
97 return callStack.release(); | 97 return callStack.release(); |
98 } | 98 } |
99 | 99 |
100 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(v8::Isolate* isola
te, v8::Handle<v8::StackTrace> stackTrace, size_t maxStackSize) | 100 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(v8::Isolate* isola
te, v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize) |
101 { | 101 { |
102 return createScriptCallStack(isolate, stackTrace, maxStackSize, true); | 102 return createScriptCallStack(isolate, stackTrace, maxStackSize, true); |
103 } | 103 } |
104 | 104 |
105 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSiz
e, bool emptyStackIsAllowed) | 105 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSiz
e, bool emptyStackIsAllowed) |
106 { | 106 { |
107 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 107 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
108 if (!isolate->InContext()) | 108 if (!isolate->InContext()) |
109 return nullptr; | 109 return nullptr; |
110 v8::HandleScope handleScope(isolate); | 110 v8::HandleScope handleScope(isolate); |
111 v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(isol
ate, maxStackSize, stackTraceOptions)); | 111 v8::Local<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(isola
te, maxStackSize, stackTraceOptions)); |
112 return createScriptCallStack(isolate, stackTrace, maxStackSize, emptyStackIs
Allowed); | 112 return createScriptCallStack(isolate, stackTrace, maxStackSize, emptyStackIs
Allowed); |
113 } | 113 } |
114 | 114 |
115 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStackForConsole(size_t m
axStackSize, bool emptyStackIsAllowed) | 115 PassRefPtrWillBeRawPtr<ScriptCallStack> createScriptCallStackForConsole(size_t m
axStackSize, bool emptyStackIsAllowed) |
116 { | 116 { |
117 size_t stackSize = 1; | 117 size_t stackSize = 1; |
118 if (InspectorInstrumentation::hasFrontends()) { | 118 if (InspectorInstrumentation::hasFrontends()) { |
119 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 119 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
120 if (!isolate->InContext()) | 120 if (!isolate->InContext()) |
121 return nullptr; | 121 return nullptr; |
122 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex
t(isolate))) | 122 if (InspectorInstrumentation::consoleAgentEnabled(currentExecutionContex
t(isolate))) |
123 stackSize = maxStackSize; | 123 stackSize = maxStackSize; |
124 } | 124 } |
125 return createScriptCallStack(stackSize, emptyStackIsAllowed); | 125 return createScriptCallStack(stackSize, emptyStackIsAllowed); |
126 } | 126 } |
127 | 127 |
128 PassRefPtrWillBeRawPtr<ScriptArguments> createScriptArguments(ScriptState* scrip
tState, const v8::FunctionCallbackInfo<v8::Value>& v8arguments, unsigned skipArg
umentCount) | 128 PassRefPtrWillBeRawPtr<ScriptArguments> createScriptArguments(ScriptState* scrip
tState, const v8::FunctionCallbackInfo<v8::Value>& v8arguments, unsigned skipArg
umentCount) |
129 { | 129 { |
130 Vector<ScriptValue> arguments; | 130 Vector<ScriptValue> arguments; |
131 for (int i = skipArgumentCount; i < v8arguments.Length(); ++i) | 131 for (int i = skipArgumentCount; i < v8arguments.Length(); ++i) |
132 arguments.append(ScriptValue(scriptState, v8arguments[i])); | 132 arguments.append(ScriptValue(scriptState, v8arguments[i])); |
133 | 133 |
134 return ScriptArguments::create(scriptState, arguments); | 134 return ScriptArguments::create(scriptState, arguments); |
135 } | 135 } |
136 | 136 |
137 } // namespace blink | 137 } // namespace blink |
OLD | NEW |