diff options
author | 2022-10-09 13:36:33 +0800 | |
---|---|---|
committer | 2022-10-08 22:36:33 -0700 | |
commit | 36ec06493e5649374a98d1b4068cd8d89d0a9bf6 (patch) | |
tree | 4bc5cd69948aca9e634ae83afe6b7d6ea3b2ca40 | |
parent | 6068ad15d4d7a4c3f2a81e554c18a0c13a3174e5 (diff) | |
download | bun-36ec06493e5649374a98d1b4068cd8d89d0a9bf6.tar.gz bun-36ec06493e5649374a98d1b4068cd8d89d0a9bf6.tar.zst bun-36ec06493e5649374a98d1b4068cd8d89d0a9bf6.zip |
Fix fetch response redirected (#1303)
* fix: sync codegen
* fix: generate class script
* fix: sync codegen
* fix: add response redirected property
-rw-r--r-- | src/bun.js/bindings/JSSink.cpp | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSink.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/JSSinkLookupTable.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.cpp | 72 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGeneratedClasses.h | 2 | ||||
-rw-r--r-- | src/bun.js/bindings/generated_classes.zig | 10 | ||||
-rw-r--r-- | src/bun.js/scripts/generate-classes.ts | 24 | ||||
-rw-r--r-- | src/bun.js/webcore/response.classes.ts | 4 | ||||
-rw-r--r-- | src/bun.js/webcore/response.zig | 10 |
9 files changed, 110 insertions, 18 deletions
diff --git a/src/bun.js/bindings/JSSink.cpp b/src/bun.js/bindings/JSSink.cpp index 47bb2cac3..c4097c8b4 100644 --- a/src/bun.js/bindings/JSSink.cpp +++ b/src/bun.js/bindings/JSSink.cpp @@ -1,6 +1,6 @@ // AUTO-GENERATED FILE. DO NOT EDIT. -// Generated by 'make generate-sink' at 2022-09-23T02:14:49.416Z +// Generated by 'make generate-sink' at 2022-10-09T04:03:11.763Z // To regenerate this file, run: // // make generate-sink diff --git a/src/bun.js/bindings/JSSink.h b/src/bun.js/bindings/JSSink.h index e55545302..4a7f26682 100644 --- a/src/bun.js/bindings/JSSink.h +++ b/src/bun.js/bindings/JSSink.h @@ -1,6 +1,6 @@ // AUTO-GENERATED FILE. DO NOT EDIT. -// Generated by 'make generate-sink' at 2022-09-23T02:14:49.415Z +// Generated by 'make generate-sink' at 2022-10-09T04:03:11.760Z // #pragma once diff --git a/src/bun.js/bindings/JSSinkLookupTable.h b/src/bun.js/bindings/JSSinkLookupTable.h index 14d547708..be66e3530 100644 --- a/src/bun.js/bindings/JSSinkLookupTable.h +++ b/src/bun.js/bindings/JSSinkLookupTable.h @@ -1,4 +1,4 @@ -// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/jarred/Code/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT! +// Automatically generated from src/bun.js/bindings/JSSink.cpp using /Users/zhiyuan.guo/Documents/playground/bun/src/bun.js/WebKit/Source/JavaScriptCore/create_hash_table. DO NOT EDIT! diff --git a/src/bun.js/bindings/ZigGeneratedClasses.cpp b/src/bun.js/bindings/ZigGeneratedClasses.cpp index 305387b12..ec53d56ba 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.cpp +++ b/src/bun.js/bindings/ZigGeneratedClasses.cpp @@ -47,6 +47,10 @@ extern "C" JSC::EncodedJSValue SubprocessPrototype__getPid(void* ptr, JSC::JSGlo JSC_DECLARE_CUSTOM_GETTER(SubprocessPrototype__pidGetterWrap); +extern "C" JSC::EncodedJSValue SubprocessPrototype__getStdout(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(SubprocessPrototype__readableGetterWrap); + + extern "C" EncodedJSValue SubprocessPrototype__doRef(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); JSC_DECLARE_HOST_FUNCTION(SubprocessPrototype__refCallback); @@ -67,6 +71,10 @@ extern "C" EncodedJSValue SubprocessPrototype__doUnref(void* ptr, JSC::JSGlobalO JSC_DECLARE_HOST_FUNCTION(SubprocessPrototype__unrefCallback); +extern "C" JSC::EncodedJSValue SubprocessPrototype__getStdin(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(SubprocessPrototype__writableGetterWrap); + + STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSSubprocessPrototype, JSSubprocessPrototype::Base); @@ -76,11 +84,13 @@ STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSSubprocessPrototype, JSSubprocessPrototype { "kill"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, SubprocessPrototype__killCallback, 1 } } , { "killed"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__killedGetterWrap, 0 } } , { "pid"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__pidGetterWrap, 0 } } , +{ "readable"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__readableGetterWrap, 0 } } , { "ref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, SubprocessPrototype__refCallback, 0 } } , { "stderr"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__stderrGetterWrap, 0 } } , { "stdin"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__stdinGetterWrap, 0 } } , { "stdout"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__stdoutGetterWrap, 0 } } , -{ "unref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, SubprocessPrototype__unrefCallback, 0 } } +{ "unref"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, SubprocessPrototype__unrefCallback, 0 } } , +{ "writable"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, SubprocessPrototype__writableGetterWrap, 0 } } }; @@ -178,6 +188,26 @@ JSC_DEFINE_CUSTOM_GETTER(SubprocessPrototype__pidGetterWrap, (JSGlobalObject * l } +JSC_DEFINE_CUSTOM_GETTER(SubprocessPrototype__readableGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSSubprocess* thisObject = jsCast<JSSubprocess*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_readable.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + SubprocessPrototype__getStdout(thisObject->wrapped(), globalObject) + ); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_readable.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + + JSC_DEFINE_HOST_FUNCTION(SubprocessPrototype__refCallback, (JSGlobalObject * lexicalGlobalObject, CallFrame* callFrame)) { auto& vm = lexicalGlobalObject->vm(); @@ -272,6 +302,26 @@ JSC_DEFINE_HOST_FUNCTION(SubprocessPrototype__unrefCallback, (JSGlobalObject * l } +JSC_DEFINE_CUSTOM_GETTER(SubprocessPrototype__writableGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSSubprocess* thisObject = jsCast<JSSubprocess*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + + if (JSValue cachedValue = thisObject->m_writable.get()) + return JSValue::encode(cachedValue); + + JSC::JSValue result = JSC::JSValue::decode( + SubprocessPrototype__getStdin(thisObject->wrapped(), globalObject) + ); + RETURN_IF_EXCEPTION(throwScope, {}); + thisObject->m_writable.set(vm, thisObject, result); + RELEASE_AND_RETURN(throwScope, JSValue::encode(result)); +} + + void JSSubprocessPrototype::finishCreation(JSC::VM& vm, JSC::JSGlobalObject* globalObject) { Base::finishCreation(vm); @@ -416,9 +466,11 @@ void JSSubprocess::visitChildrenImpl(JSCell* cell, Visitor& visitor) Base::visitChildren(thisObject, visitor); visitor.append(thisObject->m_exited); + visitor.append(thisObject->m_readable); visitor.append(thisObject->m_stderr); visitor.append(thisObject->m_stdin); visitor.append(thisObject->m_stdout); + visitor.append(thisObject->m_writable); } DEFINE_VISIT_CHILDREN(JSSubprocess);extern "C" void* SHA1Class__construct(JSC::JSGlobalObject*, JSC::CallFrame*); @@ -3117,6 +3169,10 @@ extern "C" JSC::EncodedJSValue ResponsePrototype__getOK(void* ptr, JSC::JSGlobal JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__okGetterWrap); +extern "C" JSC::EncodedJSValue ResponsePrototype__getRedirected(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); +JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__redirectedGetterWrap); + + extern "C" JSC::EncodedJSValue ResponsePrototype__getStatus(void* ptr, JSC::JSGlobalObject* lexicalGlobalObject); JSC_DECLARE_CUSTOM_GETTER(ResponsePrototype__statusGetterWrap); @@ -3149,6 +3205,7 @@ STATIC_ASSERT_ISO_SUBSPACE_SHARABLE(JSResponsePrototype, JSResponsePrototype::Ba { "headers"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, ResponsePrototype__headersGetterWrap, 0 } } , { "json"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, ResponsePrototype__jsonCallback, 0 } } , { "ok"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, ResponsePrototype__okGetterWrap, 0 } } , +{ "redirected"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, ResponsePrototype__redirectedGetterWrap, 0 } } , { "status"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, ResponsePrototype__statusGetterWrap, 0 } } , { "statusText"_s, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { HashTableValue::GetterSetterType, ResponsePrototype__statusTextGetterWrap, 0 } } , { "text"_s, static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, ResponsePrototype__textCallback, 0 } } , @@ -3309,6 +3366,19 @@ JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__okGetterWrap, (JSGlobalObject * lexi } +JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__redirectedGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) +{ + auto& vm = lexicalGlobalObject->vm(); + Zig::GlobalObject *globalObject = reinterpret_cast<Zig::GlobalObject*>(lexicalGlobalObject); + auto throwScope = DECLARE_THROW_SCOPE(vm); + JSResponse* thisObject = jsCast<JSResponse*>(JSValue::decode(thisValue)); + JSC::EnsureStillAliveScope thisArg = JSC::EnsureStillAliveScope(thisObject); + JSC::EncodedJSValue result = ResponsePrototype__getRedirected(thisObject->wrapped(), globalObject); + RETURN_IF_EXCEPTION(throwScope, {}); + RELEASE_AND_RETURN(throwScope, result); +} + + JSC_DEFINE_CUSTOM_GETTER(ResponsePrototype__statusGetterWrap, (JSGlobalObject * lexicalGlobalObject, EncodedJSValue thisValue, PropertyName attributeName)) { auto& vm = lexicalGlobalObject->vm(); diff --git a/src/bun.js/bindings/ZigGeneratedClasses.h b/src/bun.js/bindings/ZigGeneratedClasses.h index 95ccf0b10..7b2afdf2d 100644 --- a/src/bun.js/bindings/ZigGeneratedClasses.h +++ b/src/bun.js/bindings/ZigGeneratedClasses.h @@ -67,9 +67,11 @@ class JSSubprocess final : public JSC::JSDestructibleObject { DECLARE_VISIT_CHILDREN; mutable JSC::WriteBarrier<JSC::Unknown> m_exited; +mutable JSC::WriteBarrier<JSC::Unknown> m_readable; mutable JSC::WriteBarrier<JSC::Unknown> m_stderr; mutable JSC::WriteBarrier<JSC::Unknown> m_stdin; mutable JSC::WriteBarrier<JSC::Unknown> m_stdout; +mutable JSC::WriteBarrier<JSC::Unknown> m_writable; }; class JSSubprocessPrototype final : public JSC::JSNonFinalObject { public: diff --git a/src/bun.js/bindings/generated_classes.zig b/src/bun.js/bindings/generated_classes.zig index f26966de0..124602918 100644 --- a/src/bun.js/bindings/generated_classes.zig +++ b/src/bun.js/bindings/generated_classes.zig @@ -75,6 +75,9 @@ pub const JSSubprocess = struct { if (@TypeOf(Subprocess.getPid) != GetterType) @compileLog("Expected Subprocess.getPid to be a getter"); + if (@TypeOf(Subprocess.getStdout) != GetterType) + @compileLog("Expected Subprocess.getStdout to be a getter"); + if (@TypeOf(Subprocess.doRef) != CallbackType) @compileLog("Expected Subprocess.doRef to be a callback"); if (@TypeOf(Subprocess.getStderr) != GetterType) @@ -88,6 +91,9 @@ pub const JSSubprocess = struct { if (@TypeOf(Subprocess.doUnref) != CallbackType) @compileLog("Expected Subprocess.doUnref to be a callback"); + if (@TypeOf(Subprocess.getStdin) != GetterType) + @compileLog("Expected Subprocess.getStdin to be a getter"); + if (!JSC.is_bindgen) { @export(Subprocess.constructor, .{ .name = "SubprocessClass__construct" }); @export(Subprocess.doRef, .{ .name = "SubprocessPrototype__doRef" }); @@ -1001,6 +1007,9 @@ pub const JSResponse = struct { if (@TypeOf(Response.getOK) != GetterType) @compileLog("Expected Response.getOK to be a getter"); + if (@TypeOf(Response.getRedirected) != GetterType) + @compileLog("Expected Response.getRedirected to be a getter"); + if (@TypeOf(Response.getStatus) != GetterType) @compileLog("Expected Response.getStatus to be a getter"); @@ -1036,6 +1045,7 @@ pub const JSResponse = struct { @export(Response.getHeaders, .{ .name = "ResponsePrototype__getHeaders" }); @export(Response.getJSON, .{ .name = "ResponsePrototype__getJSON" }); @export(Response.getOK, .{ .name = "ResponsePrototype__getOK" }); + @export(Response.getRedirected, .{ .name = "ResponsePrototype__getRedirected" }); @export(Response.getResponseType, .{ .name = "ResponsePrototype__getResponseType" }); @export(Response.getStatus, .{ .name = "ResponsePrototype__getStatus" }); @export(Response.getStatusText, .{ .name = "ResponsePrototype__getStatusText" }); diff --git a/src/bun.js/scripts/generate-classes.ts b/src/bun.js/scripts/generate-classes.ts index 55627bcc4..13e1780f4 100644 --- a/src/bun.js/scripts/generate-classes.ts +++ b/src/bun.js/scripts/generate-classes.ts @@ -35,7 +35,7 @@ function constructorName(typeName) { return `JS${typeName}Constructor`; } -function appendSymbols(to, symbolName, prop) { +function appendSymbols(to: Map<string, string>, symbolName: (name: string) => string, prop) { var { defaultValue, getter, setter, accesosr, fn } = prop; if (accesosr) { @@ -43,16 +43,16 @@ function appendSymbols(to, symbolName, prop) { setter = accesosr.setter; } - if (getter) { - to.push([getter, symbolName(getter)]); + if (getter && !to.get(getter)) { + to.set(getter, symbolName(getter)); } - if (setter) { - to.push([setter, symbolName(setter)]); + if (setter && !to.get(setter)) { + to.set(setter, symbolName(setter)); } - if (fn) { - to.push([fn, symbolName(fn)]); + if (fn && !to.get(fn)) { + to.set(fn, symbolName(fn)); } } function propRow( @@ -929,18 +929,18 @@ function generateZig( estimatedSize, } = {} as ClassDefinition ) { - const exports: [string, string][] = []; + const exports = new Map<string, string>(); if (construct) { - exports.push([`constructor`, classSymbolName(typeName, "construct")]); + exports.set(`constructor`, classSymbolName(typeName, "construct")); } if (finalize) { - exports.push([`finalize`, classSymbolName(typeName, "finalize")]); + exports.set(`finalize`, classSymbolName(typeName, "finalize")); } if (estimatedSize) { - exports.push([`estimatedSize`, symbolName(typeName, "estimatedSize")]); + exports.set(`estimatedSize`, symbolName(typeName, "estimatedSize")); } Object.values(klass).map((a) => @@ -1108,7 +1108,7 @@ pub const ${className(typeName)} = struct { comptime { ${typeCheck()} if (!JSC.is_bindgen) { -${exports +${[...exports] .sort(([a], [b]) => a.localeCompare(b)) .map( ([internalName, externalName]) => diff --git a/src/bun.js/webcore/response.classes.ts b/src/bun.js/webcore/response.classes.ts index 89133979a..079763064 100644 --- a/src/bun.js/webcore/response.classes.ts +++ b/src/bun.js/webcore/response.classes.ts @@ -92,7 +92,9 @@ export default [ getter: "getHeaders", cache: true, }, - + redirected: { + getter: "getRedirected", + }, statusText: { getter: "getStatusText", cache: true, diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 42020d8f6..43f52d393 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -155,10 +155,18 @@ pub const Response = struct { this: *Response, globalThis: *JSC.JSGlobalObject, ) callconv(.C) JSC.JSValue { - // https://developer.mozilla.org/en-US/docs/Web/API/Response/url + // https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText return ZigString.init(this.status_text).withEncoding().toValueGC(globalThis); } + pub fn getRedirected( + this: *Response, + _: *JSC.JSGlobalObject, + ) callconv(.C) JSC.JSValue { + // https://developer.mozilla.org/en-US/docs/Web/API/Response/redirected + return JSValue.jsBoolean(this.redirected); + } + pub fn getOK( this: *Response, _: *JSC.JSGlobalObject, |