• Joyee Cheung's avatar
    [class] implement static private methods · 4e8c6281
    Joyee Cheung authored
    This patch refactors the declaration and allocation of the class variable, and
    implements static private methods:
    
    
    - The class variable is declared in the class scope with an explicit
      reference through class_scope->class_variable(). Anonymous classes
      whose class variable may be accessed transitively through static
      private method access use the dot string as the class name. Whether
      the class variable is allocated depending on whether it is used.
      Other references of the class variable in the ClassLiteral AST node
      and the ClassInfo structure are removed in favor of the reference
      through the class scope.
    - Previously the class variable was always (stack- or context-)
      allocated if the class is named. Now if the class variable is only
      referenced by name, it's stack allocated. If it's used transitively
      by access to static private methods, or may be used through eval,
      it's context allocated. Therefore we now use 1 less context slots
      in the class context if it's a named class without anyone referencing
      it by name in inner scopes.
    - Explicit access to static private methods or potential access to
      static private methods through eval results in forced context
      allocation of the class variables. In those cases, we save its index
      in context locals in the ScopeInfo and deserialize it later, so that
      we can check that the receiver of static private methods is the class
      constructor at run time. This flag is recorded as
      HasSavedClassVariableIndexField in the scope info.
    - Classes that need the class variable to be saved due to
      access to static private methods now save a
      ShouldSaveClassVariableIndexField in the preparse data so that the
      bits on the variables can be updated during a reparse. In the case
      of anonymous classes that need the class variables to be saved,
      we also re-declare the class variable after the reparse since
      the inner functions are skipped and we need to rely on the preparse
      data flags to remember declaring it.
    
    Design doc: https://docs.google.com/document/d/1rgGRw5RdzaRrM-GrIMhsn-DLULtADV2dmIdh_iIZxlc/edit
    
    Bug: v8:8330
    Change-Id: Idd07803f47614e97ad202de3b7faa9f71105eac5
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1781011
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
    Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#64219}
    4e8c6281
preparse-data.h 9.3 KB