summaryrefslogtreecommitdiff
path: root/js/src/vm/Scope.h
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/vm/Scope.h')
-rw-r--r--js/src/vm/Scope.h96
1 files changed, 30 insertions, 66 deletions
diff --git a/js/src/vm/Scope.h b/js/src/vm/Scope.h
index 4f0edcc13..fc1419bb8 100644
--- a/js/src/vm/Scope.h
+++ b/js/src/vm/Scope.h
@@ -22,6 +22,7 @@
namespace js {
class ModuleObject;
+class Scope;
enum class BindingKind : uint8_t
{
@@ -224,6 +225,21 @@ class BindingLocation
};
//
+// Allow using is<T> and as<T> on Rooted<Scope*> and Handle<Scope*>.
+//
+template <typename Wrapper>
+class WrappedPtrOperations<Scope*, Wrapper>
+{
+ public:
+ template <class U>
+ JS::Handle<U*> as() const {
+ const Wrapper& self = *static_cast<const Wrapper*>(this);
+ MOZ_ASSERT_IF(self, self->template is<U>());
+ return Handle<U*>::fromMarkedLocation(reinterpret_cast<U* const*>(self.address()));
+ }
+};
+
+//
// The base class of all Scopes.
//
class Scope : public js::gc::TenuredCell
@@ -1338,10 +1354,10 @@ class MOZ_STACK_CLASS ScopeIter
// Specializations of Rooted containers for the iterators.
//
-template <typename Outer>
-class BindingIterOperations
+template <typename Wrapper>
+class WrappedPtrOperations<BindingIter, Wrapper>
{
- const BindingIter& iter() const { return static_cast<const Outer*>(this)->get(); }
+ const BindingIter& iter() const { return static_cast<const Wrapper*>(this)->get(); }
public:
bool done() const { return iter().done(); }
@@ -1361,19 +1377,20 @@ class BindingIterOperations
uint32_t nextEnvironmentSlot() const { return iter().nextEnvironmentSlot(); }
};
-template <typename Outer>
-class MutableBindingIterOperations : public BindingIterOperations<Outer>
+template <typename Wrapper>
+class MutableWrappedPtrOperations<BindingIter, Wrapper>
+ : public WrappedPtrOperations<BindingIter, Wrapper>
{
- BindingIter& iter() { return static_cast<Outer*>(this)->get(); }
+ BindingIter& iter() { return static_cast<Wrapper*>(this)->get(); }
public:
void operator++(int) { iter().operator++(1); }
};
-template <typename Outer>
-class ScopeIterOperations
+template <typename Wrapper>
+class WrappedPtrOperations<ScopeIter, Wrapper>
{
- const ScopeIter& iter() const { return static_cast<const Outer*>(this)->get(); }
+ const ScopeIter& iter() const { return static_cast<const Wrapper*>(this)->get(); }
public:
bool done() const { return iter().done(); }
@@ -1384,69 +1401,16 @@ class ScopeIterOperations
bool hasSyntacticEnvironment() const { return iter().hasSyntacticEnvironment(); }
};
-template <typename Outer>
-class MutableScopeIterOperations : public ScopeIterOperations<Outer>
+template <typename Wrapper>
+class MutableWrappedPtrOperations<ScopeIter, Wrapper>
+ : public WrappedPtrOperations<ScopeIter, Wrapper>
{
- ScopeIter& iter() { return static_cast<Outer*>(this)->get(); }
+ ScopeIter& iter() { return static_cast<Wrapper*>(this)->get(); }
public:
void operator++(int) { iter().operator++(1); }
};
-#define SPECIALIZE_ROOTING_CONTAINERS(Iter, BaseIter) \
- template <> \
- class RootedBase<Iter> \
- : public Mutable##BaseIter##Operations<JS::Rooted<Iter>> \
- { }; \
- \
- template <> \
- class MutableHandleBase<Iter> \
- : public Mutable##BaseIter##Operations<JS::MutableHandle<Iter>> \
- { }; \
- \
- template <> \
- class HandleBase<Iter> \
- : public BaseIter##Operations<JS::Handle<Iter>> \
- { }; \
- \
- template <> \
- class PersistentRootedBase<Iter> \
- : public Mutable##BaseIter##Operations<JS::PersistentRooted<Iter>> \
- { }
-
-SPECIALIZE_ROOTING_CONTAINERS(BindingIter, BindingIter);
-SPECIALIZE_ROOTING_CONTAINERS(PositionalFormalParameterIter, BindingIter);
-SPECIALIZE_ROOTING_CONTAINERS(ScopeIter, ScopeIter);
-
-#undef SPECIALIZE_ROOTING_CONTAINERS
-
-//
-// Allow using is<T> and as<T> on Rooted<Scope*> and Handle<Scope*>.
-//
-
-template <typename Outer>
-struct ScopeCastOperation
-{
- template <class U>
- JS::Handle<U*> as() const {
- const Outer& self = *static_cast<const Outer*>(this);
- MOZ_ASSERT_IF(self, self->template is<U>());
- return Handle<U*>::fromMarkedLocation(reinterpret_cast<U* const*>(self.address()));
- }
-};
-
-template <>
-class RootedBase<Scope*> : public ScopeCastOperation<JS::Rooted<Scope*>>
-{ };
-
-template <>
-class HandleBase<Scope*> : public ScopeCastOperation<JS::Handle<Scope*>>
-{ };
-
-template <>
-class MutableHandleBase<Scope*> : public ScopeCastOperation<JS::MutableHandle<Scope*>>
-{ };
-
} // namespace js
namespace JS {