Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
strategy:
fail-fast: false
matrix:
build: [release, debug]
build: [release, debug, weval]
os: [ubuntu-latest]
outputs:
SM_TAG_EXISTS: ${{ steps.check-sm-release.outputs.SM_TAG_EXISTS }}
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ include("init-corrosion")

include("wasm-tools")
include("binaryen")
include("wizer")
include("weval")
include("wasmtime")
include("cbindgen")
Expand Down
6 changes: 3 additions & 3 deletions builtins/web/abort/abort-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const JSPropertySpec AbortController::properties[] = {
bool AbortController::signal_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);

args.rval().set(JS::GetReservedSlot(self, Slots::Signal));
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::Signal)));
return true;
}

bool AbortController::abort(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);

RootedValue reason(cx, args.get(0));
RootedObject signal(cx, JS::GetReservedSlot(self, Slots::Signal).toObjectOrNull());
RootedObject signal(cx, JS::GetReservedSlot(self, std::to_underlying(Slots::Signal)).toObjectOrNull());
if (!signal) {
return false;
}
Expand All @@ -55,7 +55,7 @@ bool AbortController::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
return false;
}

SetReservedSlot(self, Slots::Signal, JS::ObjectValue(*signal));
SetReservedSlot(self, std::to_underlying(Slots::Signal), JS::ObjectValue(*signal));

args.rval().setObject(*self);
return true;
Expand Down
2 changes: 1 addition & 1 deletion builtins/web/abort/abort-controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AbortController : public BuiltinImpl<AbortController> {
static constexpr const char *class_name = "AbortController";
static constexpr unsigned ctor_length = 0;

enum Slots : uint8_t { Signal = 0, Count };
enum class Slots : uint8_t { Signal = 0, Count };

static const JSFunctionSpec static_methods[];
static const JSPropertySpec static_properties[];
Expand Down
46 changes: 23 additions & 23 deletions builtins/web/abort/abort-signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ bool AbortSignal::aborted_get(JSContext *cx, unsigned argc, JS::Value *vp) {
bool AbortSignal::reason_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);

args.rval().set(JS::GetReservedSlot(self, Slots::Reason));
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::Reason)));
return true;
}

// https://dom.spec.whatwg.org/#dom-abortsignal-onabort
bool AbortSignal::onabort_get(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(0);

args.rval().set(JS::GetReservedSlot(self, Slots::OnAbort));
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::OnAbort)));
return true;
}

Expand All @@ -62,7 +62,7 @@ bool AbortSignal::onabort_set(JSContext *cx, unsigned argc, JS::Value *vp) {
METHOD_HEADER(1);

RootedValue new_callback(cx, args.get(0));
RootedValue curr_callback(cx, JS::GetReservedSlot(self, Slots::OnAbort));
RootedValue curr_callback(cx, JS::GetReservedSlot(self, std::to_underlying(Slots::OnAbort)));

RootedValue opts(cx, JS::FalseValue());
RootedValue type(cx, JS::StringValue(abort_type_atom));
Expand Down Expand Up @@ -140,7 +140,7 @@ bool AbortSignal::throwIfAborted(JSContext *cx, unsigned argc, JS::Value *vp) {
// Steps: Throw this's abort reason, if this's AbortController has signaled
// to abort; otherwise, does nothing.
if (is_aborted(self)) {
RootedValue reason(cx, JS::GetReservedSlot(self, Slots::Reason));
RootedValue reason(cx, JS::GetReservedSlot(self, std::to_underlying(Slots::Reason)));
JS_SetPendingException(cx, reason);
}

Expand All @@ -165,23 +165,23 @@ bool AbortSignal::on_timeout(JSContext *cx, unsigned argc, JS::Value *vp) {

AbortSignal::AlgorithmList *AbortSignal::algorithms(JSObject *self) {
MOZ_ASSERT(is_instance(self));
return static_cast<AlgorithmList *>(JS::GetReservedSlot(self, Slots::Algorithms).toPrivate());
return static_cast<AlgorithmList *>(JS::GetReservedSlot(self, std::to_underlying(Slots::Algorithms)).toPrivate());
}

WeakIndexSet *AbortSignal::source_signals(JSObject *self) {
MOZ_ASSERT(is_instance(self));
return static_cast<WeakIndexSet *>(JS::GetReservedSlot(self, Slots::SourceSignals).toPrivate());
return static_cast<WeakIndexSet *>(JS::GetReservedSlot(self, std::to_underlying(Slots::SourceSignals)).toPrivate());
}

WeakIndexSet *AbortSignal::dependent_signals(JSObject *self) {
MOZ_ASSERT(is_instance(self));
return static_cast<WeakIndexSet *>(
JS::GetReservedSlot(self, Slots::DependentSignals).toPrivate());
JS::GetReservedSlot(self, std::to_underlying(Slots::DependentSignals)).toPrivate());
}

Value AbortSignal::reason(JSObject *self) {
MOZ_ASSERT(is_instance(self));
return JS::GetReservedSlot(self, Slots::Reason);
return JS::GetReservedSlot(self, std::to_underlying(Slots::Reason));
}

// https://dom.spec.whatwg.org/#abortsignal-add
Expand All @@ -201,14 +201,14 @@ bool AbortSignal::add_algorithm(JSObject *self, js::UniquePtr<AbortAlgorithm> al

bool AbortSignal::is_dependent(JSObject *self) {
MOZ_ASSERT(is_instance(self));
return JS::GetReservedSlot(self, Slots::Dependent).toBoolean();
return JS::GetReservedSlot(self, std::to_underlying(Slots::Dependent)).toBoolean();
}

// https://dom.spec.whatwg.org/#abortsignal-aborted
bool AbortSignal::is_aborted(JSObject *self) {
MOZ_ASSERT(is_instance(self));
// An AbortSignal object is aborted when its abort reason is not undefined.
return !JS::GetReservedSlot(self, Slots::Reason).isUndefined();
return !JS::GetReservedSlot(self, std::to_underlying(Slots::Reason)).isUndefined();
}

// https://dom.spec.whatwg.org/#abortsignal-signal-abort
Expand Down Expand Up @@ -282,14 +282,14 @@ bool AbortSignal::run_abort_steps(JSContext *cx, HandleObject self) {
// Set signal's abort reason to reason if it is given; otherwise to a new "AbortError" DOMException.
bool AbortSignal::set_reason(JSContext *cx, HandleObject self, HandleValue reason) {
if (!reason.isUndefined()) {
SetReservedSlot(self, Slots::Reason, reason);
SetReservedSlot(self, std::to_underlying(Slots::Reason), reason);
} else {
RootedObject exception(cx, dom_exception::DOMException::create(cx, "AbortError", "AbortError"));
if (!exception) {
return false;
}

SetReservedSlot(self, Slots::Reason, JS::ObjectValue(*exception));
SetReservedSlot(self, std::to_underlying(Slots::Reason), JS::ObjectValue(*exception));
}

return true;
Expand All @@ -303,17 +303,17 @@ JSObject *AbortSignal::create(JSContext *cx) {
}

// An AbortSignal object has an associated abort reason, which is initially undefined.
SetReservedSlot(self, Slots::Reason, JS::UndefinedValue());
SetReservedSlot(self, std::to_underlying(Slots::Reason), JS::UndefinedValue());
// An AbortSignal object has associated abort algorithms, which is initially empty.
SetReservedSlot(self, Slots::Algorithms, JS::PrivateValue(new AlgorithmList));
SetReservedSlot(self, std::to_underlying(Slots::Algorithms), JS::PrivateValue(new AlgorithmList));
// An AbortSignal object has a dependent (a boolean), which is initially false.
SetReservedSlot(self, Slots::Dependent, JS::FalseValue());
SetReservedSlot(self, std::to_underlying(Slots::Dependent), JS::FalseValue());
// An AbortSignal object has associated source signals, which is initially empty.
SetReservedSlot(self, Slots::SourceSignals, JS::PrivateValue(new WeakIndexSet));
SetReservedSlot(self, std::to_underlying(Slots::SourceSignals), JS::PrivateValue(new WeakIndexSet));
// An AbortSignal object has associated dependent signals, which is initially empty.
SetReservedSlot(self, Slots::DependentSignals, JS::PrivateValue(new WeakIndexSet));
SetReservedSlot(self, std::to_underlying(Slots::DependentSignals), JS::PrivateValue(new WeakIndexSet));
// cache the onabort handler
SetReservedSlot(self, Slots::OnAbort, JS::NullValue());
SetReservedSlot(self, std::to_underlying(Slots::OnAbort), JS::NullValue());

if (!EventTarget::init(cx, self)) {
return nullptr;
Expand Down Expand Up @@ -411,13 +411,13 @@ JSObject *AbortSignal::create_with_signals(JSContext *cx, HandleValueArray signa
RootedObject signal(cx, &signals[i].toObject());

if (is_aborted(signal)) {
SetReservedSlot(self, Slots::Reason, reason(signal));
SetReservedSlot(self, std::to_underlying(Slots::Reason), reason(signal));
return self;
}
}

// 3. Set resultSignal's dependent to true.
SetReservedSlot(self, Slots::Dependent, JS::TrueValue());
SetReservedSlot(self, std::to_underlying(Slots::Dependent), JS::TrueValue());
auto *our_signals = source_signals(self);

// 4. For each signal of signals:
Expand Down Expand Up @@ -465,21 +465,21 @@ void AbortSignal::trace(JSTracer *trc, JSObject *self) {
MOZ_ASSERT(is_instance(self));
EventTarget::trace(trc, self);

auto has_sources = !JS::GetReservedSlot(self, Slots::SourceSignals).isNullOrUndefined();
auto has_sources = !JS::GetReservedSlot(self, std::to_underlying(Slots::SourceSignals)).isNullOrUndefined();
if (has_sources) {
auto *srcsig = source_signals(self);
srcsig->trace(trc);
srcsig->traceWeak(trc);
}

auto has_deps = !JS::GetReservedSlot(self, Slots::DependentSignals).isNullOrUndefined();
auto has_deps = !JS::GetReservedSlot(self, std::to_underlying(Slots::DependentSignals)).isNullOrUndefined();
if (has_deps) {
auto *depsig = dependent_signals(self);
depsig->trace(trc);
depsig->traceWeak(trc);
}

auto has_algorithms = !JS::GetReservedSlot(self, Slots::Algorithms).isNullOrUndefined();
auto has_algorithms = !JS::GetReservedSlot(self, std::to_underlying(Slots::Algorithms)).isNullOrUndefined();
if (has_algorithms) {
auto *algorithms = AbortSignal::algorithms(self);
algorithms->trace(trc);
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/abort/abort-signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class AbortSignal : public BuiltinImpl<AbortSignal, TraceableClassPolicy> {
friend class AbortController;

public:
static constexpr int ParentSlots = event::EventTarget::Slots::Count;
enum Slots : uint8_t {
static constexpr int ParentSlots = std::to_underlying(event::EventTarget::Slots::Count);
enum class Slots : uint8_t {
Reason = ParentSlots,
Algorithms,
Dependent,
Expand Down
16 changes: 8 additions & 8 deletions builtins/web/blob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ bool Blob::init_options(JSContext *cx, HandleObject self, HandleValue initv) {

if (is_transparent || is_native) {
auto endings = is_native ? LineEndings::Native : LineEndings::Transparent;
SetReservedSlot(self, static_cast<uint32_t>(Slots::Endings), JS::Int32Value(endings));
SetReservedSlot(self, std::to_underlying(Slots::Endings), JS::Int32Value(std::to_underlying(endings)));
}
}

Expand All @@ -551,7 +551,7 @@ bool Blob::init_options(JSContext *cx, HandleObject self, HandleValue initv) {
if (!type_str) {
return false;
}
SetReservedSlot(self, static_cast<uint32_t>(Slots::Type), JS::StringValue(type_str));
SetReservedSlot(self, std::to_underlying(Slots::Type), JS::StringValue(type_str));
}

return true;
Expand All @@ -574,9 +574,9 @@ JSObject *Blob::create(JSContext *cx, UniqueChars data, size_t data_len, HandleS
blob->replaceRawBuffer(reinterpret_cast<uint8_t *>(data.release()), data_len);
}

SetReservedSlot(self, static_cast<uint32_t>(Slots::Data), JS::PrivateValue(blob.release()));
SetReservedSlot(self, static_cast<uint32_t>(Slots::Type), JS::StringValue(type));
SetReservedSlot(self, static_cast<uint32_t>(Slots::Endings), JS::Int32Value(LineEndings::Transparent));
SetReservedSlot(self, std::to_underlying(Slots::Data), JS::PrivateValue(blob.release()));
SetReservedSlot(self, std::to_underlying(Slots::Type), JS::StringValue(type));
SetReservedSlot(self, std::to_underlying(Slots::Endings), JS::Int32Value(std::to_underlying(LineEndings::Transparent)));
return self;
}

Expand All @@ -587,9 +587,9 @@ bool Blob::init(JSContext *cx, HandleObject self, HandleValue blobParts, HandleV
return false;
}

SetReservedSlot(self, static_cast<uint32_t>(Slots::Type), JS_GetEmptyStringValue(cx));
SetReservedSlot(self, static_cast<uint32_t>(Slots::Endings), JS::Int32Value(LineEndings::Transparent));
SetReservedSlot(self, static_cast<uint32_t>(Slots::Data), JS::PrivateValue(blob.release()));
SetReservedSlot(self, std::to_underlying(Slots::Type), JS_GetEmptyStringValue(cx));
SetReservedSlot(self, std::to_underlying(Slots::Endings), JS::Int32Value(std::to_underlying(LineEndings::Transparent)));
SetReservedSlot(self, std::to_underlying(Slots::Data), JS::PrivateValue(blob.release()));

// Walk the blob parts and append them to the blob's buffer.
if (blobParts.isNull()) {
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Blob : public BuiltinImpl<Blob, FinalizableClassPolicy> {
static const JSPropertySpec properties[];

static constexpr unsigned ctor_length = 0;
enum Slots : uint8_t { Data, Type, Endings, Readers, Count };
enum LineEndings : uint8_t { Transparent, Native };
enum class Slots : uint8_t { Data, Type, Endings, Readers, Count };
enum class LineEndings : uint8_t { Transparent, Native };

using ByteBuffer = js::Vector<uint8_t, 0, js::SystemAllocPolicy>;

Expand Down
13 changes: 7 additions & 6 deletions builtins/web/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "encode.h"
#include <chrono>
#include <map>
#include <print>

#include <js/Array.h>
#include <js/experimental/TypedData.h>
Expand Down Expand Up @@ -153,7 +154,7 @@ JS::Result<mozilla::Ok> ArrayToSource(JSContext *cx, std::string &sourceOut, JS:
return JS::Result<mozilla::Ok>(JS::Error());
}

for (int i = 0; i < len; i++) {
for (uint32_t i = 0; i < len; i++) {
JS::RootedValue entry_val(cx);
JS_GetElement(cx, obj, i, &entry_val);
if (i > 0) {
Expand Down Expand Up @@ -430,7 +431,7 @@ void builtin_impl_console_log(Console::LogType log_ty, const char *msg) {
}
MOZ_ASSERT(prefix);

fprintf(stdout, "%s: %s\n", prefix, msg);
std::println(stdout, "{}: {}", prefix, msg);
fflush(stdout);
}

Expand All @@ -440,7 +441,7 @@ static bool console_out(JSContext *cx, unsigned argc, JS::Value *vp) {
std::string fullLogLine;
auto length = args.length();
JS::RootedObjectVector visitedObjects(cx);
for (int i = 0; i < length; i++) {
for (unsigned i = 0; i < length; i++) {
JS::HandleValue arg = args.get(i);
std::string source;
auto result = ToSource(cx, source, arg, &visitedObjects);
Expand Down Expand Up @@ -490,7 +491,7 @@ static bool assert_(JSContext *cx, unsigned argc, JS::Value *vp) {
if (length > 1) {
message += ": ";
JS::RootedObjectVector visitedObjects(cx);
for (int i = 0; i < length; i++) {
for (unsigned i = 0; i < length; i++) {
JS::HandleValue arg = args.get(i);
std::string source;
auto result = ToSource(cx, source, arg, &visitedObjects);
Expand Down Expand Up @@ -656,7 +657,7 @@ static bool timeLog(JSContext *cx, unsigned argc, JS::Value *vp) {
if (args.length() > 1) {
auto length = args.length();
JS::RootedObjectVector visitedObjects(cx);
for (int i = 1; i < length; i++) {
for (unsigned i = 1; i < length; i++) {
JS::HandleValue arg = args.get(i);
std::string source;
auto result = ToSource(cx, source, arg, &visitedObjects);
Expand Down Expand Up @@ -782,7 +783,7 @@ static bool trace(JSContext *cx, unsigned argc, JS::Value *vp) {
// incorporate formattedData as a label for trace.
std::string fullLogLine;
JS::RootedObjectVector visitedObjects(cx);
for (int i = 0; i < args.length(); i++) {
for (unsigned i = 0; i < args.length(); i++) {
JS::HandleValue arg = args.get(i);
std::string source;
auto result = ToSource(cx, source, arg, &visitedObjects);
Expand Down
4 changes: 2 additions & 2 deletions builtins/web/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class Console : public BuiltinNoConstructor<Console> {
private:
public:
static constexpr const char *class_name = "Console";
enum LogType : uint8_t {
enum class LogType : uint8_t {
Log,
Info,
Debug,
Warn,
Error,
};
enum Slots : uint8_t { Count };
enum class Slots : uint8_t { Count };
static const JSFunctionSpec methods[];
static const JSPropertySpec properties[];
};
Expand Down
1 change: 1 addition & 0 deletions builtins/web/crypto/crypto-key-ec-components.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_KEY_EC_COMPONENTS_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_KEY_EC_COMPONENTS_H

#include <memory>
#include <string>
#include <vector>

Expand Down
1 change: 1 addition & 0 deletions builtins/web/crypto/crypto-key-rsa-components.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef BUILTINS_WEB_CRYPTO_CRYPTO_KEY_RSA_COMPONENTS_H
#define BUILTINS_WEB_CRYPTO_CRYPTO_KEY_RSA_COMPONENTS_H

#include <memory>
#include <optional>
#include <string>
#include <vector>
Expand Down
Loading