blob: 8994fcfd675b7adf19f31aafa4c8ef7fa9f665d5 [file] [log] [blame]
weinig@apple.com89d44d22009-01-28 22:54:21 +00001/*
fpizlo@apple.com3378c482014-07-27 23:14:40 +00002 * Copyright (C) 2008-2009, 2014 Apple Inc. All rights reserved.
weinig@apple.com89d44d22009-01-28 22:54:21 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
fpizlo@apple.com3378c482014-07-27 23:14:40 +000026#ifndef DebuggerScope_h
27#define DebuggerScope_h
weinig@apple.com89d44d22009-01-28 22:54:21 +000028
29#include "JSObject.h"
30
31namespace JSC {
32
mark.lam@apple.com268dda72014-08-29 00:48:59 +000033class DebuggerCallFrame;
34class JSScope;
35
fpizlo@apple.com3378c482014-07-27 23:14:40 +000036class DebuggerScope : public JSNonFinalObject {
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000037public:
38 typedef JSNonFinalObject Base;
akling@apple.com4b9e0002015-04-13 19:12:48 +000039 static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000040
mark.lam@apple.com268dda72014-08-29 00:48:59 +000041 static DebuggerScope* create(VM& vm, JSScope* scope)
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000042 {
mark.lam@apple.com268dda72014-08-29 00:48:59 +000043 DebuggerScope* debuggerScope = new (NotNull, allocateCell<DebuggerScope>(vm.heap)) DebuggerScope(vm, scope);
44 debuggerScope->finishCreation(vm);
45 return debuggerScope;
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000046 }
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000047
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000048 static void visitChildren(JSCell*, SlotVisitor&);
49 static String className(const JSObject*);
50 static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
51 static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
52 static bool deleteProperty(JSCell*, ExecState*, PropertyName);
53 static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
54 static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
weinig@apple.com89d44d22009-01-28 22:54:21 +000055
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000056 DECLARE_EXPORT_INFO;
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000057
mark.lam@apple.com268dda72014-08-29 00:48:59 +000058 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject)
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000059 {
mark.lam@apple.com268dda72014-08-29 00:48:59 +000060 return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), info());
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000061 }
weinig@apple.com89d44d22009-01-28 22:54:21 +000062
mark.lam@apple.com268dda72014-08-29 00:48:59 +000063 class iterator {
64 public:
65 iterator(DebuggerScope* node)
66 : m_node(node)
67 {
68 }
oliver@apple.come9eda782009-10-17 01:06:40 +000069
mark.lam@apple.com268dda72014-08-29 00:48:59 +000070 DebuggerScope* get() { return m_node; }
71 iterator& operator++() { m_node = m_node->next(); return *this; }
72 // postfix ++ intentionally omitted
73
74 bool operator==(const iterator& other) const { return m_node == other.m_node; }
75 bool operator!=(const iterator& other) const { return m_node != other.m_node; }
76
77 private:
78 DebuggerScope* m_node;
79 };
80
81 iterator begin();
82 iterator end();
83 DebuggerScope* next();
84
85 void invalidateChain();
86 bool isValid() const { return !!m_scope; }
87
mark.lam@apple.comb1ed12b2014-10-02 15:15:03 +000088 bool isCatchScope() const;
89 bool isFunctionNameScope() const;
mark.lam@apple.com268dda72014-08-29 00:48:59 +000090 bool isWithScope() const;
91 bool isGlobalScope() const;
saambarati1@gmail.com060e7512015-09-03 19:45:44 +000092 bool isClosureScope() const;
93 bool isGlobalLexicalEnvironment() const;
commit-queue@webkit.org1a0a3632011-08-30 01:43:46 +000094
saambarati1@gmail.com52f68592015-07-28 21:39:34 +000095 JSValue caughtValue(ExecState*) const;
joepeck@webkit.orgde4d1cf2014-11-19 23:49:36 +000096
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000097private:
mark.lam@apple.com268dda72014-08-29 00:48:59 +000098 JS_EXPORT_PRIVATE DebuggerScope(VM&, JSScope*);
99 JS_EXPORT_PRIVATE void finishCreation(VM&);
100
101 JSScope* jsScope() const { return m_scope.get(); }
102
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000103 WriteBarrier<JSScope> m_scope;
104 WriteBarrier<DebuggerScope> m_next;
105
106 friend class DebuggerCallFrame;
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +0000107};
weinig@apple.com89d44d22009-01-28 22:54:21 +0000108
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000109inline DebuggerScope::iterator DebuggerScope::begin()
110{
111 return iterator(this);
112}
113
114inline DebuggerScope::iterator DebuggerScope::end()
115{
116 return iterator(0);
117}
118
weinig@apple.com89d44d22009-01-28 22:54:21 +0000119} // namespace JSC
120
fpizlo@apple.com3378c482014-07-27 23:14:40 +0000121#endif // DebuggerScope_h