diff options
Diffstat (limited to 'src/bun.js/bindings/bindings.cpp')
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 25 |
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)); |