Bug 155177 - [ES6] Implement RegExp sticky flag and related functionality
Summary: [ES6] Implement RegExp sticky flag and related functionality
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-03-08 11:04 PST by Michael Saboff
Modified: 2016-03-09 12:11 PST (History)
5 users (show)

See Also:


Attachments
Patch (56.78 KB, patch)
2016-03-09 10:41 PST, Michael Saboff
saam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Saboff 2016-03-08 11:04:25 PST
Implement the sticky flag, 'y', and the behavior described in the ES6 spec.
Comment 1 Radar WebKit Bug Importer 2016-03-08 11:04:52 PST
<rdar://problem/25038274>
Comment 2 Michael Saboff 2016-03-09 10:41:27 PST
Created attachment 273443 [details]
Patch
Comment 3 WebKit Commit Bot 2016-03-09 10:42:37 PST
Attachment 273443 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/yarr/YarrPattern.h:305:  The parameter name "flags" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 26 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Mark Lam 2016-03-09 10:48:38 PST
Comment on attachment 273443 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=273443&action=review

> Source/JavaScriptCore/ChangeLog:15
> +        Changed both the Yarr interpreter and jit to no loop to the next character for sticky RegExp's.

typo: "to no loop" ==> "to not loop"?
Comment 5 Mark Lam 2016-03-09 10:59:05 PST
Comment on attachment 273443 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=273443&action=review

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:179
> +    if (exec->hadException())
> +        return string;
> +    JSValue stickyValue = regexp->get(exec, exec->propertyNames().sticky);
> +    if (exec->hadException())
> +        return string;

Perhaps take this opportunity to cache "VM& vm = exec->vm();" up top and use "vm.exception()" in all these tests?
Comment 6 Saam Barati 2016-03-09 11:23:57 PST
Comment on attachment 273443 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=273443&action=review

r=me

> Source/JavaScriptCore/runtime/RegExpPrototype.cpp:179
> +    if (exec->hadException())
> +        return string;

All the exception checks in this function would be better off if they cached the VM at the top and checked vm.exception()

> Source/JavaScriptCore/yarr/YarrJIT.cpp:1848
> +                            // If the pattern size is not fixed, then store the start index, for use if we match.

second comma not needed.

> Source/JavaScriptCore/yarr/YarrJIT.cpp:1898
> +                    removeCallFrame();
> +                    move(TrustedImmPtr((void*)WTF::notFound), returnRegister);
> +                    move(TrustedImm32(0), returnRegister2);
> +                    generateReturn();

This code is repeated in a couple other places. Might be worth a helper.

> LayoutTests/js/script-tests/regexp-sticky.js:56
> +    for (var iter = 0; iter < expected.length; iter++) {
> +        let lastIndexStart = re.lastIndex;
> +
> +        let result = str.match(re);
> +        let correctResult = false;
> +	if (expected[iter] === null || result === null)
> +	    correctResult = (expected[iter] === result);
> +	else if (result.length == expected[iter].length) {
> +	    correctResult = true;
> +            for (let i = 0; i < result.length; i++) {
> +                if (result[i] != expected[iter][i])
> +                    correctResult = false;
> +            }
> +        }

Style: Indentation is off here.
Comment 7 Michael Saboff 2016-03-09 12:11:33 PST
Committed r197869: <http://trac.webkit.org/changeset/197869>