bindings: fix createTypeError and createRangeError inheritance (#11341)

This commit is contained in:
Meghan Denny
2024-05-28 16:54:08 -07:00
committed by GitHub
parent 96f29e8555
commit 367b69dff5
3 changed files with 8 additions and 16 deletions

1
.gitignore vendored
View File

@@ -54,6 +54,7 @@
/test.js /test.js
/test.ts /test.ts
/testdir /testdir
/test.zig
build build
build.ninja build.ninja
bun-binary bun-binary

View File

@@ -2465,14 +2465,7 @@ JSC__JSValue JSC__JSValue__createRangeError(const ZigString* message, const ZigS
{ {
JSC::VM& vm = globalObject->vm(); JSC::VM& vm = globalObject->vm();
ZigString code = *arg1; ZigString code = *arg1;
JSC::JSObject* rangeError = Zig::getErrorInstance(message, globalObject).asCell()->getObject(); JSC::JSObject* rangeError = Zig::getRangeErrorInstance(message, globalObject).asCell()->getObject();
static const char* range_error_name = "RangeError";
rangeError->putDirect(
vm, vm.propertyNames->name,
JSC::JSValue(JSC::jsOwnedString(
vm, WTF::String(WTF::StringImpl::createWithoutCopying({ range_error_name, 10 })))),
0);
if (code.len > 0) { if (code.len > 0) {
auto clientData = WebCore::clientData(vm); auto clientData = WebCore::clientData(vm);
@@ -2488,14 +2481,7 @@ JSC__JSValue JSC__JSValue__createTypeError(const ZigString* message, const ZigSt
{ {
JSC::VM& vm = globalObject->vm(); JSC::VM& vm = globalObject->vm();
ZigString code = *arg1; ZigString code = *arg1;
JSC::JSObject* typeError = Zig::getErrorInstance(message, globalObject).asCell()->getObject(); JSC::JSObject* typeError = Zig::getTypeErrorInstance(message, globalObject).asCell()->getObject();
static const char* range_error_name = "TypeError";
typeError->putDirect(
vm, vm.propertyNames->name,
JSC::JSValue(JSC::jsOwnedString(
vm, WTF::String(WTF::StringImpl::createWithoutCopying({ range_error_name, 9 })))),
0);
if (code.len > 0) { if (code.len > 0) {
auto clientData = WebCore::clientData(vm); auto clientData = WebCore::clientData(vm);

View File

@@ -153,3 +153,8 @@ it("self is a getter", () => {
expect(descriptor.configurable).toBe(true); expect(descriptor.configurable).toBe(true);
expect(globalThis.self).toBe(globalThis); expect(globalThis.self).toBe(globalThis);
}); });
it("errors thrown by native code should be TypeError", async () => {
expect(() => Bun.dns.prefetch()).toThrowError(TypeError);
expect(async () => await fetch("http://localhost", { body: "123" })).toThrowError(TypeError);
});