blob: 9cffdbaef93cd7006cdbef7a85b857217514e655 [file] [log] [blame]
weinig@apple.com89d44d22009-01-28 22:54:21 +00001/*
mark.lam@apple.comd27553f2019-09-18 00:36:19 +00002 * Copyright (C) 2008-2019 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
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
weinig@apple.com89d44d22009-01-28 22:54:21 +000027
commit-queue@webkit.orgcd4bef42016-06-30 23:24:58 +000028#include "DebuggerLocation.h"
weinig@apple.com89d44d22009-01-28 22:54:21 +000029#include "JSObject.h"
30
31namespace JSC {
32
mark.lam@apple.com268dda72014-08-29 00:48:59 +000033class DebuggerCallFrame;
34class JSScope;
35
utatane.tea@gmail.com86feb2f2018-03-08 18:24:07 +000036class DebuggerScope final : public JSNonFinalObject {
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000037public:
ysuzuki@apple.com71e050b2019-12-16 23:02:06 +000038 using Base = JSNonFinalObject;
mark.lam@apple.comd27553f2019-09-18 00:36:19 +000039 static constexpr unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | OverridesGetPropertyNames;
commit-queue@webkit.org6c25c522011-08-09 20:46:17 +000040
ysuzuki@apple.com71e050b2019-12-16 23:02:06 +000041 template<typename CellType, SubspaceAccess mode>
42 static IsoSubspace* subspaceFor(VM& vm)
43 {
44 return vm.debuggerScopeSpace<mode>();
45 }
46
fpizlo@apple.comcff2d0c2016-05-04 21:21:36 +000047 JS_EXPORT_PRIVATE static DebuggerScope* create(VM& vm, JSScope* scope);
mhahnenberg@apple.com7317a7f2011-09-09 21:43:14 +000048
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000049 static void visitChildren(JSCell*, SlotVisitor&);
utatane.tea@gmail.comdad62412018-07-12 08:43:38 +000050 static String className(const JSObject*, VM&);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000051 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.com78961972020-02-26 01:38:46 +000054 static bool deleteProperty(JSCell*, JSGlobalObject*, PropertyName, DeletePropertySlot&);
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +000055 static void getOwnPropertyNames(JSObject*, JSGlobalObject*, PropertyNameArray&, EnumerationMode);
56 static bool defineOwnProperty(JSObject*, JSGlobalObject*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
weinig@apple.com89d44d22009-01-28 22:54:21 +000057
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000058 DECLARE_EXPORT_INFO;
mhahnenberg@apple.comc58d54d2011-12-16 19:06:44 +000059
mark.lam@apple.com268dda72014-08-29 00:48:59 +000060 static Structure* createStructure(VM& vm, JSGlobalObject* globalObject)
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +000061 {
mark.lam@apple.com268dda72014-08-29 00:48:59 +000062 return Structure::create(vm, globalObject, jsNull(), TypeInfo(ObjectType, StructureFlags), info());
ysuzuki@apple.comaa2eac02019-12-07 00:33:58 +000063 }
mark.lam@apple.com268dda72014-08-29 00:48:59 +000064 class iterator {
65 public:
66 iterator(DebuggerScope* node)
67 : m_node(node)
68 {
69 }
oliver@apple.come9eda782009-10-17 01:06:40 +000070
mark.lam@apple.com268dda72014-08-29 00:48:59 +000071 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.comb1ed12b2014-10-02 15:15:03 +000089 bool isCatchScope() const;
90 bool isFunctionNameScope() const;
mark.lam@apple.com268dda72014-08-29 00:48:59 +000091 bool isWithScope() const;
92 bool isGlobalScope() const;
saambarati1@gmail.com060e7512015-09-03 19:45:44 +000093 bool isClosureScope() const;
94 bool isGlobalLexicalEnvironment() const;
joepeck@webkit.org4c7c0ef2015-12-18 01:09:13 +000095 bool isNestedLexicalScope() const;
commit-queue@webkit.org1a0a3632011-08-30 01:43:46 +000096
commit-queue@webkit.orgcd4bef42016-06-30 23:24:58 +000097 String name() const;
98 DebuggerLocation location() const;
99
ysuzuki@apple.com52e98bb2019-10-22 09:24:48 +0000100 JSValue caughtValue(JSGlobalObject*) const;
joepeck@webkit.orgde4d1cf2014-11-19 23:49:36 +0000101
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +0000102private:
fpizlo@apple.comcff2d0c2016-05-04 21:21:36 +0000103 DebuggerScope(VM&, Structure*, JSScope*);
104 void finishCreation(VM&);
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000105
106 JSScope* jsScope() const { return m_scope.get(); }
107
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000108 WriteBarrier<JSScope> m_scope;
109 WriteBarrier<DebuggerScope> m_next;
110
111 friend class DebuggerCallFrame;
mark.lam@apple.com0d415ea2013-09-12 02:26:14 +0000112};
weinig@apple.com89d44d22009-01-28 22:54:21 +0000113
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000114inline DebuggerScope::iterator DebuggerScope::begin()
115{
116 return iterator(this);
117}
118
119inline DebuggerScope::iterator DebuggerScope::end()
120{
ross.kirsling@sony.com2abe6c62020-05-11 02:36:05 +0000121 return iterator(nullptr);
mark.lam@apple.com268dda72014-08-29 00:48:59 +0000122}
123
weinig@apple.com89d44d22009-01-28 22:54:21 +0000124} // namespace JSC