Skip to content

Commit

Permalink
Fix _isNaiveReflectConstruct helper
Browse files Browse the repository at this point in the history
Date#toString is generic in ES2015 [1] and it doesn't throw, so we also
check Map#get (which on the other hand doesn't exist in ES5 browsers).

[1]: tc39/ecma262#1268 (comment)
  • Loading branch information
nicolo-ribaudo committed Aug 13, 2018
1 parent de16ac0 commit d6cf6ab
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/babel-helpers/src/helpers.js
Expand Up @@ -472,7 +472,15 @@ helpers.construct = helper("7.0.0-beta.0")`
try {
// If the internal slots aren't set, this throws an error similar to
// TypeError: this is not a Date object.
// Date#toString is generic in ES2015 [1] and it doesn't throw, so we also
// check Map#get (which on the other hand doesn't exist in ES5 browsers).
//
// [1]: https://github.com/tc39/ecma262/issues/1268#issuecomment-410104832
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
if (typeof Map === "function") {
Map.prototype.get.call(Reflect.construct(Map, [], function() {}));
}
return true;
} catch (e) {
return false;
Expand Down

0 comments on commit d6cf6ab

Please sign in to comment.