1 | /* |
2 | * Copyright (C) 2008-2009, 2014, 2016 Apple 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 |
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 | |
26 | #pragma once |
27 | |
28 | #include "DebuggerLocation.h" |
29 | #include "JSObject.h" |
30 | |
31 | namespace JSC { |
32 | |
33 | class DebuggerCallFrame; |
34 | class JSScope; |
35 | |
36 | class DebuggerScope final : public JSNonFinalObject { |
37 | public: |
38 | typedef JSNonFinalObject Base; |
39 | static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames; |
40 | |
41 | JS_EXPORT_PRIVATE static DebuggerScope* create(VM& vm, JSScope* scope); |
42 | |
43 | static void visitChildren(JSCell*, SlotVisitor&); |
44 | static String className(const JSObject*, VM&); |
45 | static String toStringName(const JSObject*, ExecState*); |
46 | static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&); |
47 | static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&); |
48 | static bool deleteProperty(JSCell*, ExecState*, PropertyName); |
49 | static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode); |
50 | static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow); |
51 | |
52 | DECLARE_EXPORT_INFO; |
53 | |
54 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject) |
55 | { |
56 | return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), info()); |
57 | } |
58 | |
59 | class iterator { |
60 | public: |
61 | iterator(DebuggerScope* node) |
62 | : m_node(node) |
63 | { |
64 | } |
65 | |
66 | DebuggerScope* get() { return m_node; } |
67 | iterator& operator++() { m_node = m_node->next(); return *this; } |
68 | // postfix ++ intentionally omitted |
69 | |
70 | bool operator==(const iterator& other) const { return m_node == other.m_node; } |
71 | bool operator!=(const iterator& other) const { return m_node != other.m_node; } |
72 | |
73 | private: |
74 | DebuggerScope* m_node; |
75 | }; |
76 | |
77 | iterator begin(); |
78 | iterator end(); |
79 | DebuggerScope* next(); |
80 | |
81 | void invalidateChain(); |
82 | bool isValid() const { return !!m_scope; } |
83 | |
84 | bool isCatchScope() const; |
85 | bool isFunctionNameScope() const; |
86 | bool isWithScope() const; |
87 | bool isGlobalScope() const; |
88 | bool isClosureScope() const; |
89 | bool isGlobalLexicalEnvironment() const; |
90 | bool isNestedLexicalScope() const; |
91 | |
92 | String name() const; |
93 | DebuggerLocation location() const; |
94 | |
95 | JSValue caughtValue(ExecState*) const; |
96 | |
97 | private: |
98 | DebuggerScope(VM&, Structure*, JSScope*); |
99 | void finishCreation(VM&); |
100 | |
101 | JSScope* jsScope() const { return m_scope.get(); } |
102 | |
103 | WriteBarrier<JSScope> m_scope; |
104 | WriteBarrier<DebuggerScope> m_next; |
105 | |
106 | friend class DebuggerCallFrame; |
107 | }; |
108 | |
109 | inline DebuggerScope::iterator DebuggerScope::begin() |
110 | { |
111 | return iterator(this); |
112 | } |
113 | |
114 | inline DebuggerScope::iterator DebuggerScope::end() |
115 | { |
116 | return iterator(0); |
117 | } |
118 | |
119 | } // namespace JSC |
120 | |