5 #include "src/snapshot/natives.h" 7 #include "src/base/logging.h" 8 #include "src/snapshot/snapshot-source-sink.h" 9 #include "src/vector.h" 11 #ifndef V8_USE_EXTERNAL_STARTUP_DATA 12 #error natives-external.cc is used only for the external snapshot build. 13 #endif // V8_USE_EXTERNAL_STARTUP_DATA 30 for (
size_t i = 0;
i < native_names_.size();
i++) {
31 native_names_[
i].Dispose();
35 int GetBuiltinsCount() {
return static_cast<int>(native_ids_.size()); }
36 int GetDebuggerCount() {
return debugger_count_; }
39 return native_source_[index];
44 int GetIndex(
const char*
id) {
45 for (
int i = 0; i < static_cast<int>(native_ids_.size()); ++
i) {
46 int native_id_length = native_ids_[
i].length();
47 if ((static_cast<int>(strlen(
id)) == native_id_length) &&
48 (strncmp(
id, native_ids_[
i].start(), native_id_length) == 0)) {
66 int debugger_count = source->GetInt();
67 for (
int i = 0;
i < debugger_count; ++
i)
68 store->ReadNameAndContentPair(source);
69 int library_count = source->GetInt();
70 for (
int i = 0;
i < library_count; ++
i)
71 store->ReadNameAndContentPair(source);
73 store->debugger_count_ = debugger_count;
81 const char native[] =
"native ";
82 const char extension[] =
".js";
84 sizeof(extension) - 1));
85 memcpy(name.start(), native,
sizeof(native) - 1);
86 memcpy(name.start() +
sizeof(native) - 1,
id, id_length);
87 memcpy(name.start() +
sizeof(native) - 1 + id_length, extension,
88 sizeof(extension) - 1);
95 int id_length = bytes->GetBlob(&
id);
96 int source_length = bytes->GetBlob(&source);
97 native_ids_.emplace_back(reinterpret_cast<const char*>(
id), id_length);
98 native_source_.emplace_back(reinterpret_cast<const char*>(source),
100 native_names_.push_back(NameFromId(
id, id_length));
103 std::vector<Vector<const char>> native_ids_;
104 std::vector<Vector<const char>> native_names_;
105 std::vector<Vector<const char>> native_source_;
112 template<NativeType type>
123 static bool empty() {
return holder_ ==
nullptr; }
124 static void Dispose() {
133 template <NativeType type>
137 static StartupData* natives_blob_ =
nullptr;
148 NativesStore::MakeFromScriptsSource(&bytes));
149 DCHECK(!bytes.HasMore());
158 void SetNativesFromFile(StartupData* natives_blob) {
159 DCHECK(!natives_blob_);
160 DCHECK(natives_blob);
161 DCHECK(natives_blob->data);
162 DCHECK_GT(natives_blob->raw_size, 0);
164 natives_blob_ = natives_blob;
172 void DisposeNatives() {
173 NativesHolder<CORE>::Dispose();
174 NativesHolder<EXTRAS>::Dispose();
175 NativesHolder<EXPERIMENTAL_EXTRAS>::Dispose();
185 template<NativeType type>
186 int NativesCollection<type>::GetBuiltinsCount() {
187 return NativesHolder<type>::get()->GetBuiltinsCount();
190 template<NativeType type>
191 int NativesCollection<type>::GetDebuggerCount() {
192 return NativesHolder<type>::get()->GetDebuggerCount();
195 template<NativeType type>
196 int NativesCollection<type>::GetIndex(
const char* name) {
197 return NativesHolder<type>::get()->GetIndex(name);
200 template <NativeType type>
201 Vector<const char> NativesCollection<type>::GetScriptSource(
int index) {
202 return NativesHolder<type>::get()->GetScriptSource(index);
205 template<NativeType type>
206 Vector<const char> NativesCollection<type>::GetScriptName(
int index) {
207 return NativesHolder<type>::get()->GetScriptName(index);
210 template <NativeType type>
211 Vector<const char> NativesCollection<type>::GetScriptsSource() {
212 return NativesHolder<type>::get()->GetScriptsSource();
217 #define INSTANTIATE_TEMPLATES(T) \ 218 template int NativesCollection<T>::GetBuiltinsCount(); \ 219 template int NativesCollection<T>::GetDebuggerCount(); \ 220 template int NativesCollection<T>::GetIndex(const char* name); \ 221 template Vector<const char> NativesCollection<T>::GetScriptSource(int i); \ 222 template Vector<const char> NativesCollection<T>::GetScriptName(int i); \ 223 template Vector<const char> NativesCollection<T>::GetScriptsSource(); 224 INSTANTIATE_TEMPLATES(CORE)
225 INSTANTIATE_TEMPLATES(EXTRAS)
226 INSTANTIATE_TEMPLATES(EXPERIMENTAL_EXTRAS)
227 #undef INSTANTIATE_TEMPLATES