diff options
author | 2023-05-10 16:55:13 -0700 | |
---|---|---|
committer | 2023-05-10 16:55:13 -0700 | |
commit | 96dc0471ff8f830327ca89d6cbcdbd320b379b15 (patch) | |
tree | b5ca7da53057baba39b9522c314b4b1f1cda5382 /src/bun.js/bindings/ZigGlobalObject.cpp | |
parent | 85b4be5f7189e51e63672ddc874e7c6e09ae8bef (diff) | |
download | bun-96dc0471ff8f830327ca89d6cbcdbd320b379b15.tar.gz bun-96dc0471ff8f830327ca89d6cbcdbd320b379b15.tar.zst bun-96dc0471ff8f830327ca89d6cbcdbd320b379b15.zip |
Clean-up 85b4be5f7189e51e63672ddc874e7c6e09ae8bef
- We don't need to make `Bun__fetch` exported in every C++ header file
- We shouldn't return JSObjectRef, its an unnecessary wrapper
- The version of `fetch` on the Bun global should be non-configurable so that it is safe for anyone who wants to use that without a user-modifiable one
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 6816af84e..d5ab41d71 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -118,6 +118,8 @@ #include "JavaScriptCore/RemoteInspectorServer.h" #endif +extern "C" JSC::EncodedJSValue Bun__fetch(JSC::JSGlobalObject* lexicalGlobalObject, JSC::CallFrame* callFrame); + using JSGlobalObject = JSC::JSGlobalObject; using Exception = JSC::Exception; @@ -2969,13 +2971,6 @@ 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 @@ -3131,7 +3126,7 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { JSC::Identifier::fromString(vm, "fetch"_s), JSC::JSFunction::create(vm, JSC::jsCast<JSC::JSGlobalObject*>(globalObject()), 2, - "fetch"_s, functionFetch, ImplementationVisibility::Public), + "fetch"_s, Bun__fetch, ImplementationVisibility::Public), JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0 }); extraStaticGlobals.uncheckedAppend( GlobalPropertyInfo { queueMicrotaskIdentifier, @@ -3393,11 +3388,11 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm if (JSObject* prototype = object->classRef()->prototype(this)) object->setPrototypeDirect(vm, prototype); - { + // on the Bun object we make this read-only so that it is the "safer" one to use 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); + object->putDirectNativeFunction(vm, this, identifier, 2, Bun__fetch, ImplementationVisibility::Public, NoIntrinsic, + JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::Function | JSC::PropertyAttribute::DontDelete | 0); } { |