Commit 6e72b810 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[API] Allow copying of structs with deprecated fields

The implicit copy constructor triggers a deprecation warning if the
struct contains a deprecated field. We can fix this by explicitly
declaring the copy and move constructors and assignment operators
with the deprecation warning disabled.

This CL also adds a test to check that we can indeed call the
constructors and assignment operators, which did not work before.

R=leszeks@chromium.org

Bug: v8:13092
Change-Id: Ia63ff9375de13fc6e5b5a8d59d827a742c99fb39
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3785145Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81962}
parent f7ad199e
......@@ -1234,7 +1234,6 @@ filegroup(
"src/codegen/unoptimized-compilation-info.h",
"src/common/assert-scope.cc",
"src/common/assert-scope.h",
"src/common/allow-deprecated.h",
"src/common/checks.h",
"src/common/code-memory-access-inl.h",
"src/common/code-memory-access.cc",
......
......@@ -2834,7 +2834,6 @@ v8_header_set("v8_internal_headers") {
"src/codegen/tnode.h",
"src/codegen/turbo-assembler.h",
"src/codegen/unoptimized-compilation-info.h",
"src/common/allow-deprecated.h",
"src/common/assert-scope.h",
"src/common/checks.h",
"src/common/code-memory-access-inl.h",
......
......@@ -211,6 +211,8 @@ class V8_EXPORT Isolate {
CreateParams();
~CreateParams();
ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(CreateParams)
/**
* Allows the host application to provide the address of a function that is
* notified each time code is added, moved or removed.
......
......@@ -486,6 +486,34 @@ path. Add it with -I<path> to the command line
#endif
#if defined(V8_IMMINENT_DEPRECATION_WARNINGS) || \
defined(V8_DEPRECATION_WARNINGS)
#if defined(V8_CC_MSVC)
# define START_ALLOW_USE_DEPRECATED() \
__pragma(warning(push)) \
__pragma(warning(disable : 4996))
# define END_ALLOW_USE_DEPRECATED() __pragma(warning(pop))
#else // !defined(V8_CC_MSVC)
# define START_ALLOW_USE_DEPRECATED() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define END_ALLOW_USE_DEPRECATED() _Pragma("GCC diagnostic pop")
#endif // !defined(V8_CC_MSVC)
#else // !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
// defined(V8_DEPRECATION_WARNINGS))
#define START_ALLOW_USE_DEPRECATED()
#define END_ALLOW_USE_DEPRECATED()
#endif // !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
// defined(V8_DEPRECATION_WARNINGS))
#define ALLOW_COPY_AND_MOVE_WITH_DEPRECATED_FIELDS(ClassName) \
START_ALLOW_USE_DEPRECATED() \
ClassName(const ClassName&) = default; \
ClassName(ClassName&&) = default; \
ClassName& operator=(const ClassName&) = default; \
ClassName& operator=(ClassName&&) = default; \
END_ALLOW_USE_DEPRECATED()
#if defined(__GNUC__) && !defined(__clang__) && (__GNUC__ < 6)
# define V8_ENUM_DEPRECATED(message)
# define V8_ENUM_DEPRECATE_SOON(message)
......
// Copyright 2022 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_COMMON_ALLOW_DEPRECATED_H_
#define V8_COMMON_ALLOW_DEPRECATED_H_
#if defined(V8_IMMINENT_DEPRECATION_WARNINGS) || \
defined(V8_DEPRECATION_WARNINGS)
#if defined(V8_CC_MSVC)
#define START_ALLOW_USE_DEPRECATED() \
__pragma(warning(push)) __pragma(warning(disable : 4996))
#define END_ALLOW_USE_DEPRECATED() __pragma(warning(pop))
#else // !defined(V8_CC_MSVC)
#define START_ALLOW_USE_DEPRECATED() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define END_ALLOW_USE_DEPRECATED() _Pragma("GCC diagnostic pop")
#endif // !defined(V8_CC_MSVC)
#else // !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
// defined(V8_DEPRECATION_WARNINGS))
#define START_ALLOW_USE_DEPRECATED()
#define END_ALLOW_USE_DEPRECATED()
#endif // !(defined(V8_IMMINENT_DEPRECATION_WARNINGS) ||
// defined(V8_DEPRECATION_WARNINGS))
#endif // V8_COMMON_ALLOW_DEPRECATED_H_
......@@ -10,7 +10,6 @@
#include "include/v8-cppgc.h"
#include "include/v8-embedder-heap.h"
#include "include/v8-traced-handle.h"
#include "src/common/allow-deprecated.h"
#include "src/common/globals.h"
#include "src/execution/isolate.h"
#include "src/flags/flags.h"
......
......@@ -14,7 +14,6 @@
#include "src/api/api-inl.h"
#include "src/api/api-natives.h"
#include "src/base/logging.h"
#include "src/common/allow-deprecated.h"
#include "src/execution/execution.h"
#include "src/execution/isolate.h"
#include "src/execution/messages.h"
......
......@@ -29493,3 +29493,22 @@ TEST(EmbedderInstanceTypes) {
env->Global()->Get(env.local(), v8_str("x")).ToLocalChecked();
CHECK_EQ(1, res->ToInt32(env.local()).ToLocalChecked()->Value());
}
UNINITIALIZED_TEST(IsolateCreateParamsIsMovableAndCopyable) {
// A struct with deprecated fields will trigger a deprecation warning when
// using the copy or move constructor (without special care), see
// https://crbug.com/v8/13092.
// Test that we can use the move- and copy constructor of
// Isolate::CreateParams.
v8::Isolate::CreateParams params;
// Use move constructor.
v8::Isolate::CreateParams params2{std::move(params)};
// Use copy constructor.
v8::Isolate::CreateParams params3{params2};
// Use move assignment.
params = std::move(params2);
// Use copy assignment.
params = params2;
}
......@@ -28,7 +28,6 @@
#include "include/v8-function.h"
#include "include/v8-locker.h"
#include "src/api/api-inl.h"
#include "src/common/allow-deprecated.h"
#include "src/execution/isolate.h"
#include "src/handles/global-handles.h"
#include "src/heap/factory.h"
......
......@@ -38,7 +38,6 @@
#include "src/base/optional.h"
#include "src/base/strings.h"
#include "src/codegen/assembler-inl.h"
#include "src/common/allow-deprecated.h"
#include "src/debug/debug.h"
#include "src/handles/global-handles.h"
#include "src/heap/heap-inl.h"
......
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