Skip to content

Commit

Permalink
Fix crash in test.todo + remove JSC C API usages in bun:test (#3079)
Browse files Browse the repository at this point in the history
* Fix crash in test.todo

* remove usages of JSC C API in bun:test

* Remove additional JSC-C API usages

* fix `make headers`

* URLSearchParams.length

* FormData length

* URLSearchParams length

* Fix `make headers`

* very fancy length

* Fix bug with exceptions being ignored sometimes

* Add tests for extension toHaveLength

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
  • Loading branch information
Jarred-Sumner and Jarred-Sumner authored May 26, 2023
1 parent 62f05ec commit 0f2a79b
Show file tree
Hide file tree
Showing 28 changed files with 645 additions and 364 deletions.
6 changes: 3 additions & 3 deletions src/bun.js/api/JSTranspiler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
single_external[0] = std.fmt.allocPrint(allocator, "{}", .{external}) catch unreachable;
transpiler.transform.external = single_external;
} else if (toplevel_type.isArray()) {
const count = external.getLengthOfArray(globalThis);
const count = external.getLength(globalThis);
if (count == 0) break :external;

var externals = allocator.alloc(string, count) catch unreachable;
Expand Down Expand Up @@ -606,7 +606,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
var length_iter = iter;
while (length_iter.next()) |value| {
if (value.isString()) {
const length = @truncate(u32, value.getLengthOfArray(globalThis));
const length = @truncate(u32, value.getLength(globalThis));
string_count += @as(u32, @boolToInt(length > 0));
total_name_buf_len += length;
}
Expand Down Expand Up @@ -679,7 +679,7 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std
continue;
}

if (value.isObject() and value.getLengthOfArray(globalObject) == 2) {
if (value.isObject() and value.getLength(globalObject) == 2) {
const replacementValue = JSC.JSObject.getIndex(value, globalThis, 1);
if (exportReplacementValue(replacementValue, globalThis)) |to_replace| {
const replacementKey = JSC.JSObject.getIndex(value, globalThis, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ pub const Timer = struct {
args_buf[0] = arguments;
args = args_buf[0..1];
} else {
const count = arguments.getLengthOfArray(globalThis);
const count = arguments.getLength(globalThis);
if (count > 0) {
if (count > args_buf.len) {
args = bun.default_allocator.alloc(JSC.JSValue, count) catch unreachable;
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/filesystem_router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ pub const FileSystemRouter = struct {
globalThis.allocator().destroy(arena);
return null;
}
if (val.getLengthOfArray(globalThis) == 0) continue;
if (val.getLength(globalThis) == 0) continue;
extensions.appendAssumeCapacity((val.toSlice(globalThis, allocator).clone(allocator) catch unreachable).slice()[1..]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub const ServerConfig = struct {

if (obj.getTruthy(global, "key")) |js_obj| {
if (js_obj.jsType().isArray()) {
const count = js_obj.getLengthOfArray(global);
const count = js_obj.getLength(global);
if (count > 0) {
const native_array = bun.default_allocator.alloc([*c]const u8, count) catch unreachable;

Expand Down Expand Up @@ -389,7 +389,7 @@ pub const ServerConfig = struct {

if (obj.getTruthy(global, "cert")) |js_obj| {
if (js_obj.jsType().isArray()) {
const count = js_obj.getLengthOfArray(global);
const count = js_obj.getLength(global);
if (count > 0) {
const native_array = bun.default_allocator.alloc([*c]const u8, count) catch unreachable;

Expand Down Expand Up @@ -504,7 +504,7 @@ pub const ServerConfig = struct {

if (obj.getTruthy(global, "ca")) |js_obj| {
if (js_obj.jsType().isArray()) {
const count = js_obj.getLengthOfArray(global);
const count = js_obj.getLength(global);
if (count > 0) {
const native_array = bun.default_allocator.alloc([*c]const u8, count) catch unreachable;

Expand Down
1 change: 0 additions & 1 deletion src/bun.js/base.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,6 @@ pub const JSPrivateDataPtr = TaggedPointerUnion(.{
Comment,
DebugServer,
DebugSSLServer,
DescribeScope,
DocEnd,
DocType,
Element,
Expand Down
1 change: 1 addition & 0 deletions src/bun.js/bindings/URLSearchParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class URLSearchParams : public RefCounted<URLSearchParams> {
String toString() const;
void updateFromAssociatedURL();
void sort();
size_t size() const { return m_pairs.size(); }

class Iterator {
public:
Expand Down
60 changes: 60 additions & 0 deletions src/bun.js/bindings/ZigGeneratedClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class JSBlob final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSBlob(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -112,6 +114,8 @@ class JSBuildArtifact final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSBuildArtifact(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -173,6 +177,8 @@ class JSBuildMessage final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSBuildMessage(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -231,6 +237,8 @@ class JSCryptoHasher final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSCryptoHasher(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -288,6 +296,8 @@ class JSDirent final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSDirent(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -344,6 +354,8 @@ class JSExpect final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSExpect(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -401,6 +413,8 @@ class JSExpectAny final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSExpectAny(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -457,6 +471,8 @@ class JSFileSystemRouter final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSFileSystemRouter(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -515,6 +531,8 @@ class JSListener final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSListener(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -572,6 +590,8 @@ class JSMD4 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSMD4(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -622,6 +642,8 @@ class JSMD5 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSMD5(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -672,6 +694,8 @@ class JSMatchedRoute final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSMatchedRoute(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -734,6 +758,8 @@ class JSNodeJSFS final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSNodeJSFS(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -784,6 +810,8 @@ class JSRequest final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSRequest(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -843,6 +871,8 @@ class JSResolveMessage final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSResolveMessage(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -904,6 +934,8 @@ class JSResponse final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSResponse(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -963,6 +995,8 @@ class JSSHA1 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA1(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1013,6 +1047,8 @@ class JSSHA224 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA224(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1063,6 +1099,8 @@ class JSSHA256 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA256(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1113,6 +1151,8 @@ class JSSHA384 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA384(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1163,6 +1203,8 @@ class JSSHA512 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA512(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1213,6 +1255,8 @@ class JSSHA512_256 final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSHA512_256(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1263,6 +1307,8 @@ class JSServerWebSocket final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSServerWebSocket(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1320,6 +1366,8 @@ class JSStats final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSStats(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1378,6 +1426,8 @@ class JSSubprocess final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSSubprocess(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1463,6 +1513,8 @@ class JSTCPSocket final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSTCPSocket(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1547,6 +1599,8 @@ class JSTLSSocket final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSTLSSocket(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1631,6 +1685,8 @@ class JSTextDecoder final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSTextDecoder(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1687,6 +1743,8 @@ class JSTimeout final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSTimeout(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down Expand Up @@ -1744,6 +1802,8 @@ class JSTranspiler final : public JSC::JSDestructibleObject {

void* m_ctx { nullptr };

static JSC::EncodedJSValue JSC_HOST_CALL_ATTRIBUTES call(JSC::JSGlobalObject*, JSC::CallFrame*);

JSTranspiler(JSC::VM& vm, JSC::Structure* structure, void* sinkPtr)
: Base(vm, structure)
{
Expand Down
Loading

0 comments on commit 0f2a79b

Please sign in to comment.