Skip to content

Commit

Permalink
deps: update to SpiderMonkey 124.0.2 (#41)
Browse files Browse the repository at this point in the history
* deps: update to SpiderMonkey 124.0.2

* rust toolchain update

* fixup rust toolchain

* Update builtins/web/console.cpp

Co-authored-by: Till Schneidereit <[email protected]>

---------

Co-authored-by: Till Schneidereit <[email protected]>
  • Loading branch information
guybedford and tschneidereit authored May 3, 2024
1 parent 76f2a16 commit 844e104
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 21 deletions.
1 change: 1 addition & 0 deletions builtins/web/base64.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "base64.h"
#include "mozilla/Try.h"

namespace builtins {
namespace web {
Expand Down
14 changes: 9 additions & 5 deletions builtins/web/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <map>

#include <js/Array.h>
#include "mozilla/Try.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winvalid-offsetof"
#pragma clang diagnostic ignored "-Wdeprecated-enum-enum-conversion"
Expand Down Expand Up @@ -287,13 +288,16 @@ JS::Result<mozilla::Ok> ToSource(JSContext *cx, std::string &sourceOut, JS::Hand
JS::RootedObject obj(cx, &val.toObject());

if (JS_ObjectIsFunction(obj)) {
sourceOut += "[Function";
sourceOut += "[";
std::string source;
auto id = JS_GetFunctionId(JS_ValueToFunction(cx, val));
if (id) {
JS::RootedFunction fun(cx, JS_ValueToFunction(cx, val));
if (fun) {
JS::RootedString result(cx, JS_DecompileFunction(cx, fun));
if (!result) {
return JS::Result<mozilla::Ok>(JS::Error());
}
sourceOut += " ";
JS::RootedString name(cx, id);
auto msg = core::encode(cx, name);
auto msg = core::encode(cx, result);
if (!msg) {
return JS::Result<mozilla::Ok>(JS::Error());
}
Expand Down
7 changes: 4 additions & 3 deletions builtins/web/crypto/crypto-algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ JSObject *digest(JSContext *cx, std::span<uint8_t> data, const EVP_MD *algorithm
}
// 3. Return a new ArrayBuffer containing result.
JS::RootedObject array_buffer(cx);
array_buffer.set(JS::NewArrayBufferWithContents(cx, size, buf.get()));
array_buffer.set(JS::NewArrayBufferWithContents(
cx, size, buf.get(), JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!array_buffer) {
JS_ReportOutOfMemory(cx);
return nullptr;
Expand Down Expand Up @@ -704,7 +705,7 @@ JSObject *CryptoAlgorithmHMAC_Sign_Verify::sign(JSContext *cx, JS::HandleObject

// 2. Return a new ArrayBuffer object, associated with the relevant global object of this [HTML], and containing the bytes of mac.
JS::RootedObject array_buffer(cx);
array_buffer.set(JS::NewArrayBufferWithContents(cx, size, sig.get()));
array_buffer.set(JS::NewArrayBufferWithContents(cx, size, sig.get(), JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!array_buffer) {
JS_ReportOutOfMemory(cx);
return nullptr;
Expand Down Expand Up @@ -826,7 +827,7 @@ JSObject *CryptoAlgorithmRSASSA_PKCS1_v1_5_Sign_Verify::sign(JSContext *cx, JS::

// 5. Return a new ArrayBuffer associated with the relevant global object of this [HTML], and
// containing the bytes of signature.
JS::RootedObject buffer(cx, JS::NewArrayBufferWithContents(cx, signature_length, signature.get()));
JS::RootedObject buffer(cx, JS::NewArrayBufferWithContents(cx, signature_length, signature.get(), JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!buffer) {
// We can be here is the array buffer was too large -- if that was the case then a
// JSMSG_BAD_ARRAY_LENGTH will have been created. No other failure scenarios in this path will
Expand Down
5 changes: 3 additions & 2 deletions builtins/web/crypto/crypto-key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,9 @@ JSObject *CryptoKey::createRSA(JSContext *cx, CryptoAlgorithmRSASSA_PKCS1_v1_5_I
auto exp = keyData->exponent;
std::copy(exp.begin(), exp.end(), p.get());

JS::RootedObject buffer(cx,
JS::NewArrayBufferWithContents(cx, keyData->exponent.size(), p.get()));
JS::RootedObject buffer(
cx, JS::NewArrayBufferWithContents(cx, keyData->exponent.size(), p.get(),
JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
// `buffer` takes ownership of `p` if the call to NewArrayBufferWithContents was successful
// if the call was not successful, we need to free `p` before exiting from the function.
if (!buffer) {
Expand Down
14 changes: 9 additions & 5 deletions builtins/web/fetch/request-response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bool NativeStreamSource::stream_is_body(JSContext *cx, JS::HandleObject stream)
web::fetch::RequestOrResponse::is_instance(owner(stream_source));
}

} // builtins::web::streams
} // namespace builtins::web::streams

namespace builtins::web::fetch {

Expand Down Expand Up @@ -93,7 +93,9 @@ class BodyFutureTask final : public api::AsyncTask {
// the array buffer allocation has been successful, as that ensures that the
// return path frees chunk automatically when necessary.
auto &bytes = chunk.bytes;
RootedObject buffer(cx, JS::NewArrayBufferWithContents(cx, bytes.len, bytes.ptr.get()));
RootedObject buffer(
cx, JS::NewArrayBufferWithContents(cx, bytes.len, bytes.ptr.get(),
JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!buffer) {
return error_stream_controller_with_pending_exception(cx, controller);
}
Expand Down Expand Up @@ -509,7 +511,9 @@ bool RequestOrResponse::parse_body(JSContext *cx, JS::HandleObject self, JS::Uni
JS::RootedValue result(cx);

if constexpr (result_type == RequestOrResponse::BodyReadResult::ArrayBuffer) {
JS::RootedObject array_buffer(cx, JS::NewArrayBufferWithContents(cx, len, buf.get()));
JS::RootedObject array_buffer(
cx, JS::NewArrayBufferWithContents(cx, len, buf.get(),
JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!array_buffer) {
return RejectPromiseWithPendingError(cx, result_promise);
}
Expand Down Expand Up @@ -1505,8 +1509,8 @@ JSObject *Request::create(JSContext *cx, JS::HandleObject requestInstance, JS::H
if (!url_instance)
return nullptr;

JS::RootedObject parsedURL(cx, url::URL::create(cx, url_instance, input,
worker_location::WorkerLocation::url));
JS::RootedObject parsedURL(
cx, url::URL::create(cx, url_instance, input, worker_location::WorkerLocation::url));

// 2. If `parsedURL` is failure, then throw a `TypeError`.
if (!parsedURL) {
Expand Down
4 changes: 3 additions & 1 deletion builtins/web/text-codec/text-encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ bool TextEncoder::encode(JSContext *cx, unsigned argc, JS::Value *vp) {
}

auto chars = core::encode(cx, args[0]);
JS::RootedObject buffer(cx, JS::NewArrayBufferWithContents(cx, chars.len, chars.begin()));
JS::RootedObject buffer(
cx, JS::NewArrayBufferWithContents(cx, chars.len, chars.begin(),
JS::NewArrayBufferOutOfMemory::CallerMustFreeMemory));
if (!buffer) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions cmake/spidermonkey.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(SM_REV 5a9f0adc71da2d9567f111c4a279ae06fcd8fb4a)
set(SM_REV 702095ed0ba2316b4f2905bbd597d0b2fa23951e)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SM_BUILD_TYPE debug)
Expand All @@ -7,7 +7,7 @@ else()
endif()

CPMAddPackage(NAME spidermonkey-${SM_BUILD_TYPE}
URL https://github.com/tschneidereit/spidermonkey-wasi-embedding/releases/download/rev_${SM_REV}/spidermonkey-wasm-static-lib_${SM_BUILD_TYPE}.tar.gz
URL https://github.com/bytecodealliance/spidermonkey-wasi-embedding/releases/download/rev_${SM_REV}/spidermonkey-wasm-static-lib_${SM_BUILD_TYPE}.tar.gz
DOWNLOAD_ONLY YES
)

Expand Down
3 changes: 1 addition & 2 deletions runtime/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ bool init_js() {

// TODO: check if we should set a different creation zone.
JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true).setWeakRefsEnabled(
JS::WeakRefSpecifier::EnabledWithoutCleanupSome);
options.creationOptions().setStreamsEnabled(true);

JS::DisableIncrementalGC(cx);
// JS_SetGCParameter(cx, JSGC_MAX_EMPTY_CHUNK_COUNT, 1);
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.68.2"
channel = "1.77.1"
targets = [ "wasm32-wasi" ]
profile = "minimal"

0 comments on commit 844e104

Please sign in to comment.