From 8e1b2ba32e1eecb26ec8f21628207890fab34c14 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Mon, 17 Oct 2022 22:37:18 -0700 Subject: add oniguruma for regex with variable length lookbehinds (#1329) * added pcre2 submodule * pcre2 regex boilerplate * tests for pcre2 regex * flag validation, getters, construct and compile mostly working * string escaping for source and toString(), exec, more tests * flag sorting, match, matchAll, search, split, replace * remove lib link * add destructor to PCRE2RegExp * header include * removed ternary * switched to oniguruma for regex library * revert sql changes * fix indices flag, add tests * revert settings * working error messages * more tests for lastIndex, fix logic for compile and lastIndex * move oniguruma lib to deps out dir --- src/bun.js/bindings/ZigGlobalObject.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp') diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 85b3c27ee..e69163043 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -163,6 +163,8 @@ using JSBuffer = WebCore::JSBuffer; #include "DOMJITHelpers.h" #include +#include "OnigurumaRegExp.h" + #ifdef __APPLE__ #include #else @@ -2076,6 +2078,17 @@ void GlobalObject::finishCreation(VM& vm) init.setConstructor(constructor); }); + m_OnigurumaRegExpClassStructure.initLater( + [](LazyClassStructure::Initializer& init) { + auto* prototype = OnigurumaRegExpConstructor::createPrototype(init.global); + auto* structure = OnigurumaRegExpConstructor::createClassStructure(init.global, prototype); + auto* constructor = OnigurumaRegExpConstructor::create( + init.vm, init.global, OnigurumaRegExpConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), prototype); + init.setPrototype(prototype); + init.setStructure(structure); + init.setConstructor(constructor); + }); + m_JSStringDecoderClassStructure.initLater( [](LazyClassStructure::Initializer& init) { auto* prototype = JSStringDecoderPrototype::create( @@ -2541,6 +2554,11 @@ void GlobalObject::installAPIGlobals(JSClassRef* globals, int count, JSC::VM& vm JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly); } + { + JSC::Identifier identifier = JSC::Identifier::fromString(vm, "OnigurumaRegExp"_s); + object->putDirectCustomAccessor(vm, identifier, JSC::CustomGetterSetter::create(vm, jsFunctionGetOnigurumaRegExpConstructor, nullptr), JSC::PropertyAttribute::CustomAccessor | 0); + } + { JSC::Identifier identifier = JSC::Identifier::fromString(vm, "stringHashCode"_s); object->putDirectNativeFunction(vm, this, identifier, 1, functionHashCode, ImplementationVisibility::Public, NoIntrinsic, @@ -2668,6 +2686,7 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor); thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor); thisObject->m_JSFileSinkClassStructure.visit(visitor); + thisObject->m_OnigurumaRegExpClassStructure.visit(visitor); visitor.append(thisObject->m_JSBufferSetterValue); visitor.append(thisObject->m_JSTextEncoderSetterValue); -- cgit v1.2.3