weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 1 | /* |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008-2019 Apple Inc. All rights reserved. |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 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 | |
ryanhaddad@apple.com | 22104f5 | 2016-09-28 17:08:17 +0000 | [diff] [blame] | 26 | #pragma once |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 27 | |
commit-queue@webkit.org | cd4bef4 | 2016-06-30 23:24:58 +0000 | [diff] [blame] | 28 | #include "DebuggerLocation.h" |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 29 | #include "JSObject.h" |
| 30 | |
| 31 | namespace JSC { |
| 32 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 33 | class DebuggerCallFrame; |
| 34 | class JSScope; |
| 35 | |
utatane.tea@gmail.com | 86feb2f | 2018-03-08 18:24:07 +0000 | [diff] [blame] | 36 | class DebuggerScope final : public JSNonFinalObject { |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 37 | public: |
ysuzuki@apple.com | 71e050b | 2019-12-16 23:02:06 +0000 | [diff] [blame] | 38 | using Base = JSNonFinalObject; |
mark.lam@apple.com | d27553f | 2019-09-18 00:36:19 +0000 | [diff] [blame] | 39 | static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames; |
commit-queue@webkit.org | 6c25c52 | 2011-08-09 20:46:17 +0000 | [diff] [blame] | 40 | |
ysuzuki@apple.com | 71e050b | 2019-12-16 23:02:06 +0000 | [diff] [blame] | 41 | template<typename CellType, SubspaceAccess mode> |
| 42 | static IsoSubspace* subspaceFor(VM& vm) |
| 43 | { |
| 44 | return vm.debuggerScopeSpace<mode>(); |
| 45 | } |
| 46 | |
fpizlo@apple.com | cff2d0c | 2016-05-04 21:21:36 +0000 | [diff] [blame] | 47 | JS_EXPORT_PRIVATE static DebuggerScope* create(VM& vm, JSScope* scope); |
mhahnenberg@apple.com | 7317a7f | 2011-09-09 21:43:14 +0000 | [diff] [blame] | 48 | |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 49 | static void visitChildren(JSCell*, SlotVisitor&); |
utatane.tea@gmail.com | dad6241 | 2018-07-12 08:43:38 +0000 | [diff] [blame] | 50 | static String className(const JSObject*, VM&); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 51 | static String toStringName(const JSObject*, JSGlobalObject*); |
| 52 | static bool getOwnPropertySlot(JSObject*, JSGlobalObject*, PropertyName, PropertySlot&); |
| 53 | static bool put(JSCell*, JSGlobalObject*, PropertyName, JSValue, PutPropertySlot&); |
justin_michaud@apple.com | 7896197 | 2020-02-26 01:38:46 +0000 | [diff] [blame] | 54 | static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&); |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 55 | static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, EnumerationMode); |
| 56 | static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow); |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 57 | |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 58 | DECLARE_EXPORT_INFO; |
mhahnenberg@apple.com | c58d54d | 2011-12-16 19:06:44 +0000 | [diff] [blame] | 59 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 60 | static Structure* createStructure(VM& vm, JSGlobalObject* globalObject) |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 61 | { |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 62 | return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), info()); |
ysuzuki@apple.com | aa2eac0 | 2019-12-07 00:33:58 +0000 | [diff] [blame] | 63 | } |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 64 | class iterator { |
| 65 | public: |
| 66 | iterator(DebuggerScope* node) |
| 67 | : m_node(node) |
| 68 | { |
| 69 | } |
oliver@apple.com | e9eda78 | 2009-10-17 01:06:40 +0000 | [diff] [blame] | 70 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 71 | DebuggerScope* get() { return m_node; } |
| 72 | iterator& operator++() { m_node = m_node->next(); return *this; } |
| 73 | // postfix ++ intentionally omitted |
| 74 | |
| 75 | bool operator==(const iterator& other) const { return m_node == other.m_node; } |
| 76 | bool operator!=(const iterator& other) const { return m_node != other.m_node; } |
| 77 | |
| 78 | private: |
| 79 | DebuggerScope* m_node; |
| 80 | }; |
| 81 | |
| 82 | iterator begin(); |
| 83 | iterator end(); |
| 84 | DebuggerScope* next(); |
| 85 | |
| 86 | void invalidateChain(); |
| 87 | bool isValid() const { return !!m_scope; } |
| 88 | |
mark.lam@apple.com | b1ed12b | 2014-10-02 15:15:03 +0000 | [diff] [blame] | 89 | bool isCatchScope() const; |
| 90 | bool isFunctionNameScope() const; |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 91 | bool isWithScope() const; |
| 92 | bool isGlobalScope() const; |
saambarati1@gmail.com | 060e751 | 2015-09-03 19:45:44 +0000 | [diff] [blame] | 93 | bool isClosureScope() const; |
| 94 | bool isGlobalLexicalEnvironment() const; |
joepeck@webkit.org | 4c7c0ef | 2015-12-18 01:09:13 +0000 | [diff] [blame] | 95 | bool isNestedLexicalScope() const; |
commit-queue@webkit.org | 1a0a363 | 2011-08-30 01:43:46 +0000 | [diff] [blame] | 96 | |
commit-queue@webkit.org | cd4bef4 | 2016-06-30 23:24:58 +0000 | [diff] [blame] | 97 | String name() const; |
| 98 | DebuggerLocation location() const; |
| 99 | |
ysuzuki@apple.com | 52e98bb | 2019-10-22 09:24:48 +0000 | [diff] [blame] | 100 | JSValue caughtValue(JSGlobalObject*) const; |
joepeck@webkit.org | de4d1cf | 2014-11-19 23:49:36 +0000 | [diff] [blame] | 101 | |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 102 | private: |
fpizlo@apple.com | cff2d0c | 2016-05-04 21:21:36 +0000 | [diff] [blame] | 103 | DebuggerScope(VM&, Structure*, JSScope*); |
| 104 | void finishCreation(VM&); |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 105 | |
| 106 | JSScope* jsScope() const { return m_scope.get(); } |
| 107 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 108 | WriteBarrier<JSScope> m_scope; |
| 109 | WriteBarrier<DebuggerScope> m_next; |
| 110 | |
| 111 | friend class DebuggerCallFrame; |
mark.lam@apple.com | 0d415ea | 2013-09-12 02:26:14 +0000 | [diff] [blame] | 112 | }; |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 113 | |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 114 | inline DebuggerScope::iterator DebuggerScope::begin() |
| 115 | { |
| 116 | return iterator(this); |
| 117 | } |
| 118 | |
| 119 | inline DebuggerScope::iterator DebuggerScope::end() |
| 120 | { |
ross.kirsling@sony.com | 2abe6c6 | 2020-05-11 02:36:05 +0000 | [diff] [blame] | 121 | return iterator(nullptr); |
mark.lam@apple.com | 268dda7 | 2014-08-29 00:48:59 +0000 | [diff] [blame] | 122 | } |
| 123 | |
weinig@apple.com | 89d44d2 | 2009-01-28 22:54:21 +0000 | [diff] [blame] | 124 | } // namespace JSC |