2525e8f402
This is a follow-on to crrev.com/960883003, which fixed a memory leak in this code, but uncovered another, more subtle bug: Previously, the code expected you would v8::V8::Initialize once, and v8::V8::Dispose once. The first bug was that in this case the holder_ variable would point to deallocated memory. The second bug was that once the snapshot was disposed, there was no way to get it back on a future Initialize. These are uncovered by the InitializeAndDisposeMultiple test case. The fix is to keep memory to the raw snapshot and to then cleanly build & destroy the tables in Initialize & Dispose. Since sometimes setNativesBlob is called just after Initialize, that situation must be handled, too. BUG= Review URL: https://codereview.chromium.org/974943003 Cr-Commit-Position: refs/heads/master@{#26978}
50 lines
1.4 KiB
C++
50 lines
1.4 KiB
C++
// Copyright 2011 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef V8_NATIVES_H_
|
|
#define V8_NATIVES_H_
|
|
|
|
#include "src/vector.h"
|
|
|
|
namespace v8 { class StartupData; } // Forward declaration.
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
|
|
enum NativeType {
|
|
CORE, EXPERIMENTAL, D8, TEST
|
|
};
|
|
|
|
template <NativeType type>
|
|
class NativesCollection {
|
|
public:
|
|
// Number of built-in scripts.
|
|
static int GetBuiltinsCount();
|
|
// Number of debugger implementation scripts.
|
|
static int GetDebuggerCount();
|
|
|
|
// These are used to access built-in scripts. The debugger implementation
|
|
// scripts have an index in the interval [0, GetDebuggerCount()). The
|
|
// non-debugger scripts have an index in the interval [GetDebuggerCount(),
|
|
// GetNativesCount()).
|
|
static int GetIndex(const char* name);
|
|
static Vector<const char> GetScriptSource(int index);
|
|
static Vector<const char> GetScriptName(int index);
|
|
static Vector<const char> GetScriptsSource();
|
|
};
|
|
|
|
typedef NativesCollection<CORE> Natives;
|
|
typedef NativesCollection<EXPERIMENTAL> ExperimentalNatives;
|
|
|
|
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
|
|
// Used for reading the natives at runtime. Implementation in natives-empty.cc
|
|
void SetNativesFromFile(StartupData* natives_blob);
|
|
void ReadNatives();
|
|
void DisposeNatives();
|
|
#endif
|
|
|
|
} } // namespace v8::internal
|
|
|
|
#endif // V8_NATIVES_H_
|