Skip to content

Commit 52fee24

Browse files
author
Guy Bedford
authored
component: reinclude conversion function to avoid world-based binary assumptions (#390)
1 parent 6a84d5d commit 52fee24

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

c-dependencies/js-compute-runtime/builtins/cache-override.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,23 @@ void CacheOverride::set_pci(JSObject *self, bool pci) {
7474
JS::SetReservedSlot(self, CacheOverride::Slots::PCI, JS::BooleanValue(pci));
7575
}
7676

77-
uint8_t CacheOverride::abi_tag(JSObject *self) {
77+
fastly_http_cache_override_tag_t CacheOverride::abi_tag(JSObject *self) {
7878
MOZ_ASSERT(is_instance(self));
7979
switch (CacheOverride::mode(self)) {
8080
case CacheOverride::CacheOverrideMode::None:
81-
return (uint8_t)CacheOverrideTag::None;
81+
return 0;
8282
case CacheOverride::CacheOverrideMode::Pass:
83-
return (uint8_t)CacheOverrideTag::Pass;
83+
return FASTLY_HTTP_CACHE_OVERRIDE_TAG_PASS;
8484
default:;
8585
}
8686

87-
uint8_t tag = 0;
87+
fastly_http_cache_override_tag_t tag = 0;
8888
if (!ttl(self).isUndefined())
89-
tag |= (uint8_t)CacheOverrideTag::TTL;
89+
tag |= FASTLY_HTTP_CACHE_OVERRIDE_TAG_TTL;
9090
if (!swr(self).isUndefined())
91-
tag |= (uint8_t)CacheOverrideTag::SWR;
91+
tag |= FASTLY_HTTP_CACHE_OVERRIDE_TAG_STALE_WHILE_REVALIDATE;
9292
if (!pci(self).isUndefined())
93-
tag |= (uint8_t)CacheOverrideTag::PCI;
93+
tag |= FASTLY_HTTP_CACHE_OVERRIDE_TAG_PCI;
9494

9595
return tag;
9696
}

c-dependencies/js-compute-runtime/builtins/cache-override.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ class CacheOverride : public BuiltinImpl<CacheOverride> {
2929

3030
enum class CacheOverrideMode { None, Pass, Override };
3131

32-
// These values are defined by the Fastly ABI:
33-
// https://docs.rs/fastly-shared/0.6.1/src/fastly_shared/lib.rs.html#407-412
34-
enum class CacheOverrideTag {
35-
None = 0,
36-
Pass = 1 << 0,
37-
TTL = 1 << 1,
38-
SWR = 1 << 2,
39-
PCI = 1 << 3,
40-
};
41-
42-
static_assert((int)CacheOverrideTag::Pass == FASTLY_HTTP_CACHE_OVERRIDE_TAG_PASS);
43-
static_assert((int)CacheOverrideTag::TTL == FASTLY_HTTP_CACHE_OVERRIDE_TAG_TTL);
44-
static_assert((int)CacheOverrideTag::SWR ==
45-
FASTLY_HTTP_CACHE_OVERRIDE_TAG_STALE_WHILE_REVALIDATE);
46-
static_assert((int)CacheOverrideTag::PCI == FASTLY_HTTP_CACHE_OVERRIDE_TAG_PCI);
47-
4832
static const JSFunctionSpec methods[];
4933
static const JSPropertySpec properties[];
5034
static uint8_t abi_tag(JSObject *self);

c-dependencies/js-compute-runtime/js-compute-builtins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ bool apply_cache_override(JSContext *cx, HandleObject self) {
14431443
return true;
14441444
}
14451445

1446-
uint8_t tag = builtins::CacheOverride::abi_tag(override);
1446+
fastly_http_cache_override_tag_t tag = builtins::CacheOverride::abi_tag(override);
14471447

14481448
bool has_ttl = true;
14491449
uint32_t ttl;

c-dependencies/js-compute-runtime/xqd-world/xqd_world_adapter.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,23 @@ bool xqd_fastly_http_req_body_downstream_get(fastly_request_t *ret, fastly_error
127127
return convert_result(xqd_req_body_downstream_get(&ret->f0, &ret->f1), err);
128128
}
129129

130+
int convert_tag(fastly_http_cache_override_tag_t tag) {
131+
int out_tag = 0;
132+
if ((tag & FASTLY_HTTP_CACHE_OVERRIDE_TAG_PASS) > 0) {
133+
out_tag |= CACHE_OVERRIDE_PASS;
134+
}
135+
if ((tag & FASTLY_HTTP_CACHE_OVERRIDE_TAG_TTL) > 0) {
136+
out_tag |= CACHE_OVERRIDE_TTL;
137+
}
138+
if ((tag & FASTLY_HTTP_CACHE_OVERRIDE_TAG_STALE_WHILE_REVALIDATE) > 0) {
139+
out_tag |= CACHE_OVERRIDE_STALE_WHILE_REVALIDATE;
140+
}
141+
if ((tag & FASTLY_HTTP_CACHE_OVERRIDE_TAG_PCI) > 0) {
142+
out_tag |= CACHE_OVERRIDE_PCI;
143+
}
144+
return out_tag;
145+
}
146+
130147
bool xqd_fastly_http_req_cache_override_set(fastly_request_handle_t h,
131148
fastly_http_cache_override_tag_t tag,
132149
uint32_t *maybe_ttl,
@@ -141,7 +158,7 @@ bool xqd_fastly_http_req_cache_override_set(fastly_request_handle_t h,
141158
}
142159
return convert_result(
143160
xqd_req_cache_override_v2_set(
144-
h, static_cast<int>(tag), maybe_ttl == NULL ? 0 : *maybe_ttl,
161+
h, convert_tag(tag), maybe_ttl == NULL ? 0 : *maybe_ttl,
145162
maybe_stale_while_revalidate == NULL ? 0 : *maybe_stale_while_revalidate,
146163
reinterpret_cast<char *>(sk_str.ptr), sk_str.len),
147164
err);

0 commit comments

Comments
 (0)