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 JSValue JSJavaScriptCallFrame::type(ExecState* exec) const
58 switch (impl()->type()) {
59 case DebuggerCallFrame::FunctionType:
60 return jsString(exec, UString("function"));
61 case DebuggerCallFrame::ProgramType:
62 return jsString(exec, UString("program"));
69 JSValue JSJavaScriptCallFrame::scopeChain(ExecState* exec) const
71 if (!impl()->scopeChain())
74 ScopeChainNode* scopeChain = impl()->scopeChain();
75 ScopeChainIterator iter = scopeChain->begin();
76 ScopeChainIterator end = scopeChain->end();
78 // we must always have something in the scope chain
81 MarkedArgumentBuffer list;
83 list.append(iter->get());
85 } while (iter != end);
87 return constructArray(exec, globalObject(), list);
90 JSValue JSJavaScriptCallFrame::scopeType(ExecState* exec)
92 if (!impl()->scopeChain())
95 if (!exec->argument(0).isInt32())
97 int index = exec->argument(0).asInt32();
99 ScopeChainNode* scopeChain = impl()->scopeChain();
100 ScopeChainIterator end = scopeChain->end();
102 bool foundLocalScope = false;
103 for (ScopeChainIterator iter = scopeChain->begin(); iter != end; ++iter) {
104 JSObject* scope = iter->get();
105 if (scope->isActivationObject()) {
106 if (!foundLocalScope) {
107 // First activation object is local scope, each successive activation object is closure.
109 return jsJavaScriptCallFrameLOCAL_SCOPE(exec, JSValue(), Identifier());
110 foundLocalScope = true;
112 return jsJavaScriptCallFrameCLOSURE_SCOPE(exec, JSValue(), Identifier());
116 // Last in the chain is global scope.
118 return jsJavaScriptCallFrameGLOBAL_SCOPE(exec, JSValue(), Identifier());
119 return jsJavaScriptCallFrameWITH_SCOPE(exec, JSValue(), Identifier());
124 return jsUndefined();
127 } // namespace WebCore
129 #endif // ENABLE(JAVASCRIPT_DEBUGGER)