| 1 |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
| 2 |
* vim: set ts=8 sts=2 et sw=2 tw=80: |
| 3 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 4 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 6 |
|
| 7 |
#include "frontend/AbstractScopePtr.h" |
| 8 |
|
| 9 |
#include "mozilla/Assertions.h" |
| 10 |
|
| 11 |
#include "frontend/CompilationStencil.h" // CompilationState |
| 12 |
#include "frontend/Stencil.h" |
| 13 |
#include "js/Vector.h" |
| 14 |
#include "vm/Scope.h" // for FunctionScope |
| 15 |
|
| 16 |
using namespace js; |
| 17 |
using namespace js::frontend; |
| 18 |
|
| 19 |
ScopeStencil& AbstractScopePtr::scopeData() const { |
| 20 |
MOZ_ASSERT(isScopeStencil()); |
| 21 |
return compilationState_.scopeData[index_]; |
| 22 |
} |
| 23 |
|
| 24 |
ScopeKind AbstractScopePtr::kind() const { |
| 25 |
if (isScopeStencil()) { |
| 26 |
return scopeData().kind(); |
| 27 |
} |
| 28 |
return compilationState_.scopeContext.enclosingScopeKind; |
| 29 |
} |
| 30 |
|
| 31 |
AbstractScopePtr AbstractScopePtr::enclosing() const { |
| 32 |
MOZ_ASSERT(isScopeStencil()); |
| 33 |
return scopeData().enclosing(compilationState_); |
| 34 |
} |
| 35 |
|
| 36 |
bool AbstractScopePtr::hasEnvironment() const { |
| 37 |
if (isScopeStencil()) { |
| 38 |
return scopeData().hasEnvironment(); |
| 39 |
} |
| 40 |
return compilationState_.scopeContext.enclosingScopeHasEnvironment; |
| 41 |
} |
| 42 |
|
| 43 |
bool AbstractScopePtr::isArrow() const { |
| 44 |
MOZ_ASSERT(is<FunctionScope>()); |
| 45 |
if (isScopeStencil()) { |
| 46 |
return scopeData().isArrow(); |
| 47 |
} |
| 48 |
return compilationState_.scopeContext.enclosingScopeIsArrow; |
| 49 |
} |
| 50 |
|
| 51 |
#ifdef DEBUG |
| 52 |
bool AbstractScopePtr::hasNonSyntacticScopeOnChain() const { |
| 53 |
if (isScopeStencil()) { |
| 54 |
if (kind() == ScopeKind::NonSyntactic) { |
| 55 |
return true; |
| 56 |
} |
| 57 |
return enclosing().hasNonSyntacticScopeOnChain(); |
| 58 |
} |
| 59 |
return compilationState_.scopeContext.hasNonSyntacticScopeOnChain; |
| 60 |
} |
| 61 |
#endif |