aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/bindings.cpp
diff options
context:
space:
mode:
authorGravatar zhiyuan <32867472+zhiyuang@users.noreply.github.com> 2023-03-17 18:49:41 +0800
committerGravatar GitHub <noreply@github.com> 2023-03-17 03:49:41 -0700
commitc5f2b4264993739440f73d166280c9ec74e27c1c (patch)
treeae7acff72ecadb190bf84714b34fa1ad8dabedf9 /src/bun.js/bindings/bindings.cpp
parent37293cb26a8239d4f387218a1fdadc522787835f (diff)
downloadbun-c5f2b4264993739440f73d166280c9ec74e27c1c.tar.gz
bun-c5f2b4264993739440f73d166280c9ec74e27c1c.tar.zst
bun-c5f2b4264993739440f73d166280c9ec74e27c1c.zip
Feat(test): add toMatch (#2404)
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r--src/bun.js/bindings/bindings.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index f273bca46..3b0137c28 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -2845,6 +2845,31 @@ JSC__JSString* JSC__JSValue__toStringOrNull(JSC__JSValue JSValue0, JSC__JSGlobal
return value.toStringOrNull(arg1);
}
+bool JSC__JSValue__toMatch(JSC__JSValue regexValue, JSC__JSGlobalObject* global, JSC__JSValue value) {
+ JSC::JSValue regex = JSC::JSValue::decode(regexValue);
+ JSC::JSValue str = JSC::JSValue::decode(value);
+ if (regex.asCell()->type() != RegExpObjectType || !str.isString()) {
+ return false;
+ }
+ JSC::RegExpObject* regexObject = jsDynamicCast<JSC::RegExpObject*>(regex);
+
+ return !!regexObject->match(global, JSC::asString(str));
+}
+
+bool JSC__JSValue__stringIncludes(JSC__JSValue value, JSC__JSGlobalObject* globalObject, JSC__JSValue other)
+{
+ VM& vm = globalObject->vm();
+ auto scope = DECLARE_CATCH_SCOPE(vm);
+
+ WTF::String stringToSearchIn = JSC::JSValue::decode(value).toWTFString(globalObject);
+ RETURN_IF_EXCEPTION(scope, false);
+
+ WTF::String searchString = JSC::JSValue::decode(other).toWTFString(globalObject);
+ RETURN_IF_EXCEPTION(scope, false);
+
+ return stringToSearchIn.find(searchString, 0) != WTF::notFound;
+}
+
static void populateStackFrameMetadata(JSC::VM& vm, const JSC::StackFrame* stackFrame, ZigStackFrame* frame)
{
frame->source_url = Zig::toZigString(stackFrame->sourceURL(vm));