Commit 6674aed0 authored by Wiktor Garbacz's avatar Wiktor Garbacz Committed by Commit Bot

Cleanup disallowing dynamic (de)allocation.

Change-Id: Icf4d67700bae4338ecf66411f2a5f57c5351f688
Reviewed-on: https://chromium-review.googlesource.com/504867Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarJochen Eisinger <jochen@chromium.org>
Commit-Queue: Wiktor Garbacz <wiktorg@google.com>
Cr-Commit-Position: refs/heads/master@{#45585}
parent 23cc6be3
......@@ -869,8 +869,6 @@ class V8_EXPORT HandleScope {
HandleScope(const HandleScope&) = delete;
void operator=(const HandleScope&) = delete;
void* operator new(size_t size);
void operator delete(void*, size_t);
protected:
V8_INLINE HandleScope() {}
......@@ -881,6 +879,13 @@ class V8_EXPORT HandleScope {
internal::Object* value);
private:
// Declaring operator new and delete as deleted is not spec compliant.
// Therefore declare them private instead to disable dynamic alloc
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
// Uses heap_object to obtain the current Isolate.
static internal::Object** CreateHandle(internal::HeapObject* heap_object,
internal::Object* value);
......@@ -921,10 +926,15 @@ class V8_EXPORT EscapableHandleScope : public HandleScope {
EscapableHandleScope(const EscapableHandleScope&) = delete;
void operator=(const EscapableHandleScope&) = delete;
private:
// Declaring operator new and delete as deleted is not spec compliant.
// Therefore declare them private instead to disable dynamic alloc
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
private:
internal::Object** Escape(internal::Object** escape_value);
internal::Object** escape_slot_;
};
......@@ -941,10 +951,15 @@ class V8_EXPORT SealHandleScope {
SealHandleScope(const SealHandleScope&) = delete;
void operator=(const SealHandleScope&) = delete;
private:
// Declaring operator new and delete as deleted is not spec compliant.
// Therefore declare them private instead to disable dynamic alloc
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
private:
internal::Isolate* const isolate_;
internal::Object** prev_limit_;
int prev_sealed_level_;
......@@ -7551,8 +7566,12 @@ class V8_EXPORT Isolate {
~Isolate() = delete;
Isolate(const Isolate&) = delete;
Isolate& operator=(const Isolate&) = delete;
// Deleting operator new and delete here is allowed as ctor and dtor is also
// deleted.
void* operator new(size_t size) = delete;
void* operator new[](size_t size) = delete;
void operator delete(void*, size_t) = delete;
void operator delete[](void*, size_t) = delete;
private:
template <class K, class V, class Traits>
......@@ -8278,10 +8297,15 @@ class V8_EXPORT TryCatch {
TryCatch(const TryCatch&) = delete;
void operator=(const TryCatch&) = delete;
private:
// Declaring operator new and delete as deleted is not spec compliant.
// Therefore declare them private instead to disable dynamic alloc
void* operator new(size_t size);
void* operator new[](size_t size);
void operator delete(void*, size_t);
void operator delete[](void*, size_t);
private:
void ResetInternal();
internal::Isolate* isolate_;
......
......@@ -1018,8 +1018,9 @@ HandleScope::~HandleScope() {
}
void* HandleScope::operator new(size_t) { base::OS::Abort(); }
void* HandleScope::operator new[](size_t) { base::OS::Abort(); }
void HandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
void HandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
int HandleScope::NumberOfHandles(Isolate* isolate) {
return i::HandleScope::NumberOfHandles(
......@@ -1059,8 +1060,11 @@ i::Object** EscapableHandleScope::Escape(i::Object** escape_value) {
}
void* EscapableHandleScope::operator new(size_t) { base::OS::Abort(); }
void* EscapableHandleScope::operator new[](size_t) { base::OS::Abort(); }
void EscapableHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
void EscapableHandleScope::operator delete[](void*, size_t) {
base::OS::Abort();
}
SealHandleScope::SealHandleScope(Isolate* isolate)
: isolate_(reinterpret_cast<i::Isolate*>(isolate)) {
......@@ -1081,8 +1085,9 @@ SealHandleScope::~SealHandleScope() {
}
void* SealHandleScope::operator new(size_t) { base::OS::Abort(); }
void* SealHandleScope::operator new[](size_t) { base::OS::Abort(); }
void SealHandleScope::operator delete(void*, size_t) { base::OS::Abort(); }
void SealHandleScope::operator delete[](void*, size_t) { base::OS::Abort(); }
void Context::Enter() {
i::Handle<i::Context> env = Utils::OpenHandle(this);
......@@ -2622,8 +2627,9 @@ v8::TryCatch::~TryCatch() {
}
void* v8::TryCatch::operator new(size_t) { base::OS::Abort(); }
void* v8::TryCatch::operator new[](size_t) { base::OS::Abort(); }
void v8::TryCatch::operator delete(void*, size_t) { base::OS::Abort(); }
void v8::TryCatch::operator delete[](void*, size_t) { base::OS::Abort(); }
bool v8::TryCatch::HasCaught() const {
return !reinterpret_cast<i::Object*>(exception_)->IsTheHole(isolate_);
......
......@@ -124,6 +124,17 @@ V8_INLINE Dest bit_cast(Source const& source) {
TypeName() = delete; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// A macro to disallow the dynamic allocation.
// This should be used in the private: declarations for a class
// Declaring operator new and delete as deleted is not spec compliant.
// Extract from 3.2.2 of C++11 spec:
// [...] A non-placement deallocation function for a class is
// odr-used by the definition of the destructor of that class, [...]
#define DISALLOW_NEW_AND_DELETE() \
void* operator new(size_t) { base::OS::Abort(); } \
void* operator new[](size_t) { base::OS::Abort(); }; \
void operator delete(void*, size_t) { base::OS::Abort(); } \
void operator delete[](void*, size_t) { base::OS::Abort(); }
// Newly written code should use V8_INLINE and V8_NOINLINE directly.
#define INLINE(declarator) V8_INLINE declarator
......
......@@ -89,13 +89,12 @@ class V8_EXPORT_PRIVATE Register final {
}
private:
DISALLOW_NEW_AND_DELETE();
static const int kInvalidIndex = kMaxInt;
static const int kRegisterFileStartOffset =
InterpreterFrameConstants::kRegisterFileFromFp / kPointerSize;
void* operator new(size_t size) = delete;
void operator delete(void* p) = delete;
int index_;
};
......
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