Skip to content

Commit a732711

Browse files
Merge pull request #50 from karlseguin/named_property
add named property handler
2 parents c9c1ba1 + fdfe915 commit a732711

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

src/binding.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,12 @@ void v8__ObjectTemplate__SetIndexedHandler(
889889
ptr_to_local(&self)->SetHandler(configuration);
890890
}
891891

892+
void v8__ObjectTemplate__SetNamedHandler(
893+
const v8::ObjectTemplate& self,
894+
const v8::NamedPropertyHandlerConfiguration& configuration) {
895+
ptr_to_local(&self)->SetHandler(configuration);
896+
}
897+
892898
// Array
893899

894900
const v8::Array* v8__Array__New(

src/binding.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,29 @@ typedef struct IndexedPropertyHandlerConfiguration {
808808
} IndexedPropertyHandlerConfiguration;
809809
void v8__ObjectTemplate__SetIndexedHandler(
810810
const ObjectTemplate* self,
811-
IndexedPropertyHandlerConfiguration configuration);
811+
const IndexedPropertyHandlerConfiguration* configuration);
812+
813+
typedef void (*NamedPropertyGetterCallback)(const Name*, const PropertyCallbackInfo*);
814+
typedef void (*NamedPropertySetterCallback)(const Name*, const Value*, const PropertyCallbackInfo*);
815+
typedef void (*NamedPropertyQueryCallback)(const Name*, const PropertyCallbackInfo*);
816+
typedef void (*NamedPropertyDeleterCallback)(const Name*, const PropertyCallbackInfo*);
817+
typedef void (*NamedPropertyEnumeratorCallback)(const PropertyCallbackInfo*);
818+
typedef void (*NamedPropertyDefinerCallback)(const Name*, PropertyDescriptor* desc, const PropertyCallbackInfo*);
819+
typedef void (*NamedPropertyDescriptorCallback)(const Name*, const PropertyCallbackInfo*);
820+
typedef struct NamedPropertyHandlerConfiguration {
821+
NamedPropertyGetterCallback getter;
822+
NamedPropertySetterCallback setter;
823+
NamedPropertyQueryCallback query;
824+
NamedPropertyDeleterCallback deleter;
825+
NamedPropertyEnumeratorCallback enumerator;
826+
NamedPropertyDefinerCallback definer;
827+
NamedPropertyDescriptorCallback descriptor;
828+
const Value* data;
829+
PropertyHandlerFlags flags;
830+
} NamedPropertyHandlerConfiguration;
831+
void v8__ObjectTemplate__SetNamedHandler(
832+
const ObjectTemplate* self,
833+
const NamedPropertyHandlerConfiguration* configuration);
812834

813835
// ScriptOrigin
814836
typedef struct ScriptOriginOptions {

src/v8.zig

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,24 @@ pub const IndexedPropertyHandlerConfiguration = struct {
8989
flags: c.PropertyHandlerFlags = PropertyHandlerFlags.None,
9090
};
9191

92+
pub const NamedPropertyGetterCallback = c.NamedPropertyGetterCallback;
93+
pub const NamedPropertySetterCallback = c.NamedPropertySetterCallback;
94+
pub const NamedPropertyQueryCallback = c.NamedPropertyQueryCallback;
95+
pub const NamedPropertyDeleterCallback = c.NamedPropertyDeleterCallback;
96+
pub const NamedPropertyEnumeratorCallback = c.NamedPropertyEnumeratorCallback;
97+
pub const NamedPropertyDefinerCallback = c.NamedPropertyDefinerCallback;
98+
pub const NamedPropertyDescriptorCallback = c.NamedPropertyDescriptorCallback;
99+
pub const NamedPropertyHandlerConfiguration = struct {
100+
getter: ?NamedPropertyGetterCallback = null,
101+
setter: ?NamedPropertySetterCallback = null,
102+
query: ?NamedPropertyQueryCallback = null,
103+
deleter: ?NamedPropertyDeleterCallback = null,
104+
enumerator: ?NamedPropertyEnumeratorCallback = null,
105+
definer: ?NamedPropertyDefinerCallback = null,
106+
descriptor: ?NamedPropertyDescriptorCallback = null,
107+
flags: c.PropertyHandlerFlags = PropertyHandlerFlags.None,
108+
};
109+
92110
pub const CreateParams = c.CreateParams;
93111

94112
pub const SharedPtr = c.SharedPtr;
@@ -970,7 +988,22 @@ pub const ObjectTemplate = struct {
970988
}
971989

972990
pub fn setIndexedProperty(self: Self, configuration: IndexedPropertyHandlerConfiguration, data_val: anytype) void {
973-
c.v8__ObjectTemplate__SetIndexedHandler(self.handle, c.IndexedPropertyHandlerConfiguration{
991+
const conf = c.IndexedPropertyHandlerConfiguration{
992+
.getter = configuration.getter orelse null,
993+
.setter = configuration.setter orelse null,
994+
.query = configuration.query orelse null,
995+
.deleter = configuration.deleter orelse null,
996+
.enumerator = configuration.enumerator orelse null,
997+
.definer = configuration.definer orelse null,
998+
.descriptor = configuration.descriptor orelse null,
999+
.data = getDataHandle(data_val),
1000+
.flags = configuration.flags,
1001+
};
1002+
c.v8__ObjectTemplate__SetIndexedHandler(self.handle, &conf);
1003+
}
1004+
1005+
pub fn setNamedProperty(self: Self, configuration: NamedPropertyHandlerConfiguration, data_val: anytype) void {
1006+
const conf = c.NamedPropertyHandlerConfiguration{
9741007
.getter = configuration.getter orelse null,
9751008
.setter = configuration.setter orelse null,
9761009
.query = configuration.query orelse null,
@@ -980,7 +1013,8 @@ pub const ObjectTemplate = struct {
9801013
.descriptor = configuration.descriptor orelse null,
9811014
.data = getDataHandle(data_val),
9821015
.flags = configuration.flags,
983-
});
1016+
};
1017+
c.v8__ObjectTemplate__SetNamedHandler(self.handle, &conf);
9841018
}
9851019

9861020
pub fn toValue(self: Self) Value {

0 commit comments

Comments
 (0)