2 * Copyright (C) 2008 Apple 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
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(JAVASCRIPT_DEBUGGER)
30 #include "JSJavaScriptCallFrame.h"
32 #include "JavaScriptCallFrame.h"
33 #include <runtime/ArrayPrototype.h>
34 #include <runtime/Error.h>
40 JSValue JSJavaScriptCallFrame::evaluate(ExecState* exec)
43 JSValue result = impl()->evaluate(exec->argument(0).toString(exec), exception);
46 throwError(exec, exception);
51 JSValue JSJavaScriptCallFrame::thisObject(ExecState*) const
53 return impl()->thisObject() ? JSValue(impl()->thisObject()) : jsNull();
56 #if ENABLE(TIZEN_SUPPORT_BLUE_RUNNER)
57 JSValue JSJavaScriptCallFrame::functionObject(ExecState*) const
59 return impl()->functionObject() ? impl()->functionObject() : jsNull();
63 JSValue JSJavaScriptCallFrame::type(ExecState* exec) const
65 switch (impl()->type()) {
66 case DebuggerCallFrame::FunctionType:
67 return jsString(exec, UString("function"));
68 case DebuggerCallFrame::ProgramType:
69 return jsString(exec, UString("program"));
76 JSValue JSJavaScriptCallFrame::scopeChain(ExecState* exec) const
78 if (!impl()->scopeChain())
81 ScopeChainNode* scopeChain = impl()->scopeChain();
82 ScopeChainIterator iter = scopeChain->begin();
83 ScopeChainIterator end = scopeChain->end();
85 // we must always have something in the scope chain
88 MarkedArgumentBuffer list;
90 list.append(iter->get());
92 } while (iter != end);
94 return constructArray(exec, globalObject(), list);
97 JSValue JSJavaScriptCallFrame::scopeType(ExecState* exec)
99 if (!impl()->scopeChain())
100 return jsUndefined();
102 if (!exec->argument(0).isInt32())
103 return jsUndefined();
104 int index = exec->argument(0).asInt32();
106 ScopeChainNode* scopeChain = impl()->scopeChain();
107 ScopeChainIterator end = scopeChain->end();
109 bool foundLocalScope = false;
110 for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) {
111 JSObject* scope = iter->get();
112 if (scope->isActivationObject()) {
113 if (!foundLocalScope) {
114 // First activation object is local scope, each successive activation object is closure.
116 return jsJavaScriptCallFrameLOCAL_SCOPE(exec, JSValue(), Identifier());
117 foundLocalScope = true;
119 return jsJavaScriptCallFrameCLOSURE_SCOPE(exec, JSValue(), Identifier());
123 // Last in the chain is global scope.
125 return jsJavaScriptCallFrameGLOBAL_SCOPE(exec, JSValue(), Identifier());
126 return jsJavaScriptCallFrameWITH_SCOPE(exec, JSValue(), Identifier());
131 return jsUndefined();
134 } // namespace WebCore
136 #endif // ENABLE(JAVASCRIPT_DEBUGGER)