mirror of
https://github.com/oven-sh/bun
synced 2026-02-16 22:01:47 +00:00
Compare commits
11 Commits
don/fix/un
...
don/refact
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c145687538 | ||
|
|
c0ee1cca93 | ||
|
|
ff5890dd60 | ||
|
|
553973b4b2 | ||
|
|
2c1dea818c | ||
|
|
cc125b475f | ||
|
|
cbbf88f3a6 | ||
|
|
8064a55a48 | ||
|
|
0531d6756c | ||
|
|
6135b3dec9 | ||
|
|
b08dd8795e |
@@ -140,11 +140,7 @@ const testPlatforms = [
|
||||
{ os: "linux", arch: "aarch64", abi: "musl", distro: "alpine", release: "3.20", tier: "latest" },
|
||||
{ os: "linux", arch: "x64", abi: "musl", distro: "alpine", release: "3.20", tier: "latest" },
|
||||
{ os: "linux", arch: "x64", abi: "musl", baseline: true, distro: "alpine", release: "3.20", tier: "latest" },
|
||||
{ os: "windows", arch: "x64", release: "2025", tier: "latest" },
|
||||
{ os: "windows", arch: "x64", release: "2022", tier: "previous" },
|
||||
{ os: "windows", arch: "x64", release: "2019", tier: "oldest" },
|
||||
{ os: "windows", arch: "x64", release: "2025", baseline: true, tier: "latest" },
|
||||
{ os: "windows", arch: "x64", release: "2022", baseline: true, tier: "previous" },
|
||||
{ os: "windows", arch: "x64", release: "2019", baseline: true, tier: "oldest" },
|
||||
];
|
||||
|
||||
@@ -1054,17 +1050,19 @@ async function getPipeline(options = {}) {
|
||||
);
|
||||
}
|
||||
|
||||
const { skipTests, forceTests, unifiedTests, testFiles } = options;
|
||||
if (!skipTests || forceTests) {
|
||||
steps.push(
|
||||
...testPlatforms
|
||||
.flatMap(platform => buildProfiles.map(profile => ({ ...platform, profile })))
|
||||
.map(target => ({
|
||||
key: getTargetKey(target),
|
||||
group: getTargetLabel(target),
|
||||
steps: [getTestBunStep(target, { unifiedTests, testFiles, buildId })],
|
||||
})),
|
||||
);
|
||||
if (!isMainBranch()) {
|
||||
const { skipTests, forceTests, unifiedTests, testFiles } = options;
|
||||
if (!skipTests || forceTests) {
|
||||
steps.push(
|
||||
...testPlatforms
|
||||
.flatMap(platform => buildProfiles.map(profile => ({ ...platform, profile })))
|
||||
.map(target => ({
|
||||
key: getTargetKey(target),
|
||||
group: getTargetLabel(target),
|
||||
steps: [getTestBunStep(target, { unifiedTests, testFiles, buildId })],
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isMainBranch()) {
|
||||
|
||||
@@ -1232,7 +1232,6 @@ pub const JSFrameworkRouter = struct {
|
||||
pub fn finalize(this: *JSFrameworkRouter) void {
|
||||
this.files.deinit(bun.default_allocator);
|
||||
this.router.deinit(bun.default_allocator);
|
||||
bun.default_allocator.free(this.router.types);
|
||||
for (this.stored_parse_errors.items) |i| bun.default_allocator.free(i.rel_path);
|
||||
this.stored_parse_errors.deinit(bun.default_allocator);
|
||||
bun.destroy(this);
|
||||
|
||||
@@ -88,6 +88,55 @@ JSC_DECLARE_HOST_FUNCTION(KeyObject__privateDecrypt);
|
||||
|
||||
namespace WebCore {
|
||||
|
||||
/// Encodes `undefined` if `key` is `nullptr`.
|
||||
JSC::EncodedJSValue encodeKey(const std::optional<JSCryptoKey*> key)
|
||||
{
|
||||
return key.has_value() ? JSC::JSValue::encode(key.value()) : EncodedJSValue {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Numeric Identifier (NID) of an `EVP_PKEY` storing an Eclyptic
|
||||
* Curve (EC) key. On failure, throws a JS exception and returns `NID_undef`.
|
||||
*
|
||||
* * -1: not an EC key, or `key` is `nullptr`
|
||||
* * -2: unable to identify EC curve
|
||||
* * -3: key has an unknown curve
|
||||
*
|
||||
* @param globalObject global JS object. Used to throw exceptions.
|
||||
* @param key Eclicptic Curve key. May be public/private/whatever.
|
||||
* @return std::optional<int>
|
||||
*/
|
||||
int curveName(JSC::JSGlobalObject* globalObject, const EVP_PKEY* key)
|
||||
{
|
||||
ThrowScope scope = DECLARE_THROW_SCOPE(globalObject->vm());
|
||||
// NOTE: EVP_PKEY_get0_EC_KEY handles null pointers, returning null itself.
|
||||
// NOTE: needs to live longer than ec_group, which stores a reference to
|
||||
// data owned by this key.
|
||||
EC_KEY* ec_key = EVP_PKEY_get0_EC_KEY(key);
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
|
||||
throwTypeError(globalObject, scope, "Invalid EC key"_s);
|
||||
return NID_undef;
|
||||
}
|
||||
|
||||
// note: borrowed data. do not free.
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
if (UNLIKELY(ec_group == nullptr)) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwTypeError(globalObject, scope, "Invalid EC key"_s);
|
||||
return NID_undef;
|
||||
}
|
||||
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
EC_KEY_free(ec_key);
|
||||
if (curve_name == NID_undef) {
|
||||
throwTypeError(globalObject, scope, "Unable to identify EC curve"_s);
|
||||
return NID_undef;
|
||||
}
|
||||
|
||||
return curve_name;
|
||||
}
|
||||
|
||||
static bool KeyObject__IsASN1Sequence(const unsigned char* data, size_t size,
|
||||
size_t* data_offset, size_t* data_size)
|
||||
{
|
||||
@@ -521,19 +570,9 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
auto impl = result.releaseNonNull();
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (pKeyID == EVP_PKEY_EC) {
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey.get());
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC private key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
if (curve_name == NID_undef) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
int curve_name = curveName(globalObject, pkey.get());
|
||||
if (curve_name == NID_undef) return {}; // exception already thrown
|
||||
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
curve = CryptoKeyEC::NamedCurve::P256;
|
||||
@@ -542,11 +581,9 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
else if (curve_name == NID_secp521r1)
|
||||
curve = CryptoKeyEC::NamedCurve::P521;
|
||||
else {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unsupported EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
EC_KEY_free(ec_key);
|
||||
auto impl = CryptoKeyEC::create(CryptoAlgorithmIdentifier::ECDH, curve, CryptoKeyType::Private, WTFMove(pkey), true, CryptoKeyUsageSign);
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else {
|
||||
@@ -620,19 +657,9 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
auto impl = result.releaseNonNull();
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (pKeyID == EVP_PKEY_EC) {
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey.get());
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC private key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
if (curve_name == NID_undef) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
int curve_name = curveName(globalObject, pkey.get());
|
||||
if (curve_name == NID_undef) return {}; // exception already thrown
|
||||
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
curve = CryptoKeyEC::NamedCurve::P256;
|
||||
@@ -641,7 +668,6 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
else if (curve_name == NID_secp521r1)
|
||||
curve = CryptoKeyEC::NamedCurve::P521;
|
||||
else {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unsupported EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
@@ -649,7 +675,6 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
if (UNLIKELY(result == nullptr)) {
|
||||
result = CryptoKeyEC::platformImportPkcs8(CryptoAlgorithmIdentifier::ECDSA, curve, Vector<uint8_t>(std::span { (uint8_t*)data, byteLength }), true, CryptoKeyUsageSign);
|
||||
}
|
||||
EC_KEY_free(ec_key);
|
||||
if (UNLIKELY(result == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC private key"_s));
|
||||
return {};
|
||||
@@ -666,19 +691,9 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
auto pKeyID = EVP_PKEY_id(pkey.get());
|
||||
|
||||
if (pKeyID == EVP_PKEY_EC) {
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey.get());
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC private key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
if (curve_name == NID_undef) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
int curve_name = curveName(globalObject, pkey.get());
|
||||
if (curve_name == NID_undef) return {}; // exception already thrown
|
||||
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
curve = CryptoKeyEC::NamedCurve::P256;
|
||||
@@ -687,11 +702,9 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
else if (curve_name == NID_secp521r1)
|
||||
curve = CryptoKeyEC::NamedCurve::P521;
|
||||
else {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unsupported EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
EC_KEY_free(ec_key);
|
||||
auto impl = CryptoKeyEC::create(CryptoAlgorithmIdentifier::ECDH, curve, CryptoKeyType::Private, WTFMove(pkey), true, CryptoKeyUsageSign);
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else {
|
||||
@@ -708,7 +721,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPrivateKey, (JSC::JSGlobalObject * glo
|
||||
return {};
|
||||
}
|
||||
|
||||
static JSC::EncodedJSValue KeyObject__createRSAFromPrivate(JSC::JSGlobalObject* globalObject, EVP_PKEY* pkey, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
static std::optional<JSCryptoKey*> KeyObject__createRSAFromPrivate(JSC::JSGlobalObject* globalObject, const EVP_PKEY* pkey, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
@@ -717,21 +730,21 @@ static JSC::EncodedJSValue KeyObject__createRSAFromPrivate(JSC::JSGlobalObject*
|
||||
auto publicRSA = RSAPtr(RSAPublicKey_dup(rsa_key));
|
||||
if (!publicRSA) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto publicPKey = EvpPKeyPtr(EVP_PKEY_new());
|
||||
if (EVP_PKEY_set1_RSA(publicPKey.get(), publicRSA.get()) <= 0) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto impl = CryptoKeyRSA::create(alg, CryptoAlgorithmIdentifier::SHA_1, false, CryptoKeyType::Public, WTFMove(publicPKey), true, CryptoKeyUsageVerify);
|
||||
Zig::GlobalObject* zigGlobalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject);
|
||||
auto* structure = zigGlobalObject->JSCryptoKeyStructure();
|
||||
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
return JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl));
|
||||
}
|
||||
|
||||
static JSC::EncodedJSValue KeyObject__createECFromPrivate(JSC::JSGlobalObject* globalObject, EVP_PKEY* pkey, CryptoKeyEC::NamedCurve namedCurve, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
static std::optional<JSCryptoKey*> KeyObject__createECFromPrivate(JSC::JSGlobalObject* globalObject, const EVP_PKEY* pkey, CryptoKeyEC::NamedCurve namedCurve, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
@@ -740,7 +753,7 @@ static JSC::EncodedJSValue KeyObject__createECFromPrivate(JSC::JSGlobalObject* g
|
||||
auto point = ECPointPtr(EC_POINT_dup(EC_KEY_get0_public_key(ec_key), EC_KEY_get0_group(ec_key)));
|
||||
if (!point) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private 1"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto curve = NID_undef;
|
||||
|
||||
@@ -758,28 +771,28 @@ static JSC::EncodedJSValue KeyObject__createECFromPrivate(JSC::JSGlobalObject* g
|
||||
auto publicECKey = ECKeyPtr(EC_KEY_new_by_curve_name(curve));
|
||||
if (!publicECKey) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private 2"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
// OPENSSL_EC_NAMED_CURVE needs to be set to export the key with the curve name, not with the curve parameters.
|
||||
EC_KEY_set_asn1_flag(publicECKey.get(), OPENSSL_EC_NAMED_CURVE);
|
||||
if (EC_KEY_set_public_key(publicECKey.get(), point.get()) <= 0) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private 3"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto publicPKey = EvpPKeyPtr(EVP_PKEY_new());
|
||||
if (EVP_PKEY_set1_EC_KEY(publicPKey.get(), publicECKey.get()) <= 0) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private 4"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto impl = CryptoKeyEC::create(alg, namedCurve, CryptoKeyType::Public, WTFMove(publicPKey), true, CryptoKeyUsageVerify);
|
||||
|
||||
Zig::GlobalObject* zigGlobalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject);
|
||||
auto* structure = zigGlobalObject->JSCryptoKeyStructure();
|
||||
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
return JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl));
|
||||
}
|
||||
|
||||
static JSC::EncodedJSValue KeyObject__createOKPFromPrivate(JSC::JSGlobalObject* globalObject, const WebCore::CryptoKeyOKP::KeyMaterial keyData, CryptoKeyOKP::NamedCurve namedCurve, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
static std::optional<JSCryptoKey*> KeyObject__createOKPFromPrivate(JSC::JSGlobalObject* globalObject, const WebCore::CryptoKeyOKP::KeyMaterial keyData, CryptoKeyOKP::NamedCurve namedCurve, WebCore::CryptoAlgorithmIdentifier alg)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
@@ -794,53 +807,46 @@ static JSC::EncodedJSValue KeyObject__createOKPFromPrivate(JSC::JSGlobalObject*
|
||||
auto result = CryptoKeyOKP::create(alg, namedCurve, CryptoKeyType::Public, WTFMove(public_key), true, CryptoKeyUsageVerify);
|
||||
if (UNLIKELY(result == nullptr)) {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Failed to create a public key from private"_s);
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
auto impl = result.releaseNonNull();
|
||||
|
||||
Zig::GlobalObject* zigGlobalObject = reinterpret_cast<Zig::GlobalObject*>(globalObject);
|
||||
auto* structure = zigGlobalObject->JSCryptoKeyStructure();
|
||||
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
return JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl));
|
||||
}
|
||||
|
||||
static JSC::EncodedJSValue KeyObject__createPublicFromPrivate(JSC::JSGlobalObject* globalObject, EVP_PKEY* pkey)
|
||||
static JSC::EncodedJSValue KeyObject__createPublicFromPrivate(JSC::JSGlobalObject* globalObject, const EVP_PKEY* pkey)
|
||||
{
|
||||
auto& vm = globalObject->vm();
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
auto pKeyID = EVP_PKEY_id(pkey);
|
||||
int pKeyID = EVP_PKEY_id(pkey);
|
||||
if (pKeyID == EVP_PKEY_RSA || pKeyID == EVP_PKEY_RSA_PSS) {
|
||||
return KeyObject__createRSAFromPrivate(globalObject, pkey, pKeyID == EVP_PKEY_RSA_PSS ? CryptoAlgorithmIdentifier::RSA_PSS : CryptoAlgorithmIdentifier::RSA_OAEP);
|
||||
auto alg = pKeyID == EVP_PKEY_RSA_PSS ? CryptoAlgorithmIdentifier::RSA_PSS : CryptoAlgorithmIdentifier::RSA_OAEP;
|
||||
return encodeKey(KeyObject__createRSAFromPrivate(globalObject, pkey, alg));
|
||||
} else if (pKeyID == EVP_PKEY_EC) {
|
||||
int curve_name = curveName(globalObject, pkey);
|
||||
if (curve_name == NID_undef) return {}; // exception already thrown
|
||||
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey);
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
if (curve_name == NID_undef) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
switch (curve_name) {
|
||||
case NID_X9_62_prime256v1:
|
||||
curve = CryptoKeyEC::NamedCurve::P256;
|
||||
else if (curve_name == NID_secp384r1)
|
||||
break;
|
||||
case NID_secp384r1:
|
||||
curve = CryptoKeyEC::NamedCurve::P384;
|
||||
else if (curve_name == NID_secp521r1)
|
||||
break;
|
||||
case NID_secp521r1:
|
||||
curve = CryptoKeyEC::NamedCurve::P521;
|
||||
else {
|
||||
EC_KEY_free(ec_key);
|
||||
break;
|
||||
default:
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unsupported EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
EC_KEY_free(ec_key);
|
||||
return KeyObject__createECFromPrivate(globalObject, pkey, curve, CryptoAlgorithmIdentifier::ECDSA);
|
||||
|
||||
return encodeKey(KeyObject__createECFromPrivate(globalObject, pkey, curve, CryptoAlgorithmIdentifier::ECDSA));
|
||||
} else if (pKeyID == EVP_PKEY_ED25519 || pKeyID == EVP_PKEY_X25519) {
|
||||
size_t out_len = 0;
|
||||
if (!EVP_PKEY_get_raw_private_key(pkey, nullptr, &out_len)) {
|
||||
@@ -852,7 +858,8 @@ static JSC::EncodedJSValue KeyObject__createPublicFromPrivate(JSC::JSGlobalObjec
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid private key"_s));
|
||||
return {};
|
||||
}
|
||||
return KeyObject__createOKPFromPrivate(globalObject, out, pKeyID == EVP_PKEY_ED25519 ? CryptoKeyOKP::NamedCurve::Ed25519 : CryptoKeyOKP::NamedCurve::X25519, CryptoAlgorithmIdentifier::Ed25519);
|
||||
auto curve = pKeyID == EVP_PKEY_ED25519 ? CryptoKeyOKP::NamedCurve::Ed25519 : CryptoKeyOKP::NamedCurve::X25519;
|
||||
return encodeKey(KeyObject__createOKPFromPrivate(globalObject, out, curve, CryptoAlgorithmIdentifier::Ed25519));
|
||||
} else {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid private key type"_s));
|
||||
return {};
|
||||
@@ -868,7 +875,6 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
|
||||
if (count < 1) {
|
||||
auto scope = DECLARE_THROW_SCOPE(vm);
|
||||
JSC::throwTypeError(globalObject, scope, "createPublicKey requires 1 arguments"_s);
|
||||
return {};
|
||||
}
|
||||
@@ -898,15 +904,15 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
|
||||
switch (id) {
|
||||
case CryptoKeyClass::RSA: {
|
||||
return KeyObject__createRSAFromPrivate(globalObject, downcast<WebCore::CryptoKeyRSA>(wrapped).platformKey(), wrapped.algorithmIdentifier());
|
||||
return encodeKey(KeyObject__createRSAFromPrivate(globalObject, downcast<WebCore::CryptoKeyRSA>(wrapped).platformKey(), wrapped.algorithmIdentifier()));
|
||||
}
|
||||
case CryptoKeyClass::EC: {
|
||||
auto& impl = downcast<WebCore::CryptoKeyEC>(wrapped);
|
||||
return KeyObject__createECFromPrivate(globalObject, impl.platformKey(), impl.namedCurve(), wrapped.algorithmIdentifier());
|
||||
return encodeKey(KeyObject__createECFromPrivate(globalObject, impl.platformKey(), impl.namedCurve(), wrapped.algorithmIdentifier()));
|
||||
}
|
||||
case CryptoKeyClass::OKP: {
|
||||
auto& impl = downcast<WebCore::CryptoKeyOKP>(wrapped);
|
||||
return KeyObject__createOKPFromPrivate(globalObject, impl.exportKey(), impl.namedCurve(), wrapped.algorithmIdentifier());
|
||||
encodeKey(KeyObject__createOKPFromPrivate(globalObject, impl.exportKey(), impl.namedCurve(), wrapped.algorithmIdentifier()));
|
||||
}
|
||||
default: {
|
||||
JSC::throwTypeError(globalObject, scope, "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE: Invalid key object type, expected private"_s);
|
||||
@@ -984,7 +990,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
}
|
||||
auto impl = result.releaseNonNull();
|
||||
if (impl->type() == CryptoKeyType::Private) {
|
||||
return KeyObject__createOKPFromPrivate(globalObject, impl.get().exportKey(), CryptoKeyOKP::NamedCurve::Ed25519, CryptoAlgorithmIdentifier::Ed25519);
|
||||
return encodeKey(KeyObject__createOKPFromPrivate(globalObject, impl.get().exportKey(), CryptoKeyOKP::NamedCurve::Ed25519, CryptoAlgorithmIdentifier::Ed25519));
|
||||
}
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (jwk.crv == "X25519"_s) {
|
||||
@@ -995,7 +1001,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
}
|
||||
auto impl = result.releaseNonNull();
|
||||
if (impl->type() == CryptoKeyType::Private) {
|
||||
return KeyObject__createOKPFromPrivate(globalObject, impl.get().exportKey(), CryptoKeyOKP::NamedCurve::X25519, CryptoAlgorithmIdentifier::Ed25519);
|
||||
return encodeKey(KeyObject__createOKPFromPrivate(globalObject, impl.get().exportKey(), CryptoKeyOKP::NamedCurve::X25519, CryptoAlgorithmIdentifier::Ed25519));
|
||||
}
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else {
|
||||
@@ -1010,7 +1016,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
}
|
||||
auto impl = result.releaseNonNull();
|
||||
if (impl->type() == CryptoKeyType::Private) {
|
||||
return KeyObject__createECFromPrivate(globalObject, impl.get().platformKey(), impl.get().namedCurve(), CryptoAlgorithmIdentifier::ECDSA);
|
||||
return encodeKey(KeyObject__createECFromPrivate(globalObject, impl.get().platformKey(), impl.get().namedCurve(), CryptoAlgorithmIdentifier::ECDSA));
|
||||
}
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (jwk.kty == "RSA"_s) {
|
||||
@@ -1021,7 +1027,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
}
|
||||
auto impl = result.releaseNonNull();
|
||||
if (impl->type() == CryptoKeyType::Private) {
|
||||
return KeyObject__createRSAFromPrivate(globalObject, impl.get().platformKey(), CryptoAlgorithmIdentifier::RSA_OAEP);
|
||||
return encodeKey(KeyObject__createRSAFromPrivate(globalObject, impl.get().platformKey(), CryptoAlgorithmIdentifier::RSA_OAEP));
|
||||
}
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else {
|
||||
@@ -1088,24 +1094,10 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
auto impl = result.releaseNonNull();
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (pKeyID == EVP_PKEY_EC) {
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey.get());
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
if (pem.der_data) {
|
||||
OPENSSL_clear_free(pem.der_data, pem.der_len);
|
||||
}
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC public key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
int curve_name = curveName(globalObject, pkey.get());
|
||||
if (curve_name == NID_undef) {
|
||||
if (pem.der_data) {
|
||||
OPENSSL_clear_free(pem.der_data, pem.der_len);
|
||||
}
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
if (pem.der_data) OPENSSL_clear_free(pem.der_data, pem.der_len);
|
||||
return {}; // exception already thrown
|
||||
}
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
@@ -1169,7 +1161,7 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
}
|
||||
|
||||
auto pKeyID = EVP_PKEY_id(pkey.get());
|
||||
return KeyObject__createRSAFromPrivate(globalObject, pkey.get(), pKeyID == EVP_PKEY_RSA_PSS ? CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5 : CryptoAlgorithmIdentifier::RSA_OAEP);
|
||||
return encodeKey(KeyObject__createRSAFromPrivate(globalObject, pkey.get(), pKeyID == EVP_PKEY_RSA_PSS ? CryptoAlgorithmIdentifier::RSASSA_PKCS1_v1_5 : CryptoAlgorithmIdentifier::RSA_OAEP));
|
||||
}
|
||||
|
||||
auto pKeyID = EVP_PKEY_id(pkey.get());
|
||||
@@ -1205,19 +1197,8 @@ JSC_DEFINE_HOST_FUNCTION(KeyObject__createPublicKey, (JSC::JSGlobalObject * glob
|
||||
auto impl = result.releaseNonNull();
|
||||
return JSC::JSValue::encode(JSCryptoKey::create(structure, zigGlobalObject, WTFMove(impl)));
|
||||
} else if (pKeyID == EVP_PKEY_EC) {
|
||||
EC_KEY* ec_key = EVP_PKEY_get1_EC_KEY(pkey.get());
|
||||
if (UNLIKELY(ec_key == nullptr)) {
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Invalid EC public key"_s));
|
||||
return {};
|
||||
}
|
||||
const EC_GROUP* ec_group = EC_KEY_get0_group(ec_key);
|
||||
// Get the curve name
|
||||
int curve_name = EC_GROUP_get_curve_name(ec_group);
|
||||
if (curve_name == NID_undef) {
|
||||
EC_KEY_free(ec_key);
|
||||
throwException(globalObject, scope, createTypeError(globalObject, "Unable to identify EC curve"_s));
|
||||
return {};
|
||||
}
|
||||
int curve_name = curveName(globalObject, pkey.get());
|
||||
if (curve_name == NID_undef) return {}; // exception already thrown.
|
||||
CryptoKeyEC::NamedCurve curve;
|
||||
if (curve_name == NID_X9_62_prime256v1)
|
||||
curve = CryptoKeyEC::NamedCurve::P256;
|
||||
|
||||
71
src/bun.js/bindings/sqlite/sqlite3.c
vendored
71
src/bun.js/bindings/sqlite/sqlite3.c
vendored
@@ -1,7 +1,7 @@
|
||||
// clang-format off
|
||||
/******************************************************************************
|
||||
** This file is an amalgamation of many separate C source files from SQLite
|
||||
** version 3.47.1. By combining all the individual C code files into this
|
||||
** version 3.47.2. By combining all the individual C code files into this
|
||||
** single large file, the entire code can be compiled as a single translation
|
||||
** unit. This allows many compilers to do optimizations that would not be
|
||||
** possible if the files were compiled separately. Performance improvements
|
||||
@@ -19,7 +19,7 @@
|
||||
** separate file. This file contains only code for the core SQLite library.
|
||||
**
|
||||
** The content in this amalgamation comes from Fossil check-in
|
||||
** b95d11e958643b969c47a8e5857f3793b9e6.
|
||||
** 2aabe05e2e8cae4847a802ee2daddc1d7413.
|
||||
*/
|
||||
#define SQLITE_CORE 1
|
||||
#define SQLITE_AMALGAMATION 1
|
||||
@@ -463,9 +463,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.47.1"
|
||||
#define SQLITE_VERSION_NUMBER 3047001
|
||||
#define SQLITE_SOURCE_ID "2024-11-25 12:07:48 b95d11e958643b969c47a8e5857f3793b9e69700b8f1469371386369a26e577e"
|
||||
#define SQLITE_VERSION "3.47.2"
|
||||
#define SQLITE_VERSION_NUMBER 3047002
|
||||
#define SQLITE_SOURCE_ID "2024-12-07 20:39:59 2aabe05e2e8cae4847a802ee2daddc1d7413d8fc560254d93ee3e72c14685b6c"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
@@ -35698,8 +35698,8 @@ SQLITE_PRIVATE int sqlite3AtoF(const char *z, double *pResult, int length, u8 en
|
||||
int eValid = 1; /* True exponent is either not used or is well-formed */
|
||||
int nDigit = 0; /* Number of digits processed */
|
||||
int eType = 1; /* 1: pure integer, 2+: fractional -1 or less: bad UTF16 */
|
||||
u64 s2; /* round-tripped significand */
|
||||
double rr[2];
|
||||
u64 s2;
|
||||
|
||||
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
|
||||
*pResult = 0.0; /* Default return value, in case of an error */
|
||||
@@ -35802,7 +35802,7 @@ do_atof_calc:
|
||||
e = (e*esign) + d;
|
||||
|
||||
/* Try to adjust the exponent to make it smaller */
|
||||
while( e>0 && s<(LARGEST_UINT64/10) ){
|
||||
while( e>0 && s<((LARGEST_UINT64-0x7ff)/10) ){
|
||||
s *= 10;
|
||||
e--;
|
||||
}
|
||||
@@ -35812,11 +35812,16 @@ do_atof_calc:
|
||||
}
|
||||
|
||||
rr[0] = (double)s;
|
||||
s2 = (u64)rr[0];
|
||||
#if defined(_MSC_VER) && _MSC_VER<1700
|
||||
if( s2==0x8000000000000000LL ){ s2 = 2*(u64)(0.5*rr[0]); }
|
||||
#endif
|
||||
rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
|
||||
assert( sizeof(s2)==sizeof(rr[0]) );
|
||||
memcpy(&s2, &rr[0], sizeof(s2));
|
||||
if( s2<=0x43efffffffffffffLL ){
|
||||
s2 = (u64)rr[0];
|
||||
rr[1] = s>=s2 ? (double)(s - s2) : -(double)(s2 - s);
|
||||
}else{
|
||||
rr[1] = 0.0;
|
||||
}
|
||||
assert( rr[1]<=1.0e-10*rr[0] ); /* Equal only when rr[0]==0.0 */
|
||||
|
||||
if( e>0 ){
|
||||
while( e>=100 ){
|
||||
e -= 100;
|
||||
@@ -147606,32 +147611,32 @@ static Expr *substExpr(
|
||||
if( pSubst->isOuterJoin ){
|
||||
ExprSetProperty(pNew, EP_CanBeNull);
|
||||
}
|
||||
if( pNew->op==TK_TRUEFALSE ){
|
||||
pNew->u.iValue = sqlite3ExprTruthValue(pNew);
|
||||
pNew->op = TK_INTEGER;
|
||||
ExprSetProperty(pNew, EP_IntValue);
|
||||
}
|
||||
|
||||
/* Ensure that the expression now has an implicit collation sequence,
|
||||
** just as it did when it was a column of a view or sub-query. */
|
||||
{
|
||||
CollSeq *pNat = sqlite3ExprCollSeq(pSubst->pParse, pNew);
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse,
|
||||
pSubst->pCList->a[iColumn].pExpr
|
||||
);
|
||||
if( pNat!=pColl || (pNew->op!=TK_COLUMN && pNew->op!=TK_COLLATE) ){
|
||||
pNew = sqlite3ExprAddCollateString(pSubst->pParse, pNew,
|
||||
(pColl ? pColl->zName : "BINARY")
|
||||
);
|
||||
}
|
||||
}
|
||||
ExprClearProperty(pNew, EP_Collate);
|
||||
if( ExprHasProperty(pExpr,EP_OuterON|EP_InnerON) ){
|
||||
sqlite3SetJoinExpr(pNew, pExpr->w.iJoin,
|
||||
pExpr->flags & (EP_OuterON|EP_InnerON));
|
||||
}
|
||||
sqlite3ExprDelete(db, pExpr);
|
||||
pExpr = pNew;
|
||||
if( pExpr->op==TK_TRUEFALSE ){
|
||||
pExpr->u.iValue = sqlite3ExprTruthValue(pExpr);
|
||||
pExpr->op = TK_INTEGER;
|
||||
ExprSetProperty(pExpr, EP_IntValue);
|
||||
}
|
||||
|
||||
/* Ensure that the expression now has an implicit collation sequence,
|
||||
** just as it did when it was a column of a view or sub-query. */
|
||||
{
|
||||
CollSeq *pNat = sqlite3ExprCollSeq(pSubst->pParse, pExpr);
|
||||
CollSeq *pColl = sqlite3ExprCollSeq(pSubst->pParse,
|
||||
pSubst->pCList->a[iColumn].pExpr
|
||||
);
|
||||
if( pNat!=pColl || (pExpr->op!=TK_COLUMN && pExpr->op!=TK_COLLATE) ){
|
||||
pExpr = sqlite3ExprAddCollateString(pSubst->pParse, pExpr,
|
||||
(pColl ? pColl->zName : "BINARY")
|
||||
);
|
||||
}
|
||||
}
|
||||
ExprClearProperty(pExpr, EP_Collate);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
@@ -254939,7 +254944,7 @@ static void fts5SourceIdFunc(
|
||||
){
|
||||
assert( nArg==0 );
|
||||
UNUSED_PARAM2(nArg, apUnused);
|
||||
sqlite3_result_text(pCtx, "fts5: 2024-11-25 12:07:48 b95d11e958643b969c47a8e5857f3793b9e69700b8f1469371386369a26e577e", -1, SQLITE_TRANSIENT);
|
||||
sqlite3_result_text(pCtx, "fts5: 2024-12-07 20:39:59 2aabe05e2e8cae4847a802ee2daddc1d7413d8fc560254d93ee3e72c14685b6c", -1, SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
6
src/bun.js/bindings/sqlite/sqlite3_local.h
vendored
6
src/bun.js/bindings/sqlite/sqlite3_local.h
vendored
@@ -147,9 +147,9 @@ extern "C" {
|
||||
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
|
||||
** [sqlite_version()] and [sqlite_source_id()].
|
||||
*/
|
||||
#define SQLITE_VERSION "3.47.1"
|
||||
#define SQLITE_VERSION_NUMBER 3047001
|
||||
#define SQLITE_SOURCE_ID "2024-11-25 12:07:48 b95d11e958643b969c47a8e5857f3793b9e69700b8f1469371386369a26e577e"
|
||||
#define SQLITE_VERSION "3.47.2"
|
||||
#define SQLITE_VERSION_NUMBER 3047002
|
||||
#define SQLITE_SOURCE_ID "2024-12-07 20:39:59 2aabe05e2e8cae4847a802ee2daddc1d7413d8fc560254d93ee3e72c14685b6c"
|
||||
|
||||
/*
|
||||
** CAPI3REF: Run-Time Library Version Numbers
|
||||
|
||||
@@ -5371,14 +5371,18 @@ function createNativeStreamReadable(Readable) {
|
||||
}
|
||||
|
||||
if (isClosed) {
|
||||
nativeReadable.push(null);
|
||||
ProcessNextTick(() => {
|
||||
nativeReadable.push(null);
|
||||
});
|
||||
}
|
||||
|
||||
return remainder.byteLength > 0 ? remainder : undefined;
|
||||
}
|
||||
|
||||
if (isClosed) {
|
||||
nativeReadable.push(null);
|
||||
ProcessNextTick(() => {
|
||||
nativeReadable.push(null);
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
@@ -5390,7 +5394,9 @@ function createNativeStreamReadable(Readable) {
|
||||
}
|
||||
|
||||
if (isClosed) {
|
||||
nativeReadable.push(null);
|
||||
ProcessNextTick(() => {
|
||||
nativeReadable.push(null);
|
||||
});
|
||||
}
|
||||
|
||||
return view;
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
const Api = @import("./api/schema.zig").Api;
|
||||
const Options = @import("./options.zig");
|
||||
var options: Options.BundleOptions = undefined;
|
||||
|
||||
export fn init() void {
|
||||
if (!alloc.needs_setup) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export fn setOptions(options_ptr: [*c]u8, options_len: c_int) void {}
|
||||
@@ -2484,12 +2484,13 @@ it("client should use chunked encoded if more than one write is called", async (
|
||||
req.on("error", reject);
|
||||
|
||||
// Write chunks to the request body
|
||||
req.write("Hello");
|
||||
req.write(" ");
|
||||
await sleep(100);
|
||||
req.write("World");
|
||||
req.write(" ");
|
||||
await sleep(100);
|
||||
|
||||
for (let i = 0; i < 4; i++) {
|
||||
req.write("chunk");
|
||||
await sleep(50);
|
||||
req.write(" ");
|
||||
await sleep(50);
|
||||
}
|
||||
req.write("BUN!");
|
||||
// End the request and signal no more data will be sent
|
||||
req.end();
|
||||
@@ -2497,7 +2498,7 @@ it("client should use chunked encoded if more than one write is called", async (
|
||||
const chunks = await promise;
|
||||
expect(chunks.length).toBeGreaterThan(1);
|
||||
expect(chunks[chunks.length - 1]?.toString()).toEndWith("BUN!");
|
||||
expect(Buffer.concat(chunks).toString()).toBe("Hello World BUN!");
|
||||
expect(Buffer.concat(chunks).toString()).toBe("chunk ".repeat(4) + "BUN!");
|
||||
});
|
||||
|
||||
it("client should use content-length if only one write is called", async () => {
|
||||
|
||||
@@ -544,3 +544,26 @@ it("should emit prefinish on current tick", done => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
for (const size of [0x10, 0xffff, 0x10000, 0x1f000, 0x20000, 0x20010, 0x7ffff, 0x80000, 0xa0000, 0xa0010]) {
|
||||
it(`should emit 'readable' with null data and 'close' exactly once each, 0x${size.toString(16)} bytes`, async () => {
|
||||
const path = `${tmpdir()}/${Date.now()}.readable_and_close.txt`;
|
||||
writeFileSync(path, new Uint8Array(size));
|
||||
const stream = createReadStream(path);
|
||||
const close_resolvers = Promise.withResolvers();
|
||||
const readable_resolvers = Promise.withResolvers();
|
||||
|
||||
stream.on("close", () => {
|
||||
close_resolvers.resolve();
|
||||
});
|
||||
|
||||
stream.on("readable", () => {
|
||||
const data = stream.read();
|
||||
if (data === null) {
|
||||
readable_resolvers.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
await Promise.all([close_resolvers.promise, readable_resolvers.promise]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ it("setTimeout if refreshed before run, should reschedule to run later", done =>
|
||||
let start = Date.now();
|
||||
let timer = setTimeout(() => {
|
||||
let end = Date.now();
|
||||
expect(end - start).toBeGreaterThan(149);
|
||||
expect(end - start).toBeGreaterThanOrEqual(149);
|
||||
done();
|
||||
}, 100);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user