diff options
author | 2023-03-22 18:09:51 -0700 | |
---|---|---|
committer | 2023-03-22 18:09:51 -0700 | |
commit | 31c2fea74af66d60dceab608b1cfdd9a3f08a7db (patch) | |
tree | 97f871a571ed2d48d3ef2d92240b3dcc0cdbf6b1 /src/bun.js | |
parent | a5f92224b586289fc72f0abdb68b08eef9f017db (diff) | |
download | bun-31c2fea74af66d60dceab608b1cfdd9a3f08a7db.tar.gz bun-31c2fea74af66d60dceab608b1cfdd9a3f08a7db.tar.zst bun-31c2fea74af66d60dceab608b1cfdd9a3f08a7db.zip |
A couple bug fixes (#2458)
* fix valid status code range
* update path
* highwatermark option
* throw DOMException
* remove extra transpiler output
* more transpiler tests
* comment
* get index not quickly
* replace with `getDirectIndex`
* update abort test
* throw out of range status code
* promisify test fix
* move stdio test instance files
* working crypto tests
* allow duplicate set-cookie headers
* different formatting
* revert, fix will be in different pr
* it is called
* use min buffer size
* fix url tests
* null origin for other protocols
* remove overload
* add very large file test
* await
* coerce to int64
* 64
* no cast
* add todo blob url tests
* use `tryConvertToInt52`
Diffstat (limited to 'src/bun.js')
-rw-r--r-- | src/bun.js/bindings/URLDecomposition.cpp | 15 | ||||
-rw-r--r-- | src/bun.js/bindings/URLSearchParams.cpp | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 6 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 21 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 5 | ||||
-rw-r--r-- | src/bun.js/bindings/headers.h | 3 | ||||
-rw-r--r-- | src/bun.js/bindings/headers.zig | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/webcore/HTTPHeaderMap.cpp | 11 | ||||
-rw-r--r-- | src/bun.js/fs.exports.js | 4 | ||||
-rw-r--r-- | src/bun.js/streams.exports.js | 2 | ||||
-rw-r--r-- | src/bun.js/webcore/body.zig | 24 |
11 files changed, 44 insertions, 51 deletions
diff --git a/src/bun.js/bindings/URLDecomposition.cpp b/src/bun.js/bindings/URLDecomposition.cpp index f13d6b093..14cf25b6c 100644 --- a/src/bun.js/bindings/URLDecomposition.cpp +++ b/src/bun.js/bindings/URLDecomposition.cpp @@ -32,20 +32,11 @@ namespace WebCore { String URLDecomposition::origin() const { auto fullURL = this->fullURL(); - auto protocol = fullURL.protocol(); - auto host = fullURL.host(); - auto port = fullURL.port(); - if (protocol == "file"_s) - return "file://"_s; + if (fullURL.protocolIsInHTTPFamily() or fullURL.protocolIsInFTPFamily() or fullURL.protocolIs("ws"_s) or fullURL.protocolIs("wss"_s)) + return fullURL.protocolHostAndPort(); - if (protocol.isEmpty() && host.isEmpty()) - return {}; - - if (!port) - return makeString(protocol, "://", host); - - return makeString(protocol, "://", host, ':', static_cast<uint32_t>(*port)); + return "null"_s; } String URLDecomposition::protocol() const diff --git a/src/bun.js/bindings/URLSearchParams.cpp b/src/bun.js/bindings/URLSearchParams.cpp index 2b0ffef67..37f7d0eaf 100644 --- a/src/bun.js/bindings/URLSearchParams.cpp +++ b/src/bun.js/bindings/URLSearchParams.cpp @@ -151,7 +151,8 @@ void URLSearchParams::remove(const String& name) { if (!m_pairs.removeAllMatching([&](const auto& pair) { return pair.key == name; - })) + }) + && m_pairs.size() > 0) return; updateURL(); needsSorting = true; diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 7878b96a7..303be6190 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -959,8 +959,7 @@ JSC_DEFINE_HOST_FUNCTION(functionBTOA, if (!stringToEncode.isAllLatin1()) { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); - // TODO: DOMException - JSC::throwTypeError(globalObject, scope, "The string contains invalid characters."_s); + throwException(globalObject, scope, createDOMException(globalObject, ExceptionCode::InvalidCharacterError)); return JSC::JSValue::encode(JSC::JSValue {}); } @@ -991,8 +990,7 @@ static JSC_DEFINE_HOST_FUNCTION(functionATOB, }); if (!decodedData) { auto scope = DECLARE_THROW_SCOPE(globalObject->vm()); - // TODO: DOMException - JSC::throwTypeError(globalObject, scope, "The string contains invalid characters."_s); + throwException(globalObject, scope, createDOMException(globalObject, ExceptionCode::InvalidCharacterError)); return JSC::JSValue::encode(JSC::JSValue {}); } diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index a5af29128..f43bfd4b8 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -478,12 +478,10 @@ bool Bun__deepEquals(JSC__JSGlobalObject* globalObject, JSValue v1, JSValue v2, } for (uint64_t i = 0; i < length; i++) { - // array holes come back as empty values with tryGetIndexQuickly() JSValue left = o1->canGetIndexQuickly(i) ? o1->getIndexQuickly(i) : o1->tryGetIndexQuickly(i); RETURN_IF_EXCEPTION(*scope, false); - JSValue right = o2->canGetIndexQuickly(i) ? o2->getIndexQuickly(i) : o2->tryGetIndexQuickly(i); @@ -2834,9 +2832,28 @@ int32_t JSC__JSValue__toInt32(JSC__JSValue JSValue0) return JSC::JSValue::decode(JSValue0).asInt32(); } +// truncates values larger than int32 int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) { JSC::JSValue value = JSC::JSValue::decode(JSValue0); + if (value.isCell() && value.isHeapBigInt()) { + return static_cast<int32_t>(value.toBigInt64(arg1)); + } + return value.toInt32(arg1); +} + +int64_t JSC__JSValue__coerceToInt64(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1) +{ + JSValue value = JSValue::decode(JSValue0); + if (value.isCell() && value.isHeapBigInt()) { + return value.toBigInt64(arg1); + } + + int64_t result = tryConvertToInt52(value.asDouble()); + if (result != JSValue::notInt52) { + return result; + } + return value.toInt32(arg1); } diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 1bd045218..a5a12650d 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -3058,6 +3058,10 @@ pub const JSValue = enum(JSValueReprInt) { return cppFn("coerceToInt32", .{ this, globalThis }); } + pub fn coerceToInt64(this: JSValue, globalThis: *JSC.JSGlobalObject) i64 { + return cppFn("coerceToInt64", .{ this, globalThis }); + } + const PropertyIteratorFn = *const fn ( globalObject_: *JSGlobalObject, ctx_ptr: ?*anyopaque, @@ -4192,6 +4196,7 @@ pub const JSValue = enum(JSValueReprInt) { "asPromise", "asString", "coerceToInt32", + "coerceToInt64", "createEmptyArray", "createEmptyObject", "createInternalPromise", diff --git a/src/bun.js/bindings/headers.h b/src/bun.js/bindings/headers.h index 8c9b5c1d0..5c727f397 100644 --- a/src/bun.js/bindings/headers.h +++ b/src/bun.js/bindings/headers.h @@ -1,5 +1,5 @@ // clang-format off -//-- AUTOGENERATED FILE -- 1679200292 +//-- AUTOGENERATED FILE -- 1679530947 #pragma once #include <stddef.h> @@ -288,6 +288,7 @@ CPP_DECL bJSC__JSObject JSC__JSValue__asObject(JSC__JSValue JSValue0); CPP_DECL JSC__JSPromise* JSC__JSValue__asPromise(JSC__JSValue JSValue0); CPP_DECL JSC__JSString* JSC__JSValue__asString(JSC__JSValue JSValue0); CPP_DECL int32_t JSC__JSValue__coerceToInt32(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1); +CPP_DECL int64_t JSC__JSValue__coerceToInt64(JSC__JSValue JSValue0, JSC__JSGlobalObject* arg1); CPP_DECL JSC__JSValue JSC__JSValue__createEmptyArray(JSC__JSGlobalObject* arg0, size_t arg1); CPP_DECL JSC__JSValue JSC__JSValue__createEmptyObject(JSC__JSGlobalObject* arg0, size_t arg1); CPP_DECL JSC__JSValue JSC__JSValue__createInternalPromise(JSC__JSGlobalObject* arg0); diff --git a/src/bun.js/bindings/headers.zig b/src/bun.js/bindings/headers.zig index 5779655fa..11ccd2e53 100644 --- a/src/bun.js/bindings/headers.zig +++ b/src/bun.js/bindings/headers.zig @@ -201,6 +201,7 @@ pub extern fn JSC__JSValue__asObject(JSValue0: JSC__JSValue) bJSC__JSObject; pub extern fn JSC__JSValue__asPromise(JSValue0: JSC__JSValue) ?*bindings.JSPromise; pub extern fn JSC__JSValue__asString(JSValue0: JSC__JSValue) [*c]bindings.JSString; pub extern fn JSC__JSValue__coerceToInt32(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) i32; +pub extern fn JSC__JSValue__coerceToInt64(JSValue0: JSC__JSValue, arg1: *bindings.JSGlobalObject) i64; pub extern fn JSC__JSValue__createEmptyArray(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue; pub extern fn JSC__JSValue__createEmptyObject(arg0: *bindings.JSGlobalObject, arg1: usize) JSC__JSValue; pub extern fn JSC__JSValue__createInternalPromise(arg0: *bindings.JSGlobalObject) JSC__JSValue; diff --git a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp index 580a171d3..013aad750 100644 --- a/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp +++ b/src/bun.js/bindings/webcore/HTTPHeaderMap.cpp @@ -284,18 +284,7 @@ bool HTTPHeaderMap::remove(HTTPHeaderName name) void HTTPHeaderMap::add(HTTPHeaderName name, const String& value) { if (name == HTTPHeaderName::SetCookie) { - auto cookieName = extractCookieName(value); - - size_t length = m_setCookieHeaders.size(); - const auto& cookies = m_setCookieHeaders.data(); - for (size_t i = 0; i < length; ++i) { - if (extractCookieName(cookies[i]) == cookieName) { - m_setCookieHeaders[i] = value; - return; - } - } m_setCookieHeaders.append(value); - return; } diff --git a/src/bun.js/fs.exports.js b/src/bun.js/fs.exports.js index be82f0bd3..9036e14a2 100644 --- a/src/bun.js/fs.exports.js +++ b/src/bun.js/fs.exports.js @@ -223,8 +223,8 @@ export var ReadStream = (function (InternalReadStream) { }); return Object.defineProperty( - function ReadStream(options) { - return new InternalReadStream(options); + function ReadStream(path, options) { + return new InternalReadStream(path, options); }, Symbol.hasInstance, { diff --git a/src/bun.js/streams.exports.js b/src/bun.js/streams.exports.js index 7fdf0fb6a..90c5c9b24 100644 --- a/src/bun.js/streams.exports.js +++ b/src/bun.js/streams.exports.js @@ -5301,7 +5301,7 @@ function createNativeStreamReadable(nativeType, Readable) { var DYNAMICALLY_ADJUST_CHUNK_SIZE = process.env.BUN_DISABLE_DYNAMIC_CHUNK_SIZE !== "1"; const finalizer = new FinalizationRegistry(ptr => ptr && deinit(ptr)); - const MIN_BUFFER_SIZE = 256; + const MIN_BUFFER_SIZE = 512; var NativeReadable = class NativeReadable extends Readable { #ptr; #refCount = 1; diff --git a/src/bun.js/webcore/body.zig b/src/bun.js/webcore/body.zig index 37a70343d..58d3a99b4 100644 --- a/src/bun.js/webcore/body.zig +++ b/src/bun.js/webcore/body.zig @@ -174,23 +174,13 @@ pub const Body = struct { } if (response_init.fastGet(ctx, .status)) |status_value| { - if (status_value.isHeapBigInt()) { - const less_than = switch (status_value.asBigIntCompare(ctx, JSValue.jsNumber(600))) { - .less_than => true, - else => false, - }; - const greater_than = switch (status_value.asBigIntCompare(ctx, JSValue.jsNumber(99))) { - .greater_than => true, - else => false, - }; - - if (less_than and greater_than) { - result.status_code = @truncate(u16, @intCast(u64, status_value.toInt64())); - } - } else if (status_value.isNumber()) { - const number = status_value.to(i32); - if (100 <= number and number < 999) - result.status_code = @truncate(u16, @intCast(u32, number)); + const number = status_value.coerceToInt64(ctx); + if ((200 <= number and number < 600) or number == 101) { + result.status_code = @truncate(u16, @intCast(u32, number)); + } else { + const err = ctx.createRangeErrorInstance("The status provided ({d}) must be 101 or in the range of [200, 599]", .{number}); + ctx.throwValue(err); + return null; } } |