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/. */
7 #include "frontend/TDZCheckCache.h"
9 #include "frontend/BytecodeEmitter.h"
12 using namespace js::frontend
;
15 using mozilla::Nothing
;
18 TDZCheckCache::TDZCheckCache(BytecodeEmitter
* bce
)
19 : Nestable
<TDZCheckCache
>(&bce
->innermostTDZCheckCache
),
20 cache_(bce
->fc
->nameCollectionPool()) {}
22 bool TDZCheckCache::ensureCache(BytecodeEmitter
* bce
) {
23 return cache_
|| cache_
.acquire(bce
->fc
);
26 Maybe
<MaybeCheckTDZ
> TDZCheckCache::needsTDZCheck(BytecodeEmitter
* bce
,
27 TaggedParserAtomIndex name
) {
28 if (!ensureCache(bce
)) {
32 CheckTDZMap::AddPtr p
= cache_
->lookupForAdd(name
);
34 return Some(p
->value().wrapped
);
37 MaybeCheckTDZ rv
= CheckTDZ
;
38 for (TDZCheckCache
* it
= enclosing(); it
; it
= it
->enclosing()) {
40 if (CheckTDZMap::Ptr p2
= it
->cache_
->lookup(name
)) {
47 if (!cache_
->add(p
, name
, rv
)) {
48 ReportOutOfMemory(bce
->fc
);
55 bool TDZCheckCache::noteTDZCheck(BytecodeEmitter
* bce
,
56 TaggedParserAtomIndex name
,
57 MaybeCheckTDZ check
) {
58 if (!ensureCache(bce
)) {
62 CheckTDZMap::AddPtr p
= cache_
->lookupForAdd(name
);
66 "TDZ only needs to be checked once per binding per basic block.");
69 if (!cache_
->add(p
, name
, check
)) {
70 ReportOutOfMemory(bce
->fc
);