Skip to content

Commit 9a03ae6

Browse files
bnoordhuisrvagg
authored andcommitted
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 <trev.norris@gmail.com>
1 parent d571680 commit 9a03ae6

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

Diff for: node.gyp

+2
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180
'NODE_ARCH="<(target_arch)"',
181181
'NODE_PLATFORM="<(OS)"',
182182
'NODE_WANT_INTERNALS=1',
183+
# Warn when using deprecated V8 APIs.
184+
'V8_DEPRECATION_WARNINGS=1',
183185
],
184186

185187

Diff for: 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);

Diff for: src/node.cc

+4-35
Original file line numberDiff line numberDiff line change
@@ -152,38 +152,6 @@ static uv_async_t dispatch_debug_messages_async;
152152
static Isolate* node_isolate = nullptr;
153153
static v8::Platform* default_platform;
154154

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

188156
static void CheckImmediate(uv_check_t* handle) {
189157
Environment* env = Environment::from_immediate_check_handle(handle);
@@ -3711,8 +3679,6 @@ void Init(int* argc,
37113679
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
37123680
}
37133681

3714-
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
3715-
37163682
if (!use_debug_agent) {
37173683
RegisterDebugSignalHandler();
37183684
}
@@ -3914,7 +3880,10 @@ Environment* CreateEnvironment(Isolate* isolate,
39143880
// node instance.
39153881
static void StartNodeInstance(void* arg) {
39163882
NodeInstanceData* instance_data = static_cast<NodeInstanceData*>(arg);
3917-
Isolate* isolate = Isolate::New();
3883+
Isolate::CreateParams params;
3884+
ArrayBufferAllocator array_buffer_allocator;
3885+
params.array_buffer_allocator = &array_buffer_allocator;
3886+
Isolate* isolate = Isolate::New(params);
39183887
if (track_heap_objects) {
39193888
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);
39203889
}

Diff for: src/node_internals.h

+14
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ NODE_DEPRECATED("Use ThrowUVException(isolate)",
226226
return ThrowUVException(isolate, errorno, syscall, message, path);
227227
})
228228

229+
struct ArrayBufferAllocator : public v8::ArrayBuffer::Allocator {
230+
virtual void* Allocate(size_t size) {
231+
return calloc(size, 1);
232+
}
233+
234+
virtual void* AllocateUninitialized(size_t size) {
235+
return malloc(size);
236+
}
237+
238+
virtual void Free(void* data, size_t) {
239+
free(data);
240+
}
241+
};
242+
229243
enum NodeInstanceType { MAIN, WORKER };
230244

231245
class NodeInstanceData {

0 commit comments

Comments
 (0)