-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Legacy RegExp features #832
Conversation
aafd477
to
e4c0aea
Compare
I cannot find |
@clover2123 Sorry for the late reply! This pull request based on this proposal documentation Of course i can close this pull request and wait for a more official standard documentation. |
@clover2123 Of course! |
e1e8aa6
to
fe415e5
Compare
Updated the pull request and added the related test-cases in test262 |
src/runtime/RegExpObject.h
Outdated
|
||
void setLegacyFeaturesEnabled(bool is_enabled) | ||
{ | ||
m_legacyFeaturesEnabled = is_enabled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a minor correction.
We generally don't use underscore(_
) for parameter's name.
Please fix it to another name like isEnabled
.
@@ -457,6 +458,18 @@ void RegExpObject::createRegexMatchResult(ExecutionState& state, String* str, Re | |||
} while (testResult); | |||
} | |||
|
|||
static void InvalidateLegacyRegExpStaticProperties(ExecutionState& state) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We define each function name that starts with lower case like invalidate...
.
static Value builtinRegExpInputSetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) | ||
{ | ||
if (!thisValue.isPointerValue() || thisValue.asPointerValue() != state.context()->globalObject()->regexp()) { | ||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "thisValue is not RegExp"); | ||
} | ||
state.resolveCallee()->codeBlock()->context()->regexpStatus().input = argv[0].toString(state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you call setLegacyRegExpStaticProperty
here?
} | ||
|
||
{ | ||
JSGetterSetter gs( | ||
new NativeFunctionObject(state, NativeFunctionInfo(strings->get, builtinRegExpLastMatchGetter, 0, NativeFunctionInfo::Strict)), Value(Value::EmptyValue)); | ||
m_regexp->defineOwnProperty(state, strings->lastMatch, ObjectPropertyDescriptor(gs, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::EnumerablePresent))); | ||
m_regexp->defineOwnProperty(state, strings->$Ampersand, ObjectPropertyDescriptor(gs, (ObjectPropertyDescriptor::PresentAttribute)(ObjectPropertyDescriptor::NotPresent))); | ||
new NativeFunctionObject(state, NativeFunctionInfo(strings->set, builtinRegExpLastMatchSetter, 1, NativeFunctionInfo::Strict)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This newly allocated NativeFunctionObject
seems useless.
And there are other similar cases like this. Please check and remove it.
} | ||
|
||
static Value builtinRegExpLastMatchSetter(ExecutionState& state, Value thisValue, size_t argc, Value* argv, Optional<Object*> newTarget) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the standard, RegExp.lastMatch
does not have setter (getter only).
Remove this setter function and other setter functions too.
|
fe415e5
to
c8bb1d7
Compare
@clover2123 I updated the pull request! |
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "thisValue is not RegExp"); \ | ||
} \ | ||
if (stringView.isEmpty()) { \ | ||
ErrorObject::throwBuiltinError(state, ErrorObject::TypeError, "Value is empty"); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For error messages, how about exploiting existing messages defined in ErrorObject::Messages
?
e.g) ErrorObject::Messages::GlobalObject_ThisNotRegExpObject
for the first error
src/runtime/RegExpObject.cpp
Outdated
state.resolveCallee()->codeBlock()->context()->regexpStatus().input = String::emptyString; | ||
state.resolveCallee()->codeBlock()->context()->regexpStatus().lastMatch = StringView(); | ||
state.resolveCallee()->codeBlock()->context()->regexpStatus().lastParen = StringView(); | ||
state.resolveCallee()->codeBlock()->context()->regexpStatus().leftContext = StringView(); | ||
state.resolveCallee()->codeBlock()->context()->regexpStatus().rightContext = StringView(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that RegExpStatus
could be accessed simply by state.context()->regexpStatus()
c8bb1d7
to
24d4079
Compare
@clover2123 Thank you for the review! |
It seems that you have reverted the previous update. |
Signed-off-by: bence gabor kis <[email protected]>
24d4079
to
2ddd965
Compare
Sorry for the inconvenience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: bence gabor kis [email protected]