| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #ifndef V8_SNAPSHOT_NATIVES_H_ | 5 #ifndef V8_SNAPSHOT_NATIVES_H_ | 
| 6 #define V8_SNAPSHOT_NATIVES_H_ | 6 #define V8_SNAPSHOT_NATIVES_H_ | 
| 7 | 7 | 
|  | 8 #include "include/v8.h" | 
| 8 #include "src/objects.h" | 9 #include "src/objects.h" | 
| 9 #include "src/vector.h" | 10 #include "src/vector.h" | 
| 10 | 11 | 
| 11 namespace v8 { class StartupData; }  // Forward declaration. | 12 namespace v8 { class StartupData; }  // Forward declaration. | 
| 12 | 13 | 
| 13 namespace v8 { | 14 namespace v8 { | 
| 14 namespace internal { | 15 namespace internal { | 
| 15 | 16 | 
| 16 enum NativeType { | 17 enum NativeType { | 
| 17   CORE, | 18   CORE, | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 39   static int GetDebuggerCount(); | 40   static int GetDebuggerCount(); | 
| 40 | 41 | 
| 41   // These are used to access built-in scripts.  The debugger implementation | 42   // These are used to access built-in scripts.  The debugger implementation | 
| 42   // scripts have an index in the interval [0, GetDebuggerCount()).  The | 43   // scripts have an index in the interval [0, GetDebuggerCount()).  The | 
| 43   // non-debugger scripts have an index in the interval [GetDebuggerCount(), | 44   // non-debugger scripts have an index in the interval [GetDebuggerCount(), | 
| 44   // GetNativesCount()). | 45   // GetNativesCount()). | 
| 45   static int GetIndex(const char* name); | 46   static int GetIndex(const char* name); | 
| 46   static Vector<const char> GetScriptSource(int index); | 47   static Vector<const char> GetScriptSource(int index); | 
| 47   static Vector<const char> GetScriptName(int index); | 48   static Vector<const char> GetScriptName(int index); | 
| 48   static Vector<const char> GetScriptsSource(); | 49   static Vector<const char> GetScriptsSource(); | 
| 49 |  | 
| 50   // The following methods are implemented in natives-common.cc: |  | 
| 51 |  | 
| 52   static FixedArray* GetSourceCache(Heap* heap); |  | 
| 53 }; | 50 }; | 
| 54 | 51 | 
| 55 typedef NativesCollection<CORE> Natives; | 52 typedef NativesCollection<CORE> Natives; | 
| 56 typedef NativesCollection<EXTRAS> ExtraNatives; | 53 typedef NativesCollection<EXTRAS> ExtraNatives; | 
| 57 typedef NativesCollection<EXPERIMENTAL_EXTRAS> ExperimentalExtraNatives; | 54 typedef NativesCollection<EXPERIMENTAL_EXTRAS> ExperimentalExtraNatives; | 
| 58 | 55 | 
| 59 | 56 | 
| 60 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 57 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 
| 61 // Used for reading the natives at runtime. Implementation in natives-empty.cc | 58 // Used for reading the natives at runtime. Implementation in natives-empty.cc | 
| 62 void SetNativesFromFile(StartupData* natives_blob); | 59 void SetNativesFromFile(StartupData* natives_blob); | 
| 63 void ReadNatives(); | 60 void ReadNatives(); | 
| 64 void DisposeNatives(); | 61 void DisposeNatives(); | 
| 65 #endif | 62 #endif | 
| 66 | 63 | 
|  | 64 class NativesExternalStringResource final | 
|  | 65     : public v8::String::ExternalOneByteStringResource { | 
|  | 66  public: | 
|  | 67   NativesExternalStringResource(NativeType type, int index); | 
|  | 68 | 
|  | 69   const char* data() const override { return data_; } | 
|  | 70   size_t length() const override { return length_; } | 
|  | 71 | 
|  | 72   v8::String::ExternalOneByteStringResource* EncodeForSerialization() const { | 
|  | 73     DCHECK(type_ == CORE || type_ == EXTRAS); | 
|  | 74     intptr_t val = (index_ << 1) | ((type_ == CORE) ? 0 : 1); | 
|  | 75     val = val << kPointerSizeLog2;  // Pointer align. | 
|  | 76     return reinterpret_cast<v8::String::ExternalOneByteStringResource*>(val); | 
|  | 77   } | 
|  | 78 | 
|  | 79   // Decode from serialization. | 
|  | 80   static NativesExternalStringResource* DecodeForDeserialization( | 
|  | 81       const v8::String::ExternalOneByteStringResource* encoded) { | 
|  | 82     intptr_t val = reinterpret_cast<intptr_t>(encoded) >> kPointerSizeLog2; | 
|  | 83     NativeType type = (val & 1) ? EXTRAS : CORE; | 
|  | 84     int index = static_cast<int>(val >> 1); | 
|  | 85     return new NativesExternalStringResource(type, index); | 
|  | 86   } | 
|  | 87 | 
|  | 88  private: | 
|  | 89   const char* data_; | 
|  | 90   size_t length_; | 
|  | 91   NativeType type_; | 
|  | 92   int index_; | 
|  | 93 }; | 
|  | 94 | 
| 67 }  // namespace internal | 95 }  // namespace internal | 
| 68 }  // namespace v8 | 96 }  // namespace v8 | 
| 69 | 97 | 
| 70 #endif  // V8_SNAPSHOT_NATIVES_H_ | 98 #endif  // V8_SNAPSHOT_NATIVES_H_ | 
| OLD | NEW | 
|---|