Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: third_party/WebKit/Source/core/html/parser/HTMLParserReentryPermit.h

Issue 2200613002: The HTML parser synchronously creates custom elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Eliminate redundant TODOs. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef HTMLParserReentryPermit_h
6 #define HTMLParserReentryPermit_h
7
8 #include "base/macros.h"
9 #include "wtf/PassRefPtr.h"
10 #include "wtf/RefCounted.h"
11
12 namespace blink {
13
14 // The HTML spec for parsing controls reentering the parser from
15 // script with the "parser pause flag" and "script nesting level."
16 //
17 // The parser pause flag puts a brake on whether the tokenizer will
18 // produce more tokens. When the parser is paused, nested invocations
19 // of the tokenizer unwind.
20 //
21 // The script nesting level is incremented and decremented any time
22 // the parser causes script to run. The script nesting level:
23 //
24 // - May prevent document.open from blowing away the document.
25 //
26 // - Governs whether a script element becomes the "pending
27 // parsing-blocking script." The pending parsing-blocking script in
28 // turn affects whether document.write reenters the parser.
29 //
30 // Clearing the parser pause flag is simple: Whenever the script
31 // nesting level hits zero, the parser pause flag is cleared. However
32 // setting the parser pause flag is subtle.
33 //
34 // Processing a typical script end tag, or running a chain of pending
35 // parser-blocking scripts after that, does not set the parser pause
36 // flag. However recursively parsing end script tags, or running
37 // custom element constructors, does set the parser pause flag.
38 class HTMLParserReentryPermit final : public RefCounted<HTMLParserReentryPermit> {
39 public:
40 static PassRefPtr<HTMLParserReentryPermit> create();
41 ~HTMLParserReentryPermit() = default;
42
43 unsigned scriptNestingLevel() const { return m_scriptNestingLevel; }
44 bool parserPauseFlag() const { return m_parserPauseFlag; }
45 void pause()
46 {
47 CHECK(m_scriptNestingLevel);
48 m_parserPauseFlag = true;
49 }
50
51 class ScriptNestingLevelIncrementer final {
52 STACK_ALLOCATED();
53 public:
54 explicit ScriptNestingLevelIncrementer(HTMLParserReentryPermit* permit)
55 : m_permit(permit)
56 {
57 m_permit->m_scriptNestingLevel++;
58 }
59
60 ScriptNestingLevelIncrementer(ScriptNestingLevelIncrementer&&)
61 = default;
62
63 ~ScriptNestingLevelIncrementer()
64 {
65 m_permit->m_scriptNestingLevel--;
66 if (!m_permit->m_scriptNestingLevel)
67 m_permit->m_parserPauseFlag = false;
68 }
69
70 private:
71 HTMLParserReentryPermit* m_permit;
72
73 DISALLOW_COPY_AND_ASSIGN(ScriptNestingLevelIncrementer);
74 };
75
76 ScriptNestingLevelIncrementer incrementScriptNestingLevel()
77 {
78 return ScriptNestingLevelIncrementer(this);
79 }
80
81 private:
82 HTMLParserReentryPermit();
83
84 // https://html.spec.whatwg.org/#script-nesting-level
85 unsigned m_scriptNestingLevel;
86
87 // https://html.spec.whatwg.org/#parser-pause-flag
88 bool m_parserPauseFlag;
89
90 DISALLOW_COPY_AND_ASSIGN(HTMLParserReentryPermit);
91 };
92
93 } // namespace blink
94
95 #endif // HTMLParserReentryPermit_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698