diff options
author | 2023-05-10 20:38:52 -0300 | |
---|---|---|
committer | 2023-05-10 16:38:52 -0700 | |
commit | 85b4be5f7189e51e63672ddc874e7c6e09ae8bef (patch) | |
tree | eb19dd2bd014ee4c2798c8ce863ac587c186318f /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | 643aa27a030e56580c215218247f2979d4901b46 (diff) | |
download | bun-85b4be5f7189e51e63672ddc874e7c6e09ae8bef.tar.gz bun-85b4be5f7189e51e63672ddc874e7c6e09ae8bef.tar.zst bun-85b4be5f7189e51e63672ddc874e7c6e09ae8bef.zip |
fix(fetch) fix fetch inheritance (#2842)
* patch fetch function inheritance
* fmt
* fix reserveCapacity and number of arguments for fetch
* change Bun.fetch to use Fetch.jsFunction
* merge Fetch.jsFunction and Fetch.call
* remove commented code
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index dd1c4b08d..6816af84e 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -2969,6 +2969,13 @@ extern "C" void Bun__setOnEachMicrotaskTick(JSC::VM* vm, void* ptr, void (*callb }); } + + +static JSC_DEFINE_HOST_FUNCTION(functionFetch, + (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame)) +{ + return JSC::JSValue::encode(Bun__fetch(globalObject, callFrame)); +} // This implementation works the same as setTimeout(myFunction, 0) // TODO: make it more efficient // https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate @@ -3118,10 +3125,15 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) auto& builtinNames = WebCore::builtinNames(vm); WTF::Vector<GlobalPropertyInfo> extraStaticGlobals; - extraStaticGlobals.reserveCapacity(42); + extraStaticGlobals.reserveCapacity(43); JSC::Identifier queueMicrotaskIdentifier = JSC::Identifier::fromString(vm, "queueMicrotask"_s); extraStaticGlobals.uncheckedAppend( + GlobalPropertyInfo { JSC::Identifier::fromString(vm, "fetch"_s), + JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 2, + "fetch"_s, functionFetch, ImplementationVisibility::Public), + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0 }); + extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { queueMicrotaskIdentifier, JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 2, "queueMicrotask"_s, functionQueueMicrotask, ImplementationVisibility::Public), @@ -3381,6 +3393,13 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm if (JSObject* prototype = object->classRef()->prototype(this)) object->setPrototypeDirect(vm, prototype); + + { + JSC::Identifier identifier = JSC::Identifier::fromString(vm, "fetch"_s); + object->putDirectNativeFunction(vm, this, identifier, 2, functionFetch, ImplementationVisibility::Public, NoIntrinsic, + JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); + } + { JSC::Identifier identifier = JSC::Identifier::fromString(vm, "escapeHTML"_s); static ClassInfo escapeHTMLClassInfo = *object->classInfo(); |