mirror of
https://github.com/tc39/test262.git
synced 2025-07-20 20:44:43 +02:00
Curation of the stress folder
These are not spec tests neither identify points not already covered in the tests to cover something new from the specs
This commit is contained in:
parent
a83bae960c
commit
a2447a0084
@ -1,221 +0,0 @@
|
|||||||
function numberIsNaNOnInteger(value)
|
|
||||||
{
|
|
||||||
return Number.isNaN(value);
|
|
||||||
}
|
|
||||||
noInline(numberIsNaNOnInteger);
|
|
||||||
|
|
||||||
// *** Test simple cases on integers. ***
|
|
||||||
function testNumberIsNaNOnIntegers()
|
|
||||||
{
|
|
||||||
// Bounds.
|
|
||||||
var value = numberIsNaNOnInteger(0);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(0) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger(-2147483648);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(-2147483648) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger(2147483647);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(2147483647) = " + value;
|
|
||||||
|
|
||||||
// Simple values.
|
|
||||||
var value = numberIsNaNOnInteger(-1);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(-1) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger(42);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(42) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger(-42);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(-42) = " + value;
|
|
||||||
}
|
|
||||||
noInline(testNumberIsNaNOnIntegers);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
testNumberIsNaNOnIntegers();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we don't do anything stupid when the type is unexpected.
|
|
||||||
function verifyNumberIsNaNOnIntegerWithOtherTypes()
|
|
||||||
{
|
|
||||||
var value = numberIsNaNOnInteger(Math.PI);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(Math.PI) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger("42");
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(\"42\") = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger("WebKit");
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(\"WebKit\") = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnInteger(-0);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnInteger(-0) = " + value;
|
|
||||||
}
|
|
||||||
noInline(verifyNumberIsNaNOnIntegerWithOtherTypes);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
verifyNumberIsNaNOnIntegerWithOtherTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// *** Test simple cases on doubles. ***
|
|
||||||
function numberIsNaNOnDouble(value)
|
|
||||||
{
|
|
||||||
return Number.isNaN(value);
|
|
||||||
}
|
|
||||||
noInline(numberIsNaNOnDouble);
|
|
||||||
|
|
||||||
// Test simple cases on doubles.
|
|
||||||
function testNumberIsNaNOnDoubles()
|
|
||||||
{
|
|
||||||
var value = numberIsNaNOnDouble(Math.PI);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(Math.PI) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(Math.E);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(Math.E) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(Math.LN2);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(Math.LN2) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(-0);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(-0) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(NaN);
|
|
||||||
if (!value)
|
|
||||||
throw "numberIsNaNOnDouble(NaN) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(Number.POSITIVE_INFINITY);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(Number.POSITIVE_INFINITY) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble(Number.NEGATIVE_INFINITY);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(Number.NEGATIVE_INFINITY) = " + value;
|
|
||||||
}
|
|
||||||
noInline(testNumberIsNaNOnDoubles);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
testNumberIsNaNOnDoubles();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure we don't do anything stupid when the type is unexpected.
|
|
||||||
function verifyNumberIsNaNOnDoublesWithOtherTypes()
|
|
||||||
{
|
|
||||||
var value = numberIsNaNOnDouble(1);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(1) = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble("42");
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(\"42\") = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble("WebKit");
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble(\"WebKit\") = " + value;
|
|
||||||
|
|
||||||
var value = numberIsNaNOnDouble({});
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNOnDouble({}) = " + value;
|
|
||||||
}
|
|
||||||
noInline(verifyNumberIsNaNOnDoublesWithOtherTypes);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
verifyNumberIsNaNOnDoublesWithOtherTypes();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// *** Unusual arguments. ***
|
|
||||||
function numberIsNaNNoArguments()
|
|
||||||
{
|
|
||||||
return Number.isNaN();
|
|
||||||
}
|
|
||||||
noInline(numberIsNaNNoArguments);
|
|
||||||
|
|
||||||
function numberIsNaNTooManyArguments(a, b, c)
|
|
||||||
{
|
|
||||||
return Number.isNaN(a, b, c);
|
|
||||||
}
|
|
||||||
noInline(numberIsNaNTooManyArguments);
|
|
||||||
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var value = numberIsNaNNoArguments();
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNNoArguments() = " + value;
|
|
||||||
|
|
||||||
value = numberIsNaNTooManyArguments(2, 3, 5);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNTooManyArguments() = " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// *** Constant as arguments. ***
|
|
||||||
function testNumberIsNaNOnConstants()
|
|
||||||
{
|
|
||||||
var value = Number.isNaN(0);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(0) = " + value;
|
|
||||||
var value = Number.isNaN(-0);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(-0) = " + value;
|
|
||||||
var value = Number.isNaN(1);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(1) = " + value;
|
|
||||||
var value = Number.isNaN(-1);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(-1) = " + value;
|
|
||||||
var value = Number.isNaN(42);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(42) = " + value;
|
|
||||||
var value = Number.isNaN(-42);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(-42) = " + value;
|
|
||||||
var value = Number.isNaN(Number.POSITIVE_INFINITY);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(Number.POSITIVE_INFINITY) = " + value;
|
|
||||||
var value = Number.isNaN(Number.NEGATIVE_INFINITY);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(Number.NEGATIVE_INFINITY) = " + value;
|
|
||||||
var value = Number.isNaN(Math.E);
|
|
||||||
if (value)
|
|
||||||
throw "Number.isNaN(Math.E) = " + value;
|
|
||||||
var value = Number.isNaN(NaN);
|
|
||||||
if (!value)
|
|
||||||
throw "Number.isNaN(NaN) = " + value;
|
|
||||||
}
|
|
||||||
noInline(testNumberIsNaNOnConstants);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
testNumberIsNaNOnConstants();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// *** Struct transition. ***
|
|
||||||
function numberIsNaNStructTransition(value)
|
|
||||||
{
|
|
||||||
return Number.isNaN(value);
|
|
||||||
}
|
|
||||||
noInline(numberIsNaNStructTransition);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var value = numberIsNaNStructTransition(42);
|
|
||||||
if (value)
|
|
||||||
throw "numberIsNaNStructTransition(42) = " + value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Number.isNaN = function() { return 123; }
|
|
||||||
|
|
||||||
var value = numberIsNaNStructTransition(42);
|
|
||||||
if (value !== 123)
|
|
||||||
throw "numberIsNaNStructTransition(42) after transition = " + value;
|
|
@ -1,113 +0,0 @@
|
|||||||
function shouldBe(expected, actual, msg) {
|
|
||||||
if (msg === void 0)
|
|
||||||
msg = '';
|
|
||||||
else
|
|
||||||
msg = ' for ' + msg;
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldBeDataProperty(expected, value, name) {
|
|
||||||
if (name === void 0)
|
|
||||||
name = '<property descriptor>';
|
|
||||||
shouldBe(value, expected.value, name + '.value');
|
|
||||||
shouldBe(true, expected.enumerable, name + '.enumerable');
|
|
||||||
shouldBe(true, expected.configurable, name + '.configurable');
|
|
||||||
shouldBe(true, expected.writable, name + '.writable');
|
|
||||||
shouldBe(undefined, expected.get, name + '.get');
|
|
||||||
shouldBe(undefined, expected.set, name + '.set');
|
|
||||||
}
|
|
||||||
|
|
||||||
(function testPropertyFilteringAndOrder() {
|
|
||||||
var log = [];
|
|
||||||
var sym = Symbol('test');
|
|
||||||
var O = {
|
|
||||||
0: 0,
|
|
||||||
[sym]: 3,
|
|
||||||
'a': 2,
|
|
||||||
1: 1
|
|
||||||
};
|
|
||||||
|
|
||||||
var P = new Proxy(O, {
|
|
||||||
ownKeys(target) {
|
|
||||||
log.push('ownKeys()');
|
|
||||||
return Reflect.ownKeys(target);
|
|
||||||
},
|
|
||||||
getOwnPropertyDescriptor(target, name) {
|
|
||||||
log.push(`getOwnPropertyDescriptor(${String(name)})`);
|
|
||||||
return Reflect.getOwnPropertyDescriptor(target, name);
|
|
||||||
},
|
|
||||||
get() { throw new Error('[[Get]] trap should be unreachable'); },
|
|
||||||
set() { throw new Error('[[Set]] trap should be unreachable'); },
|
|
||||||
deleteProperty() { throw new Error('[[Delete]] trap should be unreachable'); },
|
|
||||||
defineProperty() { throw new Error('[[DefineOwnProperty]] trap should be unreachable'); }
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = Object.getOwnPropertyDescriptors(P);
|
|
||||||
shouldBe('ownKeys()|getOwnPropertyDescriptor(0)|getOwnPropertyDescriptor(1)|getOwnPropertyDescriptor(a)|getOwnPropertyDescriptor(Symbol(test))', log.join('|'));
|
|
||||||
shouldBeDataProperty(result[0], 0, 'result[0]');
|
|
||||||
shouldBeDataProperty(result[1], 1, 'result[1]');
|
|
||||||
shouldBeDataProperty(result.a, 2, 'result["a"]');
|
|
||||||
shouldBeDataProperty(result[sym], 3, 'result[Symbol(test)]');
|
|
||||||
|
|
||||||
var result2 = Object.getOwnPropertyDescriptors(O);
|
|
||||||
shouldBeDataProperty(result2[0], 0, 'result2[0]');
|
|
||||||
shouldBeDataProperty(result2[1], 1, 'result2[1]');
|
|
||||||
shouldBeDataProperty(result2.a, 2, 'result2["a"]');
|
|
||||||
shouldBeDataProperty(result2[sym], 3, 'result2[Symbol(test)]');
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function testDuplicatePropertyNames() {
|
|
||||||
var i = 0;
|
|
||||||
var log = [];
|
|
||||||
var P = new Proxy({}, {
|
|
||||||
ownKeys() {
|
|
||||||
log.push(`ownKeys()`);
|
|
||||||
return [ 'A', 'A' ];
|
|
||||||
},
|
|
||||||
getOwnPropertyDescriptor(t, name) {
|
|
||||||
log.push(`getOwnPropertyDescriptor(${name})`);
|
|
||||||
if (i++) return;
|
|
||||||
return {
|
|
||||||
configurable: true,
|
|
||||||
writable: false,
|
|
||||||
value: 'VALUE'
|
|
||||||
};
|
|
||||||
},
|
|
||||||
get() { throw new Error('[[Get]] trap should be unreachable'); },
|
|
||||||
set() { throw new Error('[[Set]] trap should be unreachable'); },
|
|
||||||
deleteProperty() { throw new Error('[[Delete]] trap should be unreachable'); },
|
|
||||||
defineProperty() { throw new Error('[[DefineOwnProperty]] trap should be unreachable'); }
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = Object.getOwnPropertyDescriptors(P);
|
|
||||||
shouldBe(true, result.A.configurable, 'for result.A.configurable');
|
|
||||||
shouldBe(false, result.A.writable, 'for result.A.writable');
|
|
||||||
shouldBe('VALUE', result.A.value, 'for result.A.value');
|
|
||||||
shouldBe(false, result.A.enumerable, 'for result.A.enumerable');
|
|
||||||
shouldBe(true, Object.hasOwnProperty.call(result, 'A'));
|
|
||||||
shouldBe('ownKeys()|getOwnPropertyDescriptor(A)|getOwnPropertyDescriptor(A)', log.join('|'));
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function testUndefinedPropertyDescriptor() {
|
|
||||||
var log = [];
|
|
||||||
var P = new Proxy({}, {
|
|
||||||
ownKeys() {
|
|
||||||
log.push(`ownKeys()`);
|
|
||||||
return ['fakeProperty'];
|
|
||||||
},
|
|
||||||
getOwnPropertyDescriptor(t, name) {
|
|
||||||
log.push(`getOwnPropertyDescriptor(${name})`);
|
|
||||||
return undefined;
|
|
||||||
},
|
|
||||||
get() { throw new Error('[[Get]] trap should be unreachable'); },
|
|
||||||
set() { throw new Error('[[Set]] trap should be unreachable'); },
|
|
||||||
deleteProperty() { throw new Error('[[Delete]] trap should be unreachable'); },
|
|
||||||
defineProperty() { throw new Error('[[DefineOwnProperty]] trap should be unreachable'); }
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = Object.getOwnPropertyDescriptors(P);
|
|
||||||
shouldBe(false, result.hasOwnProperty('fakeProperty'));
|
|
||||||
shouldBe(false, 'fakeProperty' in result);
|
|
||||||
shouldBe('ownKeys()|getOwnPropertyDescriptor(fakeProperty)', log.join('|'));
|
|
||||||
})();
|
|
@ -1,153 +0,0 @@
|
|||||||
function shouldBe(expected, actual, msg) {
|
|
||||||
if (msg === void 0)
|
|
||||||
msg = '';
|
|
||||||
else
|
|
||||||
msg = ' for ' + msg;
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value' + msg + ': ' + actual + '. Expected ' + expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorMessage) {
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (String(error) !== errorMessage)
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldBeDataProperty(expected, value, name) {
|
|
||||||
if (name === void 0)
|
|
||||||
name = '<property descriptor>';
|
|
||||||
shouldBe(value, expected.value, name + '.value');
|
|
||||||
shouldBe(true, expected.enumerable, name + '.enumerable');
|
|
||||||
shouldBe(true, expected.configurable, name + '.configurable');
|
|
||||||
shouldBe(true, expected.writable, name + '.writable');
|
|
||||||
shouldBe(undefined, expected.get, name + '.get');
|
|
||||||
shouldBe(undefined, expected.set, name + '.set');
|
|
||||||
}
|
|
||||||
|
|
||||||
(function testMeta() {
|
|
||||||
shouldBe(1, Object.getOwnPropertyDescriptors.length);
|
|
||||||
|
|
||||||
shouldBe('getOwnPropertyDescriptors', Object.getOwnPropertyDescriptors.name);
|
|
||||||
|
|
||||||
var propertyDescriptor = Reflect.getOwnPropertyDescriptor(Object, 'getOwnPropertyDescriptors');
|
|
||||||
shouldBe(false, propertyDescriptor.enumerable);
|
|
||||||
shouldBe(true, propertyDescriptor.writable);
|
|
||||||
shouldBe(true, propertyDescriptor.configurable);
|
|
||||||
|
|
||||||
shouldThrow(() => new Object.getOwnPropertyDescriptors({}), "TypeError: function is not a constructor (evaluating 'new Object.getOwnPropertyDescriptors({})')");
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function testToObject() {
|
|
||||||
shouldThrow(() => Object.getOwnPropertyDescriptors(null), "TypeError: null is not an object (evaluating 'Object.getOwnPropertyDescriptors(null)')");
|
|
||||||
shouldThrow(() => Object.getOwnPropertyDescriptors(undefined), "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptors(undefined)')");
|
|
||||||
shouldThrow(() => Object.getOwnPropertyDescriptors(), "TypeError: undefined is not an object (evaluating 'Object.getOwnPropertyDescriptors()')");
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function testPrototypeProperties() {
|
|
||||||
function F() {};
|
|
||||||
F.prototype.a = 'A';
|
|
||||||
F.prototype.b = 'B';
|
|
||||||
F.prototype[9999] = '0';
|
|
||||||
F.prototype[0] = '0';
|
|
||||||
|
|
||||||
var F2 = new F();
|
|
||||||
Object.defineProperties(F2, {
|
|
||||||
'b': {
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
writable: false,
|
|
||||||
value: 'Shadowed "B"'
|
|
||||||
},
|
|
||||||
'c': {
|
|
||||||
enumerable: false,
|
|
||||||
configurable: true,
|
|
||||||
writable: false,
|
|
||||||
value: 'C'
|
|
||||||
},
|
|
||||||
9998: {
|
|
||||||
enumerable: true,
|
|
||||||
configurable: true,
|
|
||||||
writable: true,
|
|
||||||
value: 'X'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = Object.getOwnPropertyDescriptors(F2);
|
|
||||||
|
|
||||||
shouldBe(undefined, result[0]);
|
|
||||||
|
|
||||||
shouldBe(result[9998].enumerable, true);
|
|
||||||
shouldBe(result[9998].configurable, true);
|
|
||||||
shouldBe(result[9998].writable, true);
|
|
||||||
shouldBe(result[9998].value, 'X')
|
|
||||||
|
|
||||||
shouldBe(undefined, result[9999]);
|
|
||||||
|
|
||||||
shouldBe(undefined, result.a);
|
|
||||||
|
|
||||||
shouldBe(result.b.enumerable, false);
|
|
||||||
shouldBe(result.b.configurable, true);
|
|
||||||
shouldBe(result.b.writable, false);
|
|
||||||
shouldBe(result.b.value, 'Shadowed "B"');
|
|
||||||
|
|
||||||
shouldBe(result.c.enumerable, false);
|
|
||||||
shouldBe(result.c.configurable, true);
|
|
||||||
shouldBe(result.c.writable, false);
|
|
||||||
shouldBe(result.c.value, 'C');
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function testGlobalProxy(global) {
|
|
||||||
var symbol = Symbol('test');
|
|
||||||
global[symbol] = 'Symbol(test)';
|
|
||||||
|
|
||||||
var result = Object.getOwnPropertyDescriptors(global);
|
|
||||||
|
|
||||||
shouldBeDataProperty(result[symbol], 'Symbol(test)', 'global[Symbol(test)]');
|
|
||||||
delete global[symbol];
|
|
||||||
})(this);
|
|
||||||
|
|
||||||
(function testIndexedProperties() {
|
|
||||||
var object = { 0: 'test' };
|
|
||||||
var result = Object.getOwnPropertyDescriptors(object);
|
|
||||||
shouldBeDataProperty(result[0], 'test', 'result[0]');
|
|
||||||
shouldBeDataProperty(result['0'], 'test', 'result["0"]');
|
|
||||||
shouldBe(result[0], result['0']);
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
(function testPropertiesIndexedSetterOnPrototypeThrows() {
|
|
||||||
var symbol = Symbol('test');
|
|
||||||
Object.defineProperties(Object.prototype, {
|
|
||||||
0: {
|
|
||||||
configurable: true,
|
|
||||||
get() { return; },
|
|
||||||
set(v) { throw new Error("Setter on prototype should be unreachable!"); }
|
|
||||||
},
|
|
||||||
a: {
|
|
||||||
configurable: true,
|
|
||||||
get() { return; },
|
|
||||||
set(v) { throw new Error("Setter on prototype should be unreachable!"); }
|
|
||||||
},
|
|
||||||
[symbol]: {
|
|
||||||
configurable: true,
|
|
||||||
get() { return; },
|
|
||||||
set(v) { throw new Error("Setter on prototype should be unreachable!"); }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var result = Object.getOwnPropertyDescriptors({ 0: 1, a: 2, [symbol]: 3 })
|
|
||||||
delete Object.prototype[0];
|
|
||||||
delete Object.prototype.a;
|
|
||||||
delete Object.prototype[symbol];
|
|
||||||
shouldBeDataProperty(result[0], 1, 'result[0]');
|
|
||||||
shouldBeDataProperty(result.a, 2, 'result["a"]');
|
|
||||||
shouldBeDataProperty(result[symbol], 3, 'result[symbol]');
|
|
||||||
})();
|
|
@ -1,16 +0,0 @@
|
|||||||
//@ runDefault
|
|
||||||
|
|
||||||
// This test should not crash.
|
|
||||||
|
|
||||||
delete this.Function;
|
|
||||||
|
|
||||||
var test = function() {
|
|
||||||
Math.cos("0" instanceof arguments)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var k = 0; k < 10000; ++k) {
|
|
||||||
try {
|
|
||||||
test();
|
|
||||||
} catch (e) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,134 +0,0 @@
|
|||||||
//@ skip
|
|
||||||
var dv = new DataView(new SharedArrayBuffer(128));
|
|
||||||
var i8a = new Int8Array(new SharedArrayBuffer(128));
|
|
||||||
var i16a = new Int16Array(new SharedArrayBuffer(128));
|
|
||||||
var i32a = new Int32Array(new SharedArrayBuffer(128));
|
|
||||||
var u8a = new Uint8Array(new SharedArrayBuffer(128));
|
|
||||||
var u8ca = new Uint8ClampedArray(new SharedArrayBuffer(128));
|
|
||||||
var u16a = new Uint16Array(new SharedArrayBuffer(128));
|
|
||||||
var u32a = new Uint32Array(new SharedArrayBuffer(128));
|
|
||||||
var f32a = new Float32Array(new SharedArrayBuffer(128));
|
|
||||||
var f64a = new Float64Array(new SharedArrayBuffer(128));
|
|
||||||
|
|
||||||
var arrays = [i8a, i16a, i32a, u8a, u16a, u32a];
|
|
||||||
|
|
||||||
var atomics = new Map();
|
|
||||||
var genericAtomics = new Map();
|
|
||||||
for (var a of arrays) {
|
|
||||||
var map = new Map();
|
|
||||||
atomics.set(a, map);
|
|
||||||
}
|
|
||||||
var count = 0;
|
|
||||||
for (var op of ["add", "and", "compareExchange", "exchange", "load", "or", "store", "sub", "xor"]) {
|
|
||||||
var numExtraArgs;
|
|
||||||
switch (op) {
|
|
||||||
case "compareExchange":
|
|
||||||
numExtraArgs = 2;
|
|
||||||
break;
|
|
||||||
case "load":
|
|
||||||
numExtraArgs = 0;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
numExtraArgs = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
function str() {
|
|
||||||
var str = "(function (array" + count + ", index";
|
|
||||||
for (var i = 0; i < numExtraArgs; ++i)
|
|
||||||
str += ", a" + i;
|
|
||||||
str += ") { return Atomics." + op + "(array" + count + ", index";
|
|
||||||
for (var i = 0; i < numExtraArgs; ++i)
|
|
||||||
str += ", a" + i;
|
|
||||||
str += "); })";
|
|
||||||
count++;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
var f = eval(str());
|
|
||||||
noInline(f);
|
|
||||||
// Warm it up on crazy.
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
f(arrays[i % arrays.length], 0, 0, 0);
|
|
||||||
genericAtomics.set(op, f);
|
|
||||||
|
|
||||||
for (var a of arrays) {
|
|
||||||
var map = atomics.get(a);
|
|
||||||
|
|
||||||
var f = eval(str());
|
|
||||||
noInline(f);
|
|
||||||
|
|
||||||
// Warm it up on something easy.
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
f(a, 0, 0, 0);
|
|
||||||
|
|
||||||
map.set(op, f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function runAtomic(array, index, init, name, args, expectedResult, expectedOutcome)
|
|
||||||
{
|
|
||||||
for (var f of [{name: "specialized", func: atomics.get(array).get(name)},
|
|
||||||
{name: "generic", func: genericAtomics.get(name)}]) {
|
|
||||||
array[index] = init;
|
|
||||||
var result = f.func(array, index, ...args);
|
|
||||||
if (result != expectedResult)
|
|
||||||
throw new Error("Expected Atomics." + name + "(array, " + index + ", " + args.join(", ") + ") to return " + expectedResult + " but returned " + result + " for " + Object.prototype.toString.apply(array) + " and " + f.name);
|
|
||||||
if (array[index] !== expectedOutcome)
|
|
||||||
throw new Error("Expected Atomics." + name + "(array, " + index + ", " + args.join(", ") + ") to result in array[" + index + "] = " + expectedOutcome + " but got " + array[index] + " for " + Object.prototype.toString.apply(array) + " and " + f.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var a of arrays) {
|
|
||||||
runAtomic(a, 0, 13, "add", [42], 13, 55);
|
|
||||||
runAtomic(a, 0, 13, "and", [42], 13, 8);
|
|
||||||
runAtomic(a, 0, 13, "compareExchange", [25, 42], 13, 13);
|
|
||||||
runAtomic(a, 0, 13, "compareExchange", [13, 42], 13, 42);
|
|
||||||
runAtomic(a, 0, 13, "exchange", [42], 13, 42);
|
|
||||||
runAtomic(a, 0, 13, "load", [], 13, 13);
|
|
||||||
runAtomic(a, 0, 13, "or", [42], 13, 47);
|
|
||||||
runAtomic(a, 0, 13, "store", [42], 42, 42);
|
|
||||||
runAtomic(a, 0, 42, "sub", [13], 42, 29);
|
|
||||||
runAtomic(a, 0, 13, "xor", [42], 13, 39);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldFail(f, name)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
f();
|
|
||||||
} catch (e) {
|
|
||||||
if (e.name == name.name)
|
|
||||||
return;
|
|
||||||
throw new Error(f + " threw the wrong error: " + e);
|
|
||||||
}
|
|
||||||
throw new Error(f + " succeeded!");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u8ca, f32a, f64a]) {
|
|
||||||
shouldFail(() => genericAtomics.get("add")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("and")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("compareExchange")(bad, 0, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("exchange")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("load")(bad, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("or")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("store")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("sub")(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => genericAtomics.get("xor")(bad, 0, 0), TypeError);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
|
|
||||||
for (var a of arrays) {
|
|
||||||
for (var m of [atomics.get(a), genericAtomics]) {
|
|
||||||
shouldFail(() => m.get("add")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("and")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("compareExchange")(a, idx, 0, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("exchange")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("load")(a, idx), RangeError);
|
|
||||||
shouldFail(() => m.get("or")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("store")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("sub")(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => m.get("xor")(a, idx, 0), RangeError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
|||||||
//@ skip
|
|
||||||
// This is a basic test of SharedArrayBuffer API as we understand it.
|
|
||||||
|
|
||||||
if (SharedArrayBuffer == ArrayBuffer)
|
|
||||||
throw new Error("SharedArrayBuffer and ArrayBuffer should be distinct");
|
|
||||||
|
|
||||||
if (SharedArrayBuffer.prototype == ArrayBuffer.prototype)
|
|
||||||
throw new Error("SharedArrayBuffer.prototype and ArrayBuffer.prototype should be distinct");
|
|
||||||
|
|
||||||
if (SharedArrayBuffer.prototype.__proto__ != Object.prototype)
|
|
||||||
throw new Error("SharedArrayBuffer.prototype.__proto__ should be Object.prototype");
|
|
||||||
|
|
||||||
if (!(new SharedArrayBuffer(100) instanceof SharedArrayBuffer))
|
|
||||||
throw new Error("SharedArrayBuffer should be an instance of SharedArrayBuffer");
|
|
||||||
|
|
||||||
if (!(new ArrayBuffer(100) instanceof ArrayBuffer))
|
|
||||||
throw new Error("ArrayBuffer should be an instance of ArrayBuffer");
|
|
||||||
|
|
||||||
if (new SharedArrayBuffer(100) instanceof ArrayBuffer)
|
|
||||||
throw new Error("SharedArrayBuffer should not be an instance of ArrayBuffer");
|
|
||||||
|
|
||||||
if (new ArrayBuffer(100) instanceof SharedArrayBuffer)
|
|
||||||
throw new Error("ArrayBuffer should not be an instance of SharedArrayBuffer");
|
|
||||||
|
|
||||||
function checkAtomics(name, count)
|
|
||||||
{
|
|
||||||
if (!Atomics[name])
|
|
||||||
throw new Error("Missing Atomics." + name);
|
|
||||||
if (Atomics[name].length != count)
|
|
||||||
throw new Error("Atomics." + name + " should have length " + count + " but has length " + Atomics[name].length);
|
|
||||||
}
|
|
||||||
checkAtomics("add", 3);
|
|
||||||
checkAtomics("and", 3);
|
|
||||||
checkAtomics("compareExchange", 4);
|
|
||||||
checkAtomics("exchange", 3);
|
|
||||||
checkAtomics("isLockFree", 1);
|
|
||||||
checkAtomics("load", 2);
|
|
||||||
checkAtomics("or", 3);
|
|
||||||
checkAtomics("store", 3);
|
|
||||||
checkAtomics("sub", 3);
|
|
||||||
checkAtomics("wait", 4);
|
|
||||||
checkAtomics("wake", 3);
|
|
||||||
checkAtomics("xor", 3);
|
|
||||||
|
|
||||||
// These should all succeed.
|
|
||||||
var dv = new DataView(new SharedArrayBuffer(128));
|
|
||||||
var i8a = new Int8Array(new SharedArrayBuffer(128));
|
|
||||||
var i16a = new Int16Array(new SharedArrayBuffer(128));
|
|
||||||
var i32a = new Int32Array(new SharedArrayBuffer(128));
|
|
||||||
var u8a = new Uint8Array(new SharedArrayBuffer(128));
|
|
||||||
var u8ca = new Uint8ClampedArray(new SharedArrayBuffer(128));
|
|
||||||
var u16a = new Uint16Array(new SharedArrayBuffer(128));
|
|
||||||
var u32a = new Uint32Array(new SharedArrayBuffer(128));
|
|
||||||
var f32a = new Float32Array(new SharedArrayBuffer(128));
|
|
||||||
var f64a = new Float64Array(new SharedArrayBuffer(128));
|
|
||||||
|
|
||||||
function shouldFail(f, name)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
f();
|
|
||||||
} catch (e) {
|
|
||||||
if (e.name == name.name)
|
|
||||||
return;
|
|
||||||
throw new Error(f + " threw the wrong error: " + e);
|
|
||||||
}
|
|
||||||
throw new Error(f + " succeeded!");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u8ca, f32a, f64a]) {
|
|
||||||
shouldFail(() => Atomics.add(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.and(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.compareExchange(bad, 0, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.exchange(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.load(bad, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.or(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.store(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.sub(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.xor(bad, 0, 0), TypeError);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, i8a, i16a, u8a, u8ca, u16a, u32a, f32a, f64a]) {
|
|
||||||
shouldFail(() => Atomics.wait(bad, 0, 0), TypeError);
|
|
||||||
shouldFail(() => Atomics.wake(bad, 0, 0), TypeError);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
|
|
||||||
for (a of [i8a, i16a, i32a, u8a, u16a, u32a]) {
|
|
||||||
shouldFail(() => Atomics.add(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.and(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.compareExchange(a, idx, 0, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.exchange(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.load(a, idx), RangeError);
|
|
||||||
shouldFail(() => Atomics.or(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.store(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.sub(a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.xor(a, idx, 0), RangeError);
|
|
||||||
}
|
|
||||||
shouldFail(() => Atomics.wait(i32a, idx, 0), RangeError);
|
|
||||||
shouldFail(() => Atomics.wake(i32a, idx, 0), RangeError);
|
|
||||||
}
|
|
||||||
|
|
||||||
function runAtomic(array, index, init, name, args, expectedResult, expectedOutcome)
|
|
||||||
{
|
|
||||||
array[index] = init;
|
|
||||||
var result = Atomics[name](array, index, ...args);
|
|
||||||
if (result != expectedResult)
|
|
||||||
throw new Error("Expected Atomics." + name + "(array, " + index + ", " + args.join(", ") + ") to return " + expectedResult + " but returned " + result + " for " + Object.prototype.toString.apply(array));
|
|
||||||
if (array[index] !== expectedOutcome)
|
|
||||||
throw new Error("Expected Atomics." + name + "(array, " + index + ", " + args.join(", ") + ") to result in array[" + index + "] = " + expectedOutcome + " but got " + array[index] + " for " + Object.prototype.toString.apply(array));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (a of [i8a, i16a, i32a, u8a, u16a, u32a]) {
|
|
||||||
runAtomic(a, 0, 13, "add", [42], 13, 55);
|
|
||||||
runAtomic(a, 0, 13, "and", [42], 13, 8);
|
|
||||||
runAtomic(a, 0, 13, "compareExchange", [25, 42], 13, 13);
|
|
||||||
runAtomic(a, 0, 13, "compareExchange", [13, 42], 13, 42);
|
|
||||||
runAtomic(a, 0, 13, "exchange", [42], 13, 42);
|
|
||||||
runAtomic(a, 0, 13, "load", [], 13, 13);
|
|
||||||
runAtomic(a, 0, 13, "or", [42], 13, 47);
|
|
||||||
runAtomic(a, 0, 13, "store", [42], 42, 42);
|
|
||||||
runAtomic(a, 0, 42, "sub", [13], 42, 29);
|
|
||||||
runAtomic(a, 0, 13, "xor", [42], 13, 39);
|
|
||||||
}
|
|
||||||
|
|
||||||
i32a[0] = 0;
|
|
||||||
var result = Atomics.wait(i32a, 0, 1);
|
|
||||||
if (result != "not-equal")
|
|
||||||
throw "Error: bad result from Atomics.wait: " + result;
|
|
||||||
for (timeout of [0, 1, 10]) {
|
|
||||||
var result = Atomics.wait(i32a, 0, 0, timeout);
|
|
||||||
if (result != "timed-out")
|
|
||||||
throw "Error: bad result from Atomics.wait: " + result;
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
|||||||
//@ skip if $buildType == "debug"
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function shouldThrowTDZ(func) {
|
|
||||||
var hasThrown = false;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch(e) {
|
|
||||||
if (e.name.indexOf("ReferenceError") !== -1)
|
|
||||||
hasThrown = true;
|
|
||||||
}
|
|
||||||
if (!hasThrown)
|
|
||||||
throw new Error("Did not throw TDZ error");
|
|
||||||
}
|
|
||||||
noInline(shouldThrowTDZ);
|
|
||||||
|
|
||||||
function bar(f) { f(10); }
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
let result = 0;
|
|
||||||
var set = function (x) { result = x; }
|
|
||||||
var cap = function() { return tdzPerpetrator; }
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
return tdzPerpetrator;
|
|
||||||
}
|
|
||||||
let tdzPerpetrator;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var bool = !(i % 100);
|
|
||||||
if (bool)
|
|
||||||
shouldThrowTDZ(function() { foo(bool); });
|
|
||||||
else {
|
|
||||||
var result = foo(bool);
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function bar(f) { f(10); }
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
var result = 0;
|
|
||||||
var imUndefined;
|
|
||||||
var baz;
|
|
||||||
var set = function (x) { result = x; return (imUndefined, baz); }
|
|
||||||
baz = 40;
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
if (result != 10)
|
|
||||||
throw "Error: bad: " + result;
|
|
||||||
if (baz !== 40)
|
|
||||||
throw "Error: bad: " + baz;
|
|
||||||
if (imUndefined !== void 0)
|
|
||||||
throw "Error: bad value: " + imUndefined;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var result = foo(!(i % 100));
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function shouldThrowTDZ(func) {
|
|
||||||
var hasThrown = false;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch(e) {
|
|
||||||
if (e.name.indexOf("ReferenceError") !== -1)
|
|
||||||
hasThrown = true;
|
|
||||||
}
|
|
||||||
if (!hasThrown)
|
|
||||||
throw new Error("Did not throw TDZ error");
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(f) { }
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
let result = 0;
|
|
||||||
var set = function (x) { result = x; return tdzPerpetrator; }
|
|
||||||
if (b) {
|
|
||||||
OSRExit();
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
return tdzPerpetrator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let tdzPerpetrator;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
noInline(shouldThrowTDZ);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var bool = !(i % 100);
|
|
||||||
if (bool)
|
|
||||||
shouldThrowTDZ(function() { foo(bool); });
|
|
||||||
else {
|
|
||||||
var result = foo(bool);
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function bar(set) {
|
|
||||||
var result = set(0);
|
|
||||||
if (result !== void 0)
|
|
||||||
throw "Error: bad value: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
var result = 0;
|
|
||||||
var imUndefined;
|
|
||||||
var baz;
|
|
||||||
var set = function (x) {
|
|
||||||
result = x;
|
|
||||||
if (baz !== 50)
|
|
||||||
throw "Error: bad value: " + baz;
|
|
||||||
return imUndefined;
|
|
||||||
}
|
|
||||||
baz = 50;
|
|
||||||
if (b) {
|
|
||||||
OSRExit();
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var result = foo(!(i % 100));
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function bar() { }
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
var result = 0;
|
|
||||||
var set = function (x) { result = x; }
|
|
||||||
if (b) {
|
|
||||||
OSRExit();
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var result = foo(!(i % 100));
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
var n = 10000000;
|
|
||||||
|
|
||||||
function bar(f) { f(10); }
|
|
||||||
|
|
||||||
function foo(b) {
|
|
||||||
var result = 0;
|
|
||||||
var set = function (x) { result = x; }
|
|
||||||
if (b) {
|
|
||||||
bar(set);
|
|
||||||
if (result != 10)
|
|
||||||
throw "Error: bad: " + result;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < n; i++) {
|
|
||||||
var result = foo(!(i % 100));
|
|
||||||
if (result != 0)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
function Inner() {
|
|
||||||
this.i = 0;
|
|
||||||
this.doStuff = function() {
|
|
||||||
this.i++;
|
|
||||||
if (this.i > 10000)
|
|
||||||
this.isDone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var foo = function() {
|
|
||||||
var inner = new Inner();
|
|
||||||
var done = false;
|
|
||||||
inner.isDone = function() {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
var val = inner.doStuff();
|
|
||||||
if (done)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foo();
|
|
@ -1,15 +0,0 @@
|
|||||||
function foo(a) {
|
|
||||||
return a.f + 2000000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = foo({f:1});
|
|
||||||
if (result != 2000000001)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo({f:2000000000});
|
|
||||||
if (result != 4000000000)
|
|
||||||
throw "Error: bad result: " + result;
|
|
@ -1,31 +0,0 @@
|
|||||||
function foo(o) {
|
|
||||||
return o.f + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(o, i, v) {
|
|
||||||
o[i] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
function baz() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
noInline(bar);
|
|
||||||
noInline(baz);
|
|
||||||
|
|
||||||
var o0 = baz();
|
|
||||||
bar(o0, "f", "hello");
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var o = baz();
|
|
||||||
o.f = 42;
|
|
||||||
var result = foo(o);
|
|
||||||
if (result != 43)
|
|
||||||
throw "Error: bad result in loop: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(o0);
|
|
||||||
if (result != "hello1")
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
|||||||
function foo(a) {
|
|
||||||
return a * 2097144 + 1073745920;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = foo(1073736383);
|
|
||||||
if (result != 2251780886936072)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(1073745919);
|
|
||||||
if (result != 2251800885301256)
|
|
||||||
throw "Error: bad result: " + result;
|
|
@ -1,15 +0,0 @@
|
|||||||
function foo(a) {
|
|
||||||
return a * 2097144 + 10000000000;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = foo(1073741151);
|
|
||||||
if (result != 2251799812372744)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(1073741152);
|
|
||||||
if (result != 2251799814469888)
|
|
||||||
throw "Error: bad result: " + result;
|
|
@ -1,15 +0,0 @@
|
|||||||
function foo(a, b) {
|
|
||||||
return a.f + b.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = foo({f:1}, {f:2});
|
|
||||||
if (result != 3)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo({f:2000000000}, {f:2000000000});
|
|
||||||
if (result != 4000000000)
|
|
||||||
throw "Error: bad result: " + result;
|
|
@ -1,16 +0,0 @@
|
|||||||
function foo(a) {
|
|
||||||
if (a != 0)
|
|
||||||
return a + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo(42);
|
|
||||||
if (result != 43)
|
|
||||||
throw "Error: bad result in loop: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(2147483647);
|
|
||||||
if (result != 2147483648)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,15 +0,0 @@
|
|||||||
function foo(a) {
|
|
||||||
return a.f + 1000;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = foo({f:1});
|
|
||||||
if (result != 1001)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo({f:2147483148});
|
|
||||||
if (result != 2147484148)
|
|
||||||
throw "Error: bad result: " + result;
|
|
@ -1,30 +0,0 @@
|
|||||||
function get(value, prop) { return value[prop]; }
|
|
||||||
noInline(get);
|
|
||||||
|
|
||||||
function foo(record, key, attribute) {
|
|
||||||
var attrs = get(this, 'attrs');
|
|
||||||
var value = get(record, key), type = attribute.type;
|
|
||||||
|
|
||||||
if (type) {
|
|
||||||
var transform = this.transformFor(type);
|
|
||||||
value = transform.serialize(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
key = attrs && attrs[key] || (this.keyForAttribute ? this.keyForAttribute(key) : key);
|
|
||||||
|
|
||||||
return {key:key, value:value};
|
|
||||||
}
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
let i = 0;
|
|
||||||
let thisValue = {transformFor: function() { return {serialize: function() { return {} }}}};
|
|
||||||
let record = {key: "hello"};
|
|
||||||
let record2 = {key: true};
|
|
||||||
let key = "key";
|
|
||||||
let attribute = {type: "type"};
|
|
||||||
for (; i < 100000; i++) {
|
|
||||||
if (i % 2 === 0)
|
|
||||||
foo.call(thisValue, record, key, attribute);
|
|
||||||
else
|
|
||||||
foo.call(thisValue, record2, key, attribute);
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
function assert(b, m = "Bad!") {
|
|
||||||
if (!b) {
|
|
||||||
throw new Error(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function test(f, iters = 1000) {
|
|
||||||
for (let i = 0; i < iters; i++)
|
|
||||||
f(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
function func(x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
noInline(func);
|
|
||||||
|
|
||||||
var n = 2;
|
|
||||||
var prototype = {};
|
|
||||||
function prep(index, i, A, B)
|
|
||||||
{
|
|
||||||
if (index === (n - 1) && i === 5000) {
|
|
||||||
// Fire watchpoint!
|
|
||||||
A.prototype = prototype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function check(index, arr, A, B, originalPrototype)
|
|
||||||
{
|
|
||||||
if (index === (n - 1)) {
|
|
||||||
assert(originalPrototype !== prototype);
|
|
||||||
for (let i = 0; i < 5000; i++)
|
|
||||||
assert(arr[i].__proto__ === originalPrototype);
|
|
||||||
for (let i = 5000; i < 10000; i++)
|
|
||||||
assert(arr[i].__proto__ === prototype);
|
|
||||||
} else {
|
|
||||||
for (let i = 0; i < 10000; i++)
|
|
||||||
assert(arr[i].__proto__ === originalPrototype);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noInline(check);
|
|
||||||
|
|
||||||
test(function body(index) {
|
|
||||||
function A(x, f = func) {
|
|
||||||
this._value = x;
|
|
||||||
this._func = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
function B(n)
|
|
||||||
{
|
|
||||||
return new A(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
var originalPrototype = A.prototype;
|
|
||||||
let arr = [];
|
|
||||||
for (let i = 0; i < 10000; i++) {
|
|
||||||
prep(index, i, A, B);
|
|
||||||
arr.push(B(20));
|
|
||||||
}
|
|
||||||
|
|
||||||
check(index, arr, A, B, originalPrototype);
|
|
||||||
}, n);
|
|
@ -1,41 +0,0 @@
|
|||||||
function assert(b, m = "Bad!") {
|
|
||||||
if (!b) {
|
|
||||||
throw new Error(m);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function test(f, iters = 1000) {
|
|
||||||
for (let i = 0; i < iters; i++)
|
|
||||||
f(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
function func(x) {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
noInline(func);
|
|
||||||
|
|
||||||
function check(index, arr, B)
|
|
||||||
{
|
|
||||||
for (let i = 0; i < 1000; i++)
|
|
||||||
assert(arr[i] instanceof B);
|
|
||||||
}
|
|
||||||
noInline(check);
|
|
||||||
|
|
||||||
test(function body(index) {
|
|
||||||
class A {
|
|
||||||
constructor(x, f = func)
|
|
||||||
{
|
|
||||||
this._value = x;
|
|
||||||
this._func = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class B extends A {
|
|
||||||
}
|
|
||||||
|
|
||||||
let arr = [];
|
|
||||||
for (let i = 0; i < 1000; i++)
|
|
||||||
arr.push(new B(20));
|
|
||||||
|
|
||||||
check(index, arr, B);
|
|
||||||
}, 8);
|
|
@ -1,33 +0,0 @@
|
|||||||
try {
|
|
||||||
var ary_1 = [1.1,2.2,3.3]
|
|
||||||
var ary_2 = [1.1,2.2,3.3]
|
|
||||||
var ary_3 = [1.1,2.2,3.3]
|
|
||||||
ary_3['www'] = 1
|
|
||||||
var f64_1 = new Float64Array(0x10)
|
|
||||||
f64_1['0x7a'] = 0xffffffff
|
|
||||||
|
|
||||||
var flag = 0;
|
|
||||||
var p = {"a":{}};
|
|
||||||
p[Symbol.iterator] = function* () {
|
|
||||||
if (flag == 1) {
|
|
||||||
ary_2[0] = {}
|
|
||||||
}
|
|
||||||
yield 1;
|
|
||||||
yield 2;
|
|
||||||
};
|
|
||||||
var go = function(a,b,c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
[...c];
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = 2.3023e-320
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 0x100000; i++) {
|
|
||||||
go(ary_1, f64_1, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
flag = 1;
|
|
||||||
|
|
||||||
go(ary_2, f64_1, p);
|
|
||||||
} catch(e) { }
|
|
@ -1,31 +0,0 @@
|
|||||||
function dontCSE() { }
|
|
||||||
noInline(dontCSE);
|
|
||||||
|
|
||||||
function assert(b) {
|
|
||||||
if (!b)
|
|
||||||
throw new Error("Bad assertion");
|
|
||||||
}
|
|
||||||
noInline(assert);
|
|
||||||
|
|
||||||
function foo(a1) {
|
|
||||||
let o1 = {x: 20, y: 50};
|
|
||||||
let o2 = {y: 40, o1: o1};
|
|
||||||
let o3 = {};
|
|
||||||
|
|
||||||
o3.field = o1.y;
|
|
||||||
|
|
||||||
dontCSE();
|
|
||||||
|
|
||||||
if (a1) {
|
|
||||||
a1 = true;
|
|
||||||
} else {
|
|
||||||
a1 = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = o3.field;
|
|
||||||
assert(value === 50);
|
|
||||||
}
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; i++)
|
|
||||||
foo(i);
|
|
@ -1,53 +0,0 @@
|
|||||||
function foo() {
|
|
||||||
class A {
|
|
||||||
constructor() {
|
|
||||||
}
|
|
||||||
};
|
|
||||||
return A;
|
|
||||||
}
|
|
||||||
let A = foo();
|
|
||||||
let B = foo();
|
|
||||||
|
|
||||||
function makePolyProto(o) {
|
|
||||||
return o.x;
|
|
||||||
}
|
|
||||||
noInline(makePolyProto);
|
|
||||||
|
|
||||||
for (let i = 0; i < 1000; ++i) {
|
|
||||||
makePolyProto(i % 2 ? new A : new B);
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(b) {
|
|
||||||
let o = new A;
|
|
||||||
if (b) {
|
|
||||||
if (isFinalTier())
|
|
||||||
OSRExit();
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noInline(bar);
|
|
||||||
|
|
||||||
function baz(b) {
|
|
||||||
let o = new A;
|
|
||||||
if (b)
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
noInline(baz);
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; ++i) {
|
|
||||||
let b = i % 10 === 0;
|
|
||||||
let r = bar(b);
|
|
||||||
if (b) {
|
|
||||||
if (r.__proto__ !== A.prototype)
|
|
||||||
throw new Error("Bad!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; ++i) {
|
|
||||||
let b = i % 10 === 0;
|
|
||||||
let r = baz(b);
|
|
||||||
if (b) {
|
|
||||||
if (r.__proto__ !== A.prototype)
|
|
||||||
throw new Error("Bad!");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
function e() { }
|
|
||||||
noInline(e);
|
|
||||||
|
|
||||||
function foo(b, c, d) {
|
|
||||||
let x;
|
|
||||||
function bar() { return x; }
|
|
||||||
if (b) {
|
|
||||||
let y = function() { return x; }
|
|
||||||
} else {
|
|
||||||
let y = function() { return x; }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (c) {
|
|
||||||
function baz() { }
|
|
||||||
if (b) {
|
|
||||||
let y = function() { return x; }
|
|
||||||
e(y);
|
|
||||||
} else {
|
|
||||||
let y = function() { return x; }
|
|
||||||
e(y);
|
|
||||||
}
|
|
||||||
if (d)
|
|
||||||
d();
|
|
||||||
e(baz);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
foo(!!(i % 2), true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
let threw = false;
|
|
||||||
try {
|
|
||||||
foo(true, true, true);
|
|
||||||
} catch(e) {
|
|
||||||
threw = true;
|
|
||||||
}
|
|
||||||
if (!threw)
|
|
||||||
throw new Error("Bad test")
|
|
@ -1,29 +0,0 @@
|
|||||||
function test1(item) {
|
|
||||||
var o = {
|
|
||||||
10000: item,
|
|
||||||
get 10005() { },
|
|
||||||
};
|
|
||||||
let arr = new Array(10008);
|
|
||||||
for (let key of arr.keys()) {
|
|
||||||
let o2 = {};
|
|
||||||
o[key] = o2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test1({});
|
|
||||||
test1(10);
|
|
||||||
test1(10.5);
|
|
||||||
|
|
||||||
function test2(item) {
|
|
||||||
var o = {
|
|
||||||
0: item,
|
|
||||||
get 1000() { },
|
|
||||||
};
|
|
||||||
let arr = new Array(1000);
|
|
||||||
for (let key of arr.keys()) {
|
|
||||||
let o2 = {};
|
|
||||||
o[key] = o2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test2({});
|
|
||||||
test2(10);
|
|
||||||
test2(10.5);
|
|
@ -1,43 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < 100; ++i)
|
|
||||||
array.push(1024 * 1024 * 1024 * 1024 + i);
|
|
||||||
for (var i = 0; i < 100; ++i)
|
|
||||||
array.push(-(1024 * 1024 * 1024 * 1024 + i));
|
|
||||||
|
|
||||||
array.push(2251799813685248);
|
|
||||||
array.push(0.5);
|
|
||||||
|
|
||||||
function test(array, index, value)
|
|
||||||
{
|
|
||||||
return array[index] + fiatInt52(value);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
for (var index = 0; index < 100; ++index)
|
|
||||||
shouldBe(test(array, index, 20), 1024 * 1024 * 1024 * 1024 + index + 20);
|
|
||||||
for (var index = 0; index < 100; ++index)
|
|
||||||
shouldBe(test(array, index + 100, 20), -(1024 * 1024 * 1024 * 1024 + index) + 20);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Int52Overflow.
|
|
||||||
shouldBe(test(array, 200, 200), 2251799813685448);
|
|
||||||
|
|
||||||
// Not AnyIntAsDouble, Int52Overflow.
|
|
||||||
shouldBe(test(array, 201, 200), 200.5);
|
|
||||||
|
|
||||||
// Recompile the code as ArithAdd(Double, Double).
|
|
||||||
for (var i = 0; i < 1e4; ++i)
|
|
||||||
shouldBe(test(array, 201, 200), 200.5);
|
|
||||||
|
|
||||||
shouldBe(test(array, 200, 200), 2251799813685448);
|
|
||||||
shouldBe(test(array, 201, 200), 200.5);
|
|
||||||
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
function foo(e) {
|
|
||||||
if (e) {
|
|
||||||
arguments[0]--;
|
|
||||||
return arguments.callee.apply(this, arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; i++)
|
|
||||||
foo(1);
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
|||||||
function foo(o) {
|
|
||||||
o[0] = 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(a) {
|
|
||||||
var o = {};
|
|
||||||
o.f = a;
|
|
||||||
foo(arguments);
|
|
||||||
o.g = a;
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
noInline(bar);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1000; ++i) {
|
|
||||||
var result = bar(i);
|
|
||||||
if (result.f != i)
|
|
||||||
throw "Error: bad value of f: " + result.f;
|
|
||||||
if (result.g != 42)
|
|
||||||
throw "Error: bad value of g: " + result.g;
|
|
||||||
}
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
|||||||
var foo = function(o) {
|
|
||||||
return arguments;
|
|
||||||
};
|
|
||||||
|
|
||||||
var bar = function() {
|
|
||||||
var a = Array.prototype.slice.call(arguments);
|
|
||||||
var sum = 0;
|
|
||||||
for (var i = 0; i < a.length; ++i)
|
|
||||||
sum += a[i];
|
|
||||||
return sum;
|
|
||||||
};
|
|
||||||
|
|
||||||
var args = foo({}, 1, 2, 3);
|
|
||||||
var expectedArgs = Array.prototype.slice.call(args);
|
|
||||||
|
|
||||||
edenGC();
|
|
||||||
|
|
||||||
var expectedResult = 0;
|
|
||||||
var result = 0;
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
expectedResult += i + i + 1 + i + 2;
|
|
||||||
result += bar(i, i + 1, i + 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != expectedResult)
|
|
||||||
throw new Error("Incorrect result: " + result + " != " + expectedResult);
|
|
||||||
|
|
||||||
for (var i = 0; i < expectedArgs.length; ++i) {
|
|
||||||
if (args[i] !== expectedArgs[i])
|
|
||||||
throw new Error("Incorrect arg result");
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
|||||||
function makeBaseArguments() {
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(makeBaseArguments);
|
|
||||||
|
|
||||||
function makeArray(length) {
|
|
||||||
var array = new Array(length);
|
|
||||||
for (var i = 0; i < length; ++i)
|
|
||||||
array[i] = 99999;
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(makeArray);
|
|
||||||
|
|
||||||
function cons(f) {
|
|
||||||
var result = makeBaseArguments();
|
|
||||||
result.f = f;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = [];
|
|
||||||
for (var i = 0; i < 100000; ++i)
|
|
||||||
array.push(cons(i));
|
|
||||||
|
|
||||||
for (var i = 0; i < 1000000; ++i) {
|
|
||||||
var j = (i * 3) % array.length;
|
|
||||||
array[j] = cons(j);
|
|
||||||
|
|
||||||
makeArray(i % 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
if (array[i].f != i)
|
|
||||||
throw "Error: bad value of f at " + i + ": " + array[i].f;
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
function assert(a) {
|
|
||||||
if (!a)
|
|
||||||
throw Error("Bad assertion!");
|
|
||||||
}
|
|
||||||
|
|
||||||
function testProperties(o, initProperty, testProperty, shouldThrow) {
|
|
||||||
Object.defineProperty(arguments, 0, initProperty);
|
|
||||||
|
|
||||||
if (shouldThrow) {
|
|
||||||
try {
|
|
||||||
Object.defineProperty(arguments, 0, testProperty);
|
|
||||||
assert(false);
|
|
||||||
} catch(e) {
|
|
||||||
assert(e instanceof TypeError);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
assert(Object.defineProperty(arguments, 0, testProperty));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
testProperties("foo", {configurable: false}, {writable: true}, false);
|
|
||||||
testProperties("foo", {configurable: false}, {configurable: true}, true);
|
|
||||||
testProperties("foo", {configurable: false, enumareble: true}, {enumerable: false}, true);
|
|
||||||
testProperties("foo", {configurable: false, writable: false}, {writable: false}, false);
|
|
||||||
testProperties("foo", {configurable: false, writable: false}, {writable: true}, true);
|
|
||||||
testProperties("foo", {configurable: false, writable: false, value: 50}, {value: 30}, true);
|
|
||||||
testProperties("foo", {configurable: false, writable: false, value: 30}, {value: 30}, false);
|
|
||||||
testProperties("foo", {configurable: false, get: () => {return 0}}, {get: () => {return 10}}, true);
|
|
||||||
let getterFoo = () => {return 0};
|
|
||||||
testProperties("foo", {configurable: false, get: getterFoo}, {get: getterFoo}, false);
|
|
||||||
testProperties("foo", {configurable: false, set: (x) => {return 0}}, {get: (x) => {return 10}}, true);
|
|
||||||
let setterFoo = (x) => {return 0};
|
|
||||||
testProperties("foo", {configurable: false, set: setterFoo}, {set: setterFoo}, false);
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
|||||||
var index = 0;
|
|
||||||
function sideEffect()
|
|
||||||
{
|
|
||||||
return index++ === 0;
|
|
||||||
}
|
|
||||||
noInline(sideEffect);
|
|
||||||
|
|
||||||
function args(flag)
|
|
||||||
{
|
|
||||||
var a = arguments;
|
|
||||||
if (flag) {
|
|
||||||
return a[4] + a[5];
|
|
||||||
}
|
|
||||||
return a.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test(flag)
|
|
||||||
{
|
|
||||||
args(flag, 0, 1, 2);
|
|
||||||
if (sideEffect()) {
|
|
||||||
OSRExit();
|
|
||||||
args(sideEffect(), 0, 1, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e3; ++i)
|
|
||||||
test(false);
|
|
@ -1,29 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function strict(flag)
|
|
||||||
{
|
|
||||||
"use strict";
|
|
||||||
if (flag)
|
|
||||||
return arguments.length + 42;
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
noInline(strict);
|
|
||||||
|
|
||||||
function sloppy(flag)
|
|
||||||
{
|
|
||||||
if (flag)
|
|
||||||
return arguments.length + 42;
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
noInline(sloppy);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e6; ++i) {
|
|
||||||
shouldBe(strict(false), 1);
|
|
||||||
shouldBe(sloppy(false), 1);
|
|
||||||
}
|
|
||||||
shouldBe(strict(true), 43);
|
|
||||||
shouldBe(sloppy(true), 43);
|
|
@ -1,51 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorCondition) {
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (!errorCondition(error))
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function strict(flag)
|
|
||||||
{
|
|
||||||
"use strict";
|
|
||||||
if (flag)
|
|
||||||
throw arguments;
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
noInline(strict);
|
|
||||||
|
|
||||||
function sloppy(flag)
|
|
||||||
{
|
|
||||||
if (flag)
|
|
||||||
throw arguments;
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
noInline(sloppy);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e6; ++i) {
|
|
||||||
shouldBe(strict(false), 1);
|
|
||||||
shouldBe(sloppy(false), 1);
|
|
||||||
}
|
|
||||||
function isArguments(arg)
|
|
||||||
{
|
|
||||||
shouldBe(String(arg), `[object Arguments]`);
|
|
||||||
shouldBe(arg.length, 1);
|
|
||||||
shouldBe(arg[0], true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
shouldThrow(() => strict(true), isArguments);
|
|
||||||
shouldThrow(() => sloppy(true), isArguments);
|
|
@ -1,30 +0,0 @@
|
|||||||
function foo()
|
|
||||||
{
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(...args)
|
|
||||||
{
|
|
||||||
var a = [42];
|
|
||||||
if (isFinalTier())
|
|
||||||
a = args;
|
|
||||||
return {ftl: isFinalTier(), result: foo(...a)};
|
|
||||||
}
|
|
||||||
|
|
||||||
function baz()
|
|
||||||
{
|
|
||||||
return bar(1, 2, 3, 4);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(baz);
|
|
||||||
|
|
||||||
for (var i = 0; i < 100000; ++i) {
|
|
||||||
var result = baz();
|
|
||||||
if (result.ftl) {
|
|
||||||
if (result.result != 4)
|
|
||||||
throw "Error: bad result in loop in DFG: " + result.result;
|
|
||||||
} else {
|
|
||||||
if (result.result != 1)
|
|
||||||
throw "Error: bad result in loop before DFG: " + result.result;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
function foo(x) {
|
|
||||||
var tmp = x.f + 1;
|
|
||||||
return tmp + arguments[0].f;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo({f:i});
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo({f:4.5});
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,18 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function foo(x) {
|
|
||||||
var tmp = x.f + 1;
|
|
||||||
return tmp + arguments[0].f;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo({f:i});
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo({f:4.5});
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,18 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function foo(x) {
|
|
||||||
var tmp = x + 1;
|
|
||||||
return tmp + arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo(i);
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(4.5);
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,16 +0,0 @@
|
|||||||
function foo(x) {
|
|
||||||
var tmp = x + 1;
|
|
||||||
return tmp + arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo(i);
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = foo(4.5);
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,22 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function foo(x) {
|
|
||||||
var tmp = x.f + 1;
|
|
||||||
return tmp + arguments[0].f;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(x) {
|
|
||||||
return foo(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = bar({f:i});
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = bar({f:4.5});
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,22 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
function foo(x) {
|
|
||||||
var tmp = x + 1;
|
|
||||||
return tmp + arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(x) {
|
|
||||||
return foo(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = bar(i);
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = bar(4.5);
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,20 +0,0 @@
|
|||||||
function foo(x) {
|
|
||||||
var tmp = x + 1;
|
|
||||||
return tmp + arguments[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function bar(x) {
|
|
||||||
return foo(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(bar);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = bar(i);
|
|
||||||
if (result != i + i + 1)
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var result = bar(4.5);
|
|
||||||
if (result != 4.5 + 4.5 + 1)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
@ -1,24 +0,0 @@
|
|||||||
function bar() {
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
function foo(p) {
|
|
||||||
var a = bar(1, 2, 3);
|
|
||||||
var b;
|
|
||||||
if (p)
|
|
||||||
b = bar(4, 5, 6);
|
|
||||||
else
|
|
||||||
b = [7, 8, 9];
|
|
||||||
return (a[0] << 0) + (a[1] << 1) + (a[2] << 2) + (b[0] << 3) + (b[1] << 4) + (b[2] << 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 20000; ++i) {
|
|
||||||
var p = i & 1;
|
|
||||||
var q = (!p) * 3;
|
|
||||||
var result = foo(p);
|
|
||||||
if (result != (1 << 0) + (2 << 1) + (3 << 2) + ((4 + q) << 3) + ((5 + q) << 4) + ((6 + q) << 5))
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
@ -1,18 +0,0 @@
|
|||||||
function bar() {
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
function foo() {
|
|
||||||
var a = bar(1, 2, 3);
|
|
||||||
var b = bar(4, 5, 6);
|
|
||||||
return (a[0] << 0) + (a[1] << 1) + (a[2] << 2) + (b[0] << 3) + (b[1] << 4) + (b[2] << 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 20000; ++i) {
|
|
||||||
var result = foo();
|
|
||||||
if (result != (1 << 0) + (2 << 1) + (3 << 2) + (4 << 3) + (5 << 4) + (6 << 5))
|
|
||||||
throw "Error: bad result: " + result;
|
|
||||||
}
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
|||||||
function test(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function testArguments(check) {
|
|
||||||
(function () {
|
|
||||||
check(arguments, []);
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function (a, b, c) {
|
|
||||||
check(arguments, [a, b, c]);
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
'use strict';
|
|
||||||
check(arguments, []);
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function (a, b, c) {
|
|
||||||
'use strict';
|
|
||||||
check(arguments, [a, b, c]);
|
|
||||||
}());
|
|
||||||
}
|
|
||||||
|
|
||||||
testArguments(function (args) {
|
|
||||||
var iteratorMethod = args[Symbol.iterator];
|
|
||||||
test(iteratorMethod, Array.prototype.values);
|
|
||||||
var descriptor = Object.getOwnPropertyDescriptor(args, Symbol.iterator);
|
|
||||||
test(descriptor.writable, true);
|
|
||||||
test(descriptor.configurable, true);
|
|
||||||
test(descriptor.enumerable, false);
|
|
||||||
test(descriptor.value, iteratorMethod);
|
|
||||||
});
|
|
||||||
|
|
||||||
testArguments(function (args, expected) {
|
|
||||||
var iterator = args[Symbol.iterator]();
|
|
||||||
test(iterator.toString(), '[object Array Iterator]');
|
|
||||||
var index = 0;
|
|
||||||
for (var value of iterator) {
|
|
||||||
test(value, expected[index++]);
|
|
||||||
}
|
|
||||||
test(args.length, index);
|
|
||||||
|
|
||||||
var index = 0;
|
|
||||||
for (var value of args) {
|
|
||||||
test(value, expected[index++]);
|
|
||||||
}
|
|
||||||
test(args.length, index);
|
|
||||||
});
|
|
||||||
|
|
||||||
testArguments(function (args) {
|
|
||||||
var symbols = Object.getOwnPropertySymbols(args);
|
|
||||||
test(symbols.length, 1);
|
|
||||||
test(symbols[0], Symbol.iterator);
|
|
||||||
});
|
|
||||||
|
|
||||||
testArguments(function (args) {
|
|
||||||
'use strict';
|
|
||||||
args[Symbol.iterator] = 'not throw error';
|
|
||||||
});
|
|
||||||
|
|
||||||
testArguments(function (args) {
|
|
||||||
'use strict';
|
|
||||||
delete args[Symbol.iterator];
|
|
||||||
test(args[Symbol.iterator], undefined);
|
|
||||||
|
|
||||||
var symbols = Object.getOwnPropertySymbols(args);
|
|
||||||
test(symbols.length, 0);
|
|
||||||
});
|
|
@ -1,15 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var argsSloppy = (function () { return arguments; }(1,2,3));
|
|
||||||
var argsStrict = (function () { 'use strict'; return arguments; }(1,2,3));
|
|
||||||
|
|
||||||
shouldBe(Object.prototype.propertyIsEnumerable(argsSloppy, 'length'), false);
|
|
||||||
shouldBe(Object.prototype.propertyIsEnumerable(argsStrict, 'length'), false);
|
|
||||||
|
|
||||||
shouldBe(Object.keys(argsSloppy).length === Object.keys(argsStrict).length, true);
|
|
||||||
shouldBe(Object.keys(argsSloppy).indexOf('length'), -1)
|
|
||||||
shouldBe(Object.keys(argsStrict).indexOf('length'), -1);
|
|
@ -1,27 +0,0 @@
|
|||||||
function assert(a) {
|
|
||||||
if (!a)
|
|
||||||
throw Error("Bad assertion!");
|
|
||||||
}
|
|
||||||
|
|
||||||
function tryChangeNonConfigurableDescriptor(x) {
|
|
||||||
Object.defineProperty(arguments, 0, {configurable: false});
|
|
||||||
try {
|
|
||||||
Object.defineProperty(arguments, 0, x);
|
|
||||||
assert(false);
|
|
||||||
} catch(e) {
|
|
||||||
assert(e instanceof TypeError);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tryChangeNonConfigurableDescriptor({get: () => {return 50;} });
|
|
||||||
tryChangeNonConfigurableDescriptor({set: (x) => {}});
|
|
||||||
tryChangeNonConfigurableDescriptor({writable: true, enumerable: false});
|
|
||||||
|
|
||||||
function tryChangeWritableOfNonConfigurableDescriptor(x) {
|
|
||||||
Object.defineProperty(arguments, 0, {configurable: false});
|
|
||||||
Object.defineProperty(arguments, 0, {writable: true});
|
|
||||||
assert(Object.defineProperty(arguments, 0, {writable: false}));
|
|
||||||
}
|
|
||||||
|
|
||||||
tryChangeWritableOfNonConfigurableDescriptor("foo");
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
function opaqueAbs(value)
|
|
||||||
{
|
|
||||||
return Math.abs(value);
|
|
||||||
}
|
|
||||||
noInline(opaqueAbs);
|
|
||||||
|
|
||||||
// Warmup.
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
var positiveResult = opaqueAbs(i);
|
|
||||||
if (positiveResult !== i)
|
|
||||||
throw "Incorrect positive result at i = " + i + " result = " + positiveResult;
|
|
||||||
var negativeResult = opaqueAbs(-i);
|
|
||||||
if (negativeResult !== i)
|
|
||||||
throw "Incorrect negative result at -i = " + -i + " result = " + negativeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overflow.
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
var overflowResult = opaqueAbs(-2147483648);
|
|
||||||
if (overflowResult !== 2147483648)
|
|
||||||
throw "Incorrect overflow result at i = " + i + " result = " + overflowResult;
|
|
||||||
}
|
|
@ -1,427 +0,0 @@
|
|||||||
//@ skip if not $jitTests
|
|
||||||
//@ defaultNoEagerRun
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// Checked int_min < value < 0
|
|
||||||
function opaqueCheckedBetweenIntMinAndZeroExclusive(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
if (arg > (0x80000000|0)) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedBetweenIntMinAndZeroExclusive);
|
|
||||||
|
|
||||||
function testCheckedBetweenIntMinAndZeroExclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroExclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroExclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroExclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroExclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroExclusive) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedBetweenIntMinAndZeroExclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedBetweenIntMinAndZeroExclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Checked int_min < value <= 0
|
|
||||||
function opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
if (arg > (0x80000000|0)) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive);
|
|
||||||
|
|
||||||
function testCheckedBetweenIntMinExclusiveAndZeroInclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(0) !== 0) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive() on 0";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinExclusiveAndZeroInclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinExclusiveAndZeroInclusive) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedBetweenIntMinExclusiveAndZeroInclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedBetweenIntMinExclusiveAndZeroInclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Checked int_min <= value < 0
|
|
||||||
function opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
if (arg >= (0x80000000|0)) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive);
|
|
||||||
|
|
||||||
function testCheckedBetweenIntMinInclusiveAndZeroExclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedBetweenIntMinInclusiveAndZeroExclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive()";
|
|
||||||
}
|
|
||||||
let result = opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648);
|
|
||||||
if (result !== 2147483648) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648, got " + result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinInclusiveAndZeroExclusive) > 2) {
|
|
||||||
throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedBetweenIntMinInclusiveAndZeroExclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Checked int_min <= value <= 0
|
|
||||||
function opaqueCheckedBetweenIntMinAndZeroInclusive(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
if (arg >= (0x80000000|0)) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedBetweenIntMinAndZeroInclusive);
|
|
||||||
|
|
||||||
function testCheckedBetweenIntMinAndZeroInclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroInclusive) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedBetweenIntMinAndZeroInclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedBetweenIntMinAndZeroInclusive(-2147483648) !== 2147483648) {
|
|
||||||
throw "Failed testCheckedBetweenIntMinAndZeroInclusive() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedBetweenIntMinAndZeroInclusive) > 2) {
|
|
||||||
throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedBetweenIntMinAndZeroInclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked int_min < value < 0
|
|
||||||
function opaqueUncheckedBetweenIntMinAndZeroExclusive(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
if (arg > (0x80000000|0)) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedBetweenIntMinAndZeroExclusive);
|
|
||||||
|
|
||||||
function testUncheckedBetweenIntMinAndZeroExclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedBetweenIntMinAndZeroExclusive(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinAndZeroExclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinAndZeroExclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinAndZeroExclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinAndZeroExclusive) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedBetweenIntMinAndZeroExclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedBetweenIntMinAndZeroExclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked int_min < value <= 0
|
|
||||||
function opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
if (arg > (0x80000000|0)) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive);
|
|
||||||
|
|
||||||
function testUncheckedBetweenIntMinExclusiveAndZeroInclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(0) !== 0) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive() on 0";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinExclusiveAndZeroInclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinExclusiveAndZeroInclusive) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedBetweenIntMinExclusiveAndZeroInclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedBetweenIntMinExclusiveAndZeroInclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked int_min <= value < 0
|
|
||||||
function opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
if (arg >= (0x80000000|0)) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive);
|
|
||||||
|
|
||||||
function testUncheckedBetweenIntMinInclusiveAndZeroExclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648) !== -2147483648) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedBetweenIntMinInclusiveAndZeroExclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedBetweenIntMinInclusiveAndZeroExclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked int_min <= value <= 0
|
|
||||||
function opaqueUncheckedBetweenIntMinAndZeroInclusive(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
if (arg >= (0x80000000|0)) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedBetweenIntMinAndZeroInclusive);
|
|
||||||
|
|
||||||
function testUncheckedBetweenIntMinAndZeroInclusive()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedBetweenIntMinAndZeroInclusive(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinAndZeroInclusive(0) !== 0) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinAndZeroInclusive()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinAndZeroInclusive(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinAndZeroInclusive() on -2147483647";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedBetweenIntMinInclusiveAndZeroExclusive(-2147483648) !== -2147483648) {
|
|
||||||
throw "Failed testUncheckedBetweenIntMinInclusiveAndZeroExclusive() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedBetweenIntMinAndZeroInclusive) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedBetweenIntMinAndZeroInclusive(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedBetweenIntMinAndZeroInclusive();
|
|
||||||
|
|
||||||
|
|
||||||
// Checked value < 0
|
|
||||||
function opaqueCheckedLessThanZero(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedLessThanZero);
|
|
||||||
|
|
||||||
function testCheckedLessThanZero()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedLessThanZero(-i) !== i) {
|
|
||||||
throw "Failed testCheckedLessThanZero()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedLessThanZero(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedLessThanZero() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedLessThanZero) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedLessThanZero(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedLessThanZero(-i) !== i) {
|
|
||||||
throw "Failed testCheckedLessThanZero()";
|
|
||||||
}
|
|
||||||
let result = opaqueCheckedLessThanZero(-2147483648);
|
|
||||||
if (result !== 2147483648) {
|
|
||||||
throw "Failed testCheckedLessThanZero() on -2147483648, got " + result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedLessThanZero) > 2) {
|
|
||||||
throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedLessThanZero();
|
|
||||||
|
|
||||||
|
|
||||||
// Checked value <= 0
|
|
||||||
function opaqueCheckedLessThanOrEqualZero(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
return Math.abs(arg);
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueCheckedLessThanOrEqualZero);
|
|
||||||
|
|
||||||
function testCheckedLessThanOrEqualZero()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedLessThanOrEqualZero(-i) !== i) {
|
|
||||||
throw "Failed testCheckedLessThanOrEqualZero()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedLessThanOrEqualZero(0) !== 0) {
|
|
||||||
throw "Failed testCheckedLessThanOrEqualZero() on 0";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedLessThanOrEqualZero(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testCheckedLessThanOrEqualZero() on -2147483647";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedLessThanOrEqualZero) > 1) {
|
|
||||||
throw "Failed optimizing testCheckedLessThanOrEqualZero(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueCheckedLessThanOrEqualZero(-i) !== i) {
|
|
||||||
throw "Failed testCheckedLessThanOrEqualZero()";
|
|
||||||
}
|
|
||||||
if (opaqueCheckedLessThanOrEqualZero(-2147483648) !== 2147483648) {
|
|
||||||
throw "Failed testCheckedLessThanOrEqualZero() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueCheckedLessThanOrEqualZero) > 2) {
|
|
||||||
throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testCheckedLessThanOrEqualZero();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked value < 0
|
|
||||||
function opaqueUncheckedLessThanZero(arg) {
|
|
||||||
if (arg < 0) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedLessThanZero);
|
|
||||||
|
|
||||||
function testUncheckedLessThanZero()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedLessThanZero(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedLessThanZero()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanZero(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedLessThanZero() on -2147483647";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanZero(-2147483648) !== -2147483648) {
|
|
||||||
throw "Failed testUncheckedLessThanOrEqualZero() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedLessThanZero) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedLessThanZero(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedLessThanZero(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedLessThanZero()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanZero(-2147483648) !== -2147483648) {
|
|
||||||
throw "Failed testUncheckedLessThanZero() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedLessThanZero) > 2) {
|
|
||||||
throw "Math.abs() on IntMin can OSR Exit but we should quickly settle on double.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedLessThanZero();
|
|
||||||
|
|
||||||
|
|
||||||
// Unchecked value <= 0
|
|
||||||
function opaqueUncheckedLessThanOrEqualZero(arg) {
|
|
||||||
if (arg <= 0) {
|
|
||||||
return Math.abs(arg)|0;
|
|
||||||
}
|
|
||||||
throw "We should not be here";
|
|
||||||
}
|
|
||||||
noInline(opaqueUncheckedLessThanOrEqualZero);
|
|
||||||
|
|
||||||
function testUncheckedLessThanOrEqualZero()
|
|
||||||
{
|
|
||||||
for (let i = 1; i < 1e5; ++i) {
|
|
||||||
if (opaqueUncheckedLessThanOrEqualZero(-i) !== i) {
|
|
||||||
throw "Failed testUncheckedLessThanOrEqualZero()";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanOrEqualZero(0) !== 0) {
|
|
||||||
throw "Failed testUncheckedLessThanOrEqualZero() on 0";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanOrEqualZero(-2147483647) !== 2147483647) {
|
|
||||||
throw "Failed testUncheckedLessThanOrEqualZero() on -2147483647";
|
|
||||||
}
|
|
||||||
if (opaqueUncheckedLessThanOrEqualZero(-2147483648) !== -2147483648) {
|
|
||||||
throw "Failed testUncheckedLessThanOrEqualZero() on -2147483648";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (numberOfDFGCompiles(opaqueUncheckedLessThanOrEqualZero) > 1) {
|
|
||||||
throw "Failed optimizing testUncheckedLessThanOrEqualZero(). None of the tested case need to OSR Exit.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testUncheckedLessThanOrEqualZero();
|
|
@ -1,54 +0,0 @@
|
|||||||
function opaqueAbs(value)
|
|
||||||
{
|
|
||||||
return Math.abs(value)|0;
|
|
||||||
}
|
|
||||||
noInline(opaqueAbs);
|
|
||||||
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
var positiveResult = opaqueAbs(i);
|
|
||||||
if (positiveResult !== i)
|
|
||||||
throw "Incorrect result at i = " + i + " result = " + positiveResult;
|
|
||||||
var negativeResult = opaqueAbs(-i);
|
|
||||||
if (negativeResult !== i)
|
|
||||||
throw "Incorrect result at -i = " + -i + " result = " + negativeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var intMax = 2147483647;
|
|
||||||
var intMin = 2147483647;
|
|
||||||
|
|
||||||
var intMaxResult = opaqueAbs(intMax);
|
|
||||||
if (intMaxResult !== intMax)
|
|
||||||
throw "Incorrect result at intMax result = " + intMaxResult;
|
|
||||||
var intMaxResult = opaqueAbs(intMin);
|
|
||||||
if (intMaxResult !== intMin)
|
|
||||||
throw "Incorrect result at intMax result = " + intMaxResult;
|
|
||||||
|
|
||||||
// Numbers around IntMax/IntMin. Numbers outside the bounds are doubles and opaqueAbs()
|
|
||||||
// has to OSR Exit to handle them correctly.
|
|
||||||
for (let i = intMax - 1e4; i < intMax + 1e4; ++i) {
|
|
||||||
var positiveResult = opaqueAbs(i);
|
|
||||||
if (positiveResult !== (i|0))
|
|
||||||
throw "Incorrect result at i = " + i + " result = " + positiveResult;
|
|
||||||
var negativeResult = opaqueAbs(-i);
|
|
||||||
if (negativeResult !== (i|0))
|
|
||||||
throw "Incorrect result at -i = " + -i + " result = " + negativeResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edge cases and exits.
|
|
||||||
if (opaqueAbs(NaN) !== 0)
|
|
||||||
throw "opaqueAbs(NaN) failed.";
|
|
||||||
if (opaqueAbs(Infinity) !== 0)
|
|
||||||
throw "opaqueAbs(Infinity) failed.";
|
|
||||||
if (opaqueAbs(-Infinity) !== 0)
|
|
||||||
throw "opaqueAbs(-Infinity) failed.";
|
|
||||||
if (opaqueAbs(null) !== 0)
|
|
||||||
throw "opaqueAbs(null) failed.";
|
|
||||||
if (opaqueAbs(undefined) !== 0)
|
|
||||||
throw "opaqueAbs(undefined) failed.";
|
|
||||||
if (opaqueAbs(true) !== 1)
|
|
||||||
throw "opaqueAbs(true) failed.";
|
|
||||||
if (opaqueAbs(false) !== 0)
|
|
||||||
throw "opaqueAbs(false) failed.";
|
|
||||||
if (opaqueAbs({foo:"bar"}) !== 0)
|
|
||||||
throw "opaqueAbs({foo:'bar'}) failed.";
|
|
@ -1,100 +0,0 @@
|
|||||||
let testCases = [
|
|
||||||
// Numbers
|
|
||||||
['1', NaN, NaN, 2, 2],
|
|
||||||
['1.5', NaN, NaN, 1 + 1.5, 1 + 1.5],
|
|
||||||
[NaN, NaN, NaN, NaN, NaN],
|
|
||||||
|
|
||||||
// Strings.
|
|
||||||
['""', NaN, NaN, 1, 1],
|
|
||||||
['new String()', NaN, NaN, 1, 1],
|
|
||||||
['"WebKit!"', NaN, NaN, NaN, NaN],
|
|
||||||
|
|
||||||
// Objects.
|
|
||||||
['{ }', NaN, NaN, NaN, NaN],
|
|
||||||
['{ foo: 1 }', NaN, NaN, NaN, NaN],
|
|
||||||
['{ toString: function() { return ""; } }', NaN, NaN, 1, 1],
|
|
||||||
['{ toString: function() { return "WebKit"; } }', NaN, NaN, NaN, NaN],
|
|
||||||
|
|
||||||
// Others.
|
|
||||||
['null', NaN, NaN, 1, 1],
|
|
||||||
['undefined', NaN, NaN, NaN, NaN]
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let testCase of testCases) {
|
|
||||||
let otherOperand = testCase[0];
|
|
||||||
let expectedLeftValueWithHole = testCase[1];
|
|
||||||
let expectedRightValueWithHole = testCase[2];
|
|
||||||
let expectedLeftValue = testCase[3];
|
|
||||||
let expectedRightValue = testCase[4];
|
|
||||||
eval(
|
|
||||||
`// Those holes are not observable by arithmetic operation.
|
|
||||||
// The return value is always going to be NaN.
|
|
||||||
function nonObservableHoleOnLhs(array, otherValue) {
|
|
||||||
return Math.min(array[0]) + Math.min(otherValue);
|
|
||||||
}
|
|
||||||
noInline(nonObservableHoleOnLhs);
|
|
||||||
|
|
||||||
function observableHoleOnLhs(array, otherValue) {
|
|
||||||
let value = array[0];
|
|
||||||
return [Math.min(value) + Math.min(otherValue), value];
|
|
||||||
}
|
|
||||||
noInline(observableHoleOnLhs);
|
|
||||||
|
|
||||||
function nonObservableHoleOnRhs(array, otherValue) {
|
|
||||||
return Math.min(otherValue) + Math.min(array[0]);
|
|
||||||
}
|
|
||||||
noInline(nonObservableHoleOnRhs);
|
|
||||||
|
|
||||||
function observableHoleOnRhs(array, otherValue) {
|
|
||||||
let value = array[0];
|
|
||||||
return [Math.min(otherValue) + Math.min(value), value];
|
|
||||||
}
|
|
||||||
noInline(observableHoleOnRhs);
|
|
||||||
|
|
||||||
let testArray = new Array;
|
|
||||||
for (let i = 1; i < 3; ++i) {
|
|
||||||
testArray[i] = i + 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
let isEqual = function(a, b) {
|
|
||||||
if (a === a) {
|
|
||||||
return a === b;
|
|
||||||
}
|
|
||||||
return b !== b;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
let lhsResult1 = nonObservableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult1, ${expectedLeftValueWithHole}))
|
|
||||||
throw "Error on nonObservableHoleOnLhs at i = " + i + " with operand " + ${otherOperand} + " expected " + ${expectedLeftValueWithHole} + " got " + lhsResult1;
|
|
||||||
let lhsResult2 = observableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult2[0], ${expectedLeftValueWithHole}) || lhsResult2[1] !== undefined)
|
|
||||||
throw "Error on observableHoleOnLhs at i = " + i;
|
|
||||||
|
|
||||||
let rhsResult1 = nonObservableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult1, ${expectedRightValueWithHole}))
|
|
||||||
throw "Error on nonObservableHoleOnRhs at i = " + i + " with operand " + ${otherOperand} + " expected " + ${expectedRightValueWithHole} + " got " + rhsResult1;
|
|
||||||
let rhsResult2 = observableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult2[0], ${expectedRightValueWithHole}) || rhsResult2[1] !== undefined)
|
|
||||||
throw "Error on observableHoleOnRhs at i = " + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the hole, make sure everything still work correctly.
|
|
||||||
testArray[0] = 1.;
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
let lhsResult1 = nonObservableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult1, ${expectedLeftValue}))
|
|
||||||
throw "Error on non hole nonObservableHoleOnLhs at i = " + i + " expected " + ${expectedLeftValue} + " got " + lhsResult1;
|
|
||||||
let lhsResult2 = observableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult2[0], ${expectedLeftValue}) || lhsResult2[1] !== 1)
|
|
||||||
throw "Error on non hole observableHoleOnLhs at i = " + i + " expected " + ${expectedLeftValue} + " got " + lhsResult2[0];
|
|
||||||
|
|
||||||
let rhsResult1 = nonObservableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult1, ${expectedRightValue}))
|
|
||||||
throw "Error on non hole nonObservableHoleOnRhs at i = " + i + " with operand " + ${otherOperand} + " expected " + ${expectedRightValue} + " got " + rhsResult1;
|
|
||||||
let rhsResult2 = observableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult2[0], ${expectedRightValue}) || rhsResult2[1] !== 1)
|
|
||||||
throw "Error on non hole observableHoleOnRhs at i = " + i;
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
function opaqueAdd(a)
|
|
||||||
{
|
|
||||||
return a + 42;
|
|
||||||
}
|
|
||||||
noInline(opaqueAdd);
|
|
||||||
|
|
||||||
// Warm up.
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
let result = opaqueAdd(5);
|
|
||||||
if (result !== 47)
|
|
||||||
throw "Invalid opaqueAdd(5) at i = " + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overflow.
|
|
||||||
for (let i = 0; i < 1e3; ++i) {
|
|
||||||
for (let j = -50; j < 50; ++j) {
|
|
||||||
let result = opaqueAdd(2147483647 + j);
|
|
||||||
if (result !== 2147483689 + j)
|
|
||||||
throw "Invalid opaqueAdd(" + 2147483647 + j + ") at i = " + i + " j = " + j;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,271 +0,0 @@
|
|||||||
// Test value + 0.
|
|
||||||
function arithAddIdentityWrittenAsInteger(x) {
|
|
||||||
var a = x + 0;
|
|
||||||
var b = 0 + x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithAddIdentityWrittenAsInteger, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithAddIdentityWrittenAsInteger);
|
|
||||||
|
|
||||||
function testArithAddIdentityWrittenAsInteger() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(i);
|
|
||||||
if (result !== i) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(i) = " + result + ", expected " + i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(-0) = " + result + ", expected -0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var testValue = i + .5;
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(testValue);
|
|
||||||
if (result !== testValue) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(i) = " + result + ", expected " + testValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsInteger(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithAddIdentityWrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithAddIdentityWrittenAsInteger();
|
|
||||||
|
|
||||||
|
|
||||||
function arithAddIdentityWrittenAsDouble(x) {
|
|
||||||
var a = x + 0.0;
|
|
||||||
var b = 0. + x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithAddIdentityWrittenAsDouble, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithAddIdentityWrittenAsDouble);
|
|
||||||
|
|
||||||
function testArithAddIdentityWrittenAsDouble() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(i);
|
|
||||||
if (result !== i) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(i) = " + result + ", expected " + i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(-0) = " + result + ", expected -0 ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var testValue = i + .5;
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(testValue);
|
|
||||||
if (result !== testValue) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(i) = " + result + ", expected " + testValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAddIdentityWrittenAsDouble(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithAddIdentityWrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithAddIdentityWrittenAsDouble();
|
|
||||||
|
|
||||||
|
|
||||||
// Test "value + 42".
|
|
||||||
function arithAdd42WrittenAsInteger(x) {
|
|
||||||
var a = x + 42;
|
|
||||||
var b = 42 + x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithAdd42WrittenAsInteger, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithAdd42WrittenAsInteger);
|
|
||||||
|
|
||||||
function testArithAdd42WrittenAsInteger() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(13);
|
|
||||||
if (result !== 55) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(13) = " + result + ", expected 55";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(-0);
|
|
||||||
if (result !== 42) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(-0) = " + result + ", expected 42";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(13.3);
|
|
||||||
if (result !== 55.3) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(13.3) = " + result + ", expected 55.3";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithAdd42WrittenAsInteger();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Test "value + 42".
|
|
||||||
function arithAdd42WrittenAsInteger(x) {
|
|
||||||
var a = x + 42;
|
|
||||||
var b = 42 + x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithAdd42WrittenAsInteger, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithAdd42WrittenAsInteger);
|
|
||||||
|
|
||||||
function testArithAdd42WrittenAsInteger() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(13);
|
|
||||||
if (result !== 55) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(13) = " + result + ", expected 55";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(-0);
|
|
||||||
if (result !== 42) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(-0) = " + result + ", expected 42";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithAdd42WrittenAsInteger(13.3);
|
|
||||||
if (result !== 55.3) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(13.3) = " + result + ", expected 55.3";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithAdd42WrittenAsInteger(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithAdd42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithAdd42WrittenAsInteger();
|
|
||||||
|
|
||||||
function arithSub42WrittenAsDouble(x) {
|
|
||||||
var a = (x|0) - 42.0;
|
|
||||||
var b = -42. + (x|0);
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithSub42WrittenAsDouble, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithSub42WrittenAsDouble);
|
|
||||||
|
|
||||||
function testArithSub42WrittenAsDouble() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithSub42WrittenAsDouble(13);
|
|
||||||
if (result !== -29) {
|
|
||||||
throw "arithSub42WrittenAsDouble(13) = " + result + ", expected -29";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithSub42WrittenAsDouble(-0);
|
|
||||||
if (result !== -42) {
|
|
||||||
throw "arithSub42WrittenAsDouble(-0) = " + result + ", expected -42";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithSub42WrittenAsDouble(13.3);
|
|
||||||
if (result !== -29) {
|
|
||||||
throw "arithSub42WrittenAsDouble(13.3) = " + result + ", expected -29";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithSub42WrittenAsDouble();
|
|
||||||
|
|
||||||
|
|
||||||
function doubleConstant(){
|
|
||||||
Math.min(0.0);
|
|
||||||
+0.0;
|
|
||||||
} noInline(doubleConstant);
|
|
||||||
|
|
||||||
function testDoubleConstant(){
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
doubleConstant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testDoubleConstant();
|
|
@ -1,30 +0,0 @@
|
|||||||
function foo(o, v)
|
|
||||||
{
|
|
||||||
var result = o.f;
|
|
||||||
Math.clz32(v);
|
|
||||||
return result + o.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
var o = {f: 42};
|
|
||||||
o.g = 43; // Bust the transition watchpoint of {f}.
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
var result = foo({f: 42}, "42");
|
|
||||||
if (result != 84)
|
|
||||||
throw "Error: bad result in loop: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
var o = {f: 43};
|
|
||||||
var result = foo(o, {
|
|
||||||
valueOf: function()
|
|
||||||
{
|
|
||||||
delete o.f;
|
|
||||||
o.__defineGetter__("f", function() { return 44; });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (result != 87)
|
|
||||||
throw "Error: bad result at end: " + result;
|
|
||||||
|
|
@ -1,106 +0,0 @@
|
|||||||
//@ skip if $hostOS == "windows"
|
|
||||||
|
|
||||||
// Verify that the dividend propagate the NeedsNegZero if the dividend requires it.
|
|
||||||
function moduloWithNegativeZeroDividend(a, b, c)
|
|
||||||
{
|
|
||||||
var temp = a * b;
|
|
||||||
return temp % c;
|
|
||||||
}
|
|
||||||
noInline(moduloWithNegativeZeroDividend);
|
|
||||||
|
|
||||||
// Warm up with integers. The test for NegZero should not be eliminated here.
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithNegativeZeroDividend(i, 5, 5);
|
|
||||||
if (result !== 0)
|
|
||||||
throw "moduloWithNegativeZeroDividend(i, 5, 5), returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
// Produce negative zero in the multiplication.
|
|
||||||
var result = moduloWithNegativeZeroDividend(-i, 0, 2);
|
|
||||||
if (!(result === 0 && (1/result) === -Infinity))
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 0, 2) failed, returned: " + result;
|
|
||||||
|
|
||||||
// A negative dividend can produce negative zero results.
|
|
||||||
var result = moduloWithNegativeZeroDividend(-i, 5, 5);
|
|
||||||
if (!(result === 0 && (1/result) === -Infinity))
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 5, 5) failed, returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Edge cases.
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithNegativeZeroDividend(-i, 0, Infinity);
|
|
||||||
if (!(result === 0 && (1/result) === -Infinity))
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result;
|
|
||||||
|
|
||||||
var result = moduloWithNegativeZeroDividend(-i, 0, -Infinity);
|
|
||||||
if (!(result === 0 && (1/result) === -Infinity))
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result;
|
|
||||||
|
|
||||||
var result = moduloWithNegativeZeroDividend(-i, 0, NaN);
|
|
||||||
if (result === result)
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// In this case, the negative zero is irrelevant. The Neg Zero check can be eliminated.
|
|
||||||
function moduloWithUnusedNegativeZeroDividend(a, b, c)
|
|
||||||
{
|
|
||||||
var temp = a * b;
|
|
||||||
return (temp % c) | 0;
|
|
||||||
}
|
|
||||||
noInline(moduloWithUnusedNegativeZeroDividend);
|
|
||||||
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithUnusedNegativeZeroDividend(i, 5, 5);
|
|
||||||
if (result !== 0)
|
|
||||||
throw "moduloWithUnusedNegativeZeroDividend(i, 5, 5), returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Produce negative zero in the multiplication.
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithUnusedNegativeZeroDividend(-i, 0, 2);
|
|
||||||
if (!(result === 0 && (1/result) === Infinity))
|
|
||||||
throw "moduloWithUnusedNegativeZeroDividend(-i, 0, 2) failed, returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity);
|
|
||||||
if (!(result === 0 && (1/result) === Infinity))
|
|
||||||
throw "moduloWithUnusedNegativeZeroDividend(-i, 0, Infinity) failed, returned: " + result;
|
|
||||||
|
|
||||||
var result = moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity);
|
|
||||||
if (!(result === 0 && (1/result) === Infinity))
|
|
||||||
throw "moduloWithUnusedNegativeZeroDividend(-i, 0, -Infinity) failed, returned: " + result;
|
|
||||||
|
|
||||||
var result = moduloWithUnusedNegativeZeroDividend(-i, 0, NaN);
|
|
||||||
if (result !== 0)
|
|
||||||
throw "moduloWithUnusedNegativeZeroDividend(-i, 0, NaN) failed, returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// The sign of the divisor is completely irrelevant. This should never fail on negative zero divisors.
|
|
||||||
function moduloWithNegativeZeroDivisor(a, b, c)
|
|
||||||
{
|
|
||||||
var temp = a * b;
|
|
||||||
return c % temp;
|
|
||||||
}
|
|
||||||
noInline(moduloWithNegativeZeroDivisor);
|
|
||||||
|
|
||||||
// Warm up with integers.
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithNegativeZeroDivisor(i, 2, i);
|
|
||||||
if (result !== i)
|
|
||||||
throw "moduloWithNegativeZeroDividend(i, 2, i), returned: " + result;
|
|
||||||
|
|
||||||
var result = moduloWithNegativeZeroDivisor(-i, 2, i);
|
|
||||||
if (result !== i)
|
|
||||||
throw "moduloWithNegativeZeroDividend(-i, 2, i), returned: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Produce negative zero in the multiplication.
|
|
||||||
for (var i = 1; i < 1e4; ++i) {
|
|
||||||
var result = moduloWithNegativeZeroDivisor(-i, 0, 2);
|
|
||||||
if (result === result)
|
|
||||||
throw "moduloWithNegativeZeroDivisor(-i, 0, 2) failed, returned: " + result;
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
function opaqueModuloSmaller(a)
|
|
||||||
{
|
|
||||||
return (a % 5) % 13;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloSmaller);
|
|
||||||
|
|
||||||
function opaqueModuloEqual(a)
|
|
||||||
{
|
|
||||||
return (a % 5) % 5;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloEqual);
|
|
||||||
|
|
||||||
function opaqueModuloLarger(a)
|
|
||||||
{
|
|
||||||
return (a % 13) % 5;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloLarger);
|
|
||||||
|
|
||||||
function opaqueModuloSmallerNeg(a)
|
|
||||||
{
|
|
||||||
return (a % -5) % -13;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloSmallerNeg);
|
|
||||||
|
|
||||||
function opaqueModuloEqualNeg(a)
|
|
||||||
{
|
|
||||||
return (a % 5) % -5;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloEqualNeg);
|
|
||||||
|
|
||||||
function opaqueModuloLargerNeg(a)
|
|
||||||
{
|
|
||||||
return (a % -13) % 5;
|
|
||||||
}
|
|
||||||
noInline(opaqueModuloLargerNeg);
|
|
||||||
|
|
||||||
let testReducibleCases = [opaqueModuloSmaller, opaqueModuloEqual, opaqueModuloSmallerNeg, opaqueModuloEqualNeg];
|
|
||||||
let testOtherCases = [opaqueModuloLarger, opaqueModuloLargerNeg];
|
|
||||||
|
|
||||||
function opaqueExpectedOther(doubleInput)
|
|
||||||
{
|
|
||||||
return (doubleInput - 2147483648) % 13.0 % 5.0;
|
|
||||||
}
|
|
||||||
noInline(opaqueExpectedOther);
|
|
||||||
noDFG(opaqueExpectedOther);
|
|
||||||
|
|
||||||
// Warm up with integers. The test for NegZero should not be eliminated here.
|
|
||||||
for (let i = 1; i < 1e4; ++i) {
|
|
||||||
let excpectedReduced = i % 5;
|
|
||||||
for (let testFunction of testReducibleCases) {
|
|
||||||
let result = testFunction(i);
|
|
||||||
if (result !== excpectedReduced)
|
|
||||||
throw "" + testFunction.name + "(i), returned: " + result + " at i = " + i + " expected " + expectedOther;
|
|
||||||
}
|
|
||||||
let expectedOther = opaqueExpectedOther(i + 2147483648);
|
|
||||||
for (let testFunction of testOtherCases) {
|
|
||||||
let result = testFunction(i);
|
|
||||||
if (result !== expectedOther)
|
|
||||||
throw "" + testFunction.name + "(i), returned: " + result + " at i = " + i + " expected " + expectedOther;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,222 +0,0 @@
|
|||||||
// Test value * 1.
|
|
||||||
function arithMulIdentityWrittenAsInteger(x) {
|
|
||||||
var a = x * 1;
|
|
||||||
var b = 1 * x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithMulIdentityWrittenAsInteger, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithMulIdentityWrittenAsInteger);
|
|
||||||
|
|
||||||
function testArithMulIdentityWrittenAsInteger() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(i);
|
|
||||||
if (result !== i) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(i) = " + result + ", expected " + i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(-0) = " + result + ", expected -0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var testValue = i + .5;
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(testValue);
|
|
||||||
if (result !== testValue) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(i) = " + result + ", expected " + testValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsInteger(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithMulIdentityWrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithMulIdentityWrittenAsInteger();
|
|
||||||
|
|
||||||
|
|
||||||
function arithMulIdentityWrittenAsDouble(x) {
|
|
||||||
var a = x * 1.0;
|
|
||||||
var b = 1. * x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithMulIdentityWrittenAsDouble, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithMulIdentityWrittenAsDouble);
|
|
||||||
|
|
||||||
function testArithMulIdentityWrittenAsDouble() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(i);
|
|
||||||
if (result !== i) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(i) = " + result + ", expected " + i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(-0) = " + result + ", expected -0 ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var testValue = i + .5;
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(testValue);
|
|
||||||
if (result !== testValue) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(i) = " + result + ", expected " + testValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMulIdentityWrittenAsDouble(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithMulIdentityWrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithMulIdentityWrittenAsDouble();
|
|
||||||
|
|
||||||
|
|
||||||
// Test "value * 42".
|
|
||||||
function arithMul42WrittenAsInteger(x) {
|
|
||||||
var a = x * 42;
|
|
||||||
var b = 42 * x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithMul42WrittenAsInteger, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithMul42WrittenAsInteger);
|
|
||||||
|
|
||||||
function testArithMul42WrittenAsInteger() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsInteger(13);
|
|
||||||
if (result !== 546) {
|
|
||||||
throw "arithMul42WrittenAsInteger(13) = " + result + ", expected 546";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsInteger(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithMul42WrittenAsInteger(-0) = " + result + ", expected -0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsInteger(13.3);
|
|
||||||
if (result !== 558.6) {
|
|
||||||
throw "arithMul42WrittenAsInteger(13.3) = " + result + ", expected 558.6";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsInteger(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithMul42WrittenAsInteger(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsInteger(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithMul42WrittenAsInteger(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsInteger(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithMul42WrittenAsInteger(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithMul42WrittenAsInteger();
|
|
||||||
|
|
||||||
|
|
||||||
function arithMul42WrittenAsDouble(x) {
|
|
||||||
var a = x * 42.0;
|
|
||||||
var b = 42. * x;
|
|
||||||
if (!(isNaN(x) && isNaN(a) && isNaN(b)) && a !== b)
|
|
||||||
throw "Internal error on arithMul42WrittenAsDouble, a = " + a + " b = " + b;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
noInline(arithMul42WrittenAsDouble);
|
|
||||||
|
|
||||||
function testArithMul42WrittenAsDouble() {
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsDouble(13);
|
|
||||||
if (result !== 546) {
|
|
||||||
throw "arithMul42WrittenAsDouble(i) = " + result + ", expected 546";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsDouble(-0);
|
|
||||||
if (result !== -0) {
|
|
||||||
throw "arithMul42WrittenAsDouble(-0) = " + result + ", expected -0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
var result = arithMul42WrittenAsDouble(13.3);
|
|
||||||
if (result !== 558.6) {
|
|
||||||
throw "arithMul42WrittenAsDouble(13.3) = " + result + ", expected 558.6";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsDouble(NaN);
|
|
||||||
if (!isNaN(result)) {
|
|
||||||
throw "arithMul42WrittenAsDouble(NaN) = " + result + ", expected NaN";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsDouble(Infinity);
|
|
||||||
if (isFinite(result)) {
|
|
||||||
throw "arithMul42WrittenAsDouble(Infinity) = " + result + ", expected Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {;
|
|
||||||
var result = arithMul42WrittenAsDouble(-Infinity);
|
|
||||||
if (isFinite(result) || result >= 0) {
|
|
||||||
throw "arithMul42WrittenAsDouble(-Infinity) = " + result + ", expected -Infinity";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
testArithMul42WrittenAsDouble();
|
|
@ -1,373 +0,0 @@
|
|||||||
// This test that the DFG Abstract interpreter properly handles UntypedUse for various ArithXXX and CompareXXX nodes.
|
|
||||||
// This test should run without errors or crashing.
|
|
||||||
|
|
||||||
let errors = 0;
|
|
||||||
const smallValue = 2.3023e-320;
|
|
||||||
|
|
||||||
function test(functionName, testFunc) {
|
|
||||||
try{
|
|
||||||
var ary_1 = [1.1, 2.2, 3.3];
|
|
||||||
var ary_2 = ary_1;
|
|
||||||
var f64_1 = new Float64Array(0x10);
|
|
||||||
|
|
||||||
for (var i = 0; i < 200000; i++)
|
|
||||||
testFunc(ary_1, f64_1, '1');
|
|
||||||
|
|
||||||
testFunc(ary_2, f64_1, { toString:()=>{ ary_2[0] = {}; return "3"}});
|
|
||||||
if (ary_2[2] != smallValue)
|
|
||||||
throw functionName + " returned the wrong value";
|
|
||||||
} catch(e) {
|
|
||||||
errors++;
|
|
||||||
print("Exception testing " + functionName + ": " + e);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
for (let i = 0; i < 8; i++) {
|
|
||||||
test("Warmup", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.abs(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Unary -", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = -c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Unary +", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = +c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("+", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = a[1] + c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("-", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = a[1] - c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("*", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = a[1] * c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("/", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = a[1] / c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("%", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = a[1] % c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("**", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c ** a[1];
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prefix ++", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = ++c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("prefix --", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = --c;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("==", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c == 7;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("<", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c < 42;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("<=", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c <= 7;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test(">", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c > 3;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test(">=", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = c >= 12;
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.abs", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.abs(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.acos", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.acos(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.acosh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.acosh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.asin", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.asin(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.asinh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.asinh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.atan", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.atan(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.atan2", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.atan2(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.atanh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.atanh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.ceil", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.ceil(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.cos", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.cos(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.cosh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.cosh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.exp", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.exp(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.expm1", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.expm1(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.floor", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.floor(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.fround", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.fround(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.log", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.log(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.log1p", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.log1p(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.log10", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.log10(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.log2", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.log2(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.round", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.round(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.sin", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.sin(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.sign", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.sign(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.sinh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.sinh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.sqrt", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.sqrt(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.tan", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.tan(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.tanh", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.tanh(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Math.trunc", function(a, b, c){
|
|
||||||
a[0] = 1.1;
|
|
||||||
a[1] = 2.2;
|
|
||||||
var tmp = Math.trunc(c);
|
|
||||||
b[0] = a[0];
|
|
||||||
a[2] = smallValue;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if (errors)
|
|
||||||
throw "Failed " + errors + " tests."
|
|
@ -1,32 +0,0 @@
|
|||||||
function runNearStackLimit(f) {
|
|
||||||
try {
|
|
||||||
return t();
|
|
||||||
} catch (e) {
|
|
||||||
return f();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let flag = false;
|
|
||||||
function f1() {
|
|
||||||
return flag ? {} : 10;
|
|
||||||
}
|
|
||||||
noInline(f1);
|
|
||||||
|
|
||||||
function f2() {
|
|
||||||
}
|
|
||||||
|
|
||||||
function f3(arg) {
|
|
||||||
let r = -(arg ? f1() : f2());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; ++i) {
|
|
||||||
try {
|
|
||||||
f3(!!(i % 2));
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
flag = true;
|
|
||||||
for (let i = 0; i < 100000; ++i) try {
|
|
||||||
runNearStackLimit(() => {
|
|
||||||
return f3(!!(i % 2));
|
|
||||||
});
|
|
||||||
} catch (e) {}
|
|
@ -1,98 +0,0 @@
|
|||||||
let testCases = [
|
|
||||||
// Numbers
|
|
||||||
['1', 0, 0],
|
|
||||||
['1.5', 1 - 1.5, 1.5 - 1],
|
|
||||||
[NaN, NaN, NaN],
|
|
||||||
|
|
||||||
// Strings.
|
|
||||||
['""', 1, -1],
|
|
||||||
['new String()', 1, -1],
|
|
||||||
['"WebKit!"', NaN, NaN],
|
|
||||||
|
|
||||||
// Objects.
|
|
||||||
['{ }', NaN, NaN],
|
|
||||||
['{ foo: 1 }', NaN, NaN],
|
|
||||||
['{ toString: function() { return ""; } }', 1, -1],
|
|
||||||
['{ toString: function() { return "WebKit"; } }', NaN, NaN],
|
|
||||||
|
|
||||||
// Others.
|
|
||||||
['null', 1, -1],
|
|
||||||
['undefined', NaN, NaN]
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let testCase of testCases) {
|
|
||||||
let otherOperand = testCase[0];
|
|
||||||
let expectedLeftValue = testCase[1];
|
|
||||||
let expectedRightValue = testCase[2];
|
|
||||||
eval(
|
|
||||||
`// Those holes are not observable by arithmetic operation.
|
|
||||||
// The return value is always going to be NaN.
|
|
||||||
function nonObservableHoleOnLhs(array, otherValue) {
|
|
||||||
return array[0] - otherValue;
|
|
||||||
}
|
|
||||||
noInline(nonObservableHoleOnLhs);
|
|
||||||
|
|
||||||
function observableHoleOnLhs(array, otherValue) {
|
|
||||||
let value = array[0];
|
|
||||||
return [value - otherValue, value];
|
|
||||||
}
|
|
||||||
noInline(observableHoleOnLhs);
|
|
||||||
|
|
||||||
function nonObservableHoleOnRhs(array, otherValue) {
|
|
||||||
return otherValue - array[0];
|
|
||||||
}
|
|
||||||
noInline(nonObservableHoleOnRhs);
|
|
||||||
|
|
||||||
function observableHoleOnRhs(array, otherValue) {
|
|
||||||
let value = array[0];
|
|
||||||
return [otherValue - value, value];
|
|
||||||
}
|
|
||||||
noInline(observableHoleOnRhs);
|
|
||||||
|
|
||||||
let testArray = new Array;
|
|
||||||
for (let i = 1; i < 3; ++i) {
|
|
||||||
testArray[i] = i + 0.5
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
let lhsResult1 = nonObservableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (lhsResult1 == lhsResult1)
|
|
||||||
throw "Error on nonObservableHoleOnLhs at i = " + i;
|
|
||||||
let lhsResult2 = observableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (lhsResult2[0] == lhsResult2[0] || lhsResult2[1] !== undefined)
|
|
||||||
throw "Error on observableHoleOnLhs at i = " + i;
|
|
||||||
|
|
||||||
let rhsResult1 = nonObservableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (rhsResult1 == rhsResult1)
|
|
||||||
throw "Error on nonObservableHoleOnRhs at i = " + i;
|
|
||||||
let rhsResult2 = observableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (rhsResult2[0] == rhsResult2[0] || rhsResult2[1] !== undefined)
|
|
||||||
throw "Error on observableHoleOnRhs at i = " + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
let isEqual = function(a, b) {
|
|
||||||
if (a === a) {
|
|
||||||
return a === b;
|
|
||||||
}
|
|
||||||
return b !== b;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the hole, make sure everything still work correctly.
|
|
||||||
testArray[0] = 1.;
|
|
||||||
for (let i = 0; i < 1e4; ++i) {
|
|
||||||
let lhsResult1 = nonObservableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult1, ${expectedLeftValue}))
|
|
||||||
throw "Error on non hole nonObservableHoleOnLhs at i = " + i + " expected " + ${expectedLeftValue} + " got " + lhsResult1;
|
|
||||||
let lhsResult2 = observableHoleOnLhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(lhsResult2[0], ${expectedLeftValue}) || lhsResult2[1] !== 1)
|
|
||||||
throw "Error on non hole observableHoleOnLhs at i = " + i + " expected " + ${expectedLeftValue} + " got " + lhsResult2[0];
|
|
||||||
|
|
||||||
let rhsResult1 = nonObservableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult1, ${expectedRightValue}))
|
|
||||||
throw "Error on non hole nonObservableHoleOnRhs at i = " + i + " expected " + ${expectedRightValue} + " got " + rhsResult1;
|
|
||||||
let rhsResult2 = observableHoleOnRhs(testArray, ${otherOperand});
|
|
||||||
if (!isEqual(rhsResult2[0], ${expectedRightValue}) || rhsResult2[1] !== 1)
|
|
||||||
throw "Error on non hole observableHoleOnRhs at i = " + i;
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
// Require lots of arguments so that arity fixup will need a lot of stack, making
|
|
||||||
// it prone to stack overflow.
|
|
||||||
var script = "recursionCount, ";
|
|
||||||
for (var i = 0; i < 5000; ++i)
|
|
||||||
script += "dummy, "
|
|
||||||
script += "dummy";
|
|
||||||
var g = new Function(script, "return recursionCount ? g(recursionCount - 1) : 0;"); // Ensure that arguments are observed.
|
|
||||||
|
|
||||||
noInline(g);
|
|
||||||
|
|
||||||
// Ensure that f and g get optimized.
|
|
||||||
for (var i = 0; i < 10000; ++i) {
|
|
||||||
// Recurse once to ensure profiling along all control flow paths.
|
|
||||||
g(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Recurse enough times to trigger a stack overflow exception.
|
|
||||||
g(1000000);
|
|
||||||
} catch(e) {
|
|
||||||
if (! (e instanceof RangeError))
|
|
||||||
throw "bad value for e";
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
// Require lots of arguments so that arity fixup will need a lot of stack, making
|
|
||||||
// it prone to stack overflow.
|
|
||||||
var script = "";
|
|
||||||
for (var i = 0; i < 128; ++i)
|
|
||||||
script += "dummy, "
|
|
||||||
script += "dummy";
|
|
||||||
var g = new Function(script, "return arguments;"); // Ensure that arguments are observed.
|
|
||||||
|
|
||||||
function f(recursionCount)
|
|
||||||
{
|
|
||||||
if (!recursionCount)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Use too few arguments to force arity fixup.
|
|
||||||
g();
|
|
||||||
|
|
||||||
f(--recursionCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(g);
|
|
||||||
noInline(f);
|
|
||||||
|
|
||||||
// Ensure that f and g get optimized.
|
|
||||||
for (var i = 0; i < 1000000; ++i) {
|
|
||||||
// Recurse once to ensure profiling along all control flow paths.
|
|
||||||
f(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Recurse enough times to trigger a stack overflow exception.
|
|
||||||
f(1000000);
|
|
||||||
} catch(e) {
|
|
||||||
if (! (e instanceof RangeError))
|
|
||||||
throw "bad value for e";
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
function baz() { }
|
|
||||||
noInline(baz);
|
|
||||||
|
|
||||||
function bar(x, y, z) {
|
|
||||||
baz(z);
|
|
||||||
return x + y + 20.2;
|
|
||||||
}
|
|
||||||
function foo(x, b) {
|
|
||||||
let y = x + 10.54;
|
|
||||||
let z = y;
|
|
||||||
if (b) {
|
|
||||||
y += 1.23;
|
|
||||||
z += 2.199;
|
|
||||||
} else {
|
|
||||||
y += 2.27;
|
|
||||||
z += 2.18;
|
|
||||||
}
|
|
||||||
|
|
||||||
let r = bar(b ? y : z, !b ? y : z);
|
|
||||||
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (let i = 0; i < 1000; ++i)
|
|
||||||
foo(i+0.5, !!(i%2));
|
|
@ -1,3 +0,0 @@
|
|||||||
var args = "y,".repeat(30000);
|
|
||||||
var g = Function(args, "return 0");
|
|
||||||
g();
|
|
@ -1,50 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function test1(arg1, arg2, arg3)
|
|
||||||
{
|
|
||||||
return arguments.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test()
|
|
||||||
{
|
|
||||||
shouldBe(test1(), 0);
|
|
||||||
shouldBe(test1(0), 1);
|
|
||||||
shouldBe(test1(0, 1), 2);
|
|
||||||
shouldBe(test1(0, 1, 2), 3);
|
|
||||||
shouldBe(test1(0, 1, 2, 3), 4);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i)
|
|
||||||
test();
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function test1(flag, arg1, arg2, arg3)
|
|
||||||
{
|
|
||||||
if (flag)
|
|
||||||
OSRExit();
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test(flag)
|
|
||||||
{
|
|
||||||
shouldBe(test1(flag).length, 1);
|
|
||||||
shouldBe(test1(flag, 0).length, 2);
|
|
||||||
shouldBe(test1(flag, 0, 1).length, 3);
|
|
||||||
shouldBe(test1(flag, 0, 1, 2).length, 4);
|
|
||||||
shouldBe(test1(flag, 0, 1, 2, 3).length, 5);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
for (var i = 0; i < 1e5; ++i)
|
|
||||||
test(false);
|
|
||||||
|
|
||||||
test(true);
|
|
||||||
test(true);
|
|
||||||
test(true);
|
|
||||||
}());
|
|
@ -1,17 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function inlineTarget(arg1, arg2)
|
|
||||||
{
|
|
||||||
return [arg1, arg2];
|
|
||||||
}
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(null)), `[null,null]`);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
for (var i = 0; i < 3e4; ++i)
|
|
||||||
test();
|
|
@ -1,24 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function inlineTarget(arg1, arg2, arg3, arg4, arg5)
|
|
||||||
{
|
|
||||||
return [arg1, arg2, arg3, arg4, arg5];
|
|
||||||
}
|
|
||||||
|
|
||||||
function test() {
|
|
||||||
shouldBe(JSON.stringify(inlineTarget()), `[null,null,null,null,null]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42)), `[42,null,null,null,null]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43)), `[42,43,null,null,null]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43, 44)), `[42,43,44,null,null]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45)), `[42,43,44,45,null]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46)), `[42,43,44,45,46]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46, 47)), `[42,43,44,45,46]`);
|
|
||||||
shouldBe(JSON.stringify(inlineTarget(42, 43, 44, 45, 46, 47, 48)), `[42,43,44,45,46]`);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
for (var i = 0; i < 3e4; ++i)
|
|
||||||
test();
|
|
@ -1,65 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function test2(...rest)
|
|
||||||
{
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test1(arg1, arg2, arg3)
|
|
||||||
{
|
|
||||||
return test2(arg1, arg2, arg3);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test()
|
|
||||||
{
|
|
||||||
var result = test1();
|
|
||||||
shouldBe(result.length, 3);
|
|
||||||
shouldBe(result[0], undefined);
|
|
||||||
shouldBe(result[1], undefined);
|
|
||||||
shouldBe(result[2], undefined);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i)
|
|
||||||
test();
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function test1(...rest)
|
|
||||||
{
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
|
|
||||||
function test()
|
|
||||||
{
|
|
||||||
var result = test1();
|
|
||||||
shouldBe(result.length, 0);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i)
|
|
||||||
test();
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function test1(...rest)
|
|
||||||
{
|
|
||||||
return rest;
|
|
||||||
}
|
|
||||||
noInline(test1);
|
|
||||||
|
|
||||||
function test()
|
|
||||||
{
|
|
||||||
var result = test1();
|
|
||||||
shouldBe(result.length, 0);
|
|
||||||
}
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i)
|
|
||||||
test();
|
|
||||||
}());
|
|
@ -1,66 +0,0 @@
|
|||||||
//@ skip
|
|
||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error(`bad value: ${String(actual)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorMessage)
|
|
||||||
{
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (String(error) !== errorMessage)
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let arrayBuffer = new ArrayBuffer(42);
|
|
||||||
let sharedArrayBuffer = new SharedArrayBuffer(500);
|
|
||||||
shouldBe(arrayBuffer.byteLength, 42);
|
|
||||||
shouldBe(sharedArrayBuffer.byteLength, 500);
|
|
||||||
shouldBe(ArrayBuffer.prototype.hasOwnProperty('byteLength'), true);
|
|
||||||
shouldBe(SharedArrayBuffer.prototype.hasOwnProperty('byteLength'), true);
|
|
||||||
|
|
||||||
shouldBe(arrayBuffer.hasOwnProperty('byteLength'), false);
|
|
||||||
shouldBe(sharedArrayBuffer.hasOwnProperty('byteLength'), false);
|
|
||||||
|
|
||||||
shouldBe(!!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get, true);
|
|
||||||
shouldBe(!!Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get, true);
|
|
||||||
|
|
||||||
shouldBe(!!Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').set, false);
|
|
||||||
shouldBe(!!Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').set, false);
|
|
||||||
|
|
||||||
shouldBe(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get !== Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get, true);
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(sharedArrayBuffer);
|
|
||||||
}, `TypeError: Receiver should not be a shared array buffer`);
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(arrayBuffer);
|
|
||||||
}, `TypeError: Receiver should be a shared array buffer`);
|
|
||||||
|
|
||||||
for (let value of [ 0, true, "Cocoa", null, undefined, Symbol("Cappuccino") ]) {
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(value);
|
|
||||||
}, `TypeError: Receiver should be an array buffer but was not an object`);
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(value);
|
|
||||||
}, `TypeError: Receiver should be an array buffer but was not an object`);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call({});
|
|
||||||
}, `TypeError: Receiver should be an array buffer`);
|
|
||||||
shouldThrow(() => {
|
|
||||||
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call({});
|
|
||||||
}, `TypeError: Receiver should be an array buffer`);
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
// This file tests is concat spreadable when taking the fast path
|
|
||||||
// (single argument, JSArray receiver)
|
|
||||||
|
|
||||||
function arrayEq(a, b) {
|
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
let array = [1,2,3];
|
|
||||||
let {proxy:p, revoke} = Proxy.revocable([4, 5], {});
|
|
||||||
|
|
||||||
// Test it works with proxies by default
|
|
||||||
for (let i = 0; i < 10000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(array, p), [1,2,3,4,5]))
|
|
||||||
throw "failed normally with a proxy"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test it works with spreadable false.
|
|
||||||
p[Symbol.isConcatSpreadable] = false;
|
|
||||||
for (let i = 0; i < 10000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(array,p), [1,2,3,p]))
|
|
||||||
throw "failed with no spread"
|
|
||||||
}
|
|
||||||
|
|
||||||
p[Symbol.isConcatSpreadable] = undefined;
|
|
||||||
revoke();
|
|
||||||
passed = true;
|
|
||||||
try {
|
|
||||||
Array.prototype.concat.call(array,p);
|
|
||||||
passed = false;
|
|
||||||
} catch (e) { }
|
|
||||||
if (!passed)
|
|
||||||
throw "failed to throw spreading revoked proxy";
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
//@ runFTLNoCJIT
|
|
||||||
|
|
||||||
let totalFailed = 0;
|
|
||||||
|
|
||||||
function shouldEqual(testId, actual, expected) {
|
|
||||||
if (actual != expected) {
|
|
||||||
throw testId + ": ERROR: expect " + expected + ", actual " + actual;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeArray() {
|
|
||||||
return ['unmodifiable'];
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeArrayLikeObject() {
|
|
||||||
var obj = {};
|
|
||||||
obj[0] = 'unmodifiable';
|
|
||||||
obj.length = 1;
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
function emptyArraySourceMaker() {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
function singleElementArraySourceMaker() {
|
|
||||||
return ['modified_1'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make test functions with unique codeblocks.
|
|
||||||
function makeConcatTest(testId) {
|
|
||||||
return new Function("arr", "return arr.concat(['" + testId + "'])");
|
|
||||||
}
|
|
||||||
function makeConcatOnHoleyArrayTest(testId) {
|
|
||||||
return new Function("arr", "var other = ['" + testId + "']; other[1000] = '" + testId + "'; return arr.concat(other);");
|
|
||||||
}
|
|
||||||
|
|
||||||
let numIterations = 10000;
|
|
||||||
|
|
||||||
function runTest(testId, testMaker, targetMaker, sourceMaker, expectedValue, expectedException) {
|
|
||||||
var test = testMaker(testId);
|
|
||||||
noInline(test);
|
|
||||||
|
|
||||||
for (var i = 0; i < numIterations; i++) {
|
|
||||||
var exception = undefined;
|
|
||||||
|
|
||||||
var obj = targetMaker();
|
|
||||||
obj = Object.freeze(obj);
|
|
||||||
|
|
||||||
var arr = sourceMaker();
|
|
||||||
arr.constructor = { [Symbol.species]: function() { return obj; } };
|
|
||||||
|
|
||||||
try {
|
|
||||||
test(arr);
|
|
||||||
} catch (e) {
|
|
||||||
exception = "" + e;
|
|
||||||
exception = exception.substr(0, 10); // Search for "TypeError:".
|
|
||||||
}
|
|
||||||
shouldEqual(testId, exception, expectedException);
|
|
||||||
shouldEqual(testId, obj[0], expectedValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
runTest(10010, makeConcatTest, makeArray, emptyArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10011, makeConcatTest, makeArray, singleElementArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10020, makeConcatTest, makeArrayLikeObject, emptyArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10021, makeConcatTest, makeArrayLikeObject, singleElementArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
|
|
||||||
runTest(10110, makeConcatOnHoleyArrayTest, makeArray, emptyArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10111, makeConcatOnHoleyArrayTest, makeArray, singleElementArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10120, makeConcatOnHoleyArrayTest, makeArrayLikeObject, emptyArraySourceMaker, "unmodifiable", "TypeError:");
|
|
||||||
runTest(10121, makeConcatOnHoleyArrayTest, makeArrayLikeObject, singleElementArraySourceMaker, "unmodifiable", "TypeError:");
|
|
@ -1,48 +0,0 @@
|
|||||||
// This file tests is concat spreadable.
|
|
||||||
|
|
||||||
function arrayEq(a, b) {
|
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
let o = {0:1, 1:2, 2:3, length:3};
|
|
||||||
|
|
||||||
// Test it works with proxies by default
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(o,o), [o,o]))
|
|
||||||
throw "failed normally with an object"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test it works with spreadable true
|
|
||||||
o[Symbol.isConcatSpreadable] = true;
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
let result = Array.prototype.concat.call(o,o)
|
|
||||||
if (!arrayEq(result, [1,2,3,1,2,3]))
|
|
||||||
throw "failed with spread got: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test it works with many things
|
|
||||||
o[Symbol.isConcatSpreadable] = true;
|
|
||||||
let other = {}
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
let result = Array.prototype.concat.call(o,o,true,[1,2],other)
|
|
||||||
if (!arrayEq(result, [1,2,3,1,2,3,true,1,2,other]))
|
|
||||||
throw "failed with spread got: " + result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test it works with strings
|
|
||||||
String.prototype[Symbol.isConcatSpreadable] = true;
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
let result = Array.prototype.concat.call("hi","hi")
|
|
||||||
// This is what the spec says is the correct answer... D:
|
|
||||||
if (!arrayEq(result, ["h", "i", "hi"]))
|
|
||||||
throw "failed with string got: " + result + " on iteration " + i;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
function arrayEq(a, b) {
|
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let concat = Array.prototype.concat;
|
|
||||||
noInline(concat);
|
|
||||||
let array = [1, 2, 3];
|
|
||||||
let {proxy:p, revoke} = Proxy.revocable(array, { get : function(o, k) { return o[k]; } });
|
|
||||||
|
|
||||||
concat.call(p,p);
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(concat.call(p,p), [1,2,3,1,2,3]))
|
|
||||||
throw "bad";
|
|
||||||
}
|
|
||||||
revoke();
|
|
||||||
failed = true;
|
|
||||||
try {
|
|
||||||
concat.call(p,p);
|
|
||||||
} catch (e) {
|
|
||||||
failed = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (failed)
|
|
||||||
throw "bad"
|
|
||||||
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
// This file tests is concat spreadable.
|
|
||||||
|
|
||||||
function arrayEq(a, b) {
|
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
let array = [1,2,3];
|
|
||||||
let {proxy:p, revoke} = Proxy.revocable(array, { get : function(o, k) { return o[k]; } });
|
|
||||||
|
|
||||||
// Test it works with proxies by default
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(p,p), [1,2,3,1,2,3]))
|
|
||||||
throw "failed normally with a proxy"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test it works with spreadable false.
|
|
||||||
p[Symbol.isConcatSpreadable] = false;
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(p,p), [p,p]))
|
|
||||||
throw "failed with no spread"
|
|
||||||
}
|
|
||||||
|
|
||||||
p[Symbol.isConcatSpreadable] = undefined;
|
|
||||||
revoke();
|
|
||||||
passed = true;
|
|
||||||
try {
|
|
||||||
Array.prototype.concat.call(p,[]);
|
|
||||||
passed = false;
|
|
||||||
} catch (e) { }
|
|
||||||
if (!passed)
|
|
||||||
throw "failed to throw spreading revoked proxy";
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
function arrayEq(a, b) {
|
|
||||||
if (a.length !== b.length)
|
|
||||||
return false;
|
|
||||||
for (let i = 0; i < a.length; i++) {
|
|
||||||
if (a[i] !== b[i])
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
array = [1,2];
|
|
||||||
Object.defineProperty(array, 2, { get: () => { return 1; } });
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(array,array), [1,2,1,1,2,1]))
|
|
||||||
throw "failed normally with a getter"
|
|
||||||
if (!arrayEq(Array.prototype.concat.call([],array), [1,2,1]))
|
|
||||||
throw "failed with undecided and a getter"
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test with indexed types on prototype.
|
|
||||||
array = [1,2];
|
|
||||||
array.length = 3;
|
|
||||||
Array.prototype[2] = 1;
|
|
||||||
|
|
||||||
for (let i = 0; i < 100000; i++) {
|
|
||||||
if (!arrayEq(Array.prototype.concat.call(array,array), [1,2,1,1,2,1]))
|
|
||||||
throw "failed normally with an indexed prototype"
|
|
||||||
if (!arrayEq(Array.prototype.concat.call([],array), [1,2,1]))
|
|
||||||
throw "failed with undecided and an indexed prototype"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
var o = {};
|
|
||||||
o.__defineSetter__("foo", Array);
|
|
||||||
|
|
||||||
function foo()
|
|
||||||
{
|
|
||||||
o.foo = 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
noInline(foo);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
foo();
|
|
||||||
|
|
@ -1,281 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldBeArray(actual, expected) {
|
|
||||||
shouldBe(actual.length, expected.length);
|
|
||||||
for (var i = 0; i < expected.length; ++i) {
|
|
||||||
try {
|
|
||||||
shouldBe(actual[i], expected[i]);
|
|
||||||
} catch(e) {
|
|
||||||
print(JSON.stringify(actual));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorMessage) {
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (String(error) !== errorMessage)
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldBe([].copyWithin.name, 'copyWithin');
|
|
||||||
shouldBe([].copyWithin.length, 2);
|
|
||||||
shouldBe(Array.prototype.hasOwnProperty('copyWithin'), true);
|
|
||||||
shouldBe(JSON.stringify(Object.getOwnPropertyDescriptor(Array.prototype, 'copyWithin')), '{"writable":true,"enumerable":false,"configurable":true}');
|
|
||||||
|
|
||||||
// 0 arguments. (it is equivalent to copyWithin(0))
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([].copyWithin(), []);
|
|
||||||
|
|
||||||
// 1 arguments.
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-4), [1, 1, 2, 3, 4]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-2), [1, 2, 3, 1, 2]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-1), [1, 2, 3, 4, 1]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1), [1, 1, 2, 3, 4]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(2), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(3), [1, 2, 3, 1, 2]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(4), [1, 2, 3, 4, 1]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(6), [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
// 2 arguments.
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 0), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1), [2, 3, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 2), [3, 4, 5, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 3), [4, 5, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 4), [5, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 6), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1, 3), [1, 4, 5, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(2, 3), [1, 2, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(3, 3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(4, 3), [1, 2, 3, 4, 4]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(5, 3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(6, 3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-1, -2), [1, 2, 3, 4, 4]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-1, -3), [1, 2, 3, 4, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -3), [3, 4, 5, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -8), [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
// 3 arguments.
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 3, 4), [4, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 0, 5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 2), [2, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 3), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 4), [2, 3, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 5), [2, 3, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 1, 6), [2, 3, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(2, 1, 3), [1, 2, 2, 3, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(6, 1, 3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -0, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 0, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -2, -1), [4, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -3, -1), [3, 4, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -4, -1), [2, 3, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -5, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -6, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, 0, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -3, -2), [3, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -4, -2), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -5, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -6, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -0, -1), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, 0, -1), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -1), [1, 2, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -3, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -4, -1), [1, 2, 2, 3, 4]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -5, -1), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -6, -1), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, 0, -2), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -3, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -4, -2), [1, 2, 2, 3, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -5, -2), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -6, -2), [1, 2, 1, 2, 3]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -4), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(0, -1, -6), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -4), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-3, -2, -5), [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -0, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 0, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 0, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 0, 5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 2), [2, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 3), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 4), [2, 3, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 5), [2, 3, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 6), [2, 3, 4, 5, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 3), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 1, 3), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, 3, 4), [4, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -1), [4, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -3, -1), [3, 4, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -4, -1), [2, 3, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -5, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -6, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -3, -2), [3, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -4, -2), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -5, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -6, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -1), [4, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -3, -1), [3, 4, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -4, -1), [2, 3, 4, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -5, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -6, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -3, -2), [3, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -4, -2), [2, 3, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -5, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -6, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -1), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -4), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -5), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -1, -6), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -2), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -3), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -4), [1, 2, 3, 4, 5]);
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-6, -2, -5), [1, 2, 3, 4, 5]);
|
|
||||||
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(NaN, 1), [1, 2, 3, 4, 5].copyWithin(0, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(NaN, NaN, 1), [1, 2, 3, 4, 5].copyWithin(0, 0, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(NaN, NaN, NaN), [1, 2, 3, 4, 5].copyWithin(0, 0, 0));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(Infinity, 0, 1), [1, 2, 3, 4, 5].copyWithin(5, 0, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(Infinity, Infinity, 1), [1, 2, 3, 4, 5].copyWithin(5, 5, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1, Infinity, 1), [1, 2, 3, 4, 5].copyWithin(1, 5, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1, -Infinity, 1), [1, 2, 3, 4, 5].copyWithin(1, 0, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(-Infinity, 0, 1), [1, 2, 3, 4, 5].copyWithin(0, 0, 1));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1, 0, Infinity), [1, 2, 3, 4, 5].copyWithin(1, 0, 5));
|
|
||||||
shouldBeArray([1, 2, 3, 4, 5].copyWithin(1, 0, -Infinity), [1, 2, 3, 4, 5].copyWithin(1, 0, 0));
|
|
||||||
|
|
||||||
var copyWithin = Array.prototype.copyWithin;
|
|
||||||
|
|
||||||
function arrayToObject(array) {
|
|
||||||
var object = {};
|
|
||||||
for (var [key, value] of array.entries()) {
|
|
||||||
object[key] = value;
|
|
||||||
}
|
|
||||||
object.length = array.length;
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
object.length = -Infinity;
|
|
||||||
shouldBeArray(copyWithin.call(object, 1), { length: -Infinity });
|
|
||||||
shouldBe(JSON.stringify(copyWithin.call(object, 1)), '{"0":1,"1":2,"2":3,"3":4,"4":5,"length":null}');
|
|
||||||
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
object.length = -Infinity;
|
|
||||||
shouldBe(JSON.stringify(copyWithin.call(object, 1)), '{"0":1,"1":2,"2":3,"3":4,"4":5,"length":null}');
|
|
||||||
|
|
||||||
var array = [1, 2, 3, 4, 5];
|
|
||||||
var same = array.copyWithin(0, 3);
|
|
||||||
shouldBeArray(same, [4, 5, 3, 4, 5]);
|
|
||||||
shouldBeArray(array, [4, 5, 3, 4, 5]);
|
|
||||||
shouldBe(same, array);
|
|
||||||
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5, 3: 1}, 0, 3)), '{"0":1,"3":1,"length":5}');
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call(new Int32Array([1, 2, 3, 4, 5]), 0, 3, 4)), '{"0":4,"1":2,"2":3,"3":4,"4":5}');
|
|
||||||
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5.5, 3: 1}, 0, 3)), '{"0":1,"3":1,"length":5.5}');
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5.5, 3: 1}, 0.1, 3)), '{"0":1,"3":1,"length":5.5}');
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5.5, 3: 1}, 0.1, 3.3)), '{"0":1,"3":1,"length":5.5}');
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5.5, 3: 1}, 0.1, 3.8)), '{"0":1,"3":1,"length":5.5}');
|
|
||||||
shouldBe(JSON.stringify([].copyWithin.call({length: 5.5, 3: 1}, 0.1, 4.1)), '{"3":1,"length":5.5}');
|
|
||||||
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
delete object[2];
|
|
||||||
delete object[3];
|
|
||||||
delete object[4];
|
|
||||||
var result = copyWithin.call(object, 0, 3, 5);
|
|
||||||
shouldBe(JSON.stringify(result), '{"length":5}');
|
|
||||||
|
|
||||||
// 'copyWithin' in Array's @unscopables
|
|
||||||
(function () {
|
|
||||||
var array = [];
|
|
||||||
var copyWithin = 42;
|
|
||||||
var forEach = 42;
|
|
||||||
with (array) {
|
|
||||||
shouldBe(copyWithin, 42);
|
|
||||||
shouldBe(forEach, [].forEach);
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
Array.prototype.copyWithin.call(undefined);
|
|
||||||
}, 'TypeError: Array.prototype.copyWithin requires that |this| not be null or undefined');
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
Array.prototype.copyWithin.call(null);
|
|
||||||
}, 'TypeError: Array.prototype.copyWithin requires that |this| not be null or undefined');
|
|
||||||
|
|
||||||
|
|
||||||
function valueOf(code) {
|
|
||||||
return {
|
|
||||||
valueOf() {
|
|
||||||
throw new Error(code);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
object.length = valueOf(0);
|
|
||||||
copyWithin.call(object, valueOf(1), valueOf(2), valueOf(3));
|
|
||||||
}, 'Error: 0');
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
copyWithin.call(object, valueOf(1), valueOf(2), valueOf(3));
|
|
||||||
}, 'Error: 1');
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
copyWithin.call(object, 0, valueOf(2), valueOf(3));
|
|
||||||
}, 'Error: 2');
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
copyWithin.call(object, 0, 1, valueOf(3));
|
|
||||||
}, 'Error: 3');
|
|
||||||
|
|
||||||
shouldThrow(function () {
|
|
||||||
var object = arrayToObject([1, 2, 3, 4, 5]);
|
|
||||||
Object.freeze(object);
|
|
||||||
copyWithin.call(object, 0, 1, 2);
|
|
||||||
}, 'TypeError: Attempted to assign to readonly property.');
|
|
@ -1,44 +0,0 @@
|
|||||||
function shouldThrow(func, message) {
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!error)
|
|
||||||
throw new Error("not thrown.");
|
|
||||||
if (String(error) !== message)
|
|
||||||
throw new Error("bad error: " + String(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = new Array(10);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
(function (index) {
|
|
||||||
var seenOnce = false;
|
|
||||||
var storage = null;
|
|
||||||
Object.defineProperty(Array.prototype, index, {
|
|
||||||
get() {
|
|
||||||
throw new Error('get is called.' + index);
|
|
||||||
return storage;
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
if (seenOnce)
|
|
||||||
throw new Error('set is called.' + index);
|
|
||||||
seenOnce = true;
|
|
||||||
storage = value;
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
// No error, but all seenOnce becomes true.
|
|
||||||
array.fill(42);
|
|
||||||
|
|
||||||
// Ensures that all setter is called once.
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
shouldThrow(function () {
|
|
||||||
array[i] = i;
|
|
||||||
}, "Error: set is called." + i);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
Object.defineProperty(Array.prototype, i, {
|
|
||||||
get() {
|
|
||||||
throw new Error('get is called.');
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
throw new Error('set is called.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var original = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
||||||
|
|
||||||
// Doesn't throw any errors.
|
|
||||||
var filtered = original.filter(function (value, index) {
|
|
||||||
return index % 2 == 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
shouldBe(filtered.length, 5);
|
|
||||||
for (var i = 0; i < 5; ++i) {
|
|
||||||
shouldBe(filtered[i], i * 2);
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, message) {
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!error)
|
|
||||||
throw new Error("not thrown.");
|
|
||||||
if (String(error) !== message)
|
|
||||||
throw new Error("bad error: " + String(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = new Array(10);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
(function (index) {
|
|
||||||
var seenOnce = false;
|
|
||||||
Object.defineProperty(array, index, {
|
|
||||||
get() {
|
|
||||||
if (seenOnce)
|
|
||||||
throw new Error('get is called.' + index);
|
|
||||||
seenOnce = true;
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldBe(array.length, 10);
|
|
||||||
|
|
||||||
// Doesn't throw any errors.
|
|
||||||
var findValue = array.find(function (value) {
|
|
||||||
return value === 9;
|
|
||||||
});
|
|
||||||
shouldBe(findValue, 9);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
shouldThrow(function () {
|
|
||||||
var value = array[i];
|
|
||||||
}, "Error: get is called." + i);
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldBeArray(actual, expected) {
|
|
||||||
shouldBe(actual.length, expected.length);
|
|
||||||
for (var i = 0; i < expected.length; ++i) {
|
|
||||||
try {
|
|
||||||
if (Array.isArray(expected[i])) {
|
|
||||||
shouldBe(Array.isArray(actual[i]), true);
|
|
||||||
shouldBeArray(actual[i], expected[i]);
|
|
||||||
} else
|
|
||||||
shouldBe(actual[i], expected[i]);
|
|
||||||
} catch(e) {
|
|
||||||
print(JSON.stringify(actual));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorMessage) {
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (String(error) !== errorMessage)
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
[].flatMap();
|
|
||||||
}, `TypeError: Array.prototype.flatMap callback must be a function`);
|
|
||||||
|
|
||||||
var array = [42];
|
|
||||||
shouldBeArray(array.flatMap(function (v) {
|
|
||||||
"use strict";
|
|
||||||
shouldBe(v, 42);
|
|
||||||
return this;
|
|
||||||
}, `Cocoa`), [`Cocoa`]);
|
|
||||||
|
|
||||||
shouldBeArray([].flatMap((v) => v), []);
|
|
||||||
shouldBeArray([42].flatMap((v) => v), [42]);
|
|
||||||
shouldBeArray([42].flatMap((v) => [v]), [42]);
|
|
||||||
shouldBeArray([42].flatMap((v) => [[v]]), [[42]]);
|
|
||||||
shouldBeArray([42].flatMap((v) => [v, v, v]), [42,42,42]);
|
|
||||||
shouldBeArray([42,[43],44].flatMap((v) => [v, v]), [42,42,[43],[43],44,44]);
|
|
||||||
shouldBeArray([,,,,,,].flatMap((v) => [v, v]), []);
|
|
||||||
shouldBeArray([42,43,44].flatMap((v) => []), []);
|
|
||||||
shouldBeArray([42,[43],44].flatMap((v) => v), [42,43,44]);
|
|
||||||
|
|
||||||
class DerivedArray extends Array { }
|
|
||||||
shouldBe((new DerivedArray).flatMap(() => {}) instanceof DerivedArray, true);
|
|
||||||
var flatMap = [].flatMap;
|
|
||||||
var realm = createGlobalObject();
|
|
||||||
shouldBe(flatMap.call({}, () => {}) instanceof Array, true);
|
|
||||||
shouldBe(flatMap.call(new realm.Array, () => {}) instanceof Array, true);
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = 0;
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
flatMap.call(array2, () => {});
|
|
||||||
}, `TypeError: 0 is not a constructor`);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = undefined;
|
|
||||||
shouldBe(flatMap.call(array2, () => {}) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flatMap.call(array2, () => {}) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flatMap.call(array2, () => {}) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return DerivedArray;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flatMap.call(array2, () => {}) instanceof DerivedArray, true);
|
|
@ -1,108 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldBeArray(actual, expected) {
|
|
||||||
shouldBe(actual.length, expected.length);
|
|
||||||
for (var i = 0; i < expected.length; ++i) {
|
|
||||||
try {
|
|
||||||
if (Array.isArray(expected[i])) {
|
|
||||||
shouldBe(Array.isArray(actual[i]), true);
|
|
||||||
shouldBeArray(actual[i], expected[i]);
|
|
||||||
} else
|
|
||||||
shouldBe(actual[i], expected[i]);
|
|
||||||
} catch(e) {
|
|
||||||
print(JSON.stringify(actual));
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, errorMessage) {
|
|
||||||
var errorThrown = false;
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
errorThrown = true;
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!errorThrown)
|
|
||||||
throw new Error('not thrown');
|
|
||||||
if (String(error) !== errorMessage)
|
|
||||||
throw new Error(`bad error: ${String(error)}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldBe([].flat.length, 0);
|
|
||||||
shouldBe([].flat.name, `flat`);
|
|
||||||
|
|
||||||
shouldBeArray([].flat(), []);
|
|
||||||
shouldBeArray([0, 1, 2, 3, , 4].flat(), [0, 1, 2, 3, 4]);
|
|
||||||
shouldBeArray([,,,,,].flat(), []);
|
|
||||||
|
|
||||||
shouldBeArray([].flat(0), []);
|
|
||||||
shouldBeArray([0, 1, 2, 3, , 4].flat(0), [0, 1, 2, 3, 4]);
|
|
||||||
shouldBeArray([,,,,,].flat(0), []);
|
|
||||||
|
|
||||||
shouldBeArray([].flat(-1), []);
|
|
||||||
shouldBeArray([0, 1, 2, 3, , 4].flat(-1), [0, 1, 2, 3, 4]);
|
|
||||||
shouldBeArray([,,,,,].flat(-1), []);
|
|
||||||
|
|
||||||
shouldBeArray([[],[]].flat(), []);
|
|
||||||
shouldBeArray([[0],[1]].flat(), [0,1]);
|
|
||||||
shouldBeArray([[0],[],1].flat(), [0,1]);
|
|
||||||
shouldBeArray([[0],[[]],1].flat(), [0,[],1]);
|
|
||||||
shouldBeArray([[0],[[]],1].flat(1), [0,[],1]);
|
|
||||||
shouldBeArray([[0],[[]],1].flat(2), [0,1]);
|
|
||||||
|
|
||||||
shouldBeArray([[],[]].flat(0), [[],[]]);
|
|
||||||
shouldBeArray([[0],[1]].flat(0), [[0],[1]]);
|
|
||||||
shouldBeArray([[0],[],1].flat(0), [[0],[],1]);
|
|
||||||
shouldBeArray([[0],[[]],1].flat(0), [[0],[[]],1]);
|
|
||||||
|
|
||||||
shouldBeArray([[[[[[[[[[[[[[[[[[[[[42]]]]]]]]]]]]]]]]]]]]].flat(Infinity), [42]);
|
|
||||||
|
|
||||||
var array = [];
|
|
||||||
shouldBe(array.flat() !== array, true);
|
|
||||||
|
|
||||||
class DerivedArray extends Array { }
|
|
||||||
shouldBe((new DerivedArray).flat() instanceof DerivedArray, true);
|
|
||||||
var flat = [].flat;
|
|
||||||
var realm = createGlobalObject();
|
|
||||||
shouldBe(flat.call({}) instanceof Array, true);
|
|
||||||
shouldBe(flat.call(new realm.Array) instanceof Array, true);
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = 0;
|
|
||||||
|
|
||||||
shouldThrow(() => {
|
|
||||||
flat.call(array2);
|
|
||||||
}, `TypeError: 0 is not a constructor`);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = undefined;
|
|
||||||
shouldBe(flat.call(array2) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flat.call(array2) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flat.call(array2) instanceof Array, true);
|
|
||||||
|
|
||||||
var array2 = new realm.Array;
|
|
||||||
array2.constructor = {
|
|
||||||
get [Symbol.species]() {
|
|
||||||
return DerivedArray;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
shouldBe(flat.call(array2) instanceof DerivedArray, true);
|
|
@ -1,42 +0,0 @@
|
|||||||
function target1() {
|
|
||||||
return Array.from({
|
|
||||||
length: 5,
|
|
||||||
0: 0,
|
|
||||||
1: 0,
|
|
||||||
2: 0,
|
|
||||||
3: 0,
|
|
||||||
4: 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
noInline(target1);
|
|
||||||
|
|
||||||
function target2() {
|
|
||||||
return Array.from({
|
|
||||||
length: 5.4,
|
|
||||||
0: 0,
|
|
||||||
1: 0,
|
|
||||||
2: 0,
|
|
||||||
3: 0,
|
|
||||||
4: 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
noInline(target2);
|
|
||||||
|
|
||||||
function target3() {
|
|
||||||
return Array.from({
|
|
||||||
length: -5.4,
|
|
||||||
0: 0,
|
|
||||||
1: 0,
|
|
||||||
2: 0,
|
|
||||||
3: 0,
|
|
||||||
4: 0
|
|
||||||
});
|
|
||||||
}
|
|
||||||
noInline(target3);
|
|
||||||
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
target1();
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
target2();
|
|
||||||
for (var i = 0; i < 10000; ++i)
|
|
||||||
target3();
|
|
@ -1,25 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
Object.defineProperty(Array.prototype, i, {
|
|
||||||
get() {
|
|
||||||
throw new Error('get is called.');
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
throw new Error('set is called.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var original = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
||||||
|
|
||||||
// Doesn't throw any errors.
|
|
||||||
var generated = Array.from(original);
|
|
||||||
|
|
||||||
shouldBe(generated.length, 10);
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
shouldBe(generated[i], i);
|
|
||||||
}
|
|
@ -1,45 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
Object.defineProperty(Array.prototype, i, {
|
|
||||||
get() {
|
|
||||||
throw new Error('get is called.');
|
|
||||||
},
|
|
||||||
set(value) {
|
|
||||||
throw new Error('set is called.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class ArrayLike {
|
|
||||||
constructor(length) {
|
|
||||||
this.lengthCalled = false;
|
|
||||||
this._length = length;
|
|
||||||
}
|
|
||||||
set length(value) {
|
|
||||||
this.lengthCalled = true;
|
|
||||||
this._length = value;
|
|
||||||
}
|
|
||||||
get length() {
|
|
||||||
return this._length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var arrayLike = new ArrayLike(10);
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
arrayLike[i] = i;
|
|
||||||
}
|
|
||||||
shouldBe(arrayLike.lengthCalled, false);
|
|
||||||
|
|
||||||
var generated = Array.from.call(ArrayLike, arrayLike);
|
|
||||||
|
|
||||||
shouldBe(generated.length, 10);
|
|
||||||
shouldBe(generated instanceof ArrayLike, true);
|
|
||||||
for (var i = 0; i < 10; ++i) {
|
|
||||||
shouldBe(generated[i], i);
|
|
||||||
}
|
|
||||||
shouldBe(arrayLike.lengthCalled, false);
|
|
||||||
shouldBe(generated.lengthCalled, true);
|
|
@ -1,22 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
var array = [0, 1, 2, 3, 4, 5];
|
|
||||||
Object.defineProperty(Array.prototype, '0', {
|
|
||||||
get() {
|
|
||||||
throw new Error('cannot get to 0 getter');
|
|
||||||
},
|
|
||||||
set() {
|
|
||||||
throw new Error('cannot put to 0 setter');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var result = Array.from(array);
|
|
||||||
shouldBe(result.length, array.length);
|
|
||||||
shouldBe(result instanceof Array, true);
|
|
||||||
|
|
||||||
for (var i = 0; i < array.length; ++i)
|
|
||||||
shouldBe(result[i], array[i]);
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set is iterable.
|
|
||||||
var set = new Set([0, 1, 2, 3, 4, 5]);
|
|
||||||
var array = Array.from(set);
|
|
||||||
|
|
||||||
shouldBe(array.length, set.size);
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
shouldBe(set.has(array[i]), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map is iterable.
|
|
||||||
var map = new Map([
|
|
||||||
[0, 0],
|
|
||||||
[1, 0],
|
|
||||||
[2, 0],
|
|
||||||
[3, 0],
|
|
||||||
[4, 0],
|
|
||||||
[5, 0]
|
|
||||||
]);
|
|
||||||
var array = Array.from(map);
|
|
||||||
|
|
||||||
shouldBe(array.length, map.size);
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
shouldBe(array[i][1], 0);
|
|
||||||
shouldBe(map.has(array[i][0]), true);
|
|
||||||
shouldBe(map.get(array[i][0]), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// String is iterable
|
|
||||||
var string = "Cocoa Cappuccino";
|
|
||||||
var array = Array.from(string);
|
|
||||||
shouldBe(array.length, string.length);
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
shouldBe(array[i], string[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Arguments is iterable
|
|
||||||
var argumentsGenerators = [
|
|
||||||
function () {
|
|
||||||
return arguments;
|
|
||||||
},
|
|
||||||
|
|
||||||
function () {
|
|
||||||
'use strict';
|
|
||||||
return arguments;
|
|
||||||
},
|
|
||||||
|
|
||||||
function (a, b, c) {
|
|
||||||
return arguments;
|
|
||||||
},
|
|
||||||
|
|
||||||
function (a, b, c) {
|
|
||||||
'use strict';
|
|
||||||
return arguments;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
for (var gen of argumentsGenerators) {
|
|
||||||
var args = gen(1, 2, 3, 4, 5);
|
|
||||||
var array = Array.from(args);
|
|
||||||
shouldBe(array.length, args.length);
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
shouldBe(array[i], args[i]);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,129 +0,0 @@
|
|||||||
function shouldBe(actual, expected) {
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
function shouldThrow(func, message) {
|
|
||||||
var error = null;
|
|
||||||
try {
|
|
||||||
func();
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
if (!error)
|
|
||||||
throw new Error("not thrown.");
|
|
||||||
if (String(error) !== message)
|
|
||||||
throw new Error("bad error: " + String(error));
|
|
||||||
}
|
|
||||||
|
|
||||||
var originalArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
||||||
|
|
||||||
var array = Array.from(originalArray.values());
|
|
||||||
shouldBe(array.length, originalArray.length);
|
|
||||||
for (var i = 0; i < array.length; ++i) {
|
|
||||||
shouldBe(array[i], originalArray[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createIterator(callback) {
|
|
||||||
var array = [0,1,2,3,4,5];
|
|
||||||
var iterator = array[Symbol.iterator]();
|
|
||||||
iterator.return = function () {
|
|
||||||
iterator.returned = true;
|
|
||||||
if (callback)
|
|
||||||
return callback(this);
|
|
||||||
return { done: true, value: undefined };
|
|
||||||
};
|
|
||||||
iterator.returned = false;
|
|
||||||
return iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
var iterator = createIterator();
|
|
||||||
var result = Array.from(iterator);
|
|
||||||
shouldBe(result.length, 6);
|
|
||||||
for (var i = 0; i < 6; ++i) {
|
|
||||||
shouldBe(result[i], i);
|
|
||||||
}
|
|
||||||
shouldBe(iterator.returned, false);
|
|
||||||
|
|
||||||
// mapFn raises an error.
|
|
||||||
var iterator = createIterator();
|
|
||||||
shouldThrow(function () {
|
|
||||||
var result = Array.from(iterator, function () {
|
|
||||||
throw new Error('map func');
|
|
||||||
});
|
|
||||||
}, "Error: map func");
|
|
||||||
shouldBe(iterator.returned, true);
|
|
||||||
|
|
||||||
// mapFn raises an error and iterator.return also raises an error.
|
|
||||||
var iterator = createIterator(function () {
|
|
||||||
throw new Error('iterator.return');
|
|
||||||
});
|
|
||||||
|
|
||||||
// An error raised in iterator.return is discarded.
|
|
||||||
shouldThrow(function () {
|
|
||||||
var result = Array.from(iterator, function () {
|
|
||||||
throw new Error('map func');
|
|
||||||
});
|
|
||||||
}, "Error: map func");
|
|
||||||
shouldBe(iterator.returned, true);
|
|
||||||
|
|
||||||
// iterable[Symbol.iterator] is not a function.
|
|
||||||
shouldThrow(function () {
|
|
||||||
var iterator = [].values();
|
|
||||||
iterator[Symbol.iterator] = {};
|
|
||||||
Array.from(iterator);
|
|
||||||
}, "TypeError: Array.from requires that the property of the first argument, items[Symbol.iterator], when exists, be a function");
|
|
||||||
|
|
||||||
// iterable[Symbol.iterator] raises an error.
|
|
||||||
shouldThrow(function () {
|
|
||||||
var iterable = [];
|
|
||||||
iterable[Symbol.iterator] = function () {
|
|
||||||
throw new Error("iterator");
|
|
||||||
};
|
|
||||||
Array.from(iterable);
|
|
||||||
}, "Error: iterator");
|
|
||||||
|
|
||||||
// iterable[Symbol.iterator] lookup is only once.
|
|
||||||
(function () {
|
|
||||||
var iterable = [0, 1, 2, 3, 4, 5];
|
|
||||||
var count = 0;
|
|
||||||
var iteratorCallCount = 0;
|
|
||||||
Object.defineProperty(iterable, Symbol.iterator, {
|
|
||||||
get() {
|
|
||||||
++count;
|
|
||||||
return function () {
|
|
||||||
++iteratorCallCount;
|
|
||||||
return this.values();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
var generated = Array.from(iterable);
|
|
||||||
shouldBe(generated.length, iterable.length);
|
|
||||||
for (var i = 0; i < iterable.length; ++i) {
|
|
||||||
shouldBe(generated[i], iterable[i]);
|
|
||||||
}
|
|
||||||
shouldBe(count, 1);
|
|
||||||
shouldBe(iteratorCallCount, 1);
|
|
||||||
}());
|
|
||||||
|
|
||||||
// The Symbol.iterator method of the iterator generated by iterable[Symbol.iterator] is not looked up.
|
|
||||||
(function () {
|
|
||||||
var iterable = [0, 1, 2, 3, 4, 5];
|
|
||||||
var count = 0;
|
|
||||||
iterable[Symbol.iterator] = function () {
|
|
||||||
++count;
|
|
||||||
var iterator = this.values();
|
|
||||||
Object.defineProperty(iterator, Symbol.iterator, {
|
|
||||||
get() {
|
|
||||||
throw new Error('iterator[@@iterator] is touched');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return iterator;
|
|
||||||
};
|
|
||||||
var generated = Array.from(iterable);
|
|
||||||
shouldBe(generated.length, iterable.length);
|
|
||||||
for (var i = 0; i < iterable.length; ++i) {
|
|
||||||
shouldBe(generated[i], iterable[i]);
|
|
||||||
}
|
|
||||||
shouldBe(count, 1);
|
|
||||||
}());
|
|
@ -1,24 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32);
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, , 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
|
|
||||||
var value = -1;
|
|
||||||
for (var i = 0; i < 1e5; ++i) {
|
|
||||||
shouldBe(indexOfInt32(int32Array, 5), value);
|
|
||||||
shouldBe(indexOfInt32(int32Array, 6), 6);
|
|
||||||
if (i === 1e4) {
|
|
||||||
Array.prototype[5] = 5;
|
|
||||||
value = 5;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}());
|
|
@ -1,85 +0,0 @@
|
|||||||
// ArrayIndexOf intrinsic does not support ArrayStorage.
|
|
||||||
// Thus, if ArrayStorage comes, we should not use that intrinsic.
|
|
||||||
|
|
||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32Other(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Other);
|
|
||||||
|
|
||||||
function indexOfInt32Cell(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Cell);
|
|
||||||
|
|
||||||
function indexOfInt32Boolean(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Boolean);
|
|
||||||
|
|
||||||
function indexOfDoubleOther(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleOther);
|
|
||||||
|
|
||||||
function indexOfDoubleCell(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleCell);
|
|
||||||
|
|
||||||
function indexOfDoubleBoolean(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleBoolean);
|
|
||||||
|
|
||||||
function indexOfInt32(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32);
|
|
||||||
|
|
||||||
function indexOfDouble(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDouble);
|
|
||||||
|
|
||||||
var key = {};
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
var doubleArray = [0, 1, 2, 3, 4.2, 5, 6, 7, 8, 9, 10.5, 11, 12];
|
|
||||||
|
|
||||||
ensureArrayStorage(int32Array);
|
|
||||||
ensureArrayStorage(doubleArray);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
shouldBe(indexOfInt32Other(int32Array, null, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Other(int32Array, undefined, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, key, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, Symbol("Cocoa"), 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, "Cocoa", 0), -1);
|
|
||||||
shouldBe(indexOfInt32Boolean(int32Array, true, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Boolean(int32Array, false, 0), -1);
|
|
||||||
shouldBe(indexOfInt32(int32Array, 12, 0), 12);
|
|
||||||
|
|
||||||
shouldBe(indexOfDoubleOther(doubleArray, null, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleOther(doubleArray, undefined, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, key, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, Symbol("Cocoa"), 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, "Cocoa", 0), -1);
|
|
||||||
shouldBe(indexOfDoubleBoolean(doubleArray, true, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleBoolean(doubleArray, false, 0), -1);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 12, 0), 12);
|
|
||||||
}
|
|
||||||
}());
|
|
@ -1,72 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32Other(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Other);
|
|
||||||
|
|
||||||
function indexOfInt32Cell(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Cell);
|
|
||||||
|
|
||||||
function indexOfInt32Boolean(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32Boolean);
|
|
||||||
|
|
||||||
function indexOfDoubleOther(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleOther);
|
|
||||||
|
|
||||||
function indexOfDoubleCell(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleCell);
|
|
||||||
|
|
||||||
function indexOfDoubleBoolean(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDoubleBoolean);
|
|
||||||
|
|
||||||
var key = {};
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
var doubleArray = [0, 1, 2, 3, 4.2, 5, 6, 7, 8, 9, 10.5, 11, 12];
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
shouldBe(indexOfInt32Other(int32Array, null, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Other(int32Array, undefined, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, key, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, Symbol("Cocoa"), 0), -1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, "Cocoa", 0), -1);
|
|
||||||
shouldBe(indexOfInt32Boolean(int32Array, true, 0), -1);
|
|
||||||
shouldBe(indexOfInt32Boolean(int32Array, false, 0), -1);
|
|
||||||
|
|
||||||
shouldBe(indexOfDoubleOther(doubleArray, null, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleOther(doubleArray, undefined, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, key, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, Symbol("Cocoa"), 0), -1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, "Cocoa", 0), -1);
|
|
||||||
shouldBe(indexOfDoubleBoolean(doubleArray, true, 0), -1);
|
|
||||||
shouldBe(indexOfDoubleBoolean(doubleArray, false, 0), -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldBe(indexOfInt32Other(int32Array, 1, 0), 1);
|
|
||||||
shouldBe(indexOfInt32Cell(int32Array, 1, 0), 1);
|
|
||||||
shouldBe(indexOfInt32Boolean(int32Array, 1, 0), 1);
|
|
||||||
shouldBe(indexOfDoubleOther(doubleArray, 1, 0), 1);
|
|
||||||
shouldBe(indexOfDoubleCell(doubleArray, 1, 0), 1);
|
|
||||||
shouldBe(indexOfDoubleBoolean(doubleArray, 1, 0), 1);
|
|
||||||
}());
|
|
@ -1,28 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32);
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, , 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
|
|
||||||
var value = -1;
|
|
||||||
for (var i = 0; i < 1e5; ++i) {
|
|
||||||
shouldBe(indexOfInt32(int32Array, 5), value);
|
|
||||||
shouldBe(indexOfInt32(int32Array, 6), 6);
|
|
||||||
if (i === 1e4) {
|
|
||||||
value = 5;
|
|
||||||
Object.defineProperty(Array.prototype, 5, {
|
|
||||||
get: function () {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}());
|
|
@ -1,35 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32);
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, , 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
|
|
||||||
var value = -1;
|
|
||||||
for (var i = 0; i < 1e5; ++i) {
|
|
||||||
shouldBe(indexOfInt32(int32Array, 5), value);
|
|
||||||
shouldBe(indexOfInt32(int32Array, 6), 6);
|
|
||||||
if (i === 1e4) {
|
|
||||||
Object.defineProperty(Map.prototype, 5, {
|
|
||||||
get: function () {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (i === 3e4) {
|
|
||||||
value = 5;
|
|
||||||
Object.defineProperty(Array.prototype, 5, {
|
|
||||||
get: function () {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}());
|
|
@ -1,38 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
shouldBe(indexOf(array, undefined), -1);
|
|
||||||
shouldBe(indexOf(array, null), -1);
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
array.push({});
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e4; ++i) {
|
|
||||||
shouldBe(indexOf(array, undefined), -1);
|
|
||||||
shouldBe(indexOf(array, null), -1);
|
|
||||||
}
|
|
||||||
}());
|
|
||||||
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
Array.prototype[42] = 0;
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
array.push(10);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e5; ++i)
|
|
||||||
shouldBe(indexOf(array, 0), 42);
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
array.push(25.5);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e5; ++i)
|
|
||||||
shouldBe(indexOf(array, 0), 42);
|
|
||||||
}());
|
|
@ -1,33 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
array.push(10);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e5; ++i)
|
|
||||||
shouldBe(indexOf(array, 0), -1);
|
|
||||||
}());
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOf(array, value)
|
|
||||||
{
|
|
||||||
return array.indexOf(value);
|
|
||||||
}
|
|
||||||
noInline(indexOf);
|
|
||||||
|
|
||||||
var array = new Array(100);
|
|
||||||
array.push(25.5);
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e5; ++i)
|
|
||||||
shouldBe(indexOf(array, 0), -1);
|
|
||||||
}());
|
|
@ -1,63 +0,0 @@
|
|||||||
function shouldBe(actual, expected)
|
|
||||||
{
|
|
||||||
if (actual !== expected)
|
|
||||||
throw new Error('bad value: ' + actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
function indexOfInt32(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfInt32);
|
|
||||||
|
|
||||||
function indexOfDouble(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfDouble);
|
|
||||||
|
|
||||||
function indexOfString(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfString);
|
|
||||||
|
|
||||||
function indexOfObject(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfObject);
|
|
||||||
|
|
||||||
function indexOfValue(array, value, index)
|
|
||||||
{
|
|
||||||
return array.indexOf(value, index);
|
|
||||||
}
|
|
||||||
noInline(indexOfValue);
|
|
||||||
|
|
||||||
var key = {};
|
|
||||||
var int32Array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
||||||
var doubleArray = [0, 1, 2, 3, 4.2, 5, 6, 7, 8, 9, 10.5, 11, 12];
|
|
||||||
var stringArray = [ "cocoa", "cappuccino", "matcha", "rize", "kilimanjaro" ];
|
|
||||||
var objectArray = [ {}, {}, {}, {}, {}, key, {}, {}, {} ];
|
|
||||||
var valueArray = [ {}, {}, {}, {}, {}, null, {}, {}, {} ];
|
|
||||||
|
|
||||||
for (var i = 0; i < 1e5; ++i) {
|
|
||||||
shouldBe(indexOfInt32(int32Array, 3, 0), 3);
|
|
||||||
shouldBe(indexOfInt32(int32Array, 3, 8), -1);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 3, 0), 3);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 3, 20), -1);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 4.2, 8), -1);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 4.2, 0), 4);
|
|
||||||
shouldBe(indexOfDouble(doubleArray, 4.2, 20), -1);
|
|
||||||
shouldBe(indexOfString(stringArray, "cocoa", 0), 0);
|
|
||||||
shouldBe(indexOfString(stringArray, "cocoa", 4), -1);
|
|
||||||
shouldBe(indexOfString(stringArray, "cocoa", 20), -1);
|
|
||||||
shouldBe(indexOfObject(objectArray, key, 0), 5);
|
|
||||||
shouldBe(indexOfObject(objectArray, key, 6), -1);
|
|
||||||
shouldBe(indexOfObject(objectArray, key, 20), -1);
|
|
||||||
shouldBe(indexOfValue(valueArray, null, 0), 5);
|
|
||||||
shouldBe(indexOfValue(valueArray, null, 6), -1);
|
|
||||||
shouldBe(indexOfValue(valueArray, null, 20), -1);
|
|
||||||
}
|
|
||||||
}());
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user