| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "src/snapshot/natives.h" | 5 #include "src/snapshot/natives.h" |
| 6 | 6 |
| 7 #include "src/base/logging.h" | 7 #include "src/base/logging.h" |
| 8 #include "src/list.h" | 8 #include "src/list.h" |
| 9 #include "src/list-inl.h" | 9 #include "src/list-inl.h" |
| 10 #include "src/snapshot/snapshot-source-sink.h" | 10 #include "src/snapshot/snapshot-source-sink.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 static StartupData* natives_blob_ = NULL; | 144 static StartupData* natives_blob_ = NULL; |
| 145 | 145 |
| 146 | 146 |
| 147 /** | 147 /** |
| 148 * Read the Natives blob, as previously set by SetNativesFromFile. | 148 * Read the Natives blob, as previously set by SetNativesFromFile. |
| 149 */ | 149 */ |
| 150 void ReadNatives() { | 150 void ReadNatives() { |
| 151 if (natives_blob_ && NativesHolder<CORE>::empty()) { | 151 if (natives_blob_ && NativesHolder<CORE>::empty()) { |
| 152 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); | 152 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); |
| 153 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); | 153 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 154 NativesHolder<EXPERIMENTAL>::set( | |
| 155 NativesStore::MakeFromScriptsSource(&bytes)); | |
| 156 NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes)); | 154 NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 157 NativesHolder<EXPERIMENTAL_EXTRAS>::set( | 155 NativesHolder<EXPERIMENTAL_EXTRAS>::set( |
| 158 NativesStore::MakeFromScriptsSource(&bytes)); | 156 NativesStore::MakeFromScriptsSource(&bytes)); |
| 159 DCHECK(!bytes.HasMore()); | 157 DCHECK(!bytes.HasMore()); |
| 160 } | 158 } |
| 161 } | 159 } |
| 162 | 160 |
| 163 | 161 |
| 164 /** | 162 /** |
| 165 * Set the Natives (library sources) blob, as generated by js2c + the build | 163 * Set the Natives (library sources) blob, as generated by js2c + the build |
| 166 * system. | 164 * system. |
| 167 */ | 165 */ |
| 168 void SetNativesFromFile(StartupData* natives_blob) { | 166 void SetNativesFromFile(StartupData* natives_blob) { |
| 169 DCHECK(!natives_blob_); | 167 DCHECK(!natives_blob_); |
| 170 DCHECK(natives_blob); | 168 DCHECK(natives_blob); |
| 171 DCHECK(natives_blob->data); | 169 DCHECK(natives_blob->data); |
| 172 DCHECK(natives_blob->raw_size > 0); | 170 DCHECK(natives_blob->raw_size > 0); |
| 173 | 171 |
| 174 natives_blob_ = natives_blob; | 172 natives_blob_ = natives_blob; |
| 175 ReadNatives(); | 173 ReadNatives(); |
| 176 } | 174 } |
| 177 | 175 |
| 178 | 176 |
| 179 /** | 177 /** |
| 180 * Release memory allocated by SetNativesFromFile. | 178 * Release memory allocated by SetNativesFromFile. |
| 181 */ | 179 */ |
| 182 void DisposeNatives() { | 180 void DisposeNatives() { |
| 183 NativesHolder<CORE>::Dispose(); | 181 NativesHolder<CORE>::Dispose(); |
| 184 NativesHolder<EXPERIMENTAL>::Dispose(); | |
| 185 NativesHolder<EXTRAS>::Dispose(); | 182 NativesHolder<EXTRAS>::Dispose(); |
| 186 NativesHolder<EXPERIMENTAL_EXTRAS>::Dispose(); | 183 NativesHolder<EXPERIMENTAL_EXTRAS>::Dispose(); |
| 187 } | 184 } |
| 188 | 185 |
| 189 | 186 |
| 190 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. | 187 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. |
| 191 // | 188 // |
| 192 // (The callers expect a purely static interface, since this is how the | 189 // (The callers expect a purely static interface, since this is how the |
| 193 // natives are usually compiled in. Since we implement them based on | 190 // natives are usually compiled in. Since we implement them based on |
| 194 // runtime content, we have to implement this indirection to offer | 191 // runtime content, we have to implement this indirection to offer |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 223 |
| 227 // Explicit template instantiations. | 224 // Explicit template instantiations. |
| 228 #define INSTANTIATE_TEMPLATES(T) \ | 225 #define INSTANTIATE_TEMPLATES(T) \ |
| 229 template int NativesCollection<T>::GetBuiltinsCount(); \ | 226 template int NativesCollection<T>::GetBuiltinsCount(); \ |
| 230 template int NativesCollection<T>::GetDebuggerCount(); \ | 227 template int NativesCollection<T>::GetDebuggerCount(); \ |
| 231 template int NativesCollection<T>::GetIndex(const char* name); \ | 228 template int NativesCollection<T>::GetIndex(const char* name); \ |
| 232 template Vector<const char> NativesCollection<T>::GetScriptSource(int i); \ | 229 template Vector<const char> NativesCollection<T>::GetScriptSource(int i); \ |
| 233 template Vector<const char> NativesCollection<T>::GetScriptName(int i); \ | 230 template Vector<const char> NativesCollection<T>::GetScriptName(int i); \ |
| 234 template Vector<const char> NativesCollection<T>::GetScriptsSource(); | 231 template Vector<const char> NativesCollection<T>::GetScriptsSource(); |
| 235 INSTANTIATE_TEMPLATES(CORE) | 232 INSTANTIATE_TEMPLATES(CORE) |
| 236 INSTANTIATE_TEMPLATES(EXPERIMENTAL) | |
| 237 INSTANTIATE_TEMPLATES(EXTRAS) | 233 INSTANTIATE_TEMPLATES(EXTRAS) |
| 238 INSTANTIATE_TEMPLATES(EXPERIMENTAL_EXTRAS) | 234 INSTANTIATE_TEMPLATES(EXPERIMENTAL_EXTRAS) |
| 239 #undef INSTANTIATE_TEMPLATES | 235 #undef INSTANTIATE_TEMPLATES |
| 240 | 236 |
| 241 } // namespace internal | 237 } // namespace internal |
| 242 } // namespace v8 | 238 } // namespace v8 |
| OLD | NEW |