Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(793)

Unified Diff: src/natives-external.cc

Issue 974943003: Fix Initialize & Dispose for external snapshot. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/natives.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/natives-external.cc
diff --git a/src/natives-external.cc b/src/natives-external.cc
index 109f9c5f47bfe14cf25a69365502ac1ef7993df7..437addc213ddbd5a34524f4b0c185d987afefd74 100644
--- a/src/natives-external.cc
+++ b/src/natives-external.cc
@@ -132,9 +132,10 @@ class NativesHolder {
DCHECK(store);
holder_ = store;
}
+ static bool empty() { return holder_ == NULL; }
static void Dispose() {
- DCHECK(holder_);
delete holder_;
+ holder_ = NULL;
}
private:
@@ -145,19 +146,36 @@ template<NativeType type>
NativesStore* NativesHolder<type>::holder_ = NULL;
+// The natives blob. Memory is owned by caller.
+static StartupData* natives_blob_ = NULL;
+
+
+/**
+ * Read the Natives blob, as previously set by SetNativesFromFile.
+ */
+void ReadNatives() {
+ if (natives_blob_ && NativesHolder<CORE>::empty()) {
+ SnapshotByteSource bytes(natives_blob_->data, natives_blob_->raw_size);
+ NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes));
+ NativesHolder<EXPERIMENTAL>::set(
+ NativesStore::MakeFromScriptsSource(&bytes));
+ DCHECK(!bytes.HasMore());
+ }
+}
+
+
/**
- * Read the Natives (library sources) blob, as generated by js2c + the build
+ * Set the Natives (library sources) blob, as generated by js2c + the build
* system.
*/
void SetNativesFromFile(StartupData* natives_blob) {
+ DCHECK(!natives_blob_);
DCHECK(natives_blob);
DCHECK(natives_blob->data);
DCHECK(natives_blob->raw_size > 0);
- SnapshotByteSource bytes(natives_blob->data, natives_blob->raw_size);
- NativesHolder<CORE>::set(NativesStore::MakeFromScriptsSource(&bytes));
- NativesHolder<EXPERIMENTAL>::set(NativesStore::MakeFromScriptsSource(&bytes));
- DCHECK(!bytes.HasMore());
+ natives_blob_ = natives_blob;
+ ReadNatives();
}
« no previous file with comments | « src/natives.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698