| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 /** | 153 /** |
| 154 * Read the Natives blob, as previously set by SetNativesFromFile. | 154 * Read the Natives blob, as previously set by SetNativesFromFile. |
| 155 */ | 155 */ |
| 156 void ReadNatives() { | 156 void ReadNatives() { |
| 157 if (natives_blob_ && NativesHolder<CORE>::empty()) { | 157 if (natives_blob_ && NativesHolder<CORE>::empty()) { |
| 158 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); | 158 SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size); |
| 159 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); | 159 NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes)); |
| 160 NativesHolder<EXPERIMENTAL>::set( | 160 NativesHolder<EXPERIMENTAL>::set( |
| 161 NativesStore::MakeFromScriptsSource(&bytes)); | 161 NativesStore::MakeFromScriptsSource(&bytes)); |
| 162 NativesHolder<EXTRAS>::set(NativesStore::MakeFromScriptsSource(&bytes)); | |
| 163 DCHECK(!bytes.HasMore()); | 162 DCHECK(!bytes.HasMore()); |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 | 165 |
| 167 | 166 |
| 168 /** | 167 /** |
| 169 * Set the Natives (library sources) blob, as generated by js2c + the build | 168 * Set the Natives (library sources) blob, as generated by js2c + the build |
| 170 * system. | 169 * system. |
| 171 */ | 170 */ |
| 172 void SetNativesFromFile(StartupData* natives_blob) { | 171 void SetNativesFromFile(StartupData* natives_blob) { |
| 173 DCHECK(!natives_blob_); | 172 DCHECK(!natives_blob_); |
| 174 DCHECK(natives_blob); | 173 DCHECK(natives_blob); |
| 175 DCHECK(natives_blob->data); | 174 DCHECK(natives_blob->data); |
| 176 DCHECK(natives_blob->raw_size > 0); | 175 DCHECK(natives_blob->raw_size > 0); |
| 177 | 176 |
| 178 natives_blob_ = natives_blob; | 177 natives_blob_ = natives_blob; |
| 179 ReadNatives(); | 178 ReadNatives(); |
| 180 } | 179 } |
| 181 | 180 |
| 182 | 181 |
| 183 /** | 182 /** |
| 184 * Release memory allocated by SetNativesFromFile. | 183 * Release memory allocated by SetNativesFromFile. |
| 185 */ | 184 */ |
| 186 void DisposeNatives() { | 185 void DisposeNatives() { |
| 187 NativesHolder<CORE>::Dispose(); | 186 NativesHolder<CORE>::Dispose(); |
| 188 NativesHolder<EXPERIMENTAL>::Dispose(); | 187 NativesHolder<EXPERIMENTAL>::Dispose(); |
| 189 NativesHolder<EXTRAS>::Dispose(); | |
| 190 } | 188 } |
| 191 | 189 |
| 192 | 190 |
| 193 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. | 191 // Implement NativesCollection<T> bsaed on NativesHolder + NativesStore. |
| 194 // | 192 // |
| 195 // (The callers expect a purely static interface, since this is how the | 193 // (The callers expect a purely static interface, since this is how the |
| 196 // natives are usually compiled in. Since we implement them based on | 194 // natives are usually compiled in. Since we implement them based on |
| 197 // runtime content, we have to implement this indirection to offer | 195 // runtime content, we have to implement this indirection to offer |
| 198 // a static interface.) | 196 // a static interface.) |
| 199 template<NativeType type> | 197 template<NativeType type> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 224 template <NativeType type> | 222 template <NativeType type> |
| 225 Vector<const char> NativesCollection<type>::GetScriptsSource() { | 223 Vector<const char> NativesCollection<type>::GetScriptsSource() { |
| 226 return NativesHolder<type>::get()->GetScriptsSource(); | 224 return NativesHolder<type>::get()->GetScriptsSource(); |
| 227 } | 225 } |
| 228 | 226 |
| 229 | 227 |
| 230 // The compiler can't 'see' all uses of the static methods and hence | 228 // The compiler can't 'see' all uses of the static methods and hence |
| 231 // my choice to elide them. This we'll explicitly instantiate these. | 229 // my choice to elide them. This we'll explicitly instantiate these. |
| 232 template class NativesCollection<CORE>; | 230 template class NativesCollection<CORE>; |
| 233 template class NativesCollection<EXPERIMENTAL>; | 231 template class NativesCollection<EXPERIMENTAL>; |
| 234 template class NativesCollection<EXTRAS>; | |
| 235 | 232 |
| 236 } // namespace v8::internal | 233 } // namespace v8::internal |
| 237 } // namespace v8 | 234 } // namespace v8 |
| OLD | NEW |