-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make RegExp#[Symbol.*] methods call exec #411
Conversation
Sorry, some more days I'll be unavailable. I'll review it later. |
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue) | ||
// 21.2.5.11 RegExp.prototype[@@split](string, limit) | ||
? function (string, arg) { return regexMethod.call(string, this, arg); } | ||
// 21.2.5.6 RegExp.prototype[@@match](string) | ||
// 21.2.5.9 RegExp.prototype[@@search](string) | ||
: function (string) { return regexMethod.call(string, this); } | ||
); | ||
// TODO: This line makes the tests fail: | ||
// ReferenceError: Can't find variable: Reflect | ||
// hide(RegExp.prototype[SYMBOL], 'name', '[Symbol.' + KEY + ']'); |
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.
In many engines, functions .name
property non-writable non-configurable, so, I think, it would be better just remove it.
}, | ||
// `RegExp.prototype[@@match]` method | ||
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match | ||
function Symbol$match(regexp) { |
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 better compression, use named functions only when they should have the same explicit .name
property (like match
above).
tests/helpers/helpers.js
Outdated
}; | ||
try { | ||
return run(assert); | ||
} finally { |
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.
IIRC in very old IE try / finally
does not work without catch
.
@@ -0,0 +1,5 @@ | |||
'use 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.
Please, add a comment that it's AdvanceStringIndex
abstract operation and the link to the spec.
@@ -16,13 +16,17 @@ module.exports = function (KEY, length, exec) { | |||
return ''[KEY](O) != 7; | |||
})) { |
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.
Are you sure that this test also covers all engines without internal execution of .exec
method? Maybe makes sense extend it?
var A = []; | ||
var n = 0; | ||
var result; | ||
while ((result = rx.exec(S)) !== null) { |
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.
In RegExpExec
, own .exec
should be called only if it's callable. Maybe makes sense to implement RegExpExec
abstract operation?
var execCalled = false; | ||
var re = /a/; | ||
re.exec = function () { execCalled = true; return null; }; | ||
return re[SYMBOL] && (re[SYMBOL](''), execCalled); |
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 should return a negative result for the existent feature. Use, for example,
re[SYMBOL]('');
return !execCalled;
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.
Isn't it faster if it avoid throwing an error?
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's just an example. The main idea of the comment - the result should be inverted.
var O = {}; | ||
O[SYMBOL] = function () { return 7; }; | ||
return ''[KEY](O) != 7; | ||
}) || fails(function () { | ||
// Symbol-named RegExp methods call .exec |
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 test throws an uncaught stack overflow error in the promises tests and I'm not sure why.
@zloirock I manages to make the tests pass. Could you review this PR again? |
Hey guys, is this PR good to go yet? Is there still anything blocking? |
@zloirock Since Babel uses core-js@2, can I backport this PR? |
@nicolo-ribaudo feel free to add the same PR to |
I'll review it today or tomorrow. Could you rebase it? |
At first sight, LGTM. |
@nicolo-ribaudo |
’tests/tests.html’25.09.2018, 12:18, "Nicolò Ribaudo" <notifications@github.com>:How do I run the tests in a browser?
—You are receiving this because you modified the open/close state.Reply to this email directly, view it on GitHub, or mute the thread.
|
@nicolo-ribaudo |
I will fix it later. |
I use Saucelabs and run tests in all available browsers before releases. |
I'm working on this now. EDIT: Ok, I'm downloading windows, ie8, chrome 50 and chrome 51. Hopefully I will be able to debug the issue 😆 |
Which firefox version? I can't reproduce it. I'm writing down some notes for myself
Conclusion: I also need to polyfill |
IIRC it was fixed in #434 |
@zloirock In order to fix some IE8 failing tests, I need to fix this IE bug: > /^(a?)/.exec("")
["", ""] // correct
> /^(a)?/.exec("")
> ["", ""] // wrong, should be ["", undefined] I don't think that it is possible, unless we re-implement the regexp engine. Could I disable an assertion on IE8? PS. For now I got it working in Chrome 50 & 51 and I'm trying to install Safari in a VM. EDIT: Fixing the IE bug is possible |
Available in |
Ref: babel/babel#7105 (comment)