2 * Copyright (c) 2010, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
32 #include "JavaScriptCallFrame.h"
34 #if ENABLE(JAVASCRIPT_DEBUGGER)
36 #include "V8Binding.h"
40 JavaScriptCallFrame::JavaScriptCallFrame(v8::Handle<v8::Context> debuggerContext, v8::Handle<v8::Object> callFrame)
41 : m_debuggerContext(debuggerContext)
42 , m_callFrame(callFrame)
46 JavaScriptCallFrame::~JavaScriptCallFrame()
50 JavaScriptCallFrame* JavaScriptCallFrame::caller()
53 v8::HandleScope handleScope;
54 v8::Context::Scope contextScope(m_debuggerContext.get());
55 v8::Handle<v8::Value> callerFrame = m_callFrame.get()->Get(v8String("caller"));
56 if (!callerFrame->IsObject())
58 m_caller = JavaScriptCallFrame::create(m_debuggerContext.get(), v8::Handle<v8::Object>::Cast(callerFrame));
60 return m_caller.get();
63 int JavaScriptCallFrame::sourceID() const
65 v8::HandleScope handleScope;
66 v8::Context::Scope contextScope(m_debuggerContext.get());
67 v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("sourceID"));
68 if (result->IsInt32())
69 return result->Int32Value();
73 int JavaScriptCallFrame::line() const
75 v8::HandleScope handleScope;
76 v8::Context::Scope contextScope(m_debuggerContext.get());
77 v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("line"));
78 if (result->IsInt32())
79 return result->Int32Value();
83 int JavaScriptCallFrame::column() const
85 v8::HandleScope handleScope;
86 v8::Context::Scope contextScope(m_debuggerContext.get());
87 v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("column"));
88 if (result->IsInt32())
89 return result->Int32Value();
93 String JavaScriptCallFrame::functionName() const
95 v8::HandleScope handleScope;
96 v8::Context::Scope contextScope(m_debuggerContext.get());
97 v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("functionName"));
98 return toWebCoreStringWithNullOrUndefinedCheck(result);
101 v8::Handle<v8::Value> JavaScriptCallFrame::scopeChain() const
103 v8::Handle<v8::Array> scopeChain = v8::Handle<v8::Array>::Cast(m_callFrame.get()->Get(v8String("scopeChain")));
104 v8::Handle<v8::Array> result = v8::Array::New(scopeChain->Length());
105 for (uint32_t i = 0; i < scopeChain->Length(); i++)
106 result->Set(i, scopeChain->Get(i));
110 int JavaScriptCallFrame::scopeType(int scopeIndex) const
112 v8::Handle<v8::Array> scopeType = v8::Handle<v8::Array>::Cast(m_callFrame.get()->Get(v8String("scopeType")));
113 return scopeType->Get(scopeIndex)->Int32Value();
116 v8::Handle<v8::Value> JavaScriptCallFrame::thisObject() const
118 return m_callFrame.get()->Get(v8String("thisObject"));
121 v8::Handle<v8::Value> JavaScriptCallFrame::evaluate(const String& expression)
123 v8::Handle<v8::Function> evalFunction = v8::Handle<v8::Function>::Cast(m_callFrame.get()->Get(v8String("evaluate")));
124 v8::Handle<v8::Value> argv[] = { v8String(expression) };
125 return evalFunction->Call(m_callFrame.get(), 1, argv);
128 } // namespace WebCore
130 #endif // ENABLE(JAVASCRIPT_DEBUGGER)