Skip to content

Commit

Permalink
Debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed Jul 25, 2023
1 parent ac536a0 commit 3e149ea
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
17 changes: 12 additions & 5 deletions runtime/js-compute-runtime/builtins/cache-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,21 @@ JS::Result<std::string> createSurrogateKeysFromCacheKey(JSContext *cx, std::stri
return JS::Result<std::string>(surrogate_keys);
}

#define BEGIN_TRANSACTION(t, cx, promise, handle) \
CacheTransaction t{cx, promise, handle, __func__, __LINE__};

class CacheTransaction final {
JSContext *cx;
JS::RootedObject promise;
host_api::CacheHandle handle;

const char *func;
int line;

public:
CacheTransaction(JSContext *cx, JS::HandleObject promise, host_api::CacheHandle handle)
: cx{cx}, promise{this->cx, promise}, handle{handle} {}
CacheTransaction(JSContext *cx, JS::HandleObject promise, host_api::CacheHandle handle,
const char *func, const int line)
: cx{cx}, promise{this->cx, promise}, handle{handle}, func{func}, line{line} {}

~CacheTransaction() {
// An invalid handle indicates that this transaction has been committed.
Expand All @@ -229,7 +236,7 @@ class CacheTransaction final {

auto res = this->handle.transaction_cancel();
if (auto *err = res.to_err()) {
HANDLE_ERROR(this->cx, *err);
host_api::handle_fastly_error(this->cx, *err, this->line, this->func);
}

// We always reject the promise if the transaction hasn't committed.
Expand Down Expand Up @@ -268,7 +275,7 @@ bool SimpleCache::getOrSetThenHandler(JSContext *cx, JS::HandleObject owner, JS:
MOZ_ASSERT(handleVal.isInt32());

host_api::CacheHandle handle(handleVal.toInt32());
CacheTransaction transaction{cx, promise, handle};
BEGIN_TRANSACTION(transaction, cx, promise, handle);

JS::RootedValue keyVal(cx);
if (!JS_GetProperty(cx, extraObj, "key", &keyVal)) {
Expand Down Expand Up @@ -469,7 +476,7 @@ bool SimpleCache::getOrSet(JSContext *cx, unsigned argc, JS::Value *vp) {
}

auto handle = res.unwrap();
CacheTransaction transaction{cx, promise, handle};
BEGIN_TRANSACTION(transaction, cx, promise, handle);

// Check if a fresh cache item was found, if that's the case, then we will resolve
// with a SimpleCacheEntry containing the value. Else, call the content-provided
Expand Down
2 changes: 2 additions & 0 deletions runtime/js-compute-runtime/host_interface/host_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ namespace {

void init_write_options(fastly_compute_at_edge_fastly_cache_write_options_t &options,
const CacheWriteOptions &opts) {
memset(&options, 0, sizeof(options));

options.max_age_ns = opts.max_age_ns;
options.request_headers = opts.req.handle;

Expand Down
6 changes: 3 additions & 3 deletions runtime/js-compute-runtime/host_interface/host_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ void handle_fastly_error(JSContext *cx, FastlyError err, int line, const char *f

break;
case FASTLY_COMPUTE_AT_EDGE_FASTLY_ERROR_INVALID_ARGUMENT:
JS_ReportErrorUTF8(cx, "%s: Invalid argument.\n", func);
JS_ReportErrorUTF8(cx, "%s:%d: Invalid argument.\n", func, line);
break;
case FASTLY_COMPUTE_AT_EDGE_FASTLY_ERROR_BAD_HANDLE:
JS_ReportErrorUTF8(cx,
"%s: Invalid handle. Thrown when a request, response, dictionary, or "
"%s:%d: Invalid handle. Thrown when a request, response, dictionary, or "
"body handle is not valid.\n",
func);
func, line);
break;
case FASTLY_COMPUTE_AT_EDGE_FASTLY_ERROR_BUFFER_LEN:
JS_ReportErrorUTF8(cx, "%s: Buffer length error. Buffer is too long.\n", func);
Expand Down
2 changes: 1 addition & 1 deletion runtime/spidermonkey
Submodule spidermonkey updated 1 files
+1 −1 gecko-revision

0 comments on commit 3e149ea

Please sign in to comment.