Skip to content

Commit 910b5f5

Browse files
committed
Expose v8::Signature
Also replaces the v8__ObjectTemplate__SetAccessorProperty__DEFAULTX overloads with a __Config variant.
1 parent c9299ec commit 910b5f5

File tree

2 files changed

+52
-25
lines changed

2 files changed

+52
-25
lines changed

src/binding.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,15 @@ void v8__Template__Set(
11531153
ptr_to_local(&self)->Set(ptr_to_local(&key), ptr_to_local(&value), attr);
11541154
}
11551155

1156-
void v8__Template__SetAccessorProperty__DEFAULT(
1156+
void v8__Template__SetAccessorProperty(
11571157
const v8::Template& self,
11581158
const v8::Name& key,
1159-
const v8::FunctionTemplate& getter) {
1160-
ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter));
1159+
const v8::FunctionTemplate* getter,
1160+
const v8::FunctionTemplate* setter,
1161+
v8::PropertyAttribute attribute) {
1162+
v8::Local<v8::FunctionTemplate> getter_local = getter ? ptr_to_local(getter) : v8::Local<v8::FunctionTemplate>();
1163+
v8::Local<v8::FunctionTemplate> setter_local = setter ? ptr_to_local(setter) : v8::Local<v8::FunctionTemplate>();
1164+
ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), getter_local, setter_local, attribute);
11611165
}
11621166

11631167
// ObjectTemplate
@@ -1197,19 +1201,23 @@ void v8__ObjectTemplate__SetNamedHandler(
11971201
ptr_to_local(&self)->SetHandler(configuration);
11981202
}
11991203

1200-
void v8__ObjectTemplate__SetAccessorProperty__DEFAULT(
1201-
const v8::ObjectTemplate& self,
1202-
const v8::Name& key,
1203-
const v8::FunctionTemplate& getter) {
1204-
ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter));
1205-
}
1204+
typedef struct v8__AccessorPropertyConfig {
1205+
const v8::Name* key;
1206+
const v8::FunctionTemplate* getter;
1207+
const v8::FunctionTemplate* setter;
1208+
v8::PropertyAttribute attribute;
1209+
} v8__AccessorPropertyConfig;
12061210

1207-
void v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(
1211+
void v8__ObjectTemplate__SetAccessorProperty__Config(
12081212
const v8::ObjectTemplate& self,
1209-
const v8::Name& key,
1210-
const v8::FunctionTemplate& getter,
1211-
const v8::FunctionTemplate& setter) {
1212-
ptr_to_local(&self)->SetAccessorProperty(ptr_to_local(&key), ptr_to_local(&getter), ptr_to_local(&setter));
1213+
const v8__AccessorPropertyConfig* config) {
1214+
v8::Local<v8::FunctionTemplate> getter = config->getter ? ptr_to_local(config->getter) : v8::Local<v8::FunctionTemplate>();
1215+
v8::Local<v8::FunctionTemplate> setter = config->setter ? ptr_to_local(config->setter) : v8::Local<v8::FunctionTemplate>();
1216+
ptr_to_local(&self)->SetAccessorProperty(
1217+
ptr_to_local(config->key),
1218+
getter,
1219+
setter,
1220+
config->attribute);
12131221
}
12141222

12151223
void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT(
@@ -1579,6 +1587,7 @@ typedef enum ConstructorBehavior {
15791587
typedef struct v8__FunctionTemplateConfig {
15801588
v8::FunctionCallback callback;
15811589
const v8::Value* data;
1590+
const v8::Signature* signature;
15821591
int length;
15831592
ConstructorBehavior behavior;
15841593
SideEffectType side_effect_type;
@@ -1608,18 +1617,26 @@ const v8::FunctionTemplate* v8__FunctionTemplate__New__Config(
16081617
v8::SideEffectType side_effect = static_cast<v8::SideEffectType>(config->side_effect_type);
16091618
v8::ConstructorBehavior behavior = static_cast<v8::ConstructorBehavior>(config->behavior);
16101619
v8::Local<v8::Value> data = config->data ? ptr_to_local(config->data) : v8::Local<v8::Value>();
1620+
v8::Local<v8::Signature> signature = config->signature ? ptr_to_local(config->signature) : v8::Local<v8::Signature>();
16111621

16121622
return local_to_ptr(v8::FunctionTemplate::New(
16131623
isolate,
16141624
config->callback,
16151625
data,
1616-
v8::Local<v8::Signature>(), // signature - default
1626+
signature,
16171627
config->length,
16181628
behavior,
16191629
side_effect
16201630
));
16211631
}
16221632

1633+
const v8::Signature* v8__Signature__New(
1634+
v8::Isolate* isolate,
1635+
const v8::FunctionTemplate* receiver) {
1636+
v8::Local<v8::FunctionTemplate> recv = receiver ? ptr_to_local(receiver) : v8::Local<v8::FunctionTemplate>();
1637+
return local_to_ptr(v8::Signature::New(isolate, recv));
1638+
}
1639+
16231640
const v8::ObjectTemplate* v8__FunctionTemplate__InstanceTemplate(
16241641
const v8::FunctionTemplate& self) {
16251642
return local_to_ptr(ptr_to_local(&self)->InstanceTemplate());

src/binding.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ typedef struct FunctionTemplate FunctionTemplate;
1515
typedef struct Message Message;
1616
typedef struct Data Context;
1717
typedef struct Data Private;
18+
typedef struct Data Signature;
1819
typedef struct MicrotaskQueue MicrotaskQueue;
1920
// Internally, all Value types have a base InternalAddress struct.
2021
typedef uintptr_t InternalAddress;
@@ -755,10 +756,12 @@ void v8__Template__Set(
755756
const Name* key,
756757
const Data* value,
757758
PropertyAttribute attr);
758-
void v8__Template__SetAccessorProperty__DEFAULT(
759+
void v8__Template__SetAccessorProperty(
759760
const Template* self,
760761
const Name* key,
761-
const FunctionTemplate* getter);
762+
const FunctionTemplate* getter,
763+
const FunctionTemplate* setter,
764+
PropertyAttribute attribute);
762765

763766
typedef struct PropertyCallbackInfo PropertyCallbackInfo;
764767
typedef void (*AccessorNameGetterCallback)(const Name*, const PropertyCallbackInfo*);
@@ -846,6 +849,7 @@ typedef enum ConstructorBehavior {
846849
typedef struct v8__FunctionTemplateConfig {
847850
FunctionCallback callback;
848851
const Value* data;
852+
const Signature* signature;
849853
int length;
850854
ConstructorBehavior behavior;
851855
SideEffectType side_effect_type;
@@ -863,6 +867,11 @@ const FunctionTemplate* v8__FunctionTemplate__New__DEFAULT3(
863867
const FunctionTemplate* v8__FunctionTemplate__New__Config(
864868
Isolate* isolate,
865869
const v8__FunctionTemplateConfig* config);
870+
871+
// Signature
872+
const Signature* v8__Signature__New(
873+
Isolate* isolate,
874+
const FunctionTemplate* receiver);
866875
const ObjectTemplate* v8__FunctionTemplate__InstanceTemplate(
867876
const FunctionTemplate* self);
868877
const ObjectTemplate* v8__FunctionTemplate__PrototypeTemplate(
@@ -1005,15 +1014,16 @@ Object* v8__ObjectTemplate__NewInstance(
10051014
void v8__ObjectTemplate__SetInternalFieldCount(
10061015
const ObjectTemplate* self,
10071016
int value);
1008-
void v8__ObjectTemplate__SetAccessorProperty__DEFAULT(
1017+
typedef struct v8__AccessorPropertyConfig {
1018+
const Name* key;
1019+
const FunctionTemplate* getter;
1020+
const FunctionTemplate* setter;
1021+
PropertyAttribute attribute;
1022+
} v8__AccessorPropertyConfig;
1023+
1024+
void v8__ObjectTemplate__SetAccessorProperty__Config(
10091025
const ObjectTemplate* self,
1010-
const Name* key,
1011-
const FunctionTemplate* getter);
1012-
void v8__ObjectTemplate__SetAccessorProperty__DEFAULT2(
1013-
const ObjectTemplate* self,
1014-
const Name* key,
1015-
const FunctionTemplate* getter,
1016-
const FunctionTemplate* setter);
1026+
const v8__AccessorPropertyConfig* config);
10171027
void v8__ObjectTemplate__SetNativeDataProperty__DEFAULT(
10181028
const ObjectTemplate* self,
10191029
const Name* key,

0 commit comments

Comments
 (0)