Commit 28a9dc2b authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

Remove JS natives support, step 1

The natives blob is deprecated and will be removed in the next
release.

This commit does two things, 1. it disables the v8_extra_library_files
gn argument which will make building natives_blob.bin through gn
impossible; 2. it marks API functions associated with the natives blob
as V8_DEPRECATE_SOON.

Embedders should remove any uses of SetNativesDataBlob and replace all
calls to

 InitializeExternalStartupData(const char*, const char*)

with the new function

 InitializeExternalStartupDataFromFile(const char*)

Step 2 is to mark API functions as V8_DEPRECATED.
Step 3, in the next V8 release, is to remove these functions and all
other natives support in V8.

Bug: v8:7624
Change-Id: I745e96c60204a9b94d9240be65dd59bb9bdd0699
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1824944
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64080}
parent 65d05bef
...@@ -156,9 +156,7 @@ declare_args() { ...@@ -156,9 +156,7 @@ declare_args() {
# List of extra files to snapshot. They will be snapshotted in order so # List of extra files to snapshot. They will be snapshotted in order so
# if files export symbols used by later files, they should go first. # if files export symbols used by later files, they should go first.
# v8_extra_library_files = []
# This default is used by cctests. Projects using V8 will want to override.
v8_extra_library_files = [ "//test/cctest/test-extra.js" ]
v8_enable_gdbjit = v8_enable_gdbjit =
((v8_current_cpu == "x86" || v8_current_cpu == "x64") && ((v8_current_cpu == "x86" || v8_current_cpu == "x64") &&
...@@ -258,6 +256,10 @@ assert( ...@@ -258,6 +256,10 @@ assert(
assert(v8_use_snapshot || !v8_enable_shared_ro_heap, assert(v8_use_snapshot || !v8_enable_shared_ro_heap,
"Shared read-only heap requires snapshot") "Shared read-only heap requires snapshot")
assert(v8_extra_library_files == [],
"v8_extra_library_files is no longer supported. Consider implementing " +
"custom API in C++ instead.")
v8_random_seed = "314159265" v8_random_seed = "314159265"
v8_toolset_for_shell = "host" v8_toolset_for_shell = "host"
......
...@@ -9004,7 +9004,9 @@ class V8_EXPORT V8 { ...@@ -9004,7 +9004,9 @@ class V8_EXPORT V8 {
* handled entirely on the embedders' side. * handled entirely on the embedders' side.
* - The call will abort if the data is invalid. * - The call will abort if the data is invalid.
*/ */
static void SetNativesDataBlob(StartupData* startup_blob); V8_DEPRECATE_SOON(
"The natives blob is deprecated (https://crbug.com/v8/7624).",
static void SetNativesDataBlob(StartupData* startup_blob));
static void SetSnapshotDataBlob(StartupData* startup_blob); static void SetSnapshotDataBlob(StartupData* startup_blob);
/** Set the callback to invoke in case of Dcheck failures. */ /** Set the callback to invoke in case of Dcheck failures. */
...@@ -9100,8 +9102,12 @@ class V8_EXPORT V8 { ...@@ -9100,8 +9102,12 @@ class V8_EXPORT V8 {
* not perform any file IO. * not perform any file IO.
*/ */
static void InitializeExternalStartupData(const char* directory_path); static void InitializeExternalStartupData(const char* directory_path);
static void InitializeExternalStartupData(const char* natives_blob, V8_DEPRECATE_SOON(
const char* snapshot_blob); "The natives blob is deprecated (https://crbug.com/v8/7624).",
static void InitializeExternalStartupData(const char* natives_blob,
const char* snapshot_blob));
static void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
/** /**
* Sets the v8::Platform to use. This should be invoked before V8 is * Sets the v8::Platform to use. This should be invoked before V8 is
* initialized. * initialized.
......
...@@ -5723,6 +5723,11 @@ void v8::V8::InitializeExternalStartupData(const char* natives_blob, ...@@ -5723,6 +5723,11 @@ void v8::V8::InitializeExternalStartupData(const char* natives_blob,
i::InitializeExternalStartupData(natives_blob, snapshot_blob); i::InitializeExternalStartupData(natives_blob, snapshot_blob);
} }
// static
void v8::V8::InitializeExternalStartupDataFromFile(const char* snapshot_blob) {
i::InitializeExternalStartupDataFromFile(snapshot_blob);
}
const char* v8::V8::GetVersion() { return i::Version::GetVersion(); } const char* v8::V8::GetVersion() { return i::Version::GetVersion(); }
template <typename ObjectType> template <typename ObjectType>
......
...@@ -3001,9 +3001,6 @@ bool Shell::SetOptions(int argc, char* argv[]) { ...@@ -3001,9 +3001,6 @@ bool Shell::SetOptions(int argc, char* argv[]) {
options.icu_locale = argv[i] + 13; options.icu_locale = argv[i] + 13;
argv[i] = nullptr; argv[i] = nullptr;
#ifdef V8_USE_EXTERNAL_STARTUP_DATA #ifdef V8_USE_EXTERNAL_STARTUP_DATA
} else if (strncmp(argv[i], "--natives_blob=", 15) == 0) {
options.natives_blob = argv[i] + 15;
argv[i] = nullptr;
} else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) { } else if (strncmp(argv[i], "--snapshot_blob=", 16) == 0) {
options.snapshot_blob = argv[i] + 16; options.snapshot_blob = argv[i] + 16;
argv[i] = nullptr; argv[i] = nullptr;
...@@ -3592,9 +3589,8 @@ int Shell::Main(int argc, char* argv[]) { ...@@ -3592,9 +3589,8 @@ int Shell::Main(int argc, char* argv[]) {
} }
v8::V8::InitializePlatform(g_platform.get()); v8::V8::InitializePlatform(g_platform.get());
v8::V8::Initialize(); v8::V8::Initialize();
if (options.natives_blob || options.snapshot_blob) { if (options.snapshot_blob) {
v8::V8::InitializeExternalStartupData(options.natives_blob, v8::V8::InitializeExternalStartupDataFromFile(options.snapshot_blob);
options.snapshot_blob);
} else { } else {
v8::V8::InitializeExternalStartupData(argv[0]); v8::V8::InitializeExternalStartupData(argv[0]);
} }
......
...@@ -285,7 +285,6 @@ class ShellOptions { ...@@ -285,7 +285,6 @@ class ShellOptions {
SourceGroup* isolate_sources = nullptr; SourceGroup* isolate_sources = nullptr;
const char* icu_data_file = nullptr; const char* icu_data_file = nullptr;
const char* icu_locale = nullptr; const char* icu_locale = nullptr;
const char* natives_blob = nullptr;
const char* snapshot_blob = nullptr; const char* snapshot_blob = nullptr;
bool trace_enabled = false; bool trace_enabled = false;
const char* trace_path = nullptr; const char* trace_path = nullptr;
......
...@@ -38,6 +38,10 @@ void FreeStartupData() { ...@@ -38,6 +38,10 @@ void FreeStartupData() {
DeleteStartupData(&g_snapshot); DeleteStartupData(&g_snapshot);
} }
// TODO(jgruber): Rename to FreeStartupData once natives support has been
// removed (https://crbug.com/v8/7624).
void FreeStartupDataSnapshotOnly() { DeleteStartupData(&g_snapshot); }
void Load(const char* blob_file, v8::StartupData* startup_data, void Load(const char* blob_file, v8::StartupData* startup_data,
void (*setter_fn)(v8::StartupData*)) { void (*setter_fn)(v8::StartupData*)) {
ClearStartupData(startup_data); ClearStartupData(startup_data);
...@@ -67,7 +71,7 @@ void Load(const char* blob_file, v8::StartupData* startup_data, ...@@ -67,7 +71,7 @@ void Load(const char* blob_file, v8::StartupData* startup_data,
} }
void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) { void LoadFromFiles(const char* natives_blob, const char* snapshot_blob) {
Load(natives_blob, &g_natives, v8::V8::SetNativesDataBlob); Load(natives_blob, &g_natives, i::V8::SetNativesBlob);
Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob); Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob);
atexit(&FreeStartupData); atexit(&FreeStartupData);
...@@ -101,5 +105,12 @@ void InitializeExternalStartupData(const char* natives_blob, ...@@ -101,5 +105,12 @@ void InitializeExternalStartupData(const char* natives_blob,
#endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA
} }
void InitializeExternalStartupDataFromFile(const char* snapshot_blob) {
#ifdef V8_USE_EXTERNAL_STARTUP_DATA
Load(snapshot_blob, &g_snapshot, v8::V8::SetSnapshotDataBlob);
atexit(&FreeStartupDataSnapshotOnly);
#endif // V8_USE_EXTERNAL_STARTUP_DATA
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -21,6 +21,7 @@ void InitializeExternalStartupData(const char* directory_path); ...@@ -21,6 +21,7 @@ void InitializeExternalStartupData(const char* directory_path);
void InitializeExternalStartupData(const char* natives_blob, void InitializeExternalStartupData(const char* natives_blob,
const char* snapshot_blob); const char* snapshot_blob);
void InitializeExternalStartupDataFromFile(const char* snapshot_blob);
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
This diff is collapsed.
...@@ -4509,7 +4509,7 @@ UNINITIALIZED_TEST(LoadedAtStartupScripts) { ...@@ -4509,7 +4509,7 @@ UNINITIALIZED_TEST(LoadedAtStartupScripts) {
} }
} }
CHECK_EQ(count_by_type[i::Script::TYPE_NATIVE], 0); CHECK_EQ(count_by_type[i::Script::TYPE_NATIVE], 0);
CHECK_EQ(count_by_type[i::Script::TYPE_EXTENSION], 2); CHECK_EQ(count_by_type[i::Script::TYPE_EXTENSION], 1);
CHECK_EQ(count_by_type[i::Script::TYPE_NORMAL], 1); CHECK_EQ(count_by_type[i::Script::TYPE_NORMAL], 1);
CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0); CHECK_EQ(count_by_type[i::Script::TYPE_WASM], 0);
CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0); CHECK_EQ(count_by_type[i::Script::TYPE_INSPECTOR], 0);
......
...@@ -265,7 +265,9 @@ def BuildMetadata(sources, source_bytes, native_type): ...@@ -265,7 +265,9 @@ def BuildMetadata(sources, source_bytes, native_type):
metadata = { metadata = {
"builtin_count": len(sources.modules), "builtin_count": len(sources.modules),
"sources_declaration": SOURCES_DECLARATION % ToCArray(source_bytes), "sources_declaration":
SOURCES_DECLARATION % ToCArray(
source_bytes if len(source_bytes) != 0 else "\0"),
"total_length": total_length, "total_length": total_length,
"get_index_cases": "".join(get_index_cases), "get_index_cases": "".join(get_index_cases),
"get_script_source_cases": "".join(get_script_source_cases), "get_script_source_cases": "".join(get_script_source_cases),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment