aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-30 00:19:39 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-30 00:19:39 -0700
commitf24ca3900400bb41faefb42f426651d5d7e7c2e6 (patch)
tree1d75dcbd5921a66b2bbbc4d685ddca01e3196ae0 /src
parente3dc5b6b4ce2c10d1e9c61fec2e86409e4ce48b0 (diff)
downloadbun-f24ca3900400bb41faefb42f426651d5d7e7c2e6.tar.gz
bun-f24ca3900400bb41faefb42f426651d5d7e7c2e6.tar.zst
bun-f24ca3900400bb41faefb42f426651d5d7e7c2e6.zip
Fix bug in `util/types`.{isGeneratorFunction,isAsyncFunction}
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/modules/NodeUtilTypesModule.h28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/bun.js/modules/NodeUtilTypesModule.h b/src/bun.js/modules/NodeUtilTypesModule.h
index 586743fea..de9b147a4 100644
--- a/src/bun.js/modules/NodeUtilTypesModule.h
+++ b/src/bun.js/modules/NodeUtilTypesModule.h
@@ -123,8 +123,28 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsRegExp, (JSC::JSGlobalObject * globalObject
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsAsyncFunction, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
{
- GET_FIRST_CELL
- return JSValue::encode(jsBoolean(JSValue::strictEqual(globalObject, JSValue(globalObject->asyncFunctionPrototype()), cell->getObject()->getPrototype(cell->getObject(), globalObject))));
+ GET_FIRST_VALUE
+
+ auto* function = jsDynamicCast<JSFunction*>(value);
+ if (!function)
+ return JSValue::encode(jsBoolean(false));
+
+ auto *executable = function->jsExecutable();
+ if (!executable)
+ return JSValue::encode(jsBoolean(false));
+
+ if (executable->isAsyncGenerator()) {
+ return JSValue::encode(jsBoolean(true));
+ }
+
+ auto& vm = globalObject->vm();
+ auto proto = function->getPrototype(vm, globalObject);
+ if (!proto.isCell()) {
+ return JSValue::encode(jsBoolean(false));
+ }
+
+ auto *protoCell = proto.asCell();
+ return JSValue::encode(jsBoolean(protoCell->inherits<AsyncFunctionPrototype>()));
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsGeneratorFunction, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
{
@@ -137,13 +157,13 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionIsGeneratorFunction, (JSC::JSGlobalObject * g
if (!executable)
return JSValue::encode(jsBoolean(false));
- return JSValue::encode(jsBoolean(executable->isGenerator()));
+ return JSValue::encode(jsBoolean(executable->isGenerator() || executable->isAsyncGenerator()));
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsGeneratorObject, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
{
GET_FIRST_CELL
- return JSValue::encode(jsBoolean(cell->type() == JSGeneratorType));
+ return JSValue::encode(jsBoolean(cell->type() == JSGeneratorType || cell->type() == JSAsyncGeneratorType));
}
JSC_DEFINE_HOST_FUNCTION(jsFunctionIsPromise, (JSC::JSGlobalObject * globalObject, JSC::CallFrame* callframe))
{