Skip to content

Commit 037c9ca

Browse files
bnoordhuistargos
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 <[email protected]>
1 parent ab40e8e commit 037c9ca

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

node.gyp

Lines changed: 2 additions & 0 deletions
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

src/debug-agent.cc

Lines changed: 4 additions & 1 deletion
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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -148,38 +148,6 @@ static uv_async_t dispatch_debug_messages_async;
148148
static Isolate* node_isolate = nullptr;
149149
static v8::Platform* default_platform;
150150

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

184152
static void CheckImmediate(uv_check_t* handle) {
185153
Environment* env = Environment::from_immediate_check_handle(handle);
@@ -3707,8 +3675,6 @@ void Init(int* argc,
37073675
V8::SetFlagsFromString(expose_debug_as, sizeof(expose_debug_as) - 1);
37083676
}
37093677

3710-
V8::SetArrayBufferAllocator(&ArrayBufferAllocator::the_singleton);
3711-
37123678
if (!use_debug_agent) {
37133679
RegisterDebugSignalHandler();
37143680
}
@@ -3910,7 +3876,10 @@ Environment* CreateEnvironment(Isolate* isolate,
39103876
// node instance.
39113877
static void StartNodeInstance(void* arg) {
39123878
NodeInstanceData* instance_data = static_cast<NodeInstanceData*>(arg);
3913-
Isolate* isolate = Isolate::New();
3879+
Isolate::CreateParams params;
3880+
ArrayBufferAllocator array_buffer_allocator;
3881+
params.array_buffer_allocator = &array_buffer_allocator;
3882+
Isolate* isolate = Isolate::New(params);
39143883
if (track_heap_objects) {
39153884
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);
39163885
}

src/node_internals.h

Lines changed: 14 additions & 0 deletions
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)