Fix test fails in older Safari and cleanup setProperty in test.js.

This commit is contained in:
John-David Dalton
2014-01-24 18:18:50 -08:00
parent 087ed0aa6a
commit 79afa16a7f
3 changed files with 24 additions and 37 deletions

View File

@@ -20,31 +20,21 @@
<div id="exports"></div>
<script>
var setProperty = (function() {
var defineProperty = (function() {
try {
var o = {},
func = Object.defineProperty,
result = func(o, o, o) && func;
} catch(e) { }
return result;
}());
if (!defineProperty) {
return function(object, key, value) {
object[key] = value;
};
}
var _defineProperty = Object.defineProperty;
return function(object, key, value) {
// avoid a bug where overwriting non-enumerable built-ins makes them enumerable
// https://code.google.com/p/v8/issues/detail?id=1623
defineProperty(object, key, {
'configurable': true,
'enumerable': false,
'writable': true,
'value': value
});
}
try {
_defineProperty(object, key, {
'configurable': true,
'enumerable': false,
'writable': true,
'value': value
});
} catch(e) {
object[key] = value;
}
};
}());
function addBizarroMethods() {
@@ -52,9 +42,6 @@
Function.prototype._method = function() {};
// allow bypassing native checks
var _fnToString = Function.prototype.toString;
setProperty(Function.prototype, '_toString', _fnToString);
setProperty(Function.prototype, 'toString', (function() {
function fnToString() {
setProperty(Function.prototype, 'toString', _fnToString);
@@ -62,6 +49,8 @@
setProperty(Function.prototype, 'toString', fnToString);
return result;
}
var _fnToString = Function.prototype.toString;
setProperty(Function.prototype, '_toString', _fnToString);
return fnToString;
}()));

View File

@@ -213,23 +213,20 @@
* @param {string} key The name of the property to set.
* @param {*} value The property value.
*/
var setProperty = (function() {
if (!defineProperty) {
return function(object, key, value) {
object[key] = value;
};
}
return function(object, key, value) {
// avoid a bug where overwriting non-enumerable built-ins makes them enumerable
// https://code.google.com/p/v8/issues/detail?id=1623
function setProperty(object, key, value) {
// avoid a bug where overwriting non-enumerable built-ins makes them enumerable
// https://code.google.com/p/v8/issues/detail?id=1623
try {
defineProperty(object, key, {
'configurable': true,
'enumerable': false,
'writable': true,
'value': value
});
};
}());
} catch(e) {
object[key] = value;
}
}
/**
* Skips a given number of tests with a passing result.

View File

@@ -331,13 +331,14 @@
config = QUnit.config,
index = -1,
length = asserts.length,
logs = config.extrasData.logs,
queue = config.queue;
while (++index < length) {
var assert = asserts[index];
if (!assert.result && this.retries < config.asyncRetries) {
this.retries++;
config.extrasData.logs.length -= asserts.length;
logs.length = Math.max(0, logs.length - asserts.length);
asserts.length = 0;
var oldLength = queue.length;