Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: sky/engine/bindings/core/v8/ScriptCallStackFactory.cpp

Issue 922053002: Remove unused V8 integration code in Sky (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 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 "sky/engine/config.h"
32 #include "sky/engine/bindings/core/v8/ScriptCallStackFactory.h"
33
34 #include "sky/engine/bindings/core/v8/ScriptValue.h"
35 #include "sky/engine/bindings/core/v8/V8Binding.h"
36 #include "sky/engine/core/inspector/ScriptArguments.h"
37 #include "sky/engine/core/inspector/ScriptCallFrame.h"
38 #include "sky/engine/core/inspector/ScriptCallStack.h"
39 #include "sky/engine/platform/JSONValues.h"
40 #include "sky/engine/wtf/text/StringBuilder.h"
41 #include "v8/include/v8-debug.h"
42
43 namespace blink {
44
45 class ExecutionContext;
46
47 static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame)
48 {
49 StringBuilder stringBuilder;
50 stringBuilder.appendNumber(frame->GetScriptId());
51 String scriptId = stringBuilder.toString();
52 String sourceName;
53 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL());
54 if (!sourceNameValue.IsEmpty())
55 sourceName = toCoreString(sourceNameValue);
56
57 String functionName;
58 v8::Local<v8::String> functionNameValue(frame->GetFunctionName());
59 if (!functionNameValue.IsEmpty())
60 functionName = toCoreString(functionNameValue);
61
62 int sourceLineNumber = frame->GetLineNumber();
63 int sourceColumn = frame->GetColumn();
64 return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber, sourceColumn);
65 }
66
67 static void toScriptCallFramesVector(v8::Handle<v8::StackTrace> stackTrace, Vect or<ScriptCallFrame>& scriptCallFrames, size_t maxStackSize, bool emptyStackIsAll owed, v8::Isolate* isolate)
68 {
69 ASSERT(isolate->InContext());
70 int frameCount = stackTrace->GetFrameCount();
71 if (frameCount > static_cast<int>(maxStackSize))
72 frameCount = maxStackSize;
73 for (int i = 0; i < frameCount; i++) {
74 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
75 scriptCallFrames.append(toScriptCallFrame(stackFrame));
76 }
77 if (!frameCount && !emptyStackIsAllowed) {
78 // 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.
80 // Fallback to setting lineNumber to 0, and source and function name to "undefined".
81 scriptCallFrames.append(ScriptCallFrame());
82 }
83 }
84
85 static PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTra ce> stackTrace, size_t maxStackSize, bool emptyStackIsAllowed, v8::Isolate* isol ate)
86 {
87 ASSERT(isolate->InContext());
88 v8::HandleScope scope(isolate);
89 Vector<ScriptCallFrame> scriptCallFrames;
90 toScriptCallFramesVector(stackTrace, scriptCallFrames, maxStackSize, emptySt ackIsAllowed, isolate);
91 RefPtr<ScriptCallStack> callStack = ScriptCallStack::create(scriptCallFrames );
92 return callStack.release();
93 }
94
95 PassRefPtr<ScriptCallStack> createScriptCallStack(v8::Handle<v8::StackTrace> sta ckTrace, size_t maxStackSize, v8::Isolate* isolate)
96 {
97 return createScriptCallStack(stackTrace, maxStackSize, true, isolate);
98 }
99
100 PassRefPtr<ScriptCallStack> createScriptCallStack(size_t maxStackSize, bool empt yStackIsAllowed)
101 {
102 v8::Isolate* isolate = v8::Isolate::GetCurrent();
103 if (!isolate->InContext())
104 return nullptr;
105 v8::HandleScope handleScope(isolate);
106 v8::Handle<v8::StackTrace> stackTrace(v8::StackTrace::CurrentStackTrace(isol ate, maxStackSize, stackTraceOptions));
107 return createScriptCallStack(stackTrace, maxStackSize, emptyStackIsAllowed, isolate);
108 }
109
110 PassRefPtr<ScriptCallStack> createScriptCallStackForConsole(size_t maxStackSize, bool emptyStackIsAllowed)
111 {
112 size_t stackSize = 1;
113 return createScriptCallStack(stackSize, emptyStackIsAllowed);
114 }
115
116 PassRefPtr<ScriptArguments> createScriptArguments(ScriptState* scriptState, cons t v8::FunctionCallbackInfo<v8::Value>& v8arguments, unsigned skipArgumentCount)
117 {
118 Vector<ScriptValue> arguments;
119 for (int i = skipArgumentCount; i < v8arguments.Length(); ++i)
120 arguments.append(ScriptValue(scriptState, v8arguments[i]));
121
122 return ScriptArguments::create(scriptState, arguments);
123 }
124
125 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/bindings/core/v8/ScriptCallStackFactory.h ('k') | sky/engine/bindings/core/v8/ScriptController.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698