Skip to content

Commit 643aa45

Browse files
authored
feat: reenable weval patches (#303)
* chore: reenable weval patches * bump ff to latest stable release * chore: bump tools * fix: ensure poll results ordering The wasi spce doesn't really say anything about the order of ready handles, it only says that he result list<u32> contains one or more indices of handles in the argument list that is ready for I/O. We should find the oldest task. This was working previously because wasmtime v29 was using HashMap for iterating pollables for which the iteration order was random and just happened to work. Recent version of wasmtime changes that to use BTreeMap instead which broke the assumptions here. * fix: apply linter fixes from new wasi-sdk Most of the fixes are mechanical: - changing c style enums to enum classes and then using std::to_underlying to convert to numeric types - replacing printf with std::println - fixing stack address escape in builtin.h file: returning &self in the tuple gives the caller a dangling pointer, but the pointer where never actually used. * chore: switch to bytecodealliance repo * fix: apply review suggestions * fix: disable warning from third party code * fix: add comment explaining GC policy specialization
1 parent 6ff0d0d commit 643aa45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+581
-523
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Checks: >
1111
misc-unused-alias-decls,
1212
misc-unused-using-decls,
1313
-clang-analyzer-optin.core.EnumCastOutOfRange,
14+
-clang-analyzer-optin.cplusplus.UninitializedObject,
1415
-cppcoreguidelines-avoid-do-while,
1516
-cppcoreguidelines-avoid-c-arrays,
1617
-cppcoreguidelines-pro-type-reinterpret-cast,

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
fail-fast: false
2626
matrix:
27-
build: [release, debug]
27+
build: [release, debug, weval]
2828
os: [ubuntu-latest]
2929
outputs:
3030
SM_TAG_EXISTS: ${{ steps.check-sm-release.outputs.SM_TAG_EXISTS }}

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ include("init-corrosion")
3333

3434
include("wasm-tools")
3535
include("binaryen")
36-
include("wizer")
3736
include("weval")
3837
include("wasmtime")
3938
include("cbindgen")

builtins/web/abort/abort-controller.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ const JSPropertySpec AbortController::properties[] = {
2626
bool AbortController::signal_get(JSContext *cx, unsigned argc, JS::Value *vp) {
2727
METHOD_HEADER(0);
2828

29-
args.rval().set(JS::GetReservedSlot(self, Slots::Signal));
29+
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::Signal)));
3030
return true;
3131
}
3232

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

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

58-
SetReservedSlot(self, Slots::Signal, JS::ObjectValue(*signal));
58+
SetReservedSlot(self, std::to_underlying(Slots::Signal), JS::ObjectValue(*signal));
5959

6060
args.rval().setObject(*self);
6161
return true;

builtins/web/abort/abort-controller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AbortController : public BuiltinImpl<AbortController> {
1717
static constexpr const char *class_name = "AbortController";
1818
static constexpr unsigned ctor_length = 0;
1919

20-
enum Slots : uint8_t { Signal = 0, Count };
20+
enum class Slots : uint8_t { Signal = 0, Count };
2121

2222
static const JSFunctionSpec static_methods[];
2323
static const JSPropertySpec static_properties[];

builtins/web/abort/abort-signal.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ bool AbortSignal::aborted_get(JSContext *cx, unsigned argc, JS::Value *vp) {
4545
bool AbortSignal::reason_get(JSContext *cx, unsigned argc, JS::Value *vp) {
4646
METHOD_HEADER(0);
4747

48-
args.rval().set(JS::GetReservedSlot(self, Slots::Reason));
48+
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::Reason)));
4949
return true;
5050
}
5151

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

56-
args.rval().set(JS::GetReservedSlot(self, Slots::OnAbort));
56+
args.rval().set(JS::GetReservedSlot(self, std::to_underlying(Slots::OnAbort)));
5757
return true;
5858
}
5959

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

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

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

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

166166
AbortSignal::AlgorithmList *AbortSignal::algorithms(JSObject *self) {
167167
MOZ_ASSERT(is_instance(self));
168-
return static_cast<AlgorithmList *>(JS::GetReservedSlot(self, Slots::Algorithms).toPrivate());
168+
return static_cast<AlgorithmList *>(JS::GetReservedSlot(self, std::to_underlying(Slots::Algorithms)).toPrivate());
169169
}
170170

171171
WeakIndexSet *AbortSignal::source_signals(JSObject *self) {
172172
MOZ_ASSERT(is_instance(self));
173-
return static_cast<WeakIndexSet *>(JS::GetReservedSlot(self, Slots::SourceSignals).toPrivate());
173+
return static_cast<WeakIndexSet *>(JS::GetReservedSlot(self, std::to_underlying(Slots::SourceSignals)).toPrivate());
174174
}
175175

176176
WeakIndexSet *AbortSignal::dependent_signals(JSObject *self) {
177177
MOZ_ASSERT(is_instance(self));
178178
return static_cast<WeakIndexSet *>(
179-
JS::GetReservedSlot(self, Slots::DependentSignals).toPrivate());
179+
JS::GetReservedSlot(self, std::to_underlying(Slots::DependentSignals)).toPrivate());
180180
}
181181

182182
Value AbortSignal::reason(JSObject *self) {
183183
MOZ_ASSERT(is_instance(self));
184-
return JS::GetReservedSlot(self, Slots::Reason);
184+
return JS::GetReservedSlot(self, std::to_underlying(Slots::Reason));
185185
}
186186

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

202202
bool AbortSignal::is_dependent(JSObject *self) {
203203
MOZ_ASSERT(is_instance(self));
204-
return JS::GetReservedSlot(self, Slots::Dependent).toBoolean();
204+
return JS::GetReservedSlot(self, std::to_underlying(Slots::Dependent)).toBoolean();
205205
}
206206

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

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

292-
SetReservedSlot(self, Slots::Reason, JS::ObjectValue(*exception));
292+
SetReservedSlot(self, std::to_underlying(Slots::Reason), JS::ObjectValue(*exception));
293293
}
294294

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

305305
// An AbortSignal object has an associated abort reason, which is initially undefined.
306-
SetReservedSlot(self, Slots::Reason, JS::UndefinedValue());
306+
SetReservedSlot(self, std::to_underlying(Slots::Reason), JS::UndefinedValue());
307307
// An AbortSignal object has associated abort algorithms, which is initially empty.
308-
SetReservedSlot(self, Slots::Algorithms, JS::PrivateValue(new AlgorithmList));
308+
SetReservedSlot(self, std::to_underlying(Slots::Algorithms), JS::PrivateValue(new AlgorithmList));
309309
// An AbortSignal object has a dependent (a boolean), which is initially false.
310-
SetReservedSlot(self, Slots::Dependent, JS::FalseValue());
310+
SetReservedSlot(self, std::to_underlying(Slots::Dependent), JS::FalseValue());
311311
// An AbortSignal object has associated source signals, which is initially empty.
312-
SetReservedSlot(self, Slots::SourceSignals, JS::PrivateValue(new WeakIndexSet));
312+
SetReservedSlot(self, std::to_underlying(Slots::SourceSignals), JS::PrivateValue(new WeakIndexSet));
313313
// An AbortSignal object has associated dependent signals, which is initially empty.
314-
SetReservedSlot(self, Slots::DependentSignals, JS::PrivateValue(new WeakIndexSet));
314+
SetReservedSlot(self, std::to_underlying(Slots::DependentSignals), JS::PrivateValue(new WeakIndexSet));
315315
// cache the onabort handler
316-
SetReservedSlot(self, Slots::OnAbort, JS::NullValue());
316+
SetReservedSlot(self, std::to_underlying(Slots::OnAbort), JS::NullValue());
317317

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

413413
if (is_aborted(signal)) {
414-
SetReservedSlot(self, Slots::Reason, reason(signal));
414+
SetReservedSlot(self, std::to_underlying(Slots::Reason), reason(signal));
415415
return self;
416416
}
417417
}
418418

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

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

468-
auto has_sources = !JS::GetReservedSlot(self, Slots::SourceSignals).isNullOrUndefined();
468+
auto has_sources = !JS::GetReservedSlot(self, std::to_underlying(Slots::SourceSignals)).isNullOrUndefined();
469469
if (has_sources) {
470470
auto *srcsig = source_signals(self);
471471
srcsig->trace(trc);
472472
srcsig->traceWeak(trc);
473473
}
474474

475-
auto has_deps = !JS::GetReservedSlot(self, Slots::DependentSignals).isNullOrUndefined();
475+
auto has_deps = !JS::GetReservedSlot(self, std::to_underlying(Slots::DependentSignals)).isNullOrUndefined();
476476
if (has_deps) {
477477
auto *depsig = dependent_signals(self);
478478
depsig->trace(trc);
479479
depsig->traceWeak(trc);
480480
}
481481

482-
auto has_algorithms = !JS::GetReservedSlot(self, Slots::Algorithms).isNullOrUndefined();
482+
auto has_algorithms = !JS::GetReservedSlot(self, std::to_underlying(Slots::Algorithms)).isNullOrUndefined();
483483
if (has_algorithms) {
484484
auto *algorithms = AbortSignal::algorithms(self);
485485
algorithms->trace(trc);

builtins/web/abort/abort-signal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class AbortSignal : public BuiltinImpl<AbortSignal, TraceableClassPolicy> {
5151
friend class AbortController;
5252

5353
public:
54-
static constexpr int ParentSlots = event::EventTarget::Slots::Count;
55-
enum Slots : uint8_t {
54+
static constexpr int ParentSlots = std::to_underlying(event::EventTarget::Slots::Count);
55+
enum class Slots : uint8_t {
5656
Reason = ParentSlots,
5757
Algorithms,
5858
Dependent,

builtins/web/blob.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ bool Blob::init_options(JSContext *cx, HandleObject self, HandleValue initv) {
537537

538538
if (is_transparent || is_native) {
539539
auto endings = is_native ? LineEndings::Native : LineEndings::Transparent;
540-
SetReservedSlot(self, static_cast<uint32_t>(Slots::Endings), JS::Int32Value(endings));
540+
SetReservedSlot(self, std::to_underlying(Slots::Endings), JS::Int32Value(std::to_underlying(endings)));
541541
}
542542
}
543543

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

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

577-
SetReservedSlot(self, static_cast<uint32_t>(Slots::Data), JS::PrivateValue(blob.release()));
578-
SetReservedSlot(self, static_cast<uint32_t>(Slots::Type), JS::StringValue(type));
579-
SetReservedSlot(self, static_cast<uint32_t>(Slots::Endings), JS::Int32Value(LineEndings::Transparent));
577+
SetReservedSlot(self, std::to_underlying(Slots::Data), JS::PrivateValue(blob.release()));
578+
SetReservedSlot(self, std::to_underlying(Slots::Type), JS::StringValue(type));
579+
SetReservedSlot(self, std::to_underlying(Slots::Endings), JS::Int32Value(std::to_underlying(LineEndings::Transparent)));
580580
return self;
581581
}
582582

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

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

594594
// Walk the blob parts and append them to the blob's buffer.
595595
if (blobParts.isNull()) {

builtins/web/blob.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class Blob : public BuiltinImpl<Blob, FinalizableClassPolicy> {
2929
static const JSPropertySpec properties[];
3030

3131
static constexpr unsigned ctor_length = 0;
32-
enum Slots : uint8_t { Data, Type, Endings, Readers, Count };
33-
enum LineEndings : uint8_t { Transparent, Native };
32+
enum class Slots : uint8_t { Data, Type, Endings, Readers, Count };
33+
enum class LineEndings : uint8_t { Transparent, Native };
3434

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

builtins/web/console.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "encode.h"
33
#include <chrono>
44
#include <map>
5+
#include <print>
56

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

156-
for (int i = 0; i < len; i++) {
157+
for (uint32_t i = 0; i < len; i++) {
157158
JS::RootedValue entry_val(cx);
158159
JS_GetElement(cx, obj, i, &entry_val);
159160
if (i > 0) {
@@ -430,7 +431,7 @@ void builtin_impl_console_log(Console::LogType log_ty, const char *msg) {
430431
}
431432
MOZ_ASSERT(prefix);
432433

433-
fprintf(stdout, "%s: %s\n", prefix, msg);
434+
std::println(stdout, "{}: {}", prefix, msg);
434435
fflush(stdout);
435436
}
436437

@@ -440,7 +441,7 @@ static bool console_out(JSContext *cx, unsigned argc, JS::Value *vp) {
440441
std::string fullLogLine;
441442
auto length = args.length();
442443
JS::RootedObjectVector visitedObjects(cx);
443-
for (int i = 0; i < length; i++) {
444+
for (unsigned i = 0; i < length; i++) {
444445
JS::HandleValue arg = args.get(i);
445446
std::string source;
446447
auto result = ToSource(cx, source, arg, &visitedObjects);
@@ -490,7 +491,7 @@ static bool assert_(JSContext *cx, unsigned argc, JS::Value *vp) {
490491
if (length > 1) {
491492
message += ": ";
492493
JS::RootedObjectVector visitedObjects(cx);
493-
for (int i = 0; i < length; i++) {
494+
for (unsigned i = 0; i < length; i++) {
494495
JS::HandleValue arg = args.get(i);
495496
std::string source;
496497
auto result = ToSource(cx, source, arg, &visitedObjects);
@@ -656,7 +657,7 @@ static bool timeLog(JSContext *cx, unsigned argc, JS::Value *vp) {
656657
if (args.length() > 1) {
657658
auto length = args.length();
658659
JS::RootedObjectVector visitedObjects(cx);
659-
for (int i = 1; i < length; i++) {
660+
for (unsigned i = 1; i < length; i++) {
660661
JS::HandleValue arg = args.get(i);
661662
std::string source;
662663
auto result = ToSource(cx, source, arg, &visitedObjects);
@@ -782,7 +783,7 @@ static bool trace(JSContext *cx, unsigned argc, JS::Value *vp) {
782783
// incorporate formattedData as a label for trace.
783784
std::string fullLogLine;
784785
JS::RootedObjectVector visitedObjects(cx);
785-
for (int i = 0; i < args.length(); i++) {
786+
for (unsigned i = 0; i < args.length(); i++) {
786787
JS::HandleValue arg = args.get(i);
787788
std::string source;
788789
auto result = ToSource(cx, source, arg, &visitedObjects);

0 commit comments

Comments
 (0)