Skip to content

Commit ad91952

Browse files
committed
src: enable v8 deprecation warnings and fix them
Turn on V8 API deprecation warnings. Fix up the no-arg Isolate::New() calls in src/node.cc and src/debug-agent.cc. PR-URL: #2091 Reviewed-By: Trevor Norris <[email protected]>
1 parent a5745aa commit ad91952

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@
181181
'NODE_PLATFORM="<(OS)"',
182182
'NODE_V8_OPTIONS="<(node_v8_options)"',
183183
'NODE_WANT_INTERNALS=1',
184+
# Warn when using deprecated V8 APIs.
185+
'V8_DEPRECATION_WARNINGS=1',
184186
],
185187

186188

src/debug-agent.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ void Agent::Stop() {
160160

161161
void Agent::WorkerRun() {
162162
static const char* argv[] = { "node", "--debug-agent" };
163-
Isolate* isolate = Isolate::New();
163+
Isolate::CreateParams params;
164+
ArrayBufferAllocator array_buffer_allocator;
165+
params.array_buffer_allocator = &array_buffer_allocator;
166+
Isolate* isolate = Isolate::New(params);
164167
{
165168
Locker locker(isolate);
166169
Isolate::Scope isolate_scope(isolate);

src/node.cc

+4-35
Original file line numberDiff line numberDiff line change
@@ -147,38 +147,6 @@ static uv_async_t dispatch_debug_messages_async;
147147
static Isolate* node_isolate = nullptr;
148148
static v8::Platform* default_platform;
149149

150-
class ArrayBufferAllocator : public ArrayBuffer::Allocator {
151-
public:
152-
// Impose an upper limit to avoid out of memory errors that bring down
153-
// the process.
154-
static const size_t kMaxLength = 0x3fffffff;
155-
static ArrayBufferAllocator the_singleton;
156-
virtual ~ArrayBufferAllocator() = default;
157-
virtual void* Allocate(size_t length) override;
158-
virtual void* AllocateUninitialized(size_t length) override;
159-
virtual void Free(void* data, size_t length) override;
160-
private:
161-
ArrayBufferAllocator() = default;
162-
DISALLOW_COPY_AND_ASSIGN(ArrayBufferAllocator);
163-
};
164-
165-
ArrayBufferAllocator ArrayBufferAllocator::the_singleton;
166-
167-
168-
void* ArrayBufferAllocator::Allocate(size_t length) {
169-
return calloc(length, 1);
170-
}
171-
172-
173-
void* ArrayBufferAllocator::AllocateUninitialized(size_t length) {
174-
return malloc(length);
175-
}
176-
177-
178-
void ArrayBufferAllocator::Free(void* data, size_t length) {
179-
free(data);
180-
}
181-
182150

183151
static void CheckImmediate(uv_check_t* handle) {
184152
Environment* env = Environment::from_immediate_check_handle(handle);
@@ -3675,8 +3643,6 @@ void Init(int* argc,
36753643
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
36763644
}
36773645

3678-
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
3679-
36803646
if (!use_debug_agent) {
36813647
RegisterDebugSignalHandler();
36823648
}
@@ -3878,7 +3844,10 @@ Environment* CreateEnvironment(Isolate* isolate,
38783844
// node instance.
38793845
static void StartNodeInstance(void* arg) {
38803846
NodeInstanceData* instance_data = static_cast<NodeInstanceData*>(arg);
3881-
Isolate* isolate = Isolate::New();
3847+
Isolate::CreateParams params;
3848+
ArrayBufferAllocator array_buffer_allocator;
3849+
params.array_buffer_allocator = &array_buffer_allocator;
3850+
Isolate* isolate = Isolate::New(params);
38823851
// Fetch a reference to the main isolate, so we have a reference to it
38833852
// even when we need it to access it from another (debugger) thread.
38843853
if (instance_data->is_main())

src/node_internals.h

+14
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ NODE_DEPRECATED("Use ThrowUVException(isolate)",
195195
return ThrowUVException(isolate, errorno, syscall, message, path);
196196
})
197197

198+
struct ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
199+
virtual void* Allocate(size_t size) {
200+
return calloc(size, 1);
201+
}
202+
203+
virtual void* AllocateUninitialized(size_t size) {
204+
return malloc(size);
205+
}
206+
207+
virtual void Free(void* data, size_t) {
208+
free(data);
209+
}
210+
};
211+
198212
enum NodeInstanceType { MAIN, WORKER };
199213

200214
class NodeInstanceData {

0 commit comments

Comments
 (0)