WebCore/bindings/v8/JavaScriptCallFrame.cpp
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "config.h"
       
    32 #include "JavaScriptCallFrame.h"
       
    33 
       
    34 #if ENABLE(JAVASCRIPT_DEBUGGER)
       
    35 
       
    36 #include "V8Binding.h"
       
    37 
       
    38 namespace WebCore {
       
    39 
       
    40 JavaScriptCallFrame::JavaScriptCallFrame(v8::Handle<v8::Context> debuggerContext, v8::Handle<v8::Object> callFrame)
       
    41     : m_debuggerContext(debuggerContext)
       
    42     , m_callFrame(callFrame)
       
    43 {
       
    44 }
       
    45 
       
    46 JavaScriptCallFrame::~JavaScriptCallFrame()
       
    47 {
       
    48 }
       
    49 
       
    50 JavaScriptCallFrame* JavaScriptCallFrame::caller()
       
    51 {
       
    52     if (!m_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())
       
    57             return 0;
       
    58         m_caller = JavaScriptCallFrame::create(m_debuggerContext.get(), v8::Handle<v8::Object>::Cast(callerFrame));
       
    59     }
       
    60     return m_caller.get();
       
    61 }
       
    62 
       
    63 int JavaScriptCallFrame::sourceID() const
       
    64 {
       
    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();
       
    70     return 0;
       
    71 }
       
    72 
       
    73 int JavaScriptCallFrame::line() const
       
    74 {
       
    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();
       
    80     return 0;
       
    81 }
       
    82 
       
    83 String JavaScriptCallFrame::functionName() const
       
    84 {
       
    85     v8::HandleScope handleScope;
       
    86     v8::Context::Scope contextScope(m_debuggerContext.get());
       
    87     v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("functionName"));
       
    88     return toWebCoreStringWithNullOrUndefinedCheck(result);
       
    89 }
       
    90 
       
    91 v8::Handle<v8::Value> JavaScriptCallFrame::scopeChain() const
       
    92 {
       
    93     v8::Handle<v8::Array> scopeChain = v8::Handle<v8::Array>::Cast(m_callFrame.get()->Get(v8String("scopeChain")));
       
    94     v8::Handle<v8::Array> result = v8::Array::New(scopeChain->Length());
       
    95     for (uint32_t i = 0; i < scopeChain->Length(); i++)
       
    96         result->Set(i, scopeChain->Get(i));
       
    97     return result;
       
    98 }
       
    99 
       
   100 int JavaScriptCallFrame::scopeType(int scopeIndex) const
       
   101 {
       
   102     v8::Handle<v8::Array> scopeType = v8::Handle<v8::Array>::Cast(m_callFrame.get()->Get(v8String("scopeType")));
       
   103     return scopeType->Get(scopeIndex)->Int32Value();
       
   104 }
       
   105 
       
   106 v8::Handle<v8::Value> JavaScriptCallFrame::thisObject() const
       
   107 {
       
   108     return m_callFrame.get()->Get(v8String("thisObject"));
       
   109 }
       
   110 
       
   111 v8::Handle<v8::Value> JavaScriptCallFrame::evaluate(const String& expression)
       
   112 {
       
   113     v8::Handle<v8::Function> evalFunction = v8::Handle<v8::Function>::Cast(m_callFrame.get()->Get(v8String("evaluate")));
       
   114     v8::Handle<v8::Value> argv[] = { v8String(expression) };
       
   115     return evalFunction->Call(m_callFrame.get(), 1, argv);
       
   116 }
       
   117 
       
   118 } // namespace WebCore
       
   119 
       
   120 #endif // ENABLE(JAVASCRIPT_DEBUGGER)