LCOV - code coverage report
Current view: top level - src/snapshot - natives.h (source / functions) Hit Total Coverage
Test: app.info Lines: 9 9 100.0 %
Date: 2019-04-17 Functions: 4 5 80.0 %

          Line data    Source code
       1             : // Copyright 2011 the V8 project 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 V8_SNAPSHOT_NATIVES_H_
       6             : #define V8_SNAPSHOT_NATIVES_H_
       7             : 
       8             : #include "include/v8.h"
       9             : #include "src/objects.h"
      10             : #include "src/vector.h"
      11             : 
      12             : namespace v8 { class StartupData; }  // Forward declaration.
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : 
      17             : enum NativeType {
      18             :   EXTRAS,
      19             :   TEST
      20             : };
      21             : 
      22             : // Extra handling for V8_EXPORT_PRIVATE in combination with USING_V8_SHARED
      23             : // since definition of methods of classes marked as dllimport is not allowed.
      24             : template <NativeType type>
      25             : #ifdef USING_V8_SHARED
      26             : class NativesCollection {
      27             : #else
      28             : class V8_EXPORT_PRIVATE NativesCollection {
      29             : #endif  // USING_V8_SHARED
      30             : 
      31             :  public:
      32             :   // The following methods are implemented in js2c-generated code:
      33             : 
      34             :   // Number of built-in scripts.
      35             :   static int GetBuiltinsCount();
      36             :   static int GetIndex(const char* name);
      37             :   static Vector<const char> GetScriptSource(int index);
      38             :   static Vector<const char> GetScriptName(int index);
      39             :   static Vector<const char> GetScriptsSource();
      40             : };
      41             : 
      42             : using ExtraNatives = NativesCollection<EXTRAS>;
      43             : 
      44             : #ifdef V8_USE_EXTERNAL_STARTUP_DATA
      45             : // Used for reading the natives at runtime. Implementation in natives-empty.cc
      46             : void SetNativesFromFile(StartupData* natives_blob);
      47             : void ReadNatives();
      48             : void DisposeNatives();
      49             : #endif
      50             : 
      51      124838 : class NativesExternalStringResource final
      52             :     : public v8::String::ExternalOneByteStringResource {
      53             :  public:
      54             :   NativesExternalStringResource(NativeType type, int index);
      55             : 
      56     5789510 :   const char* data() const override { return data_; }
      57       62546 :   size_t length() const override { return length_; }
      58             : 
      59             :   v8::String::ExternalOneByteStringResource* EncodeForSerialization() const {
      60             :     DCHECK(type_ == EXTRAS);
      61         206 :     intptr_t val = (index_ << 1) | 1;
      62         206 :     val = val << kSystemPointerSizeLog2;  // Pointer align.
      63             :     return reinterpret_cast<v8::String::ExternalOneByteStringResource*>(val);
      64             :   }
      65             : 
      66             :   // Decode from serialization.
      67       62325 :   static NativesExternalStringResource* DecodeForDeserialization(
      68             :       const v8::String::ExternalOneByteStringResource* encoded) {
      69             :     intptr_t val =
      70       62325 :         reinterpret_cast<intptr_t>(encoded) >> kSystemPointerSizeLog2;
      71             :     DCHECK(val & 1);
      72       62325 :     int index = static_cast<int>(val >> 1);
      73       62325 :     return new NativesExternalStringResource(EXTRAS, index);
      74             :   }
      75             : 
      76             :  private:
      77             :   const char* data_;
      78             :   size_t length_;
      79             :   NativeType type_;
      80             :   int index_;
      81             : };
      82             : 
      83             : }  // namespace internal
      84             : }  // namespace v8
      85             : 
      86             : #endif  // V8_SNAPSHOT_NATIVES_H_

Generated by: LCOV version 1.10