Skip to content

Commit ca685c0

Browse files
Add V8 API compatibility shims for old-style accessor callbacks
- Add AccessorGetterCallback and AccessorSetterCallback typedefs using Local<String> (the old API) to v8-object.h - Add SetAccessor overloads that accept old-style callbacks and forward to SetNativeDataProperty with proper type conversion - Add <cstring> include for memcpy used in type conversion - Add nodejs symlink in Dockerfile.Fibers for npm scripts that expect it This allows node-fibers to compile against Node 24's V8 headers without modification, as it uses the old SetAccessor API with Local<String> and AccessorGetterCallback signatures. Co-Authored-By: Claude (global.anthropic.claude-opus-4-5-20251101-v1:0) <noreply@anthropic.com>
1 parent 41f1299 commit ca685c0

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

Dockerfile.Fibers

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ ENV PATH="/usr/src/node/node-install/usr/local/bin:$PATH"
2727
RUN which node
2828
RUN node -v
2929
RUN node -p "process.arch"
30+
# Create nodejs symlink for npm scripts that expect it
31+
RUN ln -sf /usr/src/node/node-install/usr/local/bin/node /usr/local/bin/nodejs || true
3032
RUN echo -------------------
3133
RUN git clone --branch jackstrohm_node20_fibers --depth 1 https://github.com/asana/node-fibers.git node-fibers
3234

deps/v8/include/v8-object.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef INCLUDE_V8_OBJECT_H_
66
#define INCLUDE_V8_OBJECT_H_
77

8+
#include <cstring> // for memcpy in SetAccessor compatibility shim
9+
810
#include "v8-internal.h" // NOLINT(build/include_directory)
911
#include "v8-local-handle.h" // NOLINT(build/include_directory)
1012
#include "v8-maybe.h" // NOLINT(build/include_directory)
@@ -159,6 +161,17 @@ using AccessorNameSetterCallback =
159161
void (*)(Local<Name> property, Local<Value> value,
160162
const PropertyCallbackInfo<void>& info);
161163

164+
/**
165+
* Compatibility shim for node-fibers: Old-style accessor callbacks using
166+
* Local<String> instead of Local<Name>. These were removed in V8 12.x.
167+
*/
168+
using AccessorGetterCallback =
169+
void (*)(Local<String> property, const PropertyCallbackInfo<Value>& info);
170+
171+
using AccessorSetterCallback =
172+
void (*)(Local<String> property, Local<Value> value,
173+
const PropertyCallbackInfo<void>& info);
174+
162175
/**
163176
* Access control specifications.
164177
*
@@ -380,6 +393,29 @@ class V8_EXPORT Object : public Value {
380393
setter_side_effect_type);
381394
}
382395

396+
/**
397+
* Compatibility shim for node-fibers: Old-style SetAccessor accepting
398+
* AccessorGetterCallback (Local<String> based) instead of
399+
* AccessorNameGetterCallback (Local<Name> based).
400+
*/
401+
V8_WARN_UNUSED_RESULT Maybe<bool> SetAccessor(
402+
Local<Context> context, Local<String> name,
403+
AccessorGetterCallback getter,
404+
AccessorSetterCallback setter = nullptr,
405+
Local<Value> data = Local<Value>(), PropertyAttribute attributes = None,
406+
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
407+
SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect) {
408+
// String inherits from Name. Safe type pun since Local is just a pointer.
409+
Local<Name> name_as_name;
410+
static_assert(sizeof(name_as_name) == sizeof(name), "Local size mismatch");
411+
memcpy(&name_as_name, &name, sizeof(name));
412+
return SetNativeDataProperty(
413+
context, name_as_name,
414+
reinterpret_cast<AccessorNameGetterCallback>(getter),
415+
reinterpret_cast<AccessorNameSetterCallback>(setter), data, attributes,
416+
getter_side_effect_type, setter_side_effect_type);
417+
}
418+
383419
/**
384420
* Attempts to create a property with the given name which behaves like a data
385421
* property, except that the provided getter is invoked (and provided with the

deps/v8/include/v8-template.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define INCLUDE_V8_TEMPLATE_H_
77

88
#include <cstddef>
9+
#include <cstring> // for memcpy in SetAccessor compatibility shim
910
#include <string_view>
1011

1112
#include "v8-data.h" // NOLINT(build/include_directory)
@@ -122,6 +123,28 @@ class V8_EXPORT Template : public Data {
122123
getter_side_effect_type, setter_side_effect_type);
123124
}
124125

126+
/**
127+
* Compatibility shim for node-fibers: Old-style SetAccessor accepting
128+
* AccessorGetterCallback (Local<String> based) instead of
129+
* AccessorNameGetterCallback (Local<Name> based).
130+
*/
131+
void SetAccessor(
132+
Local<String> name, AccessorGetterCallback getter,
133+
AccessorSetterCallback setter = nullptr,
134+
Local<Value> data = Local<Value>(), PropertyAttribute attribute = None,
135+
SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
136+
SideEffectType setter_side_effect_type = SideEffectType::kHasSideEffect) {
137+
// String inherits from Name. Safe type pun since Local is just a pointer.
138+
Local<Name> name_as_name;
139+
static_assert(sizeof(name_as_name) == sizeof(name), "Local size mismatch");
140+
memcpy(&name_as_name, &name, sizeof(name));
141+
SetNativeDataProperty(
142+
name_as_name,
143+
reinterpret_cast<AccessorNameGetterCallback>(getter),
144+
reinterpret_cast<AccessorNameSetterCallback>(setter), data, attribute,
145+
getter_side_effect_type, setter_side_effect_type);
146+
}
147+
125148
/**
126149
* Like SetNativeDataProperty, but V8 will replace the native data property
127150
* with a real data property on first access.

0 commit comments

Comments
 (0)