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 "src/heap/heap.h" | |
9 #include "src/heap/heap-inl.h" | |
10 #include "src/objects.h" | 8 #include "src/objects.h" |
11 #include "src/objects-inl.h" | |
12 #include "src/vector.h" | 9 #include "src/vector.h" |
13 | 10 |
14 namespace v8 { class StartupData; } // Forward declaration. | 11 namespace v8 { class StartupData; } // Forward declaration. |
15 | 12 |
16 namespace v8 { | 13 namespace v8 { |
17 namespace internal { | 14 namespace internal { |
18 | 15 |
19 enum NativeType { CORE, CODE_STUB, EXPERIMENTAL, EXTRAS, D8, TEST }; | 16 enum NativeType { CORE, CODE_STUB, EXPERIMENTAL, EXTRAS, D8, TEST }; |
20 | 17 |
21 template <NativeType type> | 18 template <NativeType type> |
22 class NativesCollection { | 19 class NativesCollection { |
23 public: | 20 public: |
24 // The following methods are implemented in js2c-generated code: | 21 // The following methods are implemented in js2c-generated code: |
25 | 22 |
26 // Number of built-in scripts. | 23 // Number of built-in scripts. |
27 static int GetBuiltinsCount(); | 24 static int GetBuiltinsCount(); |
28 // Number of debugger implementation scripts. | 25 // Number of debugger implementation scripts. |
29 static int GetDebuggerCount(); | 26 static int GetDebuggerCount(); |
30 | 27 |
31 // These are used to access built-in scripts. The debugger implementation | 28 // These are used to access built-in scripts. The debugger implementation |
32 // scripts have an index in the interval [0, GetDebuggerCount()). The | 29 // scripts have an index in the interval [0, GetDebuggerCount()). The |
33 // non-debugger scripts have an index in the interval [GetDebuggerCount(), | 30 // non-debugger scripts have an index in the interval [GetDebuggerCount(), |
34 // GetNativesCount()). | 31 // GetNativesCount()). |
35 static int GetIndex(const char* name); | 32 static int GetIndex(const char* name); |
36 static Vector<const char> GetScriptSource(int index); | 33 static Vector<const char> GetScriptSource(int index); |
37 static Vector<const char> GetScriptName(int index); | 34 static Vector<const char> GetScriptName(int index); |
38 static Vector<const char> GetScriptsSource(); | 35 static Vector<const char> GetScriptsSource(); |
39 | 36 |
40 // The following methods are implemented below: | 37 // The following methods are implemented in natives-common.cc: |
41 | 38 |
42 inline static FixedArray* GetSourceCache(Heap* heap); | 39 static FixedArray* GetSourceCache(Heap* heap); |
43 static void UpdateSourceCache(Heap* heap); | 40 static void UpdateSourceCache(Heap* heap); |
44 }; | 41 }; |
45 | 42 |
46 typedef NativesCollection<CORE> Natives; | 43 typedef NativesCollection<CORE> Natives; |
47 typedef NativesCollection<CODE_STUB> CodeStubNatives; | 44 typedef NativesCollection<CODE_STUB> CodeStubNatives; |
48 typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives; | 45 typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives; |
49 typedef NativesCollection<EXTRAS> ExtraNatives; | 46 typedef NativesCollection<EXTRAS> ExtraNatives; |
50 | 47 |
51 | 48 |
52 template <> | |
53 inline FixedArray* Natives::GetSourceCache(Heap* heap) { | |
54 return heap->natives_source_cache(); | |
55 } | |
56 | |
57 | |
58 template <> | |
59 inline FixedArray* ExperimentalNatives::GetSourceCache(Heap* heap) { | |
60 return heap->experimental_natives_source_cache(); | |
61 } | |
62 | |
63 | |
64 template <> | |
65 inline FixedArray* ExtraNatives::GetSourceCache(Heap* heap) { | |
66 return heap->extra_natives_source_cache(); | |
67 } | |
68 | |
69 | |
70 template <> | |
71 inline FixedArray* CodeStubNatives::GetSourceCache(Heap* heap) { | |
72 return heap->code_stub_natives_source_cache(); | |
73 } | |
74 | |
75 template <NativeType type> | |
76 void NativesCollection<type>::UpdateSourceCache(Heap* heap) { | |
77 for (int i = 0; i < GetBuiltinsCount(); i++) { | |
78 Object* source = GetSourceCache(heap)->get(i); | |
79 if (!source->IsUndefined()) { | |
80 ExternalOneByteString::cast(source)->update_data_cache(); | |
81 } | |
82 } | |
83 } | |
84 | |
85 | |
86 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 49 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
87 // Used for reading the natives at runtime. Implementation in natives-empty.cc | 50 // Used for reading the natives at runtime. Implementation in natives-empty.cc |
88 void SetNativesFromFile(StartupData* natives_blob); | 51 void SetNativesFromFile(StartupData* natives_blob); |
89 void ReadNatives(); | 52 void ReadNatives(); |
90 void DisposeNatives(); | 53 void DisposeNatives(); |
91 #endif | 54 #endif |
92 | 55 |
93 } } // namespace v8::internal | 56 } } // namespace v8::internal |
94 | 57 |
95 #endif // V8_SNAPSHOT_NATIVES_H_ | 58 #endif // V8_SNAPSHOT_NATIVES_H_ |
OLD | NEW |