aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/bindings.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-01-07 07:09:48 -0800
committerGravatar GitHub <noreply@github.com> 2023-01-07 07:09:48 -0800
commit87983464d8a331c1ddd09eced9920269a759f0a9 (patch)
treeb08a5aef5c2d18f25a5ee46c88bec84d5b8ee907 /src/bun.js/bindings/bindings.cpp
parentd5565ab2cdd7099a5852ba5ba6d180ef291af084 (diff)
downloadbun-87983464d8a331c1ddd09eced9920269a759f0a9.tar.gz
bun-87983464d8a331c1ddd09eced9920269a759f0a9.tar.zst
bun-87983464d8a331c1ddd09eced9920269a759f0a9.zip
Implement DNS module (#1691)
* Boilerplate for DNS stuff * Add c-ares * lookup * make * Implement dns.lookup * Create c-ares * wip * normalize * repro * Revert "repro" This reverts commit 8b93e0c295b335b8882a9601da47720348549beb. * Implement macOS `getaddrinfo_async_start` * embiggen * Update string_immutable.zig * Update Makefile * alright * Update .gitignore * Add types * more ccache * Update Dockerfile * Update Dockerfile * Update Dockerfile * Update bun.d.ts Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r--src/bun.js/bindings/bindings.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index f73a1b6e0..5f3dc3dac 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -1982,6 +1982,50 @@ void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1,
{
arg0->resolve(arg1, JSC::JSValue::decode(JSValue2));
}
+
+// This implementation closely mimicks the one in JSC::JSPromise::resolve
+void JSC__JSPromise__resolveOnNextTick(JSC__JSPromise* promise, JSC__JSGlobalObject* lexicalGlobalObject,
+ JSC__JSValue encoedValue)
+{
+ JSC::JSValue value = JSC::JSValue::decode(encoedValue);
+ VM& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ uint32_t flags = promise->internalField(JSC::JSPromise::Field::Flags).get().asUInt32();
+ if (!(flags & JSC::JSPromise::isFirstResolvingFunctionCalledFlag)) {
+ promise->internalField(JSC::JSPromise::Field::Flags).set(vm, promise, jsNumber(flags | JSC::JSPromise::isFirstResolvingFunctionCalledFlag));
+ auto* globalObject = jsCast<Zig::GlobalObject*>(promise->globalObject());
+
+ globalObject->queueMicrotask(
+ globalObject->performMicrotaskFunction(),
+ globalObject->resolvePromiseFunction(),
+ promise,
+ value,
+ JSValue {});
+ RETURN_IF_EXCEPTION(scope, void());
+ }
+}
+
+// This implementation closely mimicks the one in JSC::JSPromise::reject
+void JSC__JSPromise__rejectOnNextTick(JSC__JSPromise* promise, JSC__JSGlobalObject* lexicalGlobalObject,
+ JSC__JSValue encoedValue)
+{
+ JSC::JSValue value = JSC::JSValue::decode(encoedValue);
+ VM& vm = lexicalGlobalObject->vm();
+ auto scope = DECLARE_THROW_SCOPE(vm);
+ uint32_t flags = promise->internalField(JSC::JSPromise::Field::Flags).get().asUInt32();
+ if (!(flags & JSC::JSPromise::isFirstResolvingFunctionCalledFlag)) {
+ promise->internalField(JSC::JSPromise::Field::Flags).set(vm, promise, jsNumber(flags | JSC::JSPromise::isFirstResolvingFunctionCalledFlag));
+ auto* globalObject = jsCast<Zig::GlobalObject*>(promise->globalObject());
+
+ globalObject->queueMicrotask(
+ globalObject->performMicrotaskFunction(),
+ globalObject->rejectPromiseFunction(),
+ promise,
+ value,
+ JSValue {});
+ RETURN_IF_EXCEPTION(scope, void());
+ }
+}
JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1)
{
Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(arg0);
@@ -3574,4 +3618,16 @@ extern "C" size_t JSC__VM__externalMemorySize(JSC__VM* vm)
#else
return 0;
#endif
+}
+
+extern "C" void JSC__JSGlobalObject__queueMicrotaskJob(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1, JSC__JSValue JSValue2, JSC__JSValue JSValue3, JSC__JSValue JSValue4)
+{
+ Zig::GlobalObject* globalObject = reinterpret_cast<Zig::GlobalObject*>(arg0);
+ JSC::VM& vm = globalObject->vm();
+ globalObject->queueMicrotask(
+ JSValue(globalObject->performMicrotaskFunction()),
+ JSC::JSValue::decode(JSValue1),
+ JSC::JSValue::decode(JSValue2),
+ JSC::JSValue::decode(JSValue3),
+ JSC::JSValue::decode(JSValue4));
} \ No newline at end of file