Skip to content

Commit

Permalink
Use strict mode and auto-throwing instead of an explicit throw.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Apr 9, 2015
1 parent 49cf978 commit 2462796
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@
var globals = getGlobal();
var globalIsFinite = globals.isFinite;
var supportsDescriptors = !!Object.defineProperty && arePropertyDescriptorsSupported();
var hasStrictMode = (function () {
'use strict';
return this === null;
}.call(null));
var startsWithIsCompliant = startsWithRejectsRegex() && startsWithHandlesInfinity;
var _indexOf = Function.call.bind(String.prototype.indexOf);
var _toString = Function.call.bind(Object.prototype.toString);
Expand Down Expand Up @@ -1137,16 +1141,13 @@
};
defineProperties(Object, ObjectShims);

var assignHasPendingExceptions = supportsDescriptors && (function () {
var assignHasPendingExceptions = supportsDescriptors && hasStrictMode && (function () {
'use strict';
// Firefox 37 still has "pending exception" logic in its Object.assign implementation,
// which is 72% slower than our shim, and Firefox 40's native implementation.
var thrower = { a: 1, b: 2, c: 3 };
var keys = Object.keys(thrower);
Object.defineProperty(thrower, keys[1], {
set: function setMiddle(v) {
throw new TypeError('middle key can not be set');
}
});
Object.defineProperty(thrower, keys[1], { configurable: false, writable: false });
var semaphore = {};
try {
Object.assign(thrower, { a: semaphore, b: semaphore, c: semaphore });
Expand Down

0 comments on commit 2462796

Please sign in to comment.