Skip to content

Commit

Permalink
Merge branch 'main' into weval-matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Sep 4, 2024
2 parents d6931ca + e6205a5 commit 4e3712b
Show file tree
Hide file tree
Showing 36 changed files with 139 additions and 79 deletions.
4 changes: 2 additions & 2 deletions builtins/web/crypto/crypto-algorithm.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_CRYPTO_ALGORITHM_H
#define JS_COMPUTE_RUNTIME_CRYPTO_ALGORITHM_H
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_ALGORITHM_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_ALGORITHM_H
#include <span>

#include "builtin.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/crypto-key-ec-components.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_CRYPTO_KEY_EC_COMPONENTS_H
#define JS_COMPUTE_RUNTIME_CRYPTO_KEY_EC_COMPONENTS_H
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_KEY_EC_COMPONENTS_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_KEY_EC_COMPONENTS_H
#include <string>
#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/crypto-key-rsa-components.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_CRYPTO_KEY_RSA_COMPONENTS_H
#define JS_COMPUTE_RUNTIME_CRYPTO_KEY_RSA_COMPONENTS_H
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_KEY_RSA_COMPONENTS_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_KEY_RSA_COMPONENTS_H
#include <optional>
#include <string>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/crypto-key.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_CRYPTO_KEY_H
#define JS_COMPUTE_RUNTIME_CRYPTO_KEY_H
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_KEY_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_KEY_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/crypto.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_BUILTIN_CRYPTO_H
#define JS_COMPUTE_RUNTIME_BUILTIN_CRYPTO_H
#ifndef BUILTINS_WEB_CRYPTO_H
#define BUILTINS_WEB_CRYPTO_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/json-web-key.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_JSON_WEB_KEY_H
#define JS_COMPUTE_RUNTIME_JSON_WEB_KEY_H
#ifndef BUILTINS_WEB_CRYPTO_JSON_WEB_KEY_H
#define BUILTINS_WEB_CRYPTO_JSON_WEB_KEY_H
#include "jsapi.h"
#include <memory>
#include <optional>
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/crypto/subtle-crypto.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_SUBTLE_CRYPTO_H
#define JS_COMPUTE_RUNTIME_SUBTLE_CRYPTO_H
#ifndef BUILTINS_WEB_CRYPTO_SUBTLE_CRYPTO_H
#define BUILTINS_WEB_CRYPTO_SUBTLE_CRYPTO_H

#include "builtin.h"
#include "crypto-algorithm.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/dom-exception.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_BUILTIN_DOM_EXCEPTION_H
#define JS_COMPUTE_RUNTIME_BUILTIN_DOM_EXCEPTION_H
#ifndef BUILTINS_WEB_BUILTIN_DOM_EXCEPTION_H
#define BUILTINS_WEB_BUILTIN_DOM_EXCEPTION_H

#include "builtin.h"

Expand Down
2 changes: 1 addition & 1 deletion builtins/web/fetch/fetch_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ bool handle_incoming_request(host_api::HttpIncomingRequest *request) {
}

if (!success) {
fprintf(stderr, "Internal error.");
fprintf(stderr, "Warning: JS event loop terminated without completing the request.\n");
}

if (ENGINE->debug_logging_enabled() && ENGINE->has_pending_async_tasks()) {
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/fetch/fetch_event.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BUILTINS_FETCH_EVENT_H
#define BUILTINS_FETCH_EVENT_H
#ifndef BUILTINS_WEB_FETCH_FETCH_EVENT_H
#define BUILTINS_WEB_FETCH_FETCH_EVENT_H

#include "builtin.h"
#include "extension-api.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/fetch/headers.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BUILTINS_HEADERS_H
#define BUILTINS_HEADERS_H
#ifndef BUILTINS_WEB_FETCH_HEADERS_H
#define BUILTINS_WEB_FETCH_HEADERS_H

#include "builtin.h"
#include "host_api.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/fetch/request-response.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef BUILTIN_REQUEST_RESPONSE
#define BUILTIN_REQUEST_RESPONSE
#ifndef BUILTINS_WEB_FETCH_REQUEST_RESPONSE
#define BUILTINS_WEB_FETCH_REQUEST_RESPONSE

#include "fetch-errors.h"
#include "headers.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/performance.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_BUILTIN_PERFORMANCE_H
#define JS_COMPUTE_RUNTIME_BUILTIN_PERFORMANCE_H
#ifndef BUILTINS_WEB_BUILTIN_PERFORMANCE_H
#define BUILTINS_WEB_BUILTIN_PERFORMANCE_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/queue-microtask.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_QUEUE_MICROTASK_H
#define JS_COMPUTE_RUNTIME_QUEUE_MICROTASK_H
#ifndef BUILTINS_WEB_QUEUE_MICROTASK_H
#define BUILTINS_WEB_QUEUE_MICROTASK_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/compression-stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_COMPRESSION_STREAM_H
#define JS_COMPUTE_RUNTIME_COMPRESSION_STREAM_H
#ifndef BUILTINS_WEB_STREAMS_COMPRESSION_STREAM_H
#define BUILTINS_WEB_STREAMS_COMPRESSION_STREAM_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/decompression-stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_DECOMPRESSION_STREAM_H
#define JS_COMPUTE_RUNTIME_DECOMPRESSION_STREAM_H
#ifndef BUILTINS_WEB_STREAMS_DECOMPRESSION_STREAM_H
#define BUILTINS_WEB_STREAMS_DECOMPRESSION_STREAM_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/native-stream-sink.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_NATIVE_STREAM_SINK_H
#define JS_COMPUTE_RUNTIME_NATIVE_STREAM_SINK_H
#ifndef BUILTINS_WEB_STREAMS_NATIVE_STREAM_SINK_H
#define BUILTINS_WEB_STREAMS_NATIVE_STREAM_SINK_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/native-stream-source.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_NATIVE_STREAM_SOURCE_H
#define JS_COMPUTE_RUNTIME_NATIVE_STREAM_SOURCE_H
#ifndef BUILTINS_WEB_STREAMS_NATIVE_STREAM_SOURCE_H
#define BUILTINS_WEB_STREAMS_NATIVE_STREAM_SOURCE_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/transform-stream-default-controller.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_TRANSFORM_STREAM_DEFAULT_CONTROLLER_H
#define JS_COMPUTE_RUNTIME_TRANSFORM_STREAM_DEFAULT_CONTROLLER_H
#ifndef BUILTINS_WEB_STREAMS_TRANSFORM_STREAM_DEFAULT_CONTROLLER_H
#define BUILTINS_WEB_STREAMS_TRANSFORM_STREAM_DEFAULT_CONTROLLER_H

#include "builtin.h"

Expand Down
4 changes: 2 additions & 2 deletions builtins/web/streams/transform-stream.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_TRANSFORM_STREAM_H
#define JS_COMPUTE_RUNTIME_TRANSFORM_STREAM_H
#ifndef BUILTINS_WEB_STREAMS_TRANSFORM_STREAM_H
#define BUILTINS_WEB_STREAMS_TRANSFORM_STREAM_H

#include "builtin.h"
// #include "js-compute-builtins.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/structured-clone.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_STRUCTURED_CLONE_H
#define JS_COMPUTE_RUNTIME_STRUCTURED_CLONE_H
#ifndef BUILTINS_WEB_STRUCTURED_CLONE_H
#define BUILTINS_WEB_STRUCTURED_CLONE_H

#include "builtin.h"
#include "js/StructuredClone.h"
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/worker-location.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef JS_COMPUTE_RUNTIME_WORKER_LOCATION_H
#define JS_COMPUTE_RUNTIME_WORKER_LOCATION_H
#ifndef BUILTINS_WEB_WORKER_LOCATION_H
#define BUILTINS_WEB_WORKER_LOCATION_H

#include "builtin.h"

Expand Down
2 changes: 1 addition & 1 deletion cmake/weval.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(WEVAL_VERSION v0.2.9)
set(WEVAL_VERSION v0.2.12)

set(WEVAL_URL https://github.com/cfallin/weval/releases/download/${WEVAL_VERSION}/weval-${WEVAL_VERSION}-${HOST_ARCH}-${HOST_OS}.tar.xz)
CPMAddPackage(NAME weval URL ${WEVAL_URL} DOWNLOAD_ONLY TRUE)
Expand Down
5 changes: 3 additions & 2 deletions include/extension-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ class Engine {

bool dump_value(JS::Value val, FILE *fp = stdout);
bool print_stack(FILE *fp);
void dump_pending_exception(const char *description = "");
void dump_promise_rejection(HandleValue reason, HandleObject promise, FILE *fp);
void dump_error(HandleValue error, FILE *fp = stderr);
void dump_pending_exception(const char *description = "", FILE *fp = stderr);
void dump_promise_rejection(HandleValue reason, HandleObject promise, FILE *fp = stderr);
};


Expand Down
57 changes: 39 additions & 18 deletions runtime/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ bool print_stack(JSContext *cx, FILE *fp) {
return print_stack(cx, stackp, fp);
}

void dump_promise_rejection(JSContext *cx, HandleValue reason, HandleObject promise, FILE *fp) {
void dump_error(JSContext *cx, HandleValue error, bool *has_stack, FILE *fp) {
bool reported = false;
RootedObject stack(cx);

if (reason.isObject()) {
RootedObject err(cx, &reason.toObject());
if (error.isObject()) {
RootedObject err(cx, &error.toObject());
JSErrorReport *report = JS_ErrorFromException(cx, err);
if (report) {
fprintf(stderr, "%s\n", report->message().c_str());
Expand All @@ -124,20 +124,30 @@ void dump_promise_rejection(JSContext *cx, HandleValue reason, HandleObject prom
// If the rejection reason isn't an `Error` object, we just dump the value
// as-is.
if (!reported) {
dump_value(cx, reason, stderr);
dump_value(cx, error, stderr);
}

if (stack) {
*has_stack = true;
fprintf(stderr, "Stack:\n");
print_stack(cx, stack, stderr);
} else {
*has_stack = false;
}
}

void dump_promise_rejection(JSContext *cx, HandleValue reason, HandleObject promise, FILE *fp) {
bool has_stack;
dump_error(cx, reason, &has_stack, fp);

// If the rejection reason isn't an `Error` object, we can't get an exception
// stack from it. In that case, fall back to getting the stack from the
// promise resolution site. These should be identical in many cases, such as
// for exceptions thrown in async functions, but for some reason the
// resolution site stack seems to sometimes be wrong, so we only fall back to
// it as a last resort.
if (!stack) {
stack = JS::GetPromiseResolutionSite(promise);
}

if (stack) {
if (!has_stack) {
RootedObject stack(cx, JS::GetPromiseResolutionSite(promise));
fprintf(stderr, "Stack:\n");
print_stack(cx, stack, stderr);
}
Expand Down Expand Up @@ -294,25 +304,29 @@ static bool report_unhandled_promise_rejections(JSContext *cx) {
return true;
}

static void DumpPendingException(JSContext *cx, const char *description) {
static void DumpPendingException(JSContext *cx, const char *description, FILE *fp) {
JS::ExceptionStack exception(cx);
if (!JS::GetPendingExceptionStack(cx, &exception)) {
fprintf(stderr,
if (!JS::StealPendingExceptionStack(cx, &exception)) {
fprintf(fp,
"Error: exception pending after %s, but got another error "
"when trying to retrieve it. Aborting.\n",
description);
} else {
fprintf(stderr, "Exception while %s: ", description);
dump_value(cx, exception.exception(), stderr);
print_stack(cx, exception.stack(), stderr);
fprintf(fp, "Exception while %s\n", description);
JS::ErrorReportBuilder report(cx);
if (!report.init(cx, exception, JS::ErrorReportBuilder::WithSideEffects)) {
fprintf(fp, "unable to build error report");
} else {
JS::PrintError(fp, report, false);
}
}
}

static void abort(JSContext *cx, const char *description) {
// Note: we unconditionally print messages here, since they almost always
// indicate serious bugs.
if (JS_IsExceptionPending(cx)) {
DumpPendingException(cx, description);
DumpPendingException(cx, description, stderr);
} else {
fprintf(stderr,
"Error while %s, but no exception is pending. "
Expand Down Expand Up @@ -374,6 +388,7 @@ bool api::Engine::initialize(const char *filename) {
if (!eval_toplevel(filename, &result)) {
if (JS_IsExceptionPending(cx())) {
dump_pending_exception("pre-initializing");
fflush(stderr);
}
return false;
}
Expand Down Expand Up @@ -493,8 +508,14 @@ void api::Engine::decr_event_loop_interest() {
bool api::Engine::dump_value(JS::Value val, FILE *fp) { return ::dump_value(CONTEXT, val, fp); }
bool api::Engine::print_stack(FILE *fp) { return ::print_stack(CONTEXT, fp); }

void api::Engine::dump_pending_exception(const char *description) {
DumpPendingException(CONTEXT, description);
void api::Engine::dump_pending_exception(const char *description, FILE *fp) {
DumpPendingException(CONTEXT, description, fp);
}

void api::Engine::dump_error(JS::HandleValue err, FILE *fp) {
bool has_stack;
::dump_error(CONTEXT, err, &has_stack, fp);
fflush(fp);
}

void api::Engine::dump_promise_rejection(HandleValue reason, HandleObject promise, FILE *fp) {
Expand Down
2 changes: 0 additions & 2 deletions runtime/event_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ bool EventLoop::run_event_loop(api::Engine *engine, double total_compute) {
if (tasks_size == 0) {
exit_event_loop();
MOZ_ASSERT(!interest_complete());
fprintf(stderr, "event loop error - both task and job queues are empty, but expected "
"operations did not resolve");
return false;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/e2e/eventloop-stall/eventloop-stall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { strictEqual, deepStrictEqual, throws } from "../../assert.js";

addEventListener("fetch", (evt) =>
evt.respondWith(
(async () => {
return new Response(new ReadableStream({
start(_controller) {
// stall
},
}));
})()
)
);
1 change: 1 addition & 0 deletions tests/e2e/eventloop-stall/expect_serve_stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stderr [0] :: Warning: JS event loop terminated without completing the request.
1 change: 1 addition & 0 deletions tests/e2e/runtime-err/expect_serve_status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
500
5 changes: 5 additions & 0 deletions tests/e2e/runtime-err/expect_serve_stderr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stderr [0] :: Error while running request handler:
stderr [0] :: runtime error
stderr [0] :: Stack:
stderr [0] :: @runtime-err.js:6:13
stderr [0] :: @runtime-err.js:7:7
9 changes: 9 additions & 0 deletions tests/e2e/runtime-err/runtime-err.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { strictEqual, deepStrictEqual, throws } from "../../assert.js";

addEventListener("fetch", (evt) =>
evt.respondWith(
(async () => {
throw new Error('runtime error');
})()
)
);
Empty file.
3 changes: 2 additions & 1 deletion tests/e2e/syntax-err/expect_wizer_stderr.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Exception while pre-initializing: (new SyntaxError("expected expression, got end of script", "syntax-err.js", 2))
Exception while pre-initializing
syntax-err.js:2:1 SyntaxError: expected expression, got end of script
3 changes: 2 additions & 1 deletion tests/e2e/tla-err/expect_wizer_stderr.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Exception while pre-initializing: (new Error("blah", "tla-err.js", 3))
Exception while pre-initializing
tla-err.js:3:10 Error: blah
Loading

0 comments on commit 4e3712b

Please sign in to comment.