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

View File

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

View File

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