Skip to content

Commit 5d66928

Browse files
m4heshdJoshuaWise
andcommitted
Add GET_PROTOTYPE macro
Co-authored-by: Joshua Wise <joshuathomaswise@gmail.com>
1 parent d09f76a commit 5d66928

File tree

6 files changed

+12
-30
lines changed

6 files changed

+12
-30
lines changed

src/better_sqlite3.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
#include <node_object_wrap.h>
1313
#include <node_buffer.h>
1414

15-
// v8::Object::GetPrototype has been deprecated. See http://crbug.com/333672197
16-
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 13
17-
#define USE_GETPROTOTYPEV2
18-
#endif
19-
2015
struct Addon;
2116
class Database;
2217
class Statement;

src/objects/statement.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,7 @@ NODE_METHOD(Statement::JS_columns) {
363363
);
364364
columns.emplace_back(
365365
v8::Object::New(isolate,
366-
#ifdef USE_GETPROTOTYPEV2
367-
v8::Object::New(isolate)->GetPrototypeV2(),
368-
#else
369-
v8::Object::New(isolate)->GetPrototype(),
370-
#endif
366+
GET_PROTOTYPE(v8::Object::New(isolate)),
371367
keys.data(),
372368
values.data(),
373369
keys.size()

src/util/binder.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,10 @@ class Binder {
3333
};
3434

3535
static bool IsPlainObject(v8::Isolate* isolate, v8::Local<v8::Object> obj) {
36-
#ifdef USE_GETPROTOTYPEV2
37-
v8::Local<v8::Value> proto = obj->GetPrototypeV2();
38-
#else
39-
v8::Local<v8::Value> proto = obj->GetPrototype();
40-
#endif
36+
v8::Local<v8::Value> proto = GET_PROTOTYPE(obj);
4137
v8::Local<v8::Context> ctx = obj->GetCreationContext().ToLocalChecked();
4238
ctx->Enter();
43-
#ifdef USE_GETPROTOTYPEV2
44-
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototypeV2();
45-
#else
46-
v8::Local<v8::Value> baseProto = v8::Object::New(isolate)->GetPrototype();
47-
#endif
39+
v8::Local<v8::Value> baseProto = GET_PROTOTYPE(v8::Object::New(isolate));
4840
ctx->Exit();
4941
return proto->StrictEquals(baseProto) || proto->StrictEquals(v8::Null(isolate));
5042
}

src/util/data.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,7 @@ namespace Data {
146146
}
147147
return v8::Object::New(
148148
isolate,
149-
#ifdef USE_GETPROTOTYPEV2
150-
v8::Object::New(isolate)->GetPrototypeV2(),
151-
#else
152-
v8::Object::New(isolate)->GetPrototype(),
153-
#endif
149+
GET_PROTOTYPE(v8::Object::New(isolate)),
154150
keys.data(),
155151
values.data(),
156152
column_count

src/util/macros.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#define NODE_GETTER(name) void name(v8::Local<v8::Name> _, const v8::PropertyCallbackInfo<v8::Value>& info)
55
#define INIT(name) v8::Local<v8::Function> name(v8::Isolate* isolate, v8::Local<v8::External> data)
66

7+
#if defined(V8_MAJOR_VERSION) && V8_MAJOR_VERSION >= 13
8+
// v8::Object::GetPrototype has been deprecated. See http://crbug.com/333672197
9+
#define GET_PROTOTYPE(obj) ((obj)->GetPrototypeV2())
10+
#else
11+
#define GET_PROTOTYPE(obj) ((obj)->GetPrototype())
12+
#endif
13+
714
#define EasyIsolate v8::Isolate* isolate = v8::Isolate::GetCurrent()
815
#define OnlyIsolate info.GetIsolate()
916
#define OnlyContext isolate->GetCurrentContext()

src/util/row-builder.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ class RowBuilder {
3333
}
3434

3535
return v8::Object::New(isolate,
36-
#ifdef USE_GETPROTOTYPEV2
37-
v8::Object::New(isolate)->GetPrototypeV2(),
38-
#else
39-
v8::Object::New(isolate)->GetPrototype(),
40-
#endif
36+
GET_PROTOTYPE(v8::Object::New(isolate)),
4137
keys.data(),
4238
values.data(),
4339
column_count

0 commit comments

Comments
 (0)