Bug 325352 part 1. Align our "defined insertion point" concept more closely with the spec's "script nesting level" concept. r=hsivonen
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 08 May 2019 06:10:47 +0000
changeset 531910 990c8a382cf38762b2d81bbcba3c56e1b9920bec
parent 531909 6986b4b5c3db2c68d9b8d694d942c01a265a1afd
child 531911 264fe248bca56c113116bd5cfde490ebb554e56a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs325352
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 325352 part 1. Align our "defined insertion point" concept more closely with the spec's "script nesting level" concept. r=hsivonen This also exposes an accessor for whether the parser has a nonzero script nesting level. Differential Revision: https://phabricator.services.mozilla.com/D30313
dom/script/ScriptElement.cpp
dom/script/nsIScriptElement.h
parser/html/nsHtml5Parser.cpp
parser/html/nsHtml5Parser.h
parser/htmlparser/nsIParser.h
parser/htmlparser/nsParser.cpp
parser/htmlparser/nsParser.h
parser/prototype/PrototypeDocumentParser.h
--- a/dom/script/ScriptElement.cpp
+++ b/dom/script/ScriptElement.cpp
@@ -20,21 +20,21 @@ using namespace mozilla::dom;
 
 NS_IMETHODIMP
 ScriptElement::ScriptAvailable(nsresult aResult, nsIScriptElement* aElement,
                                bool aIsInlineClassicScript, nsIURI* aURI,
                                int32_t aLineNo) {
   if (!aIsInlineClassicScript && NS_FAILED(aResult)) {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
     if (parser) {
-      parser->PushDefinedInsertionPoint();
+      parser->IncrementScriptNestingLevel();
     }
     nsresult rv = FireErrorEvent();
     if (parser) {
-      parser->PopDefinedInsertionPoint();
+      parser->DecrementScriptNestingLevel();
     }
     return rv;
   }
   return NS_OK;
 }
 
 /* virtual */
 nsresult ScriptElement::FireErrorEvent() {
--- a/dom/script/nsIScriptElement.h
+++ b/dom/script/nsIScriptElement.h
@@ -185,27 +185,27 @@ class nsIScriptElement : public nsIScrip
   }
 
   /**
    * Informs the creator parser that the evaluation of this script is starting
    */
   void BeginEvaluating() {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
     if (parser) {
-      parser->PushDefinedInsertionPoint();
+      parser->IncrementScriptNestingLevel();
     }
   }
 
   /**
    * Informs the creator parser that the evaluation of this script is ending
    */
   void EndEvaluating() {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
     if (parser) {
-      parser->PopDefinedInsertionPoint();
+      parser->DecrementScriptNestingLevel();
     }
   }
 
   /**
    * Retrieves a pointer to the creator parser if this has one or null if not
    */
   already_AddRefed<nsIParser> GetCreatorParser() {
     nsCOMPtr<nsIParser> parser = do_QueryReferent(mCreatorParser);
--- a/parser/html/nsHtml5Parser.cpp
+++ b/parser/html/nsHtml5Parser.cpp
@@ -35,17 +35,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
   tmp->DropStreamParser();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 nsHtml5Parser::nsHtml5Parser()
     : mLastWasCR(false),
       mDocWriteSpeculativeLastWasCR(false),
       mBlocked(0),
       mDocWriteSpeculatorActive(false),
-      mInsertionPointPushLevel(0),
+      mScriptNestingLevel(0),
       mDocumentClosed(false),
       mInDocumentWrite(false),
       mInsertionPointPermanentlyUndefined(false),
       mFirstBuffer(new nsHtml5OwningUTF16Buffer((void*)nullptr)),
       mLastBuffer(mFirstBuffer),
       mExecutor(new nsHtml5TreeOpExecutor()),
       mTreeBuilder(new nsHtml5TreeBuilder(mExecutor, nullptr)),
       mTokenizer(new nsHtml5Tokenizer(mTreeBuilder, false)),
@@ -522,22 +522,26 @@ nsHtml5Parser::CancelParsingEvents() {
   MOZ_ASSERT_UNREACHABLE("Don't call this!");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 void nsHtml5Parser::Reset() { MOZ_ASSERT_UNREACHABLE("Don't call this!"); }
 
 bool nsHtml5Parser::IsInsertionPointDefined() {
   return !mExecutor->IsFlushing() && !mInsertionPointPermanentlyUndefined &&
-         (!GetStreamParser() || mInsertionPointPushLevel);
+         (!GetStreamParser() || mScriptNestingLevel != 0);
 }
 
-void nsHtml5Parser::PushDefinedInsertionPoint() { ++mInsertionPointPushLevel; }
+void nsHtml5Parser::IncrementScriptNestingLevel() { ++mScriptNestingLevel; }
+
+void nsHtml5Parser::DecrementScriptNestingLevel() { --mScriptNestingLevel; }
 
-void nsHtml5Parser::PopDefinedInsertionPoint() { --mInsertionPointPushLevel; }
+bool nsHtml5Parser::HasNonzeroScriptNestingLevel() const {
+  return mScriptNestingLevel != 0;
+}
 
 void nsHtml5Parser::MarkAsNotScriptCreated(const char* aCommand) {
   MOZ_ASSERT(!mStreamListener, "Must not call this twice.");
   eParserMode mode = NORMAL;
   if (!nsCRT::strcmp(aCommand, "view-source")) {
     mode = VIEW_SOURCE_HTML;
   } else if (!nsCRT::strcmp(aCommand, "view-source-xml")) {
     mode = VIEW_SOURCE_XML;
--- a/parser/html/nsHtml5Parser.h
+++ b/parser/html/nsHtml5Parser.h
@@ -171,26 +171,34 @@ class nsHtml5Parser final : public nsIPa
 
   /**
    * True if the insertion point (per HTML5) is defined.
    */
   virtual bool IsInsertionPointDefined() override;
 
   /**
    * Call immediately before starting to evaluate a parser-inserted script or
-   * in general when the spec says to define an insertion point.
+   * in general when the spec says to increment the script nesting level.
    */
-  virtual void PushDefinedInsertionPoint() override;
+  void IncrementScriptNestingLevel() final;
 
   /**
    * Call immediately after having evaluated a parser-inserted script or
    * generally want to restore to the state before the last
-   * PushDefinedInsertionPoint call.
+   * IncrementScriptNestingLevel call.
    */
-  virtual void PopDefinedInsertionPoint() override;
+  void DecrementScriptNestingLevel() final;
+
+  /**
+   * True if this is an HTML5 parser whose script nesting level (in
+   * the sense of
+   * <https://html.spec.whatwg.org/multipage/parsing.html#script-nesting-level>)
+   * is nonzero.
+   */
+  bool HasNonzeroScriptNestingLevel() const final;
 
   /**
    * Marks the HTML5 parser as not a script-created parser: Prepares the
    * parser to be able to read a stream.
    *
    * @param aCommand the parser command (Yeah, this is bad API design. Let's
    * make this better when retiring nsIParser)
    */
@@ -269,20 +277,20 @@ class nsHtml5Parser final : public nsIPa
   uint32_t mBlocked;
 
   /**
    * Whether the document.write() speculator is already active.
    */
   bool mDocWriteSpeculatorActive;
 
   /**
-   * The number of PushDefinedInsertionPoint calls we've seen without a
-   * matching PopDefinedInsertionPoint.
+   * The number of IncrementScriptNestingLevel calls we've seen without a
+   * matching DecrementScriptNestingLevel.
    */
-  int32_t mInsertionPointPushLevel;
+  int32_t mScriptNestingLevel;
 
   /**
    * True if document.close() has been called.
    */
   bool mDocumentClosed;
 
   bool mInDocumentWrite;
 
--- a/parser/htmlparser/nsIParser.h
+++ b/parser/htmlparser/nsIParser.h
@@ -199,26 +199,34 @@ class nsIParser : public nsParserBase {
 
   /**
    * True if the insertion point (per HTML5) is defined.
    */
   virtual bool IsInsertionPointDefined() = 0;
 
   /**
    * Call immediately before starting to evaluate a parser-inserted script or
-   * in general when the spec says to define an insertion point.
+   * in general when the spec says to increment the script nesting level.
    */
-  virtual void PushDefinedInsertionPoint() = 0;
+  virtual void IncrementScriptNestingLevel() = 0;
 
   /**
    * Call immediately after having evaluated a parser-inserted script or
    * generally want to restore to the state before the last
-   * PushDefinedInsertionPoint call.
+   * IncrementScriptNestingLevel call.
    */
-  virtual void PopDefinedInsertionPoint() = 0;
+  virtual void DecrementScriptNestingLevel() = 0;
+
+  /**
+   * True if this is an HTML5 parser whose script nesting level (in
+   * the sense of
+   * <https://html.spec.whatwg.org/multipage/parsing.html#script-nesting-level>)
+   * is nonzero.
+   */
+  virtual bool HasNonzeroScriptNestingLevel() const = 0;
 
   /**
    * Marks the HTML5 parser as not a script-created parser.
    */
   virtual void MarkAsNotScriptCreated(const char* aCommand) = 0;
 
   /**
    * True if this is a script-created HTML5 parser.
--- a/parser/htmlparser/nsParser.cpp
+++ b/parser/htmlparser/nsParser.cpp
@@ -662,19 +662,21 @@ void nsParser::HandleParserContinueEvent
 
   NS_ASSERTION(IsOkToProcessNetworkData(),
                "Interrupted in the middle of a script?");
   ContinueInterruptedParsing();
 }
 
 bool nsParser::IsInsertionPointDefined() { return false; }
 
-void nsParser::PushDefinedInsertionPoint() {}
+void nsParser::IncrementScriptNestingLevel() {}
 
-void nsParser::PopDefinedInsertionPoint() {}
+void nsParser::DecrementScriptNestingLevel() {}
+
+bool nsParser::HasNonzeroScriptNestingLevel() const { return false; }
 
 void nsParser::MarkAsNotScriptCreated(const char* aCommand) {}
 
 bool nsParser::IsScriptCreated() { return false; }
 
 /**
  *  This is the main controlling routine in the parsing process.
  *  Note that it may get called multiple times for the same scanner,
--- a/parser/htmlparser/nsParser.h
+++ b/parser/htmlparser/nsParser.h
@@ -250,22 +250,24 @@ class nsParser final : public nsIParser,
   /**
    * Return true.
    */
   virtual bool IsInsertionPointDefined() override;
 
   /**
    * No-op.
    */
-  virtual void PushDefinedInsertionPoint() override;
+  void IncrementScriptNestingLevel() final;
 
   /**
    * No-op.
    */
-  virtual void PopDefinedInsertionPoint() override;
+  void DecrementScriptNestingLevel() final;
+
+  bool HasNonzeroScriptNestingLevel() const final;
 
   /**
    * No-op.
    */
   virtual void MarkAsNotScriptCreated(const char* aCommand) override;
 
   /**
    * Always false.
--- a/parser/prototype/PrototypeDocumentParser.h
+++ b/parser/prototype/PrototypeDocumentParser.h
@@ -93,19 +93,21 @@ class PrototypeDocumentParser final : pu
   NS_IMETHOD BuildModel() override { return NS_ERROR_NOT_IMPLEMENTED; }
 
   NS_IMETHOD CancelParsingEvents() override { return NS_ERROR_NOT_IMPLEMENTED; }
 
   virtual void Reset() override {}
 
   virtual bool IsInsertionPointDefined() override { return false; }
 
-  virtual void PushDefinedInsertionPoint() override {}
+  void IncrementScriptNestingLevel() final {}
 
-  virtual void PopDefinedInsertionPoint() override {}
+  void DecrementScriptNestingLevel() final {}
+
+  bool HasNonzeroScriptNestingLevel() const final { return false; }
 
   virtual void MarkAsNotScriptCreated(const char* aCommand) override {}
 
   virtual bool IsScriptCreated() override { return false; }
 
   // End nsIParser
 
  private: