Skip to content

Commit

Permalink
Implement accessor unicodeSets for RegExp prototype
Browse files Browse the repository at this point in the history
Signed-off-by: Seonghyun Kim <[email protected]>
  • Loading branch information
ksh8281 authored and clover2123 committed Jul 24, 2024
1 parent 6374a48 commit 7762be6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/builtins/BuiltinRegExp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ static Value builtinRegExpUnicodeGetter(ExecutionState& state, Value thisValue,
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::Unicode);
}

static Value builtinRegExpUnicodeSetsGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
{
return builtinRegExpOptionGetterHelper(state, thisValue, RegExpObject::Option::UnicodeSets);
}


// Legacy RegExp Features (non-standard)
static Value builtinRegExpInputGetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget)
Expand Down Expand Up @@ -928,6 +933,13 @@ void GlobalObject::installRegExp(ExecutionState& state)
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->unicode), desc);
}

{
Value getter = new NativeFunctionObject(state, NativeFunctionInfo(strings->getUnicodeSets, builtinRegExpUnicodeSetsGetter, 0, NativeFunctionInfo::Strict));
JSGetterSetter gs(getter, Value());
ObjectPropertyDescriptor desc(gs, ObjectPropertyDescriptor::ConfigurablePresent);
m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(state, strings->unicodeSets), desc);
}

m_regexpPrototype->directDefineOwnProperty(state, ObjectPropertyName(strings->constructor), ObjectPropertyDescriptor(m_regexp, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::WritablePresent | ObjectPropertyDescriptor::ConfigurablePresent)));

m_regexp->setFunctionPrototype(state, m_regexpPrototype);
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/RegExpObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ RegExpObject::Option RegExpObject::parseOption(ExecutionState& state, String* op
case 'u':
if (tempOption & Option::Unicode)
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, "RegExp has multiple 'u' flags");
if (tempOption & Option::UnicodeSets)
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, "RegExp already have 'v' flag");
tempOption = (Option)(tempOption | Option::Unicode);
break;
case 'y':
Expand All @@ -238,6 +240,8 @@ RegExpObject::Option RegExpObject::parseOption(ExecutionState& state, String* op
case 'v':
if (tempOption & Option::UnicodeSets)
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, "RegExp has multiple 'v' flags");
if (tempOption & Option::Unicode)
ErrorObject::throwBuiltinError(state, ErrorCode::SyntaxError, "RegExp already have 'u' flag");
tempOption = (Option)(tempOption | Option::UnicodeSets);
break;
case 'd':
Expand Down
1 change: 1 addition & 0 deletions src/runtime/StaticStrings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void StaticStrings::initStaticStrings()
INIT_STATIC_STRING(getTextInfo, "get textInfo");
INIT_STATIC_STRING(getTimeZones, "get timeZones");
INIT_STATIC_STRING(getUnicode, "get unicode");
INIT_STATIC_STRING(getUnicodeSets, "get unicodeSets");
INIT_STATIC_STRING(getWeekInfo, "get weekInfo");
INIT_STATIC_STRING(get__proto__, "get __proto__");
INIT_STATIC_STRING(getbyteLength, "get byteLength");
Expand Down
1 change: 1 addition & 0 deletions src/runtime/StaticStrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ class StaticStrings {
AtomicString getTextInfo;
AtomicString getTimeZones;
AtomicString getUnicode;
AtomicString getUnicodeSets;
AtomicString getWeekInfo;
AtomicString get__proto__;
AtomicString getbyteLength;
Expand Down

0 comments on commit 7762be6

Please sign in to comment.