Debian Codegraph @

js/src/vm/RegExpStatics.cpp

raw
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 "vm/RegExpStatics.h"
8
9 #include "gc/Zone.h"
10 #include "vm/RegExpShared.h"
11
12 using namespace js;
13
14 // static
15 UniquePtr<RegExpStatics> RegExpStatics::create(JSContext* cx) {
16 return cx->make_unique<RegExpStatics>();
17 }
18
19 bool RegExpStatics::executeLazy(JSContext* cx) {
20 if (!pendingLazyEvaluation) {
21 return true;
22 }
23
24 MOZ_ASSERT(lazySource);
25 MOZ_ASSERT(matchesInput);
26 MOZ_ASSERT(lazyIndex != size_t(-1));
27
28 /* Retrieve or create the RegExpShared in this zone. */
29 Rooted<JSAtom*> source(cx, lazySource);
30 RootedRegExpShared shared(cx,
31 cx->zone()->regExps().get(cx, source, lazyFlags));
32 if (!shared) {
33 return false;
34 }
35
36 /*
37 * It is not necessary to call aboutToWrite(): evaluation of
38 * implicit copies is safe.
39 */
40
41 /* Execute the full regular expression. */
42 Rooted<JSLinearString*> input(cx, matchesInput);
43 RegExpRunStatus status =
44 RegExpShared::execute(cx, &shared, input, lazyIndex, &this->matches);
45 if (status == RegExpRunStatus::Error) {
46 return false;
47 }
48
49 /*
50 * RegExpStatics are only updated on successful (matching) execution.
51 * Re-running the same expression must therefore produce a matching result.
52 */
53 MOZ_ASSERT(status == RegExpRunStatus::Success);
54
55 /* Unset lazy state and remove rooted values that now have no use. */
56 pendingLazyEvaluation = false;
57 lazySource = nullptr;
58 lazyIndex = size_t(-1);
59
60 return true;
61 }