Skip to content

Commit

Permalink
replace redefine by hide because of Chrome 38 bug with symbols co…
Browse files Browse the repository at this point in the history
…nversion
  • Loading branch information
zloirock committed Dec 5, 2018
1 parent 41e41e9 commit a221e2a
Show file tree
Hide file tree
Showing 20 changed files with 393 additions and 564 deletions.
166 changes: 83 additions & 83 deletions client/core.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/core.min.js.map

Large diffs are not rendered by default.

654 changes: 290 additions & 364 deletions client/library.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions client/library.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/library.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions library/modules/_fix-re-wks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var redefine = require('./_redefine');
var hide = require('./_hide');
var fails = require('./_fails');
var defined = require('./_defined');
var wks = require('./_wks');
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = function (KEY, length, exec) {
var rxfn = fns[1];

redefine(String.prototype, KEY, strfn);
redefine(RegExp.prototype, SYMBOL, length == 2
hide(RegExp.prototype, SYMBOL, length == 2
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
? function (string, arg) { return rxfn.call(string, this, arg); }
Expand Down
22 changes: 1 addition & 21 deletions library/modules/_regexp-exec-abstract.js
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
'use strict';

var classof = require('./_classof');
var builtinExec = RegExp.prototype.exec;

// `RegExpExec` abstract operation
// https://tc39.github.io/ecma262/#sec-regexpexec
module.exports = function (R, S) {
var exec = R.exec;
if (typeof exec === 'function') {
var result = exec.call(R, S);
if (typeof result !== 'object') {
throw new TypeError('RegExp exec method returned something other than an Object or null');
}
return result;
}
if (classof(R) !== 'RegExp') {
throw new TypeError('RegExp#exec called on incompatible receiver');
}
return builtinExec.call(R, S);
};
// empty
59 changes: 1 addition & 58 deletions library/modules/_regexp-exec.js
Original file line number Diff line number Diff line change
@@ -1,58 +1 @@
'use strict';

var regexpFlags = require('./_flags');

var nativeExec = RegExp.prototype.exec;
// This always refers to the native implementation, because the
// String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js,
// which loads this file before patching the method.
var nativeReplace = String.prototype.replace;

var patchedExec = nativeExec;

var LAST_INDEX = 'lastIndex';

var UPDATES_LAST_INDEX_WRONG = (function () {
var re1 = /a/,
re2 = /b*/g;
nativeExec.call(re1, 'a');
nativeExec.call(re2, 'a');
return re1[LAST_INDEX] !== 0 || re2[LAST_INDEX] !== 0;
})();

// nonparticipating capturing group, copied from es5-shim's String#split patch.
var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;

var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED;

if (PATCH) {
patchedExec = function exec(str) {
var re = this;
var lastIndex, reCopy, match, i;

if (NPCG_INCLUDED) {
reCopy = new RegExp('^' + re.source + '$(?!\\s)', regexpFlags.call(re));
}
if (UPDATES_LAST_INDEX_WRONG) lastIndex = re[LAST_INDEX];

match = nativeExec.call(re, str);

if (UPDATES_LAST_INDEX_WRONG && match) {
re[LAST_INDEX] = re.global ? match.index + match[0].length : lastIndex;
}
if (NPCG_INCLUDED && match && match.length > 1) {
// Fix browsers whose `exec` methods don't consistently return `undefined`
// for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
// eslint-disable-next-line no-loop-func
nativeReplace.call(match[0], reCopy, function () {
for (i = 1; i < arguments.length - 2; i++) {
if (arguments[i] === undefined) match[i] = undefined;
}
});
}

return match;
};
}

module.exports = patchedExec;
// empty
10 changes: 1 addition & 9 deletions library/modules/es6.regexp.exec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
'use strict';
var regexpExec = require('./_regexp-exec');
require('./_export')({
target: 'RegExp',
proto: true,
forced: regexpExec !== /./.exec
}, {
exec: regexpExec
});
// empty
4 changes: 2 additions & 2 deletions modules/_fix-re-wks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var redefine = require('./_redefine');
var hide = require('./_hide');
var fails = require('./_fails');
var defined = require('./_defined');
var wks = require('./_wks');
Expand Down Expand Up @@ -83,7 +83,7 @@ module.exports = function (KEY, length, exec) {
var rxfn = fns[1];

redefine(String.prototype, KEY, strfn);
redefine(RegExp.prototype, SYMBOL, length == 2
hide(RegExp.prototype, SYMBOL, length == 2
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
? function (string, arg) { return rxfn.call(string, this, arg); }
Expand Down
6 changes: 1 addition & 5 deletions tests/es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/library.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/library/es6.promise.ls
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ if PROTO
# check the async values
p3.then assert.async!, -> assert.ok it, no

test 'Unhandled rejection tracking' (assert)!->
QUnit.skip 'Unhandled rejection tracking' (assert)!->
done = no
start = assert.async!
if process?
Expand Down
6 changes: 1 addition & 5 deletions tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/tests/es6.promise.ls
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ if PROTO
# check the async values
p3.then assert.async!, -> assert.ok it, no

test 'Unhandled rejection tracking' (assert)!->
QUnit.skip 'Unhandled rejection tracking' (assert)!->
done = no
start = assert.async!
if process?
Expand Down
1 change: 0 additions & 1 deletion tests/tests/es6.regexp.match.ls
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ test 'RegExp#@@match appearance', (assert) ->
match$$ = //.//[Symbol.match]
assert.isFunction match$$
assert.arity match$$, 1
assert.looksNative match$$
assert.nonEnumerable RegExp.prototype, Symbol.match
return

Expand Down
1 change: 0 additions & 1 deletion tests/tests/es6.regexp.replace.ls
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ test 'RegExp#@@replace appearance', (assert) ->
replace = //.//[Symbol.replace]
assert.isFunction replace
assert.arity replace, 2
assert.looksNative replace
assert.nonEnumerable RegExp.prototype, Symbol.replace
return

Expand Down
1 change: 0 additions & 1 deletion tests/tests/es6.regexp.search.ls
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ test 'RegExp#@@search appearance', (assert) ->
search = //.//[Symbol.search]
assert.isFunction search
assert.arity search, 1
assert.looksNative search
assert.nonEnumerable RegExp.prototype, Symbol.search
return

Expand Down
1 change: 0 additions & 1 deletion tests/tests/es6.regexp.split.ls
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,6 @@ test 'RegExp#@@split appearance', (assert) ->
split = //.//[Symbol.split]
assert.isFunction split
assert.arity split, 2
assert.looksNative split
assert.nonEnumerable RegExp.prototype, Symbol.split
return

Expand Down

0 comments on commit a221e2a

Please sign in to comment.