Skip to content

Commit 0eef7f5

Browse files
Merge pull request #177 from lightpanda-io/regexp
expose v8 regexp
2 parents 08a6e30 + df64b8c commit 0eef7f5

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

src/binding.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,44 @@ const v8::Value* v8__Object__GetPrivate(
15321532
ptr_to_local(&self)->GetPrivate(ptr_to_local(&ctx), ptr_to_local(&key))
15331533
);
15341534
}
1535+
1536+
// RegExp
1537+
1538+
const v8::RegExp* v8__RegExp__New(
1539+
const v8::Context& ctx,
1540+
const v8::String& pattern,
1541+
int flags) {
1542+
return maybe_local_to_ptr(
1543+
v8::RegExp::New(
1544+
ptr_to_local(&ctx),
1545+
ptr_to_local(&pattern),
1546+
static_cast<v8::RegExp::Flags>(flags))
1547+
);
1548+
}
1549+
1550+
const v8::RegExp* v8__RegExp__NewWithBacktrackLimit(
1551+
const v8::Context& ctx,
1552+
const v8::String& pattern,
1553+
int flags,
1554+
uint32_t backtrack_limit) {
1555+
return maybe_local_to_ptr(
1556+
v8::RegExp::NewWithBacktrackLimit(
1557+
ptr_to_local(&ctx),
1558+
ptr_to_local(&pattern),
1559+
static_cast<v8::RegExp::Flags>(flags),
1560+
backtrack_limit)
1561+
);
1562+
}
1563+
1564+
const v8::Object* v8__RegExp__Exec(
1565+
const v8::RegExp& self,
1566+
const v8::Context& ctx,
1567+
const v8::String& subject) {
1568+
return maybe_local_to_ptr(
1569+
ptr_to_local(&self)->Exec(ptr_to_local(&ctx), ptr_to_local(&subject))
1570+
);
1571+
}
1572+
15351573
// FunctionCallbackInfo
15361574

15371575
v8::Isolate* v8__FunctionCallbackInfo__GetIsolate(

src/binding.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ typedef Value Boolean;
5050
typedef Value Promise;
5151
typedef Value Name;
5252
typedef Value PromiseResolver;
53+
typedef Value RegExp;
5354
typedef enum CompileOptions {
5455
kNoCompileOptions = 0,
5556
kConsumeCodeCache = 1,
@@ -78,6 +79,18 @@ typedef enum PromiseRejectEvent {
7879
kPromiseRejectAfterResolved = 2,
7980
kPromiseResolveAfterResolved = 3,
8081
} PromiseRejectEvent;
82+
typedef enum RegExpFlags {
83+
kRegExpNone = 0,
84+
kRegExpGlobal = 1 << 0,
85+
kRegExpIgnoreCase = 1 << 1,
86+
kRegExpMultiline = 1 << 2,
87+
kRegExpSticky = 1 << 3,
88+
kRegExpUnicode = 1 << 4,
89+
kRegExpDotAll = 1 << 5,
90+
kRegExpLinear = 1 << 6,
91+
kRegExpHasIndices = 1 << 7,
92+
kRegExpUnicodeSets = 1 << 8,
93+
} RegExpFlags;
8194
typedef struct PromiseRejectMessage PromiseRejectMessage;
8295
typedef void (*PromiseRejectCallback)(PromiseRejectMessage);
8396
typedef Promise* (*HostImportModuleDynamicallyCallback)(Context*, Data*, Value*, String*, FixedArray*);
@@ -722,6 +735,21 @@ void v8__Object__DeletePrivate(const Object* self, const Context *ctx, const Pri
722735
void v8__Object__SetPrivate(const Object* self, const Context *ctx, const Private* private, const Value* value, MaybeBool* out);
723736
const Value* v8__Object__GetPrivate(const Object* self, const Context *ctx, const Private* private);
724737

738+
// RegExp
739+
const RegExp* v8__RegExp__New(
740+
const Context* ctx,
741+
const String* pattern,
742+
int flags);
743+
const RegExp* v8__RegExp__NewWithBacktrackLimit(
744+
const Context* ctx,
745+
const String* pattern,
746+
int flags,
747+
uint32_t backtrack_limit);
748+
const Object* v8__RegExp__Exec(
749+
const RegExp* self,
750+
const Context* ctx,
751+
const String* subject);
752+
725753
// Exception
726754
const Value* v8__Exception__Error(const String* message);
727755
const Value* v8__Exception__TypeError(const String* message);

0 commit comments

Comments
 (0)