/ runtime / ExecutableBase.cpp
ExecutableBase.cpp
  1  /*
  2   * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
  3   *
  4   * Redistribution and use in source and binary forms, with or without
  5   * modification, are permitted provided that the following conditions
  6   * are met:
  7   * 1. Redistributions of source code must retain the above copyright
  8   *    notice, this list of conditions and the following disclaimer.
  9   * 2. Redistributions in binary form must reproduce the above copyright
 10   *    notice, this list of conditions and the following disclaimer in the
 11   *    documentation and/or other materials provided with the distribution.
 12   *
 13   * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
 17   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21   * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 24   */
 25  
 26  #include "config.h"
 27  
 28  #include "EvalCodeBlock.h"
 29  #include "FunctionCodeBlock.h"
 30  #include "JSCellInlines.h"
 31  #include "ModuleProgramCodeBlock.h"
 32  #include "NativeExecutable.h"
 33  #include "ProgramCodeBlock.h"
 34  #include <wtf/CommaPrinter.h>
 35  
 36  namespace JSC {
 37  
 38  const ClassInfo ExecutableBase::s_info = { "Executable", nullptr, nullptr, nullptr, CREATE_METHOD_TABLE(ExecutableBase) };
 39  
 40  void ExecutableBase::destroy(JSCell* cell)
 41  {
 42      static_cast<ExecutableBase*>(cell)->ExecutableBase::~ExecutableBase();
 43  }
 44  
 45  void ExecutableBase::dump(PrintStream& out) const
 46  {
 47      ExecutableBase* realThis = const_cast<ExecutableBase*>(this);
 48  
 49      switch (type()) {
 50      case NativeExecutableType: {
 51          NativeExecutable* native = jsCast<NativeExecutable*>(realThis);
 52          out.print("NativeExecutable:", RawPointer(bitwise_cast<void*>(native->function())), "/", RawPointer(bitwise_cast<void*>(native->constructor())));
 53          return;
 54      }
 55      case EvalExecutableType: {
 56          EvalExecutable* eval = jsCast<EvalExecutable*>(realThis);
 57          if (CodeBlock* codeBlock = eval->codeBlock())
 58              out.print(*codeBlock);
 59          else
 60              out.print("EvalExecutable w/o CodeBlock");
 61          return;
 62      }
 63      case ProgramExecutableType: {
 64          ProgramExecutable* eval = jsCast<ProgramExecutable*>(realThis);
 65          if (CodeBlock* codeBlock = eval->codeBlock())
 66              out.print(*codeBlock);
 67          else
 68              out.print("ProgramExecutable w/o CodeBlock");
 69          return;
 70      }
 71      case ModuleProgramExecutableType: {
 72          ModuleProgramExecutable* executable = jsCast<ModuleProgramExecutable*>(realThis);
 73          if (CodeBlock* codeBlock = executable->codeBlock())
 74              out.print(*codeBlock);
 75          else
 76              out.print("ModuleProgramExecutable w/o CodeBlock");
 77          return;
 78      }
 79      case FunctionExecutableType: {
 80          FunctionExecutable* function = jsCast<FunctionExecutable*>(realThis);
 81          if (!function->eitherCodeBlock())
 82              out.print("FunctionExecutable w/o CodeBlock");
 83          else {
 84              CommaPrinter comma("/");
 85              if (function->codeBlockForCall())
 86                  out.print(comma, *function->codeBlockForCall());
 87              if (function->codeBlockForConstruct())
 88                  out.print(comma, *function->codeBlockForConstruct());
 89          }
 90          return;
 91      }
 92      default:
 93          RELEASE_ASSERT_NOT_REACHED();
 94      }
 95  }
 96  
 97  CodeBlockHash ExecutableBase::hashFor(CodeSpecializationKind kind) const
 98  {
 99      if (type() == NativeExecutableType)
100          return jsCast<const NativeExecutable*>(this)->hashFor(kind);
101      
102      return jsCast<const ScriptExecutable*>(this)->hashFor(kind);
103  }
104  
105  } // namespace JSC