| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "bindings/v8/ScriptScope.h" | 34 #include "bindings/v8/ScriptScope.h" |
| 35 #include "bindings/v8/ScriptValue.h" | 35 #include "bindings/v8/ScriptValue.h" |
| 36 #include "bindings/v8/V8Binding.h" | 36 #include "bindings/v8/V8Binding.h" |
| 37 #include "bindings/v8/V8Utilities.h" | 37 #include "bindings/v8/V8Utilities.h" |
| 38 #include "core/inspector/InspectorInstrumentation.h" | 38 #include "core/inspector/InspectorInstrumentation.h" |
| 39 #include "core/inspector/ScriptArguments.h" | 39 #include "core/inspector/ScriptArguments.h" |
| 40 #include "core/inspector/ScriptCallFrame.h" | 40 #include "core/inspector/ScriptCallFrame.h" |
| 41 #include "core/inspector/ScriptCallStack.h" | 41 #include "core/inspector/ScriptCallStack.h" |
| 42 #include "core/platform/JSONValues.h" | 42 #include "core/platform/JSONValues.h" |
| 43 #include "wtf/text/StringBuilder.h" |
| 43 | 44 |
| 44 #include <v8-debug.h> | 45 #include <v8-debug.h> |
| 45 | 46 |
| 46 namespace WebCore { | 47 namespace WebCore { |
| 47 | 48 |
| 48 class ScriptExecutionContext; | 49 class ScriptExecutionContext; |
| 49 | 50 |
| 50 static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame) | 51 static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame) |
| 51 { | 52 { |
| 53 StringBuilder stringBuilder; |
| 54 stringBuilder.appendNumber(frame->GetScriptId()); |
| 55 String scriptId = stringBuilder.toString(); |
| 52 String sourceName; | 56 String sourceName; |
| 53 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); | 57 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); |
| 54 if (!sourceNameValue.IsEmpty()) | 58 if (!sourceNameValue.IsEmpty()) |
| 55 sourceName = toWebCoreString(sourceNameValue); | 59 sourceName = toWebCoreString(sourceNameValue); |
| 56 | 60 |
| 57 String functionName; | 61 String functionName; |
| 58 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 62 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
| 59 if (!functionNameValue.IsEmpty()) | 63 if (!functionNameValue.IsEmpty()) |
| 60 functionName = toWebCoreString(functionNameValue); | 64 functionName = toWebCoreString(functionNameValue); |
| 61 | 65 |
| 62 int sourceLineNumber = frame->GetLineNumber(); | 66 int sourceLineNumber = frame->GetLineNumber(); |
| 63 int sourceColumn = frame->GetColumn(); | 67 int sourceColumn = frame->GetColumn(); |
| 64 return ScriptCallFrame(functionName, sourceName, sourceLineNumber, sourceCol
umn); | 68 return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber,
sourceColumn); |
| 65 } | 69 } |
| 66 | 70 |
| 67 static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vect
or<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAll
owed) | 71 static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vect
or<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAll
owed) |
| 68 { | 72 { |
| 69 ASSERT(v8::Context::InContext()); | 73 ASSERT(v8::Context::InContext()); |
| 70 int frameCount = stackTrace->GetFrameCount(); | 74 int frameCount = stackTrace->GetFrameCount(); |
| 71 if (frameCount > static_cast<int>(maxStackSize)) | 75 if (frameCount > static_cast<int>(maxStackSize)) |
| 72 frameCount = maxStackSize; | 76 frameCount = maxStackSize; |
| 73 for (int i = 0; i < frameCount; i++) { | 77 for (int i = 0; i < frameCount; i++) { |
| 74 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 78 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
| 75 scriptCallFrames.append(toScriptCallFrame(stackFrame)); | 79 scriptCallFrames.append(toScriptCallFrame(stackFrame)); |
| 76 } | 80 } |
| 77 if (!frameCount && !emptyStackIsAllowed) { | 81 if (!frameCount && !emptyStackIsAllowed) { |
| 78 // Successfully grabbed stack trace, but there are no frames. It may hap
pen in case | 82 // Successfully grabbed stack trace, but there are no frames. It may hap
pen in case |
| 79 // when a bound function is called from native code for example. | 83 // when a bound function is called from native code for example. |
| 80 // Fallback to setting lineNumber to 0, and source and function name to
"undefined". | 84 // Fallback to setting lineNumber to 0, and source and function name to
"undefined". |
| 81 scriptCallFrames.append(ScriptCallFrame("undefined", "undefined", 0)); | 85 scriptCallFrames.append(ScriptCallFrame("undefined", "", "undefined", 0)
); |
| 82 } | 86 } |
| 83 } | 87 } |
| 84 | 88 |
| 85 static PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTra
ce> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed) | 89 static PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTra
ce> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed) |
| 86 { | 90 { |
| 87 ASSERT(v8::Context::InContext()); | 91 ASSERT(v8::Context::InContext()); |
| 88 v8::HandleScope scope; | 92 v8::HandleScope scope; |
| 89 Vector<ScriptCallFrame> scriptCallFrames; | 93 Vector<ScriptCallFrame> scriptCallFrames; |
| 90 toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptySt
ackIsAllowed); | 94 toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptySt
ackIsAllowed); |
| 91 return ScriptCallStack::create(scriptCallFrames); | 95 return ScriptCallStack::create(scriptCallFrames); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 ScriptState* state = ScriptState::forContext(context); | 137 ScriptState* state = ScriptState::forContext(context); |
| 134 | 138 |
| 135 Vector<ScriptValue> arguments; | 139 Vector<ScriptValue> arguments; |
| 136 for (int i = skipArgumentCount; i < v8arguments.Length(); ++i) | 140 for (int i = skipArgumentCount; i < v8arguments.Length(); ++i) |
| 137 arguments.append(ScriptValue(v8arguments[i])); | 141 arguments.append(ScriptValue(v8arguments[i])); |
| 138 | 142 |
| 139 return ScriptArguments::create(state, arguments); | 143 return ScriptArguments::create(state, arguments); |
| 140 } | 144 } |
| 141 | 145 |
| 142 } // namespace WebCore | 146 } // namespace WebCore |
| OLD | NEW |