Curation: Removed all test files that depend on $vm (implementation-contributed/javascriptcore) (#1629)

- Eliminates:
  - controlFlowProfiler/*
  - exceptionFuzz/*
This commit is contained in:
Rick Waldron 2018-07-24 00:32:37 -04:00 committed by Leo Balter
parent 2d27462e70
commit 8ec747f743
144 changed files with 0 additions and 11500 deletions

View File

@ -1,63 +0,0 @@
load("./driver/driver.js");
var afSimple = y => y + 1,
afBlock = y => { y++; return y + 1;},
afBlockWithCondition = x => { x > 0 ? x++ : x--; return x;};
checkBasicBlock(afSimple, "y + 1", ShouldNotHaveExecuted);
afSimple(1);
checkBasicBlock(afSimple, "y + 1", ShouldHaveExecuted);
checkBasicBlock(afBlock, "y++", ShouldNotHaveExecuted);
afBlock(2);
checkBasicBlock(afBlock, "y++", ShouldHaveExecuted);
checkBasicBlock(afBlock, "return y + 1", ShouldHaveExecuted);
checkBasicBlock(afBlockWithCondition,'x++', ShouldNotHaveExecuted);
afBlockWithCondition(10);
checkBasicBlock(afBlockWithCondition,'x++', ShouldHaveExecuted);
checkBasicBlock(afBlockWithCondition,'return x', ShouldHaveExecuted);
checkBasicBlock(afBlockWithCondition,'x--', ShouldNotHaveExecuted);
afBlockWithCondition(-10);
checkBasicBlock(afBlockWithCondition,'x--', ShouldHaveExecuted);
function foo1(test) {
var f1 = () => { "hello"; }
if (test)
f1();
}
foo1(false);
checkBasicBlock(foo1, '() =>', ShouldNotHaveExecuted);
checkBasicBlock(foo1, '; }', ShouldNotHaveExecuted);
foo1(true);
checkBasicBlock(foo1, '() =>', ShouldHaveExecuted);
checkBasicBlock(foo1, '; }', ShouldHaveExecuted);
function foo2(test) {
var f1 = x => { "hello"; }
if (test)
f1();
}
foo2(false);
checkBasicBlock(foo2, 'x =>', ShouldNotHaveExecuted);
checkBasicBlock(foo2, '; }', ShouldNotHaveExecuted);
foo2(true);
checkBasicBlock(foo2, 'x =>', ShouldHaveExecuted);
checkBasicBlock(foo2, '; }', ShouldHaveExecuted);
function foo3(test) {
var f1 = (xyz) => { "hello"; }
if (test)
f1();
}
foo3(false);
checkBasicBlock(foo3, '(xyz) =>', ShouldNotHaveExecuted);
checkBasicBlock(foo3, '; }', ShouldNotHaveExecuted);
foo3(true);
checkBasicBlock(foo3, '(xyz) =>', ShouldHaveExecuted);
checkBasicBlock(foo3, '; }', ShouldHaveExecuted);

View File

@ -1,159 +0,0 @@
load("./driver/driver.js");
function foo() {}
function bar() {}
function baz() {}
function testIf(x) {
if (x < 10) { foo(); } else if (x < 20) { bar(); } else { baz() }
}
testIf(9);
// Note, the check will be against the basic block that contains the first matched character.
// So in this following case, the block that contains the '{'.
checkBasicBlock(testIf, "{ foo", ShouldHaveExecuted);
// In this case, it will test the basic block that contains the ' ' character.
checkBasicBlock(testIf, " foo", ShouldHaveExecuted);
checkBasicBlock(testIf, "} else if", ShouldHaveExecuted);
checkBasicBlock(testIf, "else if", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "else {", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "{ baz", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " baz", ShouldNotHaveExecuted);
testIf(21);
checkBasicBlock(testIf, "else if (x < 20)", ShouldHaveExecuted);
checkBasicBlock(testIf, "{ bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIf, "else {", ShouldHaveExecuted);
checkBasicBlock(testIf, "{ baz", ShouldHaveExecuted);
checkBasicBlock(testIf, " baz", ShouldHaveExecuted);
testIf(11);
checkBasicBlock(testIf, "{ bar", ShouldHaveExecuted);
checkBasicBlock(testIf, " bar", ShouldHaveExecuted);
function testForRegular(x) {
for (var i = 0; i < x; i++) { foo(); } bar();
}
testForRegular(0);
checkBasicBlock(testForRegular, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForRegular, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForRegular, " bar", ShouldHaveExecuted);
testForRegular(1);
checkBasicBlock(testForRegular, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForRegular, "} bar", ShouldHaveExecuted);
function testForIn(x) {
for (var i in x) { foo(); } bar();
}
testForIn({});
checkBasicBlock(testForIn, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForIn, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForIn, " bar", ShouldHaveExecuted);
testForIn({foo: 20});
checkBasicBlock(testForIn, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForIn, "} bar", ShouldHaveExecuted);
function testForOf(x) {
for (var i of x) { foo(); } bar();
}
testForOf([]);
checkBasicBlock(testForOf, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, " foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testForOf, " bar", ShouldHaveExecuted);
testForOf([20]);
checkBasicBlock(testForOf, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testForOf, "} bar", ShouldHaveExecuted);
function testWhile(x) {
var i = 0; while (i++ < x) { foo(); } bar();
}
testWhile(0);
checkBasicBlock(testWhile, "{ foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, " foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, "} bar", ShouldNotHaveExecuted);
checkBasicBlock(testWhile, " bar", ShouldHaveExecuted);
testWhile(1);
checkBasicBlock(testWhile, "{ foo", ShouldHaveExecuted);
checkBasicBlock(testWhile, "} bar", ShouldHaveExecuted);
// No braces tests.
function testIfNoBraces(x) {
if (x < 10) foo(); else if (x < 20) bar(); else baz();
}
testIfNoBraces(9);
checkBasicBlock(testIfNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "; else if", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, " else if", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, " bar", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "else baz", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "baz", ShouldNotHaveExecuted);
testIfNoBraces(21);
checkBasicBlock(testIfNoBraces, "else baz", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "baz", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "; else baz", ShouldNotHaveExecuted);
checkBasicBlock(testIfNoBraces, "else if (x < 20)", ShouldHaveExecuted);
// Note that the whitespace preceding bar is part of the previous basic block.
// An if statement's if-true basic block text offset begins at the start offset
// of the if-true block, in this case, just the expression "bar()".
checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldNotHaveExecuted);
testIfNoBraces(11);
checkBasicBlock(testIfNoBraces, " bar", ShouldHaveExecuted);
checkBasicBlock(testIfNoBraces, "bar", ShouldHaveExecuted);
function testForRegularNoBraces(x) {
for (var i = 0; i < x; i++) foo(); bar();
}
testForRegularNoBraces(0);
checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
testForRegularNoBraces(1);
checkBasicBlock(testForRegularNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForRegularNoBraces, " bar", ShouldHaveExecuted);
function testForInNoBraces(x) {
for (var i in x) foo(); bar();
}
testForInNoBraces({});
checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForInNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForInNoBraces, " bar", ShouldHaveExecuted);
testForInNoBraces({foo: 20});
checkBasicBlock(testForInNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForInNoBraces, "; bar", ShouldHaveExecuted);
function testForOfNoBraces(x) {
for (var i of x) foo(); bar();
}
testForOfNoBraces([]);
checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testForOfNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testForOfNoBraces, " bar", ShouldHaveExecuted);
testForOfNoBraces([20]);
checkBasicBlock(testForOfNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testForOfNoBraces, "; bar", ShouldHaveExecuted);
function testWhileNoBraces(x) {
var i = 0; while (i++ < x) foo(); bar();
}
testWhileNoBraces(0);
checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testWhileNoBraces, "; bar", ShouldNotHaveExecuted);
checkBasicBlock(testWhileNoBraces, " bar", ShouldHaveExecuted);
testWhileNoBraces(1);
checkBasicBlock(testWhileNoBraces, " foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "foo", ShouldHaveExecuted);
checkBasicBlock(testWhileNoBraces, "; bar", ShouldHaveExecuted);

View File

@ -1,44 +0,0 @@
load("./driver/driver.js");
function foo(){ }
function bar(){ }
function baz(){ }
function testConditionalBasic(x) {
return x ? 10 : 20;
}
testConditionalBasic(false);
checkBasicBlock(testConditionalBasic, "x", ShouldHaveExecuted);
checkBasicBlock(testConditionalBasic, "20", ShouldHaveExecuted);
checkBasicBlock(testConditionalBasic, "10", ShouldNotHaveExecuted);
testConditionalBasic(true);
checkBasicBlock(testConditionalBasic, "10", ShouldHaveExecuted);
function testConditionalFunctionCall(x, y) {
x ? y ? foo()
: baz()
: bar()
}
testConditionalFunctionCall(false, false);
checkBasicBlock(testConditionalFunctionCall, "x ?", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "? y", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "bar", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, ": bar", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "y ?", ShouldNotHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "? foo", ShouldNotHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "foo", ShouldNotHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "baz", ShouldNotHaveExecuted);
testConditionalFunctionCall(true, false);
checkBasicBlock(testConditionalFunctionCall, "y ?", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "? foo", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, ": baz", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "baz", ShouldHaveExecuted);
checkBasicBlock(testConditionalFunctionCall, "foo", ShouldNotHaveExecuted);
testConditionalFunctionCall(true, true);
checkBasicBlock(testConditionalFunctionCall, "foo", ShouldHaveExecuted);

View File

@ -1,16 +0,0 @@
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
function assert(condition, reason) {
if (!condition)
throw new Error(reason);
}
var ShouldHaveExecuted = true;
var ShouldNotHaveExecuted = false;
function checkBasicBlock(func, expr, expectation) {
if (expectation === ShouldHaveExecuted)
assert(hasBasicBlockExecuted(func, expr, "should have executed"));
else
assert(!hasBasicBlockExecuted(func, expr, "should not have executed"));
}

View File

@ -1,72 +0,0 @@
var basicBlockExecutionCount = $vm.basicBlockExecutionCount;
load("./driver/driver.js");
function noop() { ; }
function foo(num) {
for (let i = 0; i < num; i++) {
noop();
}
}
function a() { ; }
function b() { ; }
function baz(num) {
for (let i = 0; i < num; i++) {
i % 2 ? a() : b();
}
}
function jaz(num) {
for (let i = 0; i < num; i++) {
if (i % 2)
a();
else
b();
}
}
function testWhile(num) {
let i = num;
while (i--) {
noop();
if (i % 2)
a();
else
b();
}
}
foo(120);
assert(basicBlockExecutionCount(foo, "noop()") === 120);
noop();
assert(basicBlockExecutionCount(noop, ";") === 121);
baz(140);
assert(basicBlockExecutionCount(baz, "a()") === 140/2);
assert(basicBlockExecutionCount(baz, "b()") === 140/2);
assert(basicBlockExecutionCount(a, ";") === 140/2);
assert(basicBlockExecutionCount(b, ";") === 140/2);
jaz(140);
assert(basicBlockExecutionCount(jaz, "a()") === 140/2);
assert(basicBlockExecutionCount(jaz, "b()") === 140/2);
testWhile(140);
assert(basicBlockExecutionCount(testWhile, "noop()") === 140);
assert(basicBlockExecutionCount(testWhile, "a()") === 140/2);
assert(basicBlockExecutionCount(testWhile, "b()") === 140/2);
if (is32BitPlatform()) {
function testMax() {
let j = 0;
let numIters = Math.pow(2, 32) + 10;
for (let i = 0; i < numIters; i++) {
j++;
}
}
testMax();
assert(basicBlockExecutionCount(testMax, "j++") === Math.pow(2, 32) - 1);
}

View File

@ -1,58 +0,0 @@
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
load("./driver/driver.js");
var a, b, c, d;
function testIf(x) {
if (x > 10 && x < 20) {
return a;
} else if (x > 20 && x < 30) {
return b;
} else if (x > 30 && x < 40) {
return c;
} else {
return d;
}
return null;
}
function noMatches(x) {
if (x > 10 && x < 20) {
return a;
} else if (x > 20 && x < 30) {
return b;
} else {
return c;
}
}
assert(!hasBasicBlockExecuted(testIf, "return a"), "should not have executed yet.");
assert(!hasBasicBlockExecuted(testIf, "return b"), "should not have executed yet.");
assert(!hasBasicBlockExecuted(testIf, "return c"), "should not have executed yet.");
assert(!hasBasicBlockExecuted(testIf, "return d"), "should not have executed yet.");
testIf(11);
assert(hasBasicBlockExecuted(testIf, "return a"), "should have executed.");
assert(hasBasicBlockExecuted(testIf, "x > 10"), "should have executed.");
assert(!hasBasicBlockExecuted(testIf, "return b"), "should not have executed yet.");
testIf(21);
assert(hasBasicBlockExecuted(testIf, "return b"), "should have executed.");
assert(!hasBasicBlockExecuted(testIf, "return c"), "should not have executed yet.");
testIf(31);
assert(hasBasicBlockExecuted(testIf, "return c"), "should have executed.");
assert(!hasBasicBlockExecuted(testIf, "return d"), "should not have executed yet.");
testIf(0);
assert(hasBasicBlockExecuted(testIf, "return d"), "should have executed.");
noMatches(0);
assert(!hasBasicBlockExecuted(noMatches, "return a"), "should not have executed yet.");
assert(hasBasicBlockExecuted(noMatches, "x > 10"), "should have executed.");
assert(!hasBasicBlockExecuted(noMatches, "return b"), "should not have executed yet.");
assert(hasBasicBlockExecuted(noMatches, "x > 20"), "should have executed.");
assert(hasBasicBlockExecuted(noMatches, "return c"), "should have executed.");

View File

@ -1,78 +0,0 @@
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
load("./driver/driver.js");
function forRegular(limit) {
var sum = 0;
for (var i = 0; i < limit; i++) {
sum += i;
}
return sum;
}
function forIn(o) {
var s = "";
var p;
for (p in o) {
s += p;
}
}
function forOf(a) {
var s = "";
var p;
for (p of a) {
s += p;
}
}
function whileLoop(limit) {
var i = 0;
var sum = 0;
while (i < limit) {
sum += i;
i++;
}
return sum;
}
assert(!hasBasicBlockExecuted(forRegular, "var sum"), "should not have executed yet.");
forRegular(0);
assert(hasBasicBlockExecuted(forRegular, "var sum"), "should have executed.");
assert(!hasBasicBlockExecuted(forRegular, "sum += i"), "should not have executed yet.");
forRegular(1);
assert(hasBasicBlockExecuted(forRegular, "sum += i"), "should have executed.");
assert(!hasBasicBlockExecuted(forIn, "var s"), "should not have executed yet.");
forIn({});
assert(hasBasicBlockExecuted(forIn, "var s"), "should have executed.");
assert(!hasBasicBlockExecuted(forIn, "s += p"), "should not have executed yet.");
forIn({foo: "bar"});
assert(hasBasicBlockExecuted(forIn, "s += p"), "should have executed.");
assert(!hasBasicBlockExecuted(forOf, "var s"), "should not have executed yet.");
forOf([]);
assert(hasBasicBlockExecuted(forOf, "var s"), "should have executed.");
assert(!hasBasicBlockExecuted(forOf, "s += p"), "should not have executed yet.");
forOf(["a"]);
assert(hasBasicBlockExecuted(forOf, "s += p"), "should have executed.");
assert(!hasBasicBlockExecuted(whileLoop, "var sum"), "should not have executed yet.");
whileLoop(0);
assert(hasBasicBlockExecuted(whileLoop, "var sum"), "should have executed.");
assert(!hasBasicBlockExecuted(whileLoop, "sum += i"), "should not have executed yet.");
whileLoop(1);
assert(hasBasicBlockExecuted(whileLoop, "sum += i"), "should have executed.");

View File

@ -1,30 +0,0 @@
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
load("./driver/driver.js");
var a, b, c;
function testSwitch(s) {
switch (s) {
case "foo":
return a;
case "bar":
return b;
default:
return c;
}
}
assert(!hasBasicBlockExecuted(testSwitch, "switch"), "should not have executed yet.");
testSwitch("foo");
assert(hasBasicBlockExecuted(testSwitch, "switch"), "should have executed.");
assert(hasBasicBlockExecuted(testSwitch, "return a"), "should have executed.");
assert(!hasBasicBlockExecuted(testSwitch, "return b"), "should not have executed yet.");
assert(!hasBasicBlockExecuted(testSwitch, "return c"), "should not have executed yet.");
testSwitch("bar");
assert(hasBasicBlockExecuted(testSwitch, "return b"), "should have executed.");
assert(!hasBasicBlockExecuted(testSwitch, "return c"), "should not have executed yet.");
testSwitch("");
assert(hasBasicBlockExecuted(testSwitch, "return c"), "should have executed.");

View File

@ -1,48 +0,0 @@
var hasBasicBlockExecuted = $vm.hasBasicBlockExecuted;
load("./driver/driver.js");
function tierUpToBaseline(func, arg)
{
for (var i = 0; i < 50; i++)
func(arg);
}
function tierUpToDFG(func, arg)
{
for (var i = 0; i < 50; i++)
func(arg);
}
function baselineTest(arg) {
if (arg > 20) {
return 20;
} else {
return 30;
}
}
function dfgTest(arg) {
if (arg > 20) {
return 20;
} else {
return 30;
}
}
noInline(baselineTest);
noInline(dfgTest);
tierUpToBaseline(baselineTest, 10);
tierUpToDFG(dfgTest, 10);
assert(!hasBasicBlockExecuted(baselineTest, "return 20"), "should not have executed yet.");
assert(hasBasicBlockExecuted(baselineTest, "return 30"), "should have executed.");
baselineTest(25);
assert(hasBasicBlockExecuted(baselineTest, "return 20"), "should have executed.");
assert(!hasBasicBlockExecuted(dfgTest, "return 20"), "should not have executed yet.");
assert(hasBasicBlockExecuted(dfgTest, "return 30"), "should have executed.");
dfgTest(25);
assert(hasBasicBlockExecuted(dfgTest, "return 20"), "should have executed.");

View File

@ -1,365 +0,0 @@
var enableExceptionFuzz = $vm.enableExceptionFuzz;
try {
// 3D Cube Rotation
// http://www.speich.net/computer/moztesting/3d.htm
// Created by Simon Speich
enableExceptionFuzz();
var Q = new Array();
var MTrans = new Array(); // transformation matrix
var MQube = new Array(); // position information of qube
var I = new Array(); // entity matrix
var Origin = new Object();
var Testing = new Object();
var LoopTimer;
var validation = {
20: 2889.0000000000045,
40: 2889.0000000000055,
80: 2889.000000000005,
160: 2889.0000000000055
};
var DisplArea = new Object();
DisplArea.Width = 300;
DisplArea.Height = 300;
function DrawLine(From, To) {
var x1 = From.V[0];
var x2 = To.V[0];
var y1 = From.V[1];
var y2 = To.V[1];
var dx = Math.abs(x2 - x1);
var dy = Math.abs(y2 - y1);
var x = x1;
var y = y1;
var IncX1, IncY1;
var IncX2, IncY2;
var Den;
var Num;
var NumAdd;
var NumPix;
if (x2 >= x1) { IncX1 = 1; IncX2 = 1; }
else { IncX1 = -1; IncX2 = -1; }
if (y2 >= y1) { IncY1 = 1; IncY2 = 1; }
else { IncY1 = -1; IncY2 = -1; }
if (dx >= dy) {
IncX1 = 0;
IncY2 = 0;
Den = dx;
Num = dx / 2;
NumAdd = dy;
NumPix = dx;
}
else {
IncX2 = 0;
IncY1 = 0;
Den = dy;
Num = dy / 2;
NumAdd = dx;
NumPix = dy;
}
NumPix = Math.round(Q.LastPx + NumPix);
var i = Q.LastPx;
for (; i < NumPix; i++) {
Num += NumAdd;
if (Num >= Den) {
Num -= Den;
x += IncX1;
y += IncY1;
}
x += IncX2;
y += IncY2;
}
Q.LastPx = NumPix;
}
function CalcCross(V0, V1) {
var Cross = new Array();
Cross[0] = V0[1]*V1[2] - V0[2]*V1[1];
Cross[1] = V0[2]*V1[0] - V0[0]*V1[2];
Cross[2] = V0[0]*V1[1] - V0[1]*V1[0];
return Cross;
}
function CalcNormal(V0, V1, V2) {
var A = new Array(); var B = new Array();
for (var i = 0; i < 3; i++) {
A[i] = V0[i] - V1[i];
B[i] = V2[i] - V1[i];
}
A = CalcCross(A, B);
var Length = Math.sqrt(A[0]*A[0] + A[1]*A[1] + A[2]*A[2]);
for (var i = 0; i < 3; i++) A[i] = A[i] / Length;
A[3] = 1;
return A;
}
function CreateP(X,Y,Z) {
this.V = [X,Y,Z,1];
}
// multiplies two matrices
function MMulti(M1, M2) {
var M = [[],[],[],[]];
var i = 0;
var j = 0;
for (; i < 4; i++) {
j = 0;
for (; j < 4; j++) M[i][j] = M1[i][0] * M2[0][j] + M1[i][1] * M2[1][j] + M1[i][2] * M2[2][j] + M1[i][3] * M2[3][j];
}
return M;
}
//multiplies matrix with vector
function VMulti(M, V) {
var Vect = new Array();
var i = 0;
for (;i < 4; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2] + M[i][3] * V[3];
return Vect;
}
function VMulti2(M, V) {
var Vect = new Array();
var i = 0;
for (;i < 3; i++) Vect[i] = M[i][0] * V[0] + M[i][1] * V[1] + M[i][2] * V[2];
return Vect;
}
// add to matrices
function MAdd(M1, M2) {
var M = [[],[],[],[]];
var i = 0;
var j = 0;
for (; i < 4; i++) {
j = 0;
for (; j < 4; j++) M[i][j] = M1[i][j] + M2[i][j];
}
return M;
}
function Translate(M, Dx, Dy, Dz) {
var T = [
[1,0,0,Dx],
[0,1,0,Dy],
[0,0,1,Dz],
[0,0,0,1]
];
return MMulti(T, M);
}
function RotateX(M, Phi) {
var a = Phi;
a *= Math.PI / 180;
var Cos = Math.cos(a);
var Sin = Math.sin(a);
var R = [
[1,0,0,0],
[0,Cos,-Sin,0],
[0,Sin,Cos,0],
[0,0,0,1]
];
return MMulti(R, M);
}
function RotateY(M, Phi) {
var a = Phi;
a *= Math.PI / 180;
var Cos = Math.cos(a);
var Sin = Math.sin(a);
var R = [
[Cos,0,Sin,0],
[0,1,0,0],
[-Sin,0,Cos,0],
[0,0,0,1]
];
return MMulti(R, M);
}
function RotateZ(M, Phi) {
var a = Phi;
a *= Math.PI / 180;
var Cos = Math.cos(a);
var Sin = Math.sin(a);
var R = [
[Cos,-Sin,0,0],
[Sin,Cos,0,0],
[0,0,1,0],
[0,0,0,1]
];
return MMulti(R, M);
}
function DrawQube() {
// calc current normals
var CurN = new Array();
var i = 5;
Q.LastPx = 0;
for (; i > -1; i--) CurN[i] = VMulti2(MQube, Q.Normal[i]);
if (CurN[0][2] < 0) {
if (!Q.Line[0]) { DrawLine(Q[0], Q[1]); Q.Line[0] = true; };
if (!Q.Line[1]) { DrawLine(Q[1], Q[2]); Q.Line[1] = true; };
if (!Q.Line[2]) { DrawLine(Q[2], Q[3]); Q.Line[2] = true; };
if (!Q.Line[3]) { DrawLine(Q[3], Q[0]); Q.Line[3] = true; };
}
if (CurN[1][2] < 0) {
if (!Q.Line[2]) { DrawLine(Q[3], Q[2]); Q.Line[2] = true; };
if (!Q.Line[9]) { DrawLine(Q[2], Q[6]); Q.Line[9] = true; };
if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };
if (!Q.Line[10]) { DrawLine(Q[7], Q[3]); Q.Line[10] = true; };
}
if (CurN[2][2] < 0) {
if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };
if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };
if (!Q.Line[6]) { DrawLine(Q[6], Q[7]); Q.Line[6] = true; };
if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };
}
if (CurN[3][2] < 0) {
if (!Q.Line[4]) { DrawLine(Q[4], Q[5]); Q.Line[4] = true; };
if (!Q.Line[8]) { DrawLine(Q[5], Q[1]); Q.Line[8] = true; };
if (!Q.Line[0]) { DrawLine(Q[1], Q[0]); Q.Line[0] = true; };
if (!Q.Line[11]) { DrawLine(Q[0], Q[4]); Q.Line[11] = true; };
}
if (CurN[4][2] < 0) {
if (!Q.Line[11]) { DrawLine(Q[4], Q[0]); Q.Line[11] = true; };
if (!Q.Line[3]) { DrawLine(Q[0], Q[3]); Q.Line[3] = true; };
if (!Q.Line[10]) { DrawLine(Q[3], Q[7]); Q.Line[10] = true; };
if (!Q.Line[7]) { DrawLine(Q[7], Q[4]); Q.Line[7] = true; };
}
if (CurN[5][2] < 0) {
if (!Q.Line[8]) { DrawLine(Q[1], Q[5]); Q.Line[8] = true; };
if (!Q.Line[5]) { DrawLine(Q[5], Q[6]); Q.Line[5] = true; };
if (!Q.Line[9]) { DrawLine(Q[6], Q[2]); Q.Line[9] = true; };
if (!Q.Line[1]) { DrawLine(Q[2], Q[1]); Q.Line[1] = true; };
}
Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];
Q.LastPx = 0;
}
function Loop() {
if (Testing.LoopCount > Testing.LoopMax) return;
var TestingStr = String(Testing.LoopCount);
while (TestingStr.length < 3) TestingStr = "0" + TestingStr;
MTrans = Translate(I, -Q[8].V[0], -Q[8].V[1], -Q[8].V[2]);
MTrans = RotateX(MTrans, 1);
MTrans = RotateY(MTrans, 3);
MTrans = RotateZ(MTrans, 5);
MTrans = Translate(MTrans, Q[8].V[0], Q[8].V[1], Q[8].V[2]);
MQube = MMulti(MTrans, MQube);
var i = 8;
for (; i > -1; i--) {
Q[i].V = VMulti(MTrans, Q[i].V);
}
DrawQube();
Testing.LoopCount++;
Loop();
}
function Init(CubeSize) {
// init/reset vars
Origin.V = [150,150,20,1];
Testing.LoopCount = 0;
Testing.LoopMax = 50;
Testing.TimeMax = 0;
Testing.TimeAvg = 0;
Testing.TimeMin = 0;
Testing.TimeTemp = 0;
Testing.TimeTotal = 0;
Testing.Init = false;
// transformation matrix
MTrans = [
[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]
];
// position information of qube
MQube = [
[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]
];
// entity matrix
I = [
[1,0,0,0],
[0,1,0,0],
[0,0,1,0],
[0,0,0,1]
];
// create qube
Q[0] = new CreateP(-CubeSize,-CubeSize, CubeSize);
Q[1] = new CreateP(-CubeSize, CubeSize, CubeSize);
Q[2] = new CreateP( CubeSize, CubeSize, CubeSize);
Q[3] = new CreateP( CubeSize,-CubeSize, CubeSize);
Q[4] = new CreateP(-CubeSize,-CubeSize,-CubeSize);
Q[5] = new CreateP(-CubeSize, CubeSize,-CubeSize);
Q[6] = new CreateP( CubeSize, CubeSize,-CubeSize);
Q[7] = new CreateP( CubeSize,-CubeSize,-CubeSize);
// center of gravity
Q[8] = new CreateP(0, 0, 0);
// anti-clockwise edge check
Q.Edge = [[0,1,2],[3,2,6],[7,6,5],[4,5,1],[4,0,3],[1,5,6]];
// calculate squad normals
Q.Normal = new Array();
for (var i = 0; i < Q.Edge.length; i++) Q.Normal[i] = CalcNormal(Q[Q.Edge[i][0]].V, Q[Q.Edge[i][1]].V, Q[Q.Edge[i][2]].V);
// line drawn ?
Q.Line = [false,false,false,false,false,false,false,false,false,false,false,false];
// create line pixels
Q.NumPx = 9 * 2 * CubeSize;
for (var i = 0; i < Q.NumPx; i++) CreateP(0,0,0);
MTrans = Translate(MTrans, Origin.V[0], Origin.V[1], Origin.V[2]);
MQube = MMulti(MTrans, MQube);
var i = 0;
for (; i < 9; i++) {
Q[i].V = VMulti(MTrans, Q[i].V);
}
DrawQube();
Testing.Init = true;
Loop();
// Perform a simple sum-based verification.
var sum = 0;
for (var i = 0; i < Q.length; ++i) {
var vector = Q[i].V;
for (var j = 0; j < vector.length; ++j)
sum += vector[j];
}
if (sum != validation[CubeSize])
throw "Error: bad vector sum for CubeSize = " + CubeSize + "; expected " + validation[CubeSize] + " but got " + sum;
}
for ( var i = 20; i <= 160; i *= 2 ) {
Init(i);
}
Q = null;
MTrans = null;
MQube = null;
I = null;
Origin = null;
Testing = null;
LoopTime = null;
DisplArea = null;
} catch (e) {
print("JSC EXCEPTION FUZZ: Caught exception: " + e);
}

View File

@ -1,431 +0,0 @@
var enableExceptionFuzz = $vm.enableExceptionFuzz;
try {
/*
* Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
enableExceptionFuzz();
Date.parseFunctions = {count:0};
Date.parseRegexes = [];
Date.formatFunctions = {count:0};
Date.prototype.dateFormat = function(format) {
if (Date.formatFunctions[format] == null) {
Date.createNewFormat(format);
}
var func = Date.formatFunctions[format];
return this[func]();
}
Date.createNewFormat = function(format) {
var funcName = "format" + Date.formatFunctions.count++;
Date.formatFunctions[format] = funcName;
var code = "Date.prototype." + funcName + " = function(){return ";
var special = false;
var ch = '';
for (var i = 0; i < format.length; ++i) {
ch = format.charAt(i);
if (!special && ch == "\\") {
special = true;
}
else if (special) {
special = false;
code += "'" + String.escape(ch) + "' + ";
}
else {
code += Date.getFormatCode(ch);
}
}
eval(code.substring(0, code.length - 3) + ";}");
}
Date.getFormatCode = function(character) {
switch (character) {
case "d":
return "String.leftPad(this.getDate(), 2, '0') + ";
case "D":
return "Date.dayNames[this.getDay()].substring(0, 3) + ";
case "j":
return "this.getDate() + ";
case "l":
return "Date.dayNames[this.getDay()] + ";
case "S":
return "this.getSuffix() + ";
case "w":
return "this.getDay() + ";
case "z":
return "this.getDayOfYear() + ";
case "W":
return "this.getWeekOfYear() + ";
case "F":
return "Date.monthNames[this.getMonth()] + ";
case "m":
return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
case "M":
return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
case "n":
return "(this.getMonth() + 1) + ";
case "t":
return "this.getDaysInMonth() + ";
case "L":
return "(this.isLeapYear() ? 1 : 0) + ";
case "Y":
return "this.getFullYear() + ";
case "y":
return "('' + this.getFullYear()).substring(2, 4) + ";
case "a":
return "(this.getHours() < 12 ? 'am' : 'pm') + ";
case "A":
return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
case "g":
return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
case "G":
return "this.getHours() + ";
case "h":
return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
case "H":
return "String.leftPad(this.getHours(), 2, '0') + ";
case "i":
return "String.leftPad(this.getMinutes(), 2, '0') + ";
case "s":
return "String.leftPad(this.getSeconds(), 2, '0') + ";
case "O":
return "this.getGMTOffset() + ";
case "T":
return "this.getTimezone() + ";
case "Z":
return "(this.getTimezoneOffset() * -60) + ";
default:
return "'" + String.escape(character) + "' + ";
}
}
Date.parseDate = function(input, format) {
if (Date.parseFunctions[format] == null) {
Date.createParser(format);
}
var func = Date.parseFunctions[format];
return Date[func](input);
}
Date.createParser = function(format) {
var funcName = "parse" + Date.parseFunctions.count++;
var regexNum = Date.parseRegexes.length;
var currentGroup = 1;
Date.parseFunctions[format] = funcName;
var code = "Date." + funcName + " = function(input){\n"
+ "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"
+ "var d = new Date();\n"
+ "y = d.getFullYear();\n"
+ "m = d.getMonth();\n"
+ "d = d.getDate();\n"
+ "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
+ "if (results && results.length > 0) {"
var regex = "";
var special = false;
var ch = '';
for (var i = 0; i < format.length; ++i) {
ch = format.charAt(i);
if (!special && ch == "\\") {
special = true;
}
else if (special) {
special = false;
regex += String.escape(ch);
}
else {
obj = Date.formatCodeToRegex(ch, currentGroup);
currentGroup += obj.g;
regex += obj.s;
if (obj.g && obj.c) {
code += obj.c;
}
}
}
code += "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
+ "{return new Date(y, m, d, h, i, s);}\n"
+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
+ "{return new Date(y, m, d, h, i);}\n"
+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"
+ "{return new Date(y, m, d, h);}\n"
+ "else if (y > 0 && m >= 0 && d > 0)\n"
+ "{return new Date(y, m, d);}\n"
+ "else if (y > 0 && m >= 0)\n"
+ "{return new Date(y, m);}\n"
+ "else if (y > 0)\n"
+ "{return new Date(y);}\n"
+ "}return null;}";
Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$");
eval(code);
}
Date.formatCodeToRegex = function(character, currentGroup) {
switch (character) {
case "D":
return {g:0,
c:null,
s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
case "j":
case "d":
return {g:1,
c:"d = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{1,2})"};
case "l":
return {g:0,
c:null,
s:"(?:" + Date.dayNames.join("|") + ")"};
case "S":
return {g:0,
c:null,
s:"(?:st|nd|rd|th)"};
case "w":
return {g:0,
c:null,
s:"\\d"};
case "z":
return {g:0,
c:null,
s:"(?:\\d{1,3})"};
case "W":
return {g:0,
c:null,
s:"(?:\\d{2})"};
case "F":
return {g:1,
c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
s:"(" + Date.monthNames.join("|") + ")"};
case "M":
return {g:1,
c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
case "n":
case "m":
return {g:1,
c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
s:"(\\d{1,2})"};
case "t":
return {g:0,
c:null,
s:"\\d{1,2}"};
case "L":
return {g:0,
c:null,
s:"(?:1|0)"};
case "Y":
return {g:1,
c:"y = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{4})"};
case "y":
return {g:1,
c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
+ "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
s:"(\\d{1,2})"};
case "a":
return {g:1,
c:"if (results[" + currentGroup + "] == 'am') {\n"
+ "if (h == 12) { h = 0; }\n"
+ "} else { if (h < 12) { h += 12; }}",
s:"(am|pm)"};
case "A":
return {g:1,
c:"if (results[" + currentGroup + "] == 'AM') {\n"
+ "if (h == 12) { h = 0; }\n"
+ "} else { if (h < 12) { h += 12; }}",
s:"(AM|PM)"};
case "g":
case "G":
case "h":
case "H":
return {g:1,
c:"h = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{1,2})"};
case "i":
return {g:1,
c:"i = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"};
case "s":
return {g:1,
c:"s = parseInt(results[" + currentGroup + "], 10);\n",
s:"(\\d{2})"};
case "O":
return {g:0,
c:null,
s:"[+-]\\d{4}"};
case "T":
return {g:0,
c:null,
s:"[A-Z]{3}"};
case "Z":
return {g:0,
c:null,
s:"[+-]\\d{1,5}"};
default:
return {g:0,
c:null,
s:String.escape(character)};
}
}
Date.prototype.getTimezone = function() {
return this.toString().replace(
/^.*? ([A-Z]{3}) [0-9]{4}.*$/, "$1").replace(
/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/, "$1$2$3");
}
Date.prototype.getGMTOffset = function() {
return (this.getTimezoneOffset() > 0 ? "-" : "+")
+ String.leftPad(Math.floor(this.getTimezoneOffset() / 60), 2, "0")
+ String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
}
Date.prototype.getDayOfYear = function() {
var num = 0;
Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
for (var i = 0; i < this.getMonth(); ++i) {
num += Date.daysInMonth[i];
}
return num + this.getDate() - 1;
}
Date.prototype.getWeekOfYear = function() {
// Skip to Thursday of this week
var now = this.getDayOfYear() + (4 - this.getDay());
// Find the first Thursday of the year
var jan1 = new Date(this.getFullYear(), 0, 1);
var then = (7 - jan1.getDay() + 4);
document.write(then);
return String.leftPad(((now - then) / 7) + 1, 2, "0");
}
Date.prototype.isLeapYear = function() {
var year = this.getFullYear();
return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
}
Date.prototype.getFirstDayOfMonth = function() {
var day = (this.getDay() - (this.getDate() - 1)) % 7;
return (day < 0) ? (day + 7) : day;
}
Date.prototype.getLastDayOfMonth = function() {
var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
return (day < 0) ? (day + 7) : day;
}
Date.prototype.getDaysInMonth = function() {
Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
return Date.daysInMonth[this.getMonth()];
}
Date.prototype.getSuffix = function() {
switch (this.getDate()) {
case 1:
case 21:
case 31:
return "st";
case 2:
case 22:
return "nd";
case 3:
case 23:
return "rd";
default:
return "th";
}
}
String.escape = function(string) {
return string.replace(/('|\\)/g, "\\$1");
}
String.leftPad = function (val, size, ch) {
var result = new String(val);
if (ch == null) {
ch = " ";
}
while (result.length < size) {
result = ch + result;
}
return result;
}
Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];
Date.monthNames =
["January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"];
Date.dayNames =
["Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"];
Date.y2kYear = 50;
Date.monthNumbers = {
Jan:0,
Feb:1,
Mar:2,
Apr:3,
May:4,
Jun:5,
Jul:6,
Aug:7,
Sep:8,
Oct:9,
Nov:10,
Dec:11};
Date.patterns = {
ISO8601LongPattern:"Y-m-d H:i:s",
ISO8601ShortPattern:"Y-m-d",
ShortDatePattern: "n/j/Y",
LongDatePattern: "l, F d, Y",
FullDateTimePattern: "l, F d, Y g:i:s A",
MonthDayPattern: "F d",
ShortTimePattern: "g:i A",
LongTimePattern: "g:i:s A",
SortableDateTimePattern: "Y-m-d\\TH:i:s",
UniversalSortableDateTimePattern: "Y-m-d H:i:sO",
YearMonthPattern: "F, Y"};
var date = new Date("1/1/2007 1:11:11");
for (i = 0; i < 4000; ++i) {
var shortFormat = date.dateFormat("Y-m-d");
var longFormat = date.dateFormat("l, F d, Y g:i:s A");
date.setTime(date.getTime() + 84266956);
}
// FIXME: Find a way to validate this test.
// https://bugs.webkit.org/show_bug.cgi?id=114849
} catch (e) {
print("JSC EXCEPTION FUZZ: Caught exception: " + e);
}

File diff suppressed because one or more lines are too long

View File

@ -1,61 +0,0 @@
var SimpleObject = $vm.SimpleObject;
var setHiddenValue = $vm.setHiddenValue;
load("./driver/driver.js");
function excludeStructure(edges) {
return edges.filter((x) => x.to.className !== "Structure");
}
let simpleObject1NodeId;
let simpleObject2NodeId;
let simpleObject1 = new SimpleObject;
let simpleObject2 = new SimpleObject;
(function() {
let snapshot = createCheapHeapSnapshot();
let nodes = snapshot.nodesWithClassName("SimpleObject");
assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances");
let simpleObject1Node = nodes[0].outgoingEdges.length === 2 ? nodes[0] : nodes[1];
let simpleObject2Node = nodes[0].outgoingEdges.length === 1 ? nodes[0] : nodes[1];
assert(simpleObject1Node.outgoingEdges.length === 1, "'simpleObject1' should reference only its structure");
assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure");
})();
setHiddenValue(simpleObject1, simpleObject2);
(function() {
let snapshot = createCheapHeapSnapshot();
let nodes = snapshot.nodesWithClassName("SimpleObject");
assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances");
let simpleObject1Node = nodes[0].outgoingEdges.length === 2 ? nodes[0] : nodes[1];
let simpleObject2Node = nodes[0].outgoingEdges.length === 1 ? nodes[0] : nodes[1];
assert(simpleObject1Node.outgoingEdges.length === 2, "'simpleObject1' should reference its structure and hidden value");
assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure");
assert(excludeStructure(simpleObject1Node.outgoingEdges)[0].to.id === simpleObject2Node.id, "'simpleObject1' should reference 'simpleObject2'");
simpleObject1NodeId = simpleObject1Node.id;
simpleObject2NodeId = simpleObject2Node.id;
})();
simpleObject2 = null;
(function() {
let snapshot = createCheapHeapSnapshot();
let nodes = snapshot.nodesWithClassName("SimpleObject");
assert(nodes.length === 2, "Snapshot should contain 2 'SimpleObject' instances");
let simpleObject1Node = nodes[0].id === simpleObject1NodeId ? nodes[0] : nodes[1];
let simpleObject2Node = nodes[0].id === simpleObject2NodeId ? nodes[0] : nodes[1];
assert(simpleObject1Node.id === simpleObject1NodeId && simpleObject2Node.id === simpleObject2NodeId, "node identifiers were maintained");
assert(simpleObject1Node.outgoingEdges.length === 2, "'simpleObject1' should reference its structure and hidden value");
assert(simpleObject2Node.outgoingEdges.length === 1, "'simpleObject2' should reference only its structure");
assert(excludeStructure(simpleObject1Node.outgoingEdges)[0].to.id === simpleObject2NodeId, "'simpleObject1' should reference 'simpleObject2'");
})();
simpleObject1 = null;
(function() {
let snapshot = createCheapHeapSnapshot();
let nodes = snapshot.nodesWithClassName("SimpleObject");
assert(nodes.length === 0, "Snapshot should not contain a 'SimpleObject' instance");
})();

View File

@ -1,101 +0,0 @@
var SimpleObject = $vm.SimpleObject;
var setHiddenValue = $vm.setHiddenValue;
load("./driver/driver.js");
let simpleObject = new SimpleObject;
setHiddenValue(simpleObject, "hiddenValue"); // Internal
simpleObject.propertyName1 = "propertyValue1"; // Property
simpleObject["propertyName2"] = "propertyValue2"; // Property
simpleObject[100] = "indexedValue"; // Index
simpleObject[0xffffffff + 100] = "largeIndexValueBecomingProperty"; // Property
simpleObject.point = {x:"x1", y:"y1"}; // Property => object with 2 inline properties.
// ----------
function excludeStructure(edges) {
return edges.filter((x) => x.to.className !== "Structure");
}
let snapshot = createHeapSnapshot();
// Internal, Property, and Index edges on an Object.
let nodes = snapshot.nodesWithClassName("SimpleObject");
assert(nodes.length === 1, "Snapshot should contain 1 'SimpleObject' instance");
let simpleObjectNode = nodes[0];
let edges = excludeStructure(simpleObjectNode.outgoingEdges);
let pointNode = null;
let seenHiddenValue = false;
let seenPropertyName1 = false;
let seenPropertyName2 = false;
let seenIndex100 = false;
let seenLargeIndex = false;
let seenObjectWithInlineStorage = false;
let largeIndexName = (0xffffffff + 100).toString();
for (let edge of edges) {
switch (edge.type) {
case "Internal":
assert(!seenHiddenValue);
seenHiddenValue = true;
break;
case "Property":
if (edge.data === "propertyName1")
seenPropertyName1 = true;
else if (edge.data === "propertyName2")
seenPropertyName2 = true;
else if (edge.data === largeIndexName)
seenLargeIndex = true;
else if (edge.data === "point") {
seenPoint = true;
pointNode = edge.to;
} else
assert(false, "Unexpected property name");
break;
case "Index":
if (edge.data === 100)
seenIndex100 = true;
break;
case "Variable":
assert(false, "Should not see a variable edge for SimpleObject instance");
break;
default:
assert(false, "Unexpected edge type");
break;
}
}
assert(seenHiddenValue, "Should see Internal edge for hidden value");
assert(seenPropertyName1, "Should see Property edge for propertyName1");
assert(seenPropertyName2, "Should see Property edge for propertyName2");
assert(seenIndex100, "Should see Index edge for index 100");
assert(seenLargeIndex, "Should see Property edge for index " + largeIndexName);
// Property on an Object's inline storage.
let pointEdges = excludeStructure(pointNode.outgoingEdges);
let seenPropertyX = false;
let seenPropertyY = false;
for (let edge of pointEdges) {
switch (edge.type) {
case "Property":
if (edge.data === "x")
seenPropertyX = true;
else if (edge.data === "y")
seenPropertyY = true;
else
assert(false, "Unexpected property name");
break;
case "Index":
case "Variable":
case "Internal":
assert(false, "Unexpected edge type");
break;
}
}
assert(seenPropertyX, "Should see Property edge for x");
assert(seenPropertyY, "Should see Property edge for y");

View File

@ -1,25 +0,0 @@
var createBuiltin = $vm.createBuiltin;
import { shouldBe } from "./resources/assert.js";
import * as ns from "./namespace-object-try-get.js"
function tryGetByIdText(propertyName) { return `(function (base) { return @tryGetById(base, '${propertyName}'); })`; }
function tryGetByIdTextStrict(propertyName) { return `(function (base) { "use strict"; return @tryGetById(base, '${propertyName}'); })`; }
{
let get = createBuiltin(tryGetByIdText("empty"));
noInline(get);
// Do not throw.
shouldBe(get(ns), null);
let getStrict = createBuiltin(tryGetByIdTextStrict("empty"));
noInline(getStrict);
// Do not throw.
shouldBe(getStrict(ns), null);
}
export let empty;

View File

@ -1,40 +0,0 @@
var createBuiltin = $vm.createBuiltin;
count = createBuiltin("(function () { return @argumentCount(); })");
countNoInline = createBuiltin("(function () { return @argumentCount(); })");
noInline(countNoInline);
function inlineCount() { return count(); }
noInline(inlineCount);
function inlineCount1() { return count(1); }
noInline(inlineCount1);
function inlineCount2() { return count(1,2); }
noInline(inlineCount2);
function inlineCountVarArgs(list) { return count(...list); }
noInline(inlineCountVarArgs);
function assert(condition, message) {
if (!condition)
throw new Error(message);
}
for (i = 0; i < 1000000; i++) {
assert(count(1,1,2) === 3, i);
assert(count() === 0, i);
assert(count(1) === 1, i);
assert(count(...[1,2,3,4,5]) === 5, i);
assert(count(...[]) === 0, i);
assert(inlineCount() === 0, i);
assert(inlineCount1() === 1, i);
assert(inlineCount2() === 2, i);
assert(inlineCountVarArgs([1,2,3,4]) === 4, i);
assert(inlineCountVarArgs([]) === 0, i);
// Insert extra junk so that inlineCountVarArgs.arguments.length !== count.arguments.length
assert(inlineCountVarArgs([1], 2, 4) === 1, i);
assert(countNoInline(4) === 1, i)
assert(countNoInline() === 0, i);
}

View File

@ -1,20 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(1);
})`);
noInline(builtin);
(function () {
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(), undefined);
shouldBe(builtin(1), undefined);
shouldBe(builtin(1, 2), 2);
shouldBe(builtin(1, 2, 3), 2);
}
}());

View File

@ -1,33 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
function test()
{
return 42;
}
noInline(test);
var builtin = createBuiltin(`(function (a) {
return @argument(2);
})`);
function inlining(a, b, c)
{
return builtin(1, 2, test(), 4, 5, 6, 7);
}
noInline(inlining);
function escape(value)
{
return value;
}
noInline(escape);
(function () {
for (var i = 0; i < 1e4; ++i)
shouldBe(escape(inlining(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), 42);
}());

View File

@ -1,23 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(0);
})`);
function escape(value)
{
return value;
}
noInline(escape);
(function () {
for (var i = 0; i < 1e4; ++i) {
shouldBe(escape(builtin()), undefined);
shouldBe(escape(builtin(42)), 42);
}
}());

View File

@ -1,27 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(5);
})`);
function inlining(a, b, c)
{
return builtin.call(this, ...[1, 2, 3, 4, 5, 6, 7]);
}
noInline(inlining);
function escape(value)
{
return value;
}
noInline(escape);
(function () {
for (var i = 0; i < 1e4; ++i)
shouldBe(escape(inlining(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), 6);
}());

View File

@ -1,27 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(5);
})`);
function inlining(a, b, c)
{
return builtin.call(this, ...[1, 2, 3, 4, 5, 6, 7]);
}
noInline(inlining);
function escape(value)
{
return value;
}
noInline(escape);
(function () {
for (var i = 0; i < 1e4; ++i)
shouldBe(escape(inlining(0)), 6);
}());

View File

@ -1,33 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(0);
})`);
function builtinCaller1()
{
return builtin();
}
function builtinCaller2()
{
return builtin(42);
}
function escape(value)
{
return value;
}
noInline(escape);
(function () {
for (var i = 0; i < 1e4; ++i) {
shouldBe(escape(builtinCaller1()), undefined);
shouldBe(escape(builtinCaller2()), 42);
}
}());

View File

@ -1,17 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
return @argument(0);
})`);
(function () {
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(), undefined);
shouldBe(builtin(42), 42);
}
}());

View File

@ -1,21 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function (a) {
a = 42;
return @argument(0);
})`);
noInline(builtin);
(function () {
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(), undefined);
shouldBe(builtin(1), 42);
shouldBe(builtin(1, 2), 42);
shouldBe(builtin(1, 2, 3), 42);
}
}());

View File

@ -1,23 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var builtin = createBuiltin(`(function () {
return @argument(0);
})`);
function test()
{
var result = builtin();
shouldBe(result, undefined);
var result = builtin(42);
shouldBe(result, 42);
}
noInline(test);
for (var i = 0; i < 1e4; ++i)
test();

View File

@ -1,251 +0,0 @@
// This test was originally for message passing of typed arrays. But it turns out that it is a good
// stress of JSC inline caches as well. So, this is a DOMless version of the test.
var abort = $vm.abort;
var window;
(function() {
var listeners = [];
var messages = [];
window = {
addEventListener: function(type, listener) {
listeners.push(listener);
},
postMessage: function(message) {
messages.push(message);
},
_handleEvents: function() {
for (var i = 0; i < messages.length; ++i) {
for (var j = 0; j < listeners.length; ++j)
listeners[j]({data: messages[i]});
}
messages = [];
}
};
})();
window.jsTestIsAsync = true;
window.testsComplete = 0;
function testPassed() { }
function testFailed(string) {
try {
throw new Error("Test failed: " + string);
} catch (e) {
print(e.message);
print(e.stack);
abort();
}
}
function classCompare(testName, got, sent) {
var classString = Object.prototype.toString;
var gotClass = classString.call(got);
var sentClass = classString.call(sent);
if (gotClass !== sentClass) {
testFailed(testName + ": class " + sentClass + " became " + gotClass);
return false;
} else {
testPassed(testName + ": classes are " + sentClass);
return true;
}
}
function bufferCompare(testName, got, sent) {
if (!classCompare(testName, got, sent)) {
return false;
}
if (got.byteLength !== sent.byteLength) {
testFailed(testName + ": expected byteLength " + sent.byteLength + " bytes, got " + got.byteLength);
return false;
} else {
testPassed(testName + ": buffer lengths are " + sent.byteLength);
}
var gotReader = new Uint8Array(got);
var sentReader = new Uint8Array(sent);
for (var i = 0; i < sent.byteLength; ++i) {
if (gotReader[i] !== sentReader[i]) {
testFailed(testName + ": buffers differ starting at byte " + i);
return false;
}
}
testPassed(testName + ": buffers have the same contents");
return true;
}
function viewCompare(testName, got, sent) {
if (!classCompare(testName, got, sent)) {
return false;
}
if (!bufferCompare(testName, got.buffer, sent.buffer)) {
return false;
}
if (got.byteOffset !== sent.byteOffset) {
testFailed(testName + ": offset " + sent.byteOffset + " became " + got.byteOffset);
return false;
} else {
testPassed(testName + ": offset is " + sent.byteOffset);
}
if (got.byteLength !== sent.byteLength) {
testFailed(testName + ": length " + sent.byteLength + " became " + got.byteLength);
return false;
} else {
testPassed(testName + ": length is " + sent.byteLength);
}
return true;
}
function typedArrayCompare(testName, got, sent) {
if (!viewCompare(testName, got, sent)) {
return false;
}
if (got.BYTES_PER_ELEMENT !== sent.BYTES_PER_ELEMENT) {
// Sanity checking.
testFailed(testName + ": expected BYTES_PER_ELEMENT " + sent.BYTES_PER_ELEMENT + ", saw " + got.BYTES_PER_ELEMENT);
return false;
}
return true;
}
function dataViewCompare(testName, got, sent) {
return viewCompare(testName, got, sent);
}
function dataViewCompare2(testName, got, sent) {
for (var i = 0; i < 2; ++i) {
if (!dataViewCompare(testName, got[i], sent[i])) {
return false;
}
}
if (got[0].buffer !== got[1].buffer) {
testFailed(testName + ": expected the same ArrayBuffer for both views");
return false;
}
return true;
}
function dataViewCompare3(testName, got, sent) {
for (var i = 0; i < 3; i += 2) {
if (!dataViewCompare(testName, got[i], sent[i])) {
return false;
}
}
if (got[1].x !== sent[1].x || got[1].y !== sent[1].y) {
testFailed(testName + ": {x:1, y:1} was not transferred properly");
return false;
}
if (got[0].buffer !== got[2].buffer) {
testFailed(testName + ": expected the same ArrayBuffer for both views");
return false;
}
return false;
}
function createBuffer(length) {
var buffer = new ArrayBuffer(length);
var view = new Uint8Array(buffer);
for (var i = 0; i < length; ++i) {
view[i] = i + 1;
}
return buffer;
}
function createTypedArray(typedArrayType, length) {
var view = new typedArrayType(length);
for (var i = 0; i < length; ++i) {
view[i] = i + 1;
}
return view;
}
function createTypedArrayOverBuffer(typedArrayType, typedArrayElementSize, length, subStart, subLength) {
var buffer = new ArrayBuffer(length * typedArrayElementSize);
if (subStart === undefined) {
subStart = 0;
subLength = length;
}
return new typedArrayType(buffer, subStart * typedArrayElementSize, subLength);
}
var basicBufferTypes = [
["Int32", Int32Array, 4],
["Uint32", Uint32Array, 4],
["Int8", Int8Array, 1],
["Uint8", Uint8Array, 1],
["Uint8Clamped", Uint8ClampedArray, 1],
["Int16", Int16Array, 2],
["Uint16", Uint16Array, 2],
["Float32", Float32Array, 4],
["Float64", Float64Array, 8]
];
var arrayBuffer1 = createBuffer(1);
var testList = [
['ArrayBuffer0', new ArrayBuffer(0), bufferCompare],
['ArrayBuffer1', createBuffer(1), bufferCompare],
['ArrayBuffer128', createBuffer(128), bufferCompare],
['DataView0', new DataView(new ArrayBuffer(0)), dataViewCompare],
['DataView1', new DataView(createBuffer(1)), dataViewCompare],
['DataView1-dup', [new DataView(arrayBuffer1), new DataView(arrayBuffer1)], dataViewCompare2],
['DataView1-dup2', [new DataView(arrayBuffer1), {x:1, y:1}, new DataView(arrayBuffer1)], dataViewCompare3],
['DataView128', new DataView(createBuffer(128)), dataViewCompare],
['DataView1_offset_at_end', new DataView(createBuffer(1), 1, 0), dataViewCompare],
['DataView128_offset_at_end', new DataView(createBuffer(128), 128, 0), dataViewCompare],
['DataView128_offset_slice_length_0', new DataView(createBuffer(128), 64, 0), dataViewCompare],
['DataView128_offset_slice_length_1', new DataView(createBuffer(128), 64, 1), dataViewCompare],
['DataView128_offset_slice_length_16', new DataView(createBuffer(128), 64, 16), dataViewCompare],
['DataView128_offset_slice_unaligned', new DataView(createBuffer(128), 63, 15), dataViewCompare]
];
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_0", createTypedArray(t[1], 0), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_1", createTypedArray(t[1], 1), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128", createTypedArray(t[1], 128), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_0_buffer", createTypedArrayOverBuffer(t[1], t[2], 0), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_1_buffer", createTypedArrayOverBuffer(t[1], t[2], 1), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128_buffer", createTypedArrayOverBuffer(t[1], t[2], 128), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_1_buffer_offset_at_end", createTypedArrayOverBuffer(t[1], t[2], 1, 1, 0), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128_buffer_offset_at_end", createTypedArrayOverBuffer(t[1], t[2], 128, 128, 0), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128_buffer_offset_slice_length_0", createTypedArrayOverBuffer(t[1], t[2], 128, 64, 0), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128_buffer_offset_slice_length_1", createTypedArrayOverBuffer(t[1], t[2], 128, 64, 1), typedArrayCompare];}));
testList = testList.concat(basicBufferTypes.map(function(t)
{return [t[0] + "_128_buffer_offset_slice_length_16", createTypedArrayOverBuffer(t[1], t[2], 128, 64, 16), typedArrayCompare];}));
function doneTest() {
if (++window.testsComplete == testList.length) {
}
}
function windowHandleMessage(e) {
var currentTest = testList[e.data.testNum];
var expectedResult = currentTest[1];
try {
currentTest[2](currentTest[0], e.data.testData, expectedResult);
} catch(e) {
testFailed(currentTest[0] + ": unexpected exception " + e);
}
doneTest();
}
window.addEventListener('message', windowHandleMessage);
for (var t = 0; t < testList.length; ++t) {
var currentTest = testList[t];
var message = {testNum: t, testData: currentTest[1]};
window.postMessage(message, '*');
}
window._handleEvents();

View File

@ -1,12 +0,0 @@
var createBuiltin = $vm.createBuiltin;
var target = createBuiltin(`(function (array)
{
if (array) {
@idWithProfile(array, "SpecOther").push(42);
}
return array;
})`);
noInline(target);
for (var i = 0; i < 1e5; ++i)
target([42]);

View File

@ -1,57 +0,0 @@
function assertEq(a, b) {
if (a !== b)
throw new Error("values not the same: " + a + " and " + b);
}
function withArrayArgInt32(i, array) {
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithInt32");
}
noInline(withArrayArgInt32);
function withArrayLiteralInt32(i) {
let array = [0,1,2];
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithInt32");
}
noInline(withArrayLiteralInt32);
function withArrayArgDouble(i, array) {
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithDouble");
}
noInline(withArrayArgDouble);
function withArrayLiteralDouble(i) {
let array = [0,1.3145,2];
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithDouble");
}
noInline(withArrayLiteralDouble);
function withArrayArgContiguous(i, array) {
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithContiguous");
}
noInline(withArrayArgContiguous);
function withArrayLiteralContiguous(i) {
let array = [0,"string",2];
let result = array[i];
assertEq($vm.indexingMode(array), "CopyOnWriteArrayWithContiguous");
}
noInline(withArrayLiteralContiguous);
function test() {
withArrayArgInt32(0, [0,1,2]);
withArrayArgDouble(0, [0,1.3145,2]);
withArrayArgContiguous(0, [0,"string",2]);
withArrayLiteralInt32(0);
withArrayLiteralDouble(0);
withArrayLiteralContiguous(0);
}
for (let i = 0; i < 10000; i++)
test();

View File

@ -1,22 +0,0 @@
var createDOMJITFunctionObject = $vm.createDOMJITFunctionObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var array = [];
for (var i = 0; i < 100; ++i)
array.push(createDOMJITFunctionObject());
function calling(dom)
{
return dom.func();
}
noInline(calling);
for (var i = 0; i < 1e3; ++i) {
array.forEach((obj) => {
shouldBe(calling(obj), 42);
});
}

View File

@ -1,54 +0,0 @@
var createDOMJITNodeObject = $vm.createDOMJITNodeObject;
var createDOMJITCheckSubClassObject = $vm.createDOMJITCheckSubClassObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + 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)}`);
}
var array = [];
for (var i = 0; i < 100; ++i)
array.push(createDOMJITCheckSubClassObject());
// DOMJITNode is an instance of a super class (DOMJITNode) of DOMJITCheckSubClassObject.
var node = createDOMJITNodeObject();
node.func = createDOMJITCheckSubClassObject().func;
function calling(dom)
{
return dom.func();
}
noInline(calling);
array.forEach((obj) => {
shouldBe(calling(obj), 42);
});
shouldThrow(() => {
calling(node);
}, `TypeError: Type error`);
for (var i = 0; i < 1e3; ++i) {
array.forEach((obj) => {
shouldBe(calling(obj), 42);
});
}
shouldThrow(() => {
calling(node);
}, `TypeError: Type error`);

View File

@ -1,12 +0,0 @@
var createBuiltin = $vm.createBuiltin;
const test = createBuiltin(`(function (arg) {
let other = @undefined;
@idWithProfile(other, "SpecObject");
return arg == other;
})`);
for (let i = 0; i < 10000; i++) {
test({});
test(null);
}

View File

@ -1,69 +0,0 @@
var createCustomTestGetterSetter = $vm.createCustomTestGetterSetter;
function assert(b, m) {
if (!b)
throw new Error("Bad:" + m);
}
class Class { };
let items = [
new Class,
new Class,
new Class,
new Class,
];
let customGetterSetter = createCustomTestGetterSetter();
items.forEach((x) => {
x.__proto__ = customGetterSetter;
assert(x.__proto__ === customGetterSetter);
});
function validate(x, valueResult, accessorResult) {
assert(x.customValue === valueResult);
assert(x.customAccessor === accessorResult);
let o = {};
x.customValue = o;
assert(o.result === valueResult);
o = {};
x.customAccessor = o;
assert(o.result === accessorResult);
assert(x.randomProp === 42 || x.randomProp === undefined);
}
noInline(validate);
let start = Date.now();
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], customGetterSetter, items[i]);
}
}
customGetterSetter.randomProp = 42;
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], customGetterSetter, items[i]);
}
}
items.forEach((x) => {
Reflect.setPrototypeOf(x, {
get customValue() { return 42; },
get customAccessor() { return 22; },
set customValue(x) { x.result = 42; },
set customAccessor(x) { x.result = 22; },
});
});
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], 42, 22);
}
}

View File

@ -1,21 +0,0 @@
function foo() {
var value = bar($vm.dfgTrue());
fiatInt52(value);
fiatInt52(value);
}
var thingy = false;
function bar(p) {
if (thingy)
return "hello";
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i)
foo();
thingy = true;
foo();

View File

@ -1,21 +0,0 @@
function foo() {
var value = bar($vm.dfgTrue());
fiatInt52(value);
fiatInt52(value);
}
var thingy = false;
function bar(p) {
if (thingy)
return 5.5;
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i)
foo();
thingy = true;
foo();

View File

@ -1,16 +0,0 @@
function foo() {
var value = bar($vm.dfgTrue());
fiatInt52(value);
fiatInt52(value);
}
function bar(p) {
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i)
foo();

View File

@ -1,16 +0,0 @@
function foo() {
var o = {f:42};
var result = 0;
OSRExit();
for (var i = 0; i < 10000; ++i) {
if (!$vm.dfgTrue())
result += o.f;
}
return result;
}
for (var i = 0; i < 1000; ++i) {
foo();
fullGC();
}

View File

@ -1,29 +0,0 @@
var abort = $vm.abort;
function assert(b) {
if (!b) {
abort();
}
}
noInline(assert);
let test;
function f(eval) {
assert(eval === test);
eval(0x0);
f(test);
}
for (let i = 0; i < 20; ++i) {
test = function test() { return i; }
}
let error;
try {
f(test);
} catch(e) {
error = e;
}
assert(!!error);
assert(error instanceof RangeError);

View File

@ -1,41 +0,0 @@
var createDOMJITGetterBaseJSObject = $vm.createDOMJITGetterBaseJSObject;
function assert(b, m) {
if (!b)
throw new Error("Bad:" + m);
}
function makePolyProtoObject() {
function foo() {
class C {
constructor() {
this._field = 25;
}
};
return new C;
}
for (let i = 0; i < 15; ++i)
foo();
return foo();
}
let proto = createDOMJITGetterBaseJSObject();
let obj = makePolyProtoObject();
obj.__proto__ = proto;
function validate(x, v) {
assert(x.customGetter === v, x.customGetter);
}
noInline(validate);
for (let i = 0; i < 1000; ++i)
validate(obj, proto);
proto.foo = 25;
for (let i = 0; i < 1000; ++i)
validate(obj, proto);
Reflect.setPrototypeOf(obj, {});
for (let i = 0; i < 1000; ++i) {
validate(obj, undefined);
}

View File

@ -1,39 +0,0 @@
var createDOMJITGetterComplexObject = $vm.createDOMJITGetterComplexObject;
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)}`);
}
(function () {
let domjit = createDOMJITGetterComplexObject();
function access(object)
{
return object.customGetter;
}
noInline(access);
let normal = {
customGetter: 42
};
for (let i = 0; i < 1e4; ++i) {
shouldBe(access(domjit), 42);
shouldBe(access(normal), 42);
}
domjit.enableException();
shouldThrow(() => access(domjit), `Error: DOMJITGetterComplex slow call exception`);
}());

View File

@ -1,69 +0,0 @@
var createDOMJITGetterComplexObject = $vm.createDOMJITGetterComplexObject;
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)}`);
}
(function () {
let domjit = createDOMJITGetterComplexObject();
function access(object)
{
return object.customGetter;
}
noInline(access);
for (var i = 0; i < 1e4; ++i)
shouldBe(access(domjit), 42);
domjit.enableException();
shouldThrow(() => access(domjit), `Error: DOMJITGetterComplex slow call exception`);
}());
(function () {
let domjit = createDOMJITGetterComplexObject();
function access(object)
{
return object.customGetter;
}
noInline(access);
for (let i = 0; i < 1e2; ++i)
shouldBe(access(domjit), 42);
domjit.enableException();
shouldThrow(() => access(domjit), `Error: DOMJITGetterComplex slow call exception`);
}());
(function () {
let domjit = createDOMJITGetterComplexObject();
function access(object)
{
return object.customGetter;
}
noInline(access);
for (let i = 0; i < 50; ++i)
shouldBe(access(domjit), 42);
domjit.enableException();
shouldThrow(() => access(domjit), `Error: DOMJITGetterComplex slow call exception`);
}());
(function () {
let domjit = createDOMJITGetterComplexObject();
function access(object)
{
return object.customGetter;
}
noInline(access);
for (let i = 0; i < 10; ++i)
shouldBe(access(domjit), 42);
domjit.enableException();
shouldThrow(() => access(domjit), `Error: DOMJITGetterComplex slow call exception`);
}());

View File

@ -1,30 +0,0 @@
var createDOMJITGetterComplexObject = $vm.createDOMJITGetterComplexObject;
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)}`);
}
var complex = createDOMJITGetterComplexObject();
var object = {};
object.__proto__ = complex;
function access(object)
{
return object.customGetter;
}
noInline(access);
for (var i = 0; i < 1e4; ++i) {
shouldThrow(() => {
access(object);
}, `TypeError: The DOMJITGetterComplex.customGetter getter can only be used on instances of DOMJITGetterComplex`);
}

View File

@ -1,16 +0,0 @@
var createDOMJITGetterComplexObject = $vm.createDOMJITGetterComplexObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
var complex = createDOMJITGetterComplexObject();
function access(complex)
{
return complex.customGetter;
}
noInline(access);
for (var i = 0; i < 1e4; ++i) {
shouldBe(access(complex), 42);
}

View File

@ -1,21 +0,0 @@
var createDOMJITGetterObject = $vm.createDOMJITGetterObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
var domjit1 = createDOMJITGetterObject();
var domjit2 = createDOMJITGetterObject();
function access(domjit)
{
return domjit.customGetter + domjit.customGetter;
}
for (var i = 0; i < 1e4; ++i)
shouldBe(access((i & 0x1) ? domjit1 : domjit2), 84);
shouldBe(access({ customGetter: 42 }), 84);
domjit1.test = 44;
shouldBe(access(domjit1), 84);

View File

@ -1,19 +0,0 @@
var createDOMJITNodeObject = $vm.createDOMJITNodeObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
var domjit = createDOMJITNodeObject();
function access(domjit)
{
return domjit.customGetter + domjit.customGetter;
}
for (var i = 0; i < 1e4; ++i)
shouldBe(access(domjit), 84);
shouldBe(access({ customGetter: 42 }), 84);
domjit.test = 44;
shouldBe(access(domjit), 84);

View File

@ -1,20 +0,0 @@
var createDOMJITGetterObject = $vm.createDOMJITGetterObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
var domjits = [];
for (var i = 0; i < 100; ++i)
domjits.push(createDOMJITGetterObject());
function access(domjit)
{
return domjit.customGetter + domjit.customGetter;
}
for (var i = 0; i < 1e2; ++i) {
for (var j = 0; j < domjits.length; ++j)
shouldBe(access(domjits[j]), 84);
}

View File

@ -1,54 +0,0 @@
var createDOMJITGetterComplexObject = $vm.createDOMJITGetterComplexObject;
function assert(b) {
if (!b) throw new Error("bad value");
}
noInline(assert);
let i;
var o1 = createDOMJITGetterComplexObject();
o1.x = "x";
var o2 = {
customGetter: 40
}
var o3 = {
x: 100,
customGetter: "f"
}
function bar(i) {
if (i === -1000)
return o1;
if (i % 2)
return o3;
else
return o2;
}
noInline(bar);
function foo(i) {
var o = bar(i);
let v;
let v2;
let v3;
try {
v2 = o.x;
v = o.customGetter + v2;
} catch(e) {
assert(v2 === "x");
assert(o === o1);
}
}
noInline(foo);
foo(i);
for (i = 0; i < 1000; i++)
foo(i);
o1.enableException();
i = -1000;
for (let j = 0; j < 1000; j++)
foo(i);

View File

@ -1,28 +0,0 @@
var createDOMJITGetterObject = $vm.createDOMJITGetterObject;
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)}`);
}
var domjit = createDOMJITGetterObject();
for (var i = 0; i < 1e3; ++i) {
shouldThrow(() => {
Reflect.get(domjit, 'customGetter', { customGetter: 42 });
}, `TypeError: The DOMJITNode.customGetter getter can only be used on instances of DOMJITNode`);
}

View File

@ -1,20 +0,0 @@
var createDOMJITGetterObject = $vm.createDOMJITGetterObject;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
var domjit = createDOMJITGetterObject();
function access(domjit)
{
return domjit.customGetter + domjit.customGetter;
}
for (var i = 0; i < 1e4; ++i)
shouldBe(access(domjit), 84);
shouldBe(access({ customGetter: 42 }), 84);
domjit.test = 44;
shouldBe(access(domjit), 84);

View File

@ -1,33 +0,0 @@
var createBuiltin = $vm.createBuiltin;
let i;
function verify(a, b, c, d, e, f) {
function assert(b, m) {
if (!b)
throw new Error(m);
}
assert(a === i);
assert(b === i+1);
assert(c === i+2);
assert(d === null);
assert(e === undefined);
assert(f === undefined);
}
noInline(verify);
function func(a, b, c, d, e, f)
{
verify(a, b, c, d, e, f);
return !!(a%2) ? a + b + c + d : a + b + c + d;
}
const bar = createBuiltin(`(function (f, a, b, c, d) {
let y = @idWithProfile(null, "SpecInt32Only");
return f(a, b, c, y);
})`);
noInline(bar);
for (i = 0; i < 1000; ++i) {
bar(func, i, i+1, i+2, i+3);
}

View File

@ -1,24 +0,0 @@
function foo() {
return fiatInt52(bar($vm.dfgTrue())) + 1;
}
var thingy = false;
function bar(p) {
if (thingy)
return "hello";
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i) {
var result = foo();
if (result != 43 && result != 6.5)
throw "Error: bad result: " + result;
}
thingy = true;
var result = foo();
if (result != "hello1")
throw "Error: bad result at end: " + result;

View File

@ -1,24 +0,0 @@
function foo() {
return fiatInt52(bar($vm.dfgTrue())) + 1;
}
var thingy = false;
function bar(p) {
if (thingy)
return 5.5;
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i) {
var result = foo();
if (result != 43 && result != 6.5)
throw "Error: bad result: " + result;
}
thingy = true;
var result = foo();
if (result != 6.5)
throw "Error: bad result at end: " + result;

View File

@ -1,11 +0,0 @@
function foo() {
return fiatInt52($vm.dfgTrue() ? 5.5 : 42) + 1;
}
noInline(foo);
for (var i = 0; i < 1000000; ++i) {
var result = foo();
if (result != 43 && result != 6.5)
throw "Error: bad result: " + result;
}

View File

@ -1,11 +0,0 @@
function foo() {
return fiatInt52($vm.dfgTrue() ? 42 : 5.5) + 1;
}
noInline(foo);
for (var i = 0; i < 1000000; ++i) {
var result = foo();
if (result != 43 && result != 6.5)
throw "Error: bad result: " + result;
}

View File

@ -1,16 +0,0 @@
function foo() {
return fiatInt52(bar($vm.dfgTrue())) + 1;
}
function bar(p) {
return p ? 42 : 5.5;
}
noInline(foo);
noInline(bar);
for (var i = 0; i < 1000000; ++i) {
var result = foo();
if (result != 43 && result != 6.5)
throw "Error: bad result: " + result;
}

View File

@ -1,7 +0,0 @@
let o = { foo: 1, bar: 2, baz: 3 };
if ($vm.inlineCapacity(o) <= 3)
throw new Error("There should be inline capacity");
delete o.foo;
$vm.flattenDictionaryObject(o);
o.foo = 1;

View File

@ -1,17 +0,0 @@
function foo(a, b) {
var value = $vm.dfgTrue() ? -0 : "foo";
if (a * b == value)
return [$vm.dfgTrue(), true];
return [$vm.dfgTrue(), false];
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(1, 1);
if (result[1] !== false)
throw "Error: bad result: " + result;
}
var result = foo(-1, 0);
if (result[1] !== true && result[0])
throw "Error: bad result at end: " + result;

View File

@ -1,24 +0,0 @@
function foo(f) {
if ($vm.dfgTrue())
f = bar;
return f().f;
}
noInline(foo);
var object;
function bar() {
return object;
}
function baz() { return {f:42}; };
object = {f:42};
for (var i = 0; i < 1000; ++i)
foo((i & 1) ? bar : baz);
object = {e:1, f:2};
var result = foo(bar);
if (result != 2)
throw "Error: bad result: " + result;

View File

@ -1,17 +0,0 @@
function foo(a, b) {
if ($vm.dfgTrue())
a = b = 5.4;
var c = a + b;
if (isFinalTier())
OSRExit();
return c + 0.5;
}
noInline(foo);
for (var i = 0; i < 100000; ++i) {
var result = foo(1.4, 1.3);
if (result != 1.4 + 1.3 + 0.5 && result != 5.4 + 5.4 + 0.5)
throw "Error: bad result: " + result;
}

View File

@ -1,17 +0,0 @@
function foo(a, b) {
if ($vm.dfgTrue())
a = b = 2000000000;
var c = a + b;
if (isFinalTier())
OSRExit();
return c + 42;
}
noInline(foo);
for (var i = 0; i < 100000; ++i) {
var result = foo(2000000001, 2000000001);
if (result != 2000000001 + 2000000001 + 42 && result != 2000000000 + 2000000000 + 42)
throw "Error: bad result: " + result;
}

View File

@ -1,14 +0,0 @@
function foo(x) {
if ($vm.dfgTrue())
x = "hello";
return x + " world";
}
noInline(foo);
for (var i = 0; i < 100000; ++i) {
var result = foo({toString:function() { return "foo" }});
if (result != "foo world" && result != "hello world")
throw "Error: bad result: " + result;
}

View File

@ -1,14 +0,0 @@
function foo(x, p) {
if ($vm.dfgTrue())
x = p ? "hello" : "bar";
return x + " world";
}
noInline(foo);
for (var i = 0; i < 100000; ++i) {
var result = foo({toString:function() { return "foo" }}, i & 1);
if (result != "foo world" && result != "hello world" && result != "bar world")
throw "Error: bad result: " + result;
}

View File

@ -1,34 +0,0 @@
var createProxy = $vm.createProxy;
var theO;
function deleteAll() {
delete theO.a;
delete theO.b;
delete theO.c;
delete theO.d;
for (var i = 0; i < 10; ++i)
theO["i" + i] = 42;
theO.a = 11;
theO.b = 12;
theO.c = 13;
theO.d = 14;
}
function foo(o_) {
var o = o_;
var result = 0;
for (var s in o) {
result += o[s];
deleteAll();
}
return result;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(createProxy(theO = {a:1, b:2, c:3, d:4}));
if (result != 1 + 12 + 13 + 14)
throw "Error: bad result: " + result;
}

View File

@ -1,18 +0,0 @@
var createProxy = $vm.createProxy;
function foo(o_) {
var o = o_;
var result = 0;
for (var s in o) {
result += o[s];
}
return result;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(createProxy({a:1, b:2, c:3, d:4}));
if (result != 1 + 2 + 3 + 4)
throw "Error: bad result: " + result;
}

View File

@ -1,40 +0,0 @@
// Tests that opaque roots behave correctly during young generation collections
var Element = $vm.Element;
var Root = $vm.Root;
var getElement = $vm.getElement;
try {
// regression test for bug 160773. This should not crash.
new (Element.bind());
} catch(e) {
}
// Create the primary Root.
var root = new Root();
// This secondary root is for allocating a second Element without overriding
// the primary Root's Element.
var otherRoot = new Root();
// Run an Eden collection so that the Root will be in the old gen (and won't be rescanned).
edenGC();
// Create a new Element and set a custom property on it.
var elem = new Element(root);
elem.customProperty = "hello";
// Make the Element unreachable except through the ephemeron with the Root.
elem = null;
// Create another Element so that we process the weak handles in block of the original Element.
var test = new Element(otherRoot);
// Run another Eden collection to process the weak handles in the Element's block. If opaque roots
// are cleared then we'll think that the original Element is dead because the Root won't be in the
// set of opaque roots.
edenGC();
// Check if the primary Root's Element exists and has our custom property.
var elem = getElement(root);
if (elem.customProperty != "hello")
throw new Error("bad value of customProperty: " + elem.customProperty);

View File

@ -1,112 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + 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)}`);
}
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "hello");
})`);
noInline(builtin);
var obj = { get hello() { return 42; }, world:33 };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj), 42);
var obj2 = { hello: 22 };
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(obj), 42);
shouldBe(builtin(obj2), 22);
}
var obj3 = { };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj3), undefined);
var obj4 = {
__proto__: { hello: 33 }
};
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj4), undefined);
var target5 = "Hello";
var target6 = 42;
var target7 = false;
var target8 = Symbol("Cocoa");
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(target5), undefined);
shouldBe(builtin(target6), undefined);
shouldBe(builtin(target7), undefined);
shouldBe(builtin(target8), undefined);
}
shouldThrow(() => {
builtin(null);
}, `TypeError: null is not an object`);
shouldThrow(() => {
builtin(undefined);
}, `TypeError: undefined is not an object`);
shouldBe(builtin(obj), 42);
shouldBe(builtin(obj2), 22);
shouldBe(builtin(obj3), undefined);
shouldBe(builtin(obj4), undefined);
shouldBe(builtin(target5), undefined);
shouldBe(builtin(target6), undefined);
shouldBe(builtin(target7), undefined);
shouldBe(builtin(target8), undefined);
}());
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "hello");
})`);
noInline(builtin);
var obj = { };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj), undefined);
shouldBe(builtin(obj), undefined);
obj.hello = 42;
shouldBe(builtin(obj), 42);
}());
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "length");
})`);
noInline(builtin);
var array = [0, 1, 2];
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(array), 3);
shouldBe(builtin({}), undefined);
var obj = { length:2 };
var obj2 = { get length() { return 2; } };
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(array), 3);
shouldBe(builtin(obj), 2);
shouldBe(builtin(obj2), 2);
shouldBe(builtin("Cocoa"), 5);
}
}());

View File

@ -1,110 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + 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)}`);
}
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "hello");
})`);
noInline(builtin);
var obj = { hello: 42, world:33 };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj), 42);
var obj2 = { hello: 22 };
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(obj), 42);
shouldBe(builtin(obj2), 22);
}
var obj3 = { };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj3), undefined);
var obj4 = {
__proto__: { hello: 33 }
};
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj4), undefined);
var target5 = "Hello";
var target6 = 42;
var target7 = false;
var target8 = Symbol("Cocoa");
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(target5), undefined);
shouldBe(builtin(target6), undefined);
shouldBe(builtin(target7), undefined);
shouldBe(builtin(target8), undefined);
}
shouldThrow(() => {
builtin(null);
}, `TypeError: null is not an object`);
shouldThrow(() => {
builtin(undefined);
}, `TypeError: undefined is not an object`);
shouldBe(builtin(obj), 42);
shouldBe(builtin(obj2), 22);
shouldBe(builtin(obj3), undefined);
shouldBe(builtin(obj4), undefined);
shouldBe(builtin(target5), undefined);
shouldBe(builtin(target6), undefined);
shouldBe(builtin(target7), undefined);
shouldBe(builtin(target8), undefined);
}());
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "hello");
})`);
noInline(builtin);
var obj = { };
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(obj), undefined);
shouldBe(builtin(obj), undefined);
obj.hello = 42;
shouldBe(builtin(obj), 42);
}());
(function () {
var builtin = createBuiltin(`(function (obj) {
return @getByIdDirect(obj, "length");
})`);
noInline(builtin);
var array = [0, 1, 2];
for (var i = 0; i < 1e4; ++i)
shouldBe(builtin(array), 3);
shouldBe(builtin({}), undefined);
var obj = { length:2 };
for (var i = 0; i < 1e4; ++i) {
shouldBe(builtin(array), 3);
shouldBe(builtin(obj), 2);
shouldBe(builtin("Cocoa"), 5);
}
}());

View File

@ -1,15 +0,0 @@
var setGlobalConstRedeclarationShouldNotThrow = $vm.setGlobalConstRedeclarationShouldNotThrow;
function assert(b) {
if (!b)
throw new Error("Bad assertion.");
}
setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
for (let i = 0; i < 100; i++) {
load("./global-const-redeclaration-setting/first.js");
assert(foo === 20);
load("./global-const-redeclaration-setting/second.js");
assert(foo === 40);
}

View File

@ -1,20 +0,0 @@
var setGlobalConstRedeclarationShouldNotThrow = $vm.setGlobalConstRedeclarationShouldNotThrow;
function assert(b) {
if (!b)
throw new Error("Bad assertion.");
}
setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
load("./global-const-redeclaration-setting/first.js");
assert(foo === 20);
let threw = false;
try {
load("./global-const-redeclaration-setting/strict.js"); // We ignore the setting and always throw an error when in strict mode!
} catch(e) {
threw = true;
}
assert(threw);
assert(foo === 20);

View File

@ -1,20 +0,0 @@
var setGlobalConstRedeclarationShouldNotThrow = $vm.setGlobalConstRedeclarationShouldNotThrow;
function assert(b) {
if (!b)
throw new Error("Bad assertion.");
}
setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
load("./global-const-redeclaration-setting/first.js");
assert(foo === 20);
let threw = false;
try {
load("./global-const-redeclaration-setting/let.js"); // Redeclaration a 'let' variable should throw because this doesn't break backwards compat.
} catch(e) {
threw = true;
}
assert(threw);
assert(foo === 20);

View File

@ -1,20 +0,0 @@
var setGlobalConstRedeclarationShouldNotThrow = $vm.setGlobalConstRedeclarationShouldNotThrow;
function assert(b) {
if (!b)
throw new Error("Bad assertion.");
}
setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
load("./global-const-redeclaration-setting/let.js");
assert(foo === 50);
let threw = false;
try {
load("./global-const-redeclaration-setting/first.js"); // Redeclaration of a 'let' to 'const' should always throw because it isn't breaking backwards compat.
} catch(e) {
threw = true;
}
assert(threw);
assert(foo === 50);

View File

@ -1,13 +0,0 @@
var setGlobalConstRedeclarationShouldNotThrow = $vm.setGlobalConstRedeclarationShouldNotThrow;
function assert(b) {
if (!b)
throw new Error("Bad assertion.");
}
setGlobalConstRedeclarationShouldNotThrow(); // Allow duplicate const declarations at the global level.
load("./global-const-redeclaration-setting/first.js");
assert(foo === 20);
load("./global-const-redeclaration-setting/second.js");
assert(foo === 40);

View File

@ -1,48 +0,0 @@
//@ if isFTLEnabled then runFTLNoCJIT else skip end
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var didFTLCompile = false;
var ftlTrue = $vm.ftlTrue;
function test1(array)
{
didFTLCompile = ftlTrue();
return 2 in array;
}
noInline(test1);
var array = [1, 2, 3, 4];
ensureArrayStorage(array);
didFTLCompile = false;
for (var i = 0; i < 1e5; ++i)
shouldBe(test1(array), true);
shouldBe(didFTLCompile, true);
var array = [1, 2, , 4];
ensureArrayStorage(array);
shouldBe(test1(array), false);
var array = [];
ensureArrayStorage(array);
shouldBe(test1(array), false);
function test2(array)
{
didFTLCompile = ftlTrue();
return 13 in array;
}
noInline(test2);
var array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14];
ensureArrayStorage(array1);
var array2 = [1, 2];
ensureArrayStorage(array2);
didFTLCompile = false;
for (var i = 0; i < 1e5; ++i)
shouldBe(test2(array2), false);
shouldBe(didFTLCompile, true);
shouldBe(test2(array2), false);
shouldBe(test2(array1), true);

View File

@ -1,61 +0,0 @@
//@ if isFTLEnabled then runFTLNoCJIT else skip end
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var didFTLCompile = false;
var ftlTrue = $vm.ftlTrue;
function test1(array)
{
didFTLCompile = ftlTrue();
return 2 in array;
}
noInline(test1);
var object = { a: 10 };
Object.defineProperties(object, {
"0": {
get: function() { return this.a; },
set: function(x) { this.a = x; },
},
});
var array = [1, 2, 3, 4];
array.__proto__ = object;
ensureArrayStorage(array);
didFTLCompile = false;
for (var i = 0; i < 1e5; ++i)
shouldBe(test1(array), true);
shouldBe(didFTLCompile, true);
var array = [1, 2, , 4];
array.__proto__ = object;
ensureArrayStorage(array);
shouldBe(test1(array), false);
var array = [];
array.__proto__ = object;
ensureArrayStorage(array);
shouldBe(test1(array), false);
function test2(array)
{
didFTLCompile = ftlTrue();
return 9 in array;
}
noInline(test2);
var array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
array1.__proto__ = object;
ensureArrayStorage(array1);
var array2 = [1, 2];
array2.__proto__ = object;
ensureArrayStorage(array2);
didFTLCompile = false;
for (var i = 0; i < 1e5; ++i)
shouldBe(test2(array2), false);
shouldBe(didFTLCompile, true);
shouldBe(test2(array2), false);
shouldBe(test2(array1), true);

View File

@ -1,55 +0,0 @@
var abort = $vm.abort;
(async function () {
const { shouldBe } = await import('./import-tests/should.js');
{
let a = await import('./import-tests/cocoa.js');
let b = await import('./import-tests/cocoa.js');
shouldBe(a, b);
shouldBe(a.hello(), 42);
}
{
let a = await import('./import-tests/multiple.js');
let a2 = await a.result();
shouldBe(a !== a2, true);
shouldBe(a2.ok(), 42);
let a3 = await a.result();
shouldBe(a2, a3);
}
{
let error = null;
try {
let a = await import({ toString() { throw new Error('out'); } });
} catch (e) {
error = e;
}
shouldBe(error !== null, true);
shouldBe(String(error), `Error: out`);
}
{
async function load(cond) {
if (cond)
return import('./import-tests/cocoa.js');
return undefined;
}
let v = await load(false);
shouldBe(v, undefined);
let v2 = await load(true);
let v3 = await import('./import-tests/cocoa.js');
shouldBe(v2, v2);
}
{
let value = './import-tests/cocoa.js';
let v = await import(value);
let v2 = await import('./import-tests/cocoa.js');
shouldBe(v, v2);
}
}()).catch((error) => {
print(String(error));
abort();
});

View File

@ -1,38 +0,0 @@
var abort = $vm.abort;
(async function () {
const { shouldBe, shouldThrow } = await import("./import-tests/should.js");
{
let cocoa = await eval(`import("./import-tests/cocoa.js")`);
shouldBe(cocoa.hello(), 42);
}
{
let cocoa = await (0, eval)(`import("./import-tests/cocoa.js")`);
shouldBe(cocoa.hello(), 42);
}
{
let cocoa = await eval(`eval('import("./import-tests/cocoa.js")')`);
shouldBe(cocoa.hello(), 42);
}
{
let cocoa = await ((new Function(`return eval('import("./import-tests/cocoa.js")')`))());
shouldBe(cocoa.hello(), 42);
}
{
let cocoa = await eval(`(new Function('return import("./import-tests/cocoa.js")'))()`);
shouldBe(cocoa.hello(), 42);
}
{
let cocoa = await [`import("./import-tests/cocoa.js")`].map(eval)[0];
shouldBe(cocoa.hello(), 42);
}
}()).catch((error) => {
print(String(error));
abort();
});

View File

@ -1,17 +0,0 @@
var abort = $vm.abort;
function shouldBe(actual, expected)
{
if (actual !== expected)
abort();
}
let x = {
get toString() {
throw new Error('bad');
}
};
import(x).then(abort, function (error) {
shouldBe(String(error), `Error: bad`);
});

View File

@ -1,66 +0,0 @@
var abort = $vm.abort;
function testSyntaxError(script, message) {
var error = null;
try {
eval(script);
} catch (e) {
error = e;
}
if (!error)
throw new Error("Expected syntax error not thrown");
if (String(error) !== message)
throw new Error(`Bad error: ${String(error)}`);
}
async function testSyntax(script, message) {
var error = null;
try {
await eval(script);
} catch (e) {
error = e;
}
if (error) {
if (error instanceof SyntaxError)
throw new Error("Syntax error thrown");
}
}
testSyntaxError(`import)`, `SyntaxError: Unexpected token ')'. import call expects exactly one argument.`);
testSyntaxError(`new import(`, `SyntaxError: Cannot use new with import.`);
testSyntaxError(`import.hello()`, `SyntaxError: Unexpected identifier 'hello'. "import." can only followed with meta.`);
testSyntaxError(`import[`, `SyntaxError: Unexpected token '['. import call expects exactly one argument.`);
testSyntaxError(`import<`, `SyntaxError: Unexpected token '<'. import call expects exactly one argument.`);
testSyntaxError(`import()`, `SyntaxError: Unexpected token ')'`);
testSyntaxError(`import(a, b)`, `SyntaxError: Unexpected token ','. import call expects exactly one argument.`);
testSyntaxError(`import(a, b, c)`, `SyntaxError: Unexpected token ','. import call expects exactly one argument.`);
testSyntaxError(`import(...a)`, `SyntaxError: Unexpected token '...'`);
testSyntaxError(`import(,a)`, `SyntaxError: Unexpected token ','`);
testSyntaxError(`import(,)`, `SyntaxError: Unexpected token ','`);
testSyntaxError(`import("Hello";`, `SyntaxError: Unexpected token ';'. import call expects exactly one argument.`);
testSyntaxError(`import("Hello"];`, `SyntaxError: Unexpected token ']'. import call expects exactly one argument.`);
testSyntaxError(`import("Hello",;`, `SyntaxError: Unexpected token ','. import call expects exactly one argument.`);
testSyntaxError(`import("Hello", "Hello2";`, `SyntaxError: Unexpected token ','. import call expects exactly one argument.`);
testSyntaxError(`import = 42`, `SyntaxError: Unexpected token '='. import call expects exactly one argument.`);
testSyntaxError(`[import] = 42`, `SyntaxError: Unexpected token ']'. import call expects exactly one argument.`);
testSyntaxError(`{import} = 42`, `SyntaxError: Unexpected token '}'. import call expects exactly one argument.`);
testSyntaxError(`let import = 42`, `SyntaxError: Unexpected keyword 'import'`);
testSyntaxError(`var import = 42`, `SyntaxError: Cannot use the keyword 'import' as a variable name.`);
testSyntaxError(`const import = 42`, `SyntaxError: Cannot use the keyword 'import' as a lexical variable name.`);
(async function () {
await testSyntax(`import("./import-tests/cocoa.js")`);
await testSyntax(`import("./import-tests/../import-tests/cocoa.js")`);
await testSyntax(`import("./import-tests/../import-tests/cocoa.js").then(() => { })`);
await testSyntax(`(import("./import-tests/../import-tests/cocoa.js").then(() => { }))`);
await testSyntax(`(import("./import-tests/../import-tests/cocoa.js"))`);
await testSyntax(`import("./import-tests/../import-tests/cocoa.js").catch(() => { })`);
await testSyntax(`(import("./import-tests/../import-tests/cocoa.js").catch(() => { }))`);
}()).catch((error) => {
print(String(error));
abort();
});

View File

@ -1,2 +0,0 @@
import("").then($vm.abort, function () {
});

View File

@ -1,19 +0,0 @@
var createImpureGetter = $vm.createImpureGetter;
var setImpureGetterDelegate = $vm.setImpureGetterDelegate;
var ig = createImpureGetter(null);
ig.x = 42;
var foo = function(o) {
return o.x;
};
noInline(foo);
for (var i = 0; i < 10000; ++i)
foo(ig);
setImpureGetterDelegate(ig, {x:"x"});
if (foo(ig) !== "x")
throw new Error("Incorrect result!");

View File

@ -1,25 +0,0 @@
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
function test1(object)
{
return "customValue" in object;
}
noInline(test1);
function test2(object)
{
return "customAccessor" in object;
}
noInline(test2);
var target1 = $vm.createCustomTestGetterSetter();
var target2 = { __proto__: target1 };
for (var i = 0; i < 1e5; ++i) {
shouldBe(test1(target1), true);
shouldBe(test1(target2), true);
shouldBe(test2(target1), true);
shouldBe(test2(target2), true);
}

View File

@ -1,15 +0,0 @@
function foo(a, b, c) {
var o = {f:42};
if ($vm.dfgTrue())
o.f = a + b + c;
return o.f | 0;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(2000000000, 2000000000, -2000000000);
if (result != 2000000000 && result != 42)
throw "Error: bad result: " + result;
}

View File

@ -1,15 +0,0 @@
function foo(a, b, c) {
var o = {f:42};
if ($vm.dfgTrue())
o.f = (a * b + 5) * c + 5;
return o.f | 0;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(65536, 65536, 0);
if (result != 5 && result != 42)
throw "Error: bad result: " + result;
}

View File

@ -1,15 +0,0 @@
function foo(a, b, c) {
var o = {f:42};
if ($vm.dfgTrue())
o.f = a * b * c;
return o.f | 0;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(65536, 65536, 0);
if (result != 0 && result != 42)
throw "Error: bad result: " + result;
}

View File

@ -1,15 +0,0 @@
function foo(a, b) {
var o = {f:42};
if ($vm.dfgTrue())
o.f = -(a + b);
return o.f | 0;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(1073741824, 1073741824);
if (result != -2147483648 && result != 42)
throw "Error: bad result: " + result;
}

View File

@ -1,15 +0,0 @@
function foo(a, b) {
var o = {f:42};
if ($vm.dfgTrue())
o.f = a - b - 2000000000;
return o.f | 0;
}
noInline(foo);
for (var i = 0; i < 10000; ++i) {
var result = foo(2000000000, -2000000000);
if (result != 2000000000 && result != 42)
throw "Error: bad result: " + result;
}

View File

@ -1,101 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function assert(x) {
if (!x)
throw Error("Bad");
}
let isConstructor = createBuiltin("(function (c) { return @isConstructor(c); })");
// Functions.
assert(isConstructor(assert));
assert(isConstructor(class{}));
assert(isConstructor(function(){}));
// Proxy functions.
assert(isConstructor(new Proxy(assert, {})));
assert(isConstructor(new Proxy(class{}, {})));
assert(isConstructor(new Proxy(function(){}, {})));
// Bound functions.
assert(isConstructor(assert.bind(null), {}));
assert(isConstructor((class{}).bind(null), {}));
assert(isConstructor(function(){}.bind(null), {}));
// Builtin constructors.
assert(isConstructor(Array));
assert(isConstructor(ArrayBuffer));
assert(isConstructor(Boolean));
assert(isConstructor(Date));
assert(isConstructor(Error));
assert(isConstructor(Function));
assert(isConstructor(Map));
assert(isConstructor(Number));
assert(isConstructor(Object));
assert(isConstructor(Promise));
assert(isConstructor(Proxy));
assert(isConstructor(RegExp));
assert(isConstructor(Set));
assert(isConstructor(String));
assert(isConstructor(WeakMap));
assert(isConstructor(WeakSet));
// Non-function values.
assert(!isConstructor(undefined));
assert(!isConstructor(null));
assert(!isConstructor(true));
assert(!isConstructor(false));
assert(!isConstructor(0));
assert(!isConstructor(1));
assert(!isConstructor(1.1));
assert(!isConstructor(-1));
assert(!isConstructor(Date.now()));
assert(!isConstructor(new Date));
assert(!isConstructor(Infinity));
assert(!isConstructor(NaN));
assert(!isConstructor(""));
assert(!isConstructor("test"));
assert(!isConstructor([]));
assert(!isConstructor({}));
assert(!isConstructor(/regex/));
assert(!isConstructor(Math));
assert(!isConstructor(JSON));
assert(!isConstructor(Symbol()));
assert(!isConstructor(new Error));
assert(!isConstructor(new Proxy({}, {})));
assert(!isConstructor(Array.prototype));
// Symbol is not a constructor.
assert(!isConstructor(Symbol));
// Getters / setters are not constructors.
assert(!isConstructor(Object.getOwnPropertyDescriptor({get f(){}}, "f").get));
assert(!isConstructor(Object.getOwnPropertyDescriptor({set f(x){}}, "f").set));
// Arrow functions are not constructors.
assert(!isConstructor(()=>{}));
// Generators are not constructors.
assert(!isConstructor(function*(){}));
// Native builtins are not constructors.
assert(!isConstructor(isConstructor));
// https://tc39.github.io/ecma262/#sec-built-in-function-objects
// Built-in function objects that are not identified as constructors do not
// implement the [[Construct]] internal method unless otherwise specified in
// the description of a particular function.
assert(!isConstructor(Array.of));
assert(!isConstructor(Object.getOwnPropertyDescriptor));
assert(!isConstructor(Date.now));
assert(!isConstructor(Math.cos));
assert(!isConstructor(JSON.stringify));
assert(!isConstructor(Promise.all));
assert(!isConstructor(Symbol.for));
assert(!isConstructor(Array.prototype.push));
// Proxy and bound functions carry forward non-constructor-ness.
assert(!isConstructor(new Proxy(Symbol, {})));
assert(!isConstructor(new Proxy(Math.cos, {})));
assert(!isConstructor(Symbol.bind(null)));
assert(!isConstructor(Math.cos.bind(null)));

View File

@ -1,77 +0,0 @@
var createBuiltin = $vm.createBuiltin;
let typedArrays = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array];
function makeFn(dontInline) {
let foo = createBuiltin(`(function (a) { "use strict"; return @isTypedArrayView(a); })`);
if (dontInline)
noInline(foo)
return foo;
}
typedArrays.forEach(function() {
let test = Function(
`
let foo = makeFn();
let bar = makeFn(true);
let view = new Int8Array(10);
for (i = 0; i < 100000; i++) {
if (!foo(view))
throw new Error(i);
if (!bar(view))
throw new Error(i);
}
`
);
test();
});
typedArrays.forEach(constructor1 => {
typedArrays.forEach(constructor2 => {
let test = Function(
`
let foo = makeFn();
let bar = makeFn(true);
let view1 = new ${constructor1.name}(10);
let view2 = new ${constructor2.name}(10);
for (i = 0; i < 100000; i++) {
let view = i % 2 === 0 ? view1 : view2;
if (!foo(view))
throw new Error(i);
if (!bar(view))
throw new Error(i);
}
`
);
test();
});
});
let test = function() {
let foo = makeFn();
let bar = makeFn(true);
for (i = 0; i < 100000; i++) {
if (foo(true))
throw new Error(i);
if (bar(true))
throw new Error(i);
}
}
test();
test = function() {
let bar = makeFn(true);
let view = new Int8Array(10);
let obj = new DataView(new ArrayBuffer(10));
for (i = 0; i < 100000; i++) {
if (i % 2 === 0) {
if (!foo(view))
throw new Error(i);
} else {
if (foo(obj))
throw new Error(i);
}
}
}

View File

@ -1,23 +0,0 @@
//@ runFTLNoCJIT
// This test passes if it does not crash or trigger any assertion failures.
var setImpureGetterDelegate = $vm.setImpureGetterDelegate;
function shouldEqual(actual, expected) {
if (actual != expected) {
throw "ERROR: expect " + expected + ", actual " + actual;
}
}
var arrayBuffer = new ArrayBuffer(0x20);
var dataView_A = new DataView(arrayBuffer);
var dataView_B = new DataView(arrayBuffer);
var exception;
try {
setImpureGetterDelegate(dataView_A, dataView_B);
} catch (e) {
exception = e;
}
shouldEqual(exception, "TypeError: argument is not an ImpureGetter");

View File

@ -1,28 +0,0 @@
//@ runFTLNoCJIT
// This test passes if it does not crash or trigger any assertion failures.
var getHiddenValue = $vm.getHiddenValue;
var setHiddenValue = $vm.setHiddenValue;
function shouldEqual(actual, expected) {
if (actual != expected) {
throw "ERROR: expect " + expected + ", actual " + actual;
}
}
function test(testAction, expectedException) {
var exception;
try {
testAction();
} catch (e) {
exception = e;
}
shouldEqual(exception, expectedException);
}
test(() => { getHiddenValue(); }, "TypeError: Invalid use of getHiddenValue test function");
test(() => { getHiddenValue({}); }, "TypeError: Invalid use of getHiddenValue test function");
test(() => { setHiddenValue(); }, "TypeError: Invalid use of setHiddenValue test function");
test(() => { setHiddenValue({}); }, "TypeError: Invalid use of setHiddenValue test function");

View File

@ -1,21 +0,0 @@
//@ runFTLNoCJIT("--createPreHeaders=false")
function foo(object, predicate) {
for (var j = 0; j < 10; ++j) {
var result = 0;
var i = 0;
if ($vm.dfgTrue())
predicate = 42;
while (predicate >= 42) {
result += object.array[i++];
if (i >= object.array.length)
break;
}
}
return result;
}
noInline(foo);
for (var i = 0; i < 10000; ++i)
foo({array: [1, 2, 3]}, {valueOf: function() { return 42; }});

View File

@ -1,19 +0,0 @@
//@ runFTLNoCJIT("--createPreHeaders=false")
function foo(object, predicate) {
var result = 0;
var i = 0;
if ($vm.dfgTrue())
predicate = 42;
while (predicate >= 42) {
result += object.array[i++];
if (i >= object.array.length)
break;
}
return result;
}
noInline(foo);
for (var i = 0; i < 10000; ++i)
foo({array: [1, 2, 3]}, {valueOf: function() { return 42; }});

View File

@ -1,161 +0,0 @@
var createBuiltin = $vm.createBuiltin;
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)}`);
}
function checkProperty(object, name, value, attributes = { writable: true, enumerable: true, configurable: true })
{
var desc = Object.getOwnPropertyDescriptor(object, name);
shouldBe(!!desc, true);
shouldBe(desc.writable, attributes.writable);
shouldBe(desc.enumerable, attributes.enumerable);
shouldBe(desc.configurable, attributes.configurable);
shouldBe(desc.value, value);
}
{
let result = Object.assign({}, RegExp);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["$1","$2","$3","$4","$5","$6","$7","$8","$9","input","lastMatch","lastParen","leftContext","multiline","rightContext"]`);
}
{
function Hello() { }
let result = Object.assign(Hello, {
ok: 42
});
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["arguments","caller","length","name","ok","prototype"]`);
checkProperty(result, "ok", 42);
}
{
let result = Object.assign({ ok: 42 }, { 0: 0, 1: 1 });
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["0","1","ok"]`);
checkProperty(result, "ok", 42);
checkProperty(result, "0", 0);
checkProperty(result, "1", 1);
}
{
let object = { 0: 0, 1: 1 };
ensureArrayStorage(object);
let result = Object.assign({ ok: 42 }, object);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["0","1","ok"]`);
checkProperty(result, "ok", 42);
checkProperty(result, "0", 0);
checkProperty(result, "1", 1);
}
{
let called = false;
let result = Object.assign({}, {
get hello() {
called = true;
return 42;
}
});
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["hello"]`);
shouldBe(called, true);
checkProperty(result, "hello", 42);
}
{
let object = {};
Object.defineProperty(object, "__proto__", {
value: 42,
enumerable: true,
writable: true,
configurable: true
});
checkProperty(object, "__proto__", 42);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(object).sort()), `["__proto__"]`);
let result = Object.assign({}, object);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `[]`);
shouldBe(Object.getOwnPropertyDescriptor(result, "__proto__"), undefined);
shouldBe(result.__proto__, Object.prototype);
}
{
let object = {};
Object.defineProperty(object, "hello", {
value: 42,
writable: false,
enumerable: true,
configurable: false
});
checkProperty(object, "hello", 42, { writable: false, enumerable: true, configurable: false });
shouldBe(JSON.stringify(Object.getOwnPropertyNames(object).sort()), `["hello"]`);
shouldThrow(() => {
Object.assign(object, { hello: 50 });
}, `TypeError: Attempted to assign to readonly property.`);
}
{
let counter = 0;
let helloCalled = null;
let okCalled = null;
let source = {};
source.hello = 42;
source.ok = 52;
checkProperty(source, "hello", 42);
checkProperty(source, "ok", 52);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(source)), `["hello","ok"]`);
let result = Object.assign({
set hello(value) {
this.__hello = value;
helloCalled = counter++;
},
set ok(value) {
this.__ok = value;
okCalled = counter++;
}
}, source);
checkProperty(result, "__hello", 42);
checkProperty(result, "__ok", 52);
shouldBe(JSON.stringify(Object.getOwnPropertyNames(result).sort()), `["__hello","__ok","hello","ok"]`);
shouldBe(helloCalled, 0);
shouldBe(okCalled, 1);
}
{
let builtin = createBuiltin(`(function (obj) {
return @getByIdDirectPrivate(obj, "generatorState");
})`);
function* hello() { }
let generator = hello();
shouldBe(typeof builtin(generator), "number");
let result = Object.assign({}, generator);
shouldBe(typeof builtin(result), "undefined");
}
{
let object = {};
let setterCalledWithValue = null;
let result = Object.assign(object, {
get hello() {
Object.defineProperty(object, "added", {
get() {
return 42;
},
set(value) {
setterCalledWithValue = value;
}
});
return 0;
}
}, {
added: "world"
});
shouldBe(result.added, 42);
shouldBe(result.hello, 0);
shouldBe(setterCalledWithValue, "world");
}

View File

@ -1,29 +0,0 @@
var createProxy = $vm.createProxy;
let foo = {};
let properties = [];
let p = new Proxy(foo, { get:(target, property) => {
properties.push(property.toString());
if (property === Symbol.toStringTag)
return "bad things";
return target[property];
}});
for (i = 0; i < 5; i++) {
if (p != "[object bad things]")
throw new Error("bad toString result.");
if (properties[0] !== "Symbol(Symbol.toPrimitive)" || properties[1] !== "valueOf" || properties[2] !== "toString" || properties[3] !== "Symbol(Symbol.toStringTag)")
throw new Error("bad property accesses.");
properties = [];
}
p = createProxy(foo);
for (i = 0; i < 5; i++) {
let str = "bad things" + i;
foo[Symbol.toStringTag] = str;
if (p != "[object " + str + "]")
throw new Error("bad toString result.");
}

View File

@ -1,95 +0,0 @@
var createCustomTestGetterSetter = $vm.createCustomTestGetterSetter;
function assert(b, m) {
if (!b)
throw new Error("Bad:" + m);
}
function makePolyProtoObject() {
function foo() {
class C {
constructor() { this.field = 20; }
};
return new C;
}
for (let i = 0; i < 15; ++i) {
assert(foo().field === 20);
}
return foo();
}
let items = [
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
makePolyProtoObject(),
];
let customGetterSetter = createCustomTestGetterSetter();
items.forEach((x) => {
x.__proto__ = customGetterSetter;
assert(x.__proto__ === customGetterSetter);
});
function validate(x, valueResult, accessorResult) {
assert(x.customValue === valueResult);
assert(x.customAccessor === accessorResult);
let o = {};
x.customValue = o;
assert(o.result === valueResult);
o = {};
x.customAccessor = o;
assert(o.result === accessorResult);
assert(x.randomProp === 42 || x.randomProp === undefined);
}
noInline(validate);
let start = Date.now();
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], customGetterSetter, items[i]);
}
}
customGetterSetter.randomProp = 42;
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], customGetterSetter, items[i]);
}
}
items.forEach((x) => {
Reflect.setPrototypeOf(x, {
get customValue() { return 42; },
get customAccessor() { return 22; },
set customValue(x) { x.result = 42; },
set customAccessor(x) { x.result = 22; },
});
});
for (let i = 0; i < 10000; ++i) {
for (let i = 0; i < items.length; ++i) {
validate(items[i], 42, 22);
}
}
if (false)
print(Date.now() - start);

View File

@ -1,76 +0,0 @@
var createProxy = $vm.createProxy;
var niters = 100000;
// proxy -> target -> x
function cacheOnTarget() {
var target = {x:42};
var proxy = createProxy(target);
var getX = function(o) { return o.x; };
noInline(getX);
var sum = 0;
for (var i = 0; i < niters; ++i)
sum += getX(proxy);
if (sum != 42 * niters)
throw new Error("Incorrect result");
};
// proxy -> target -> proto -> x
function cacheOnPrototypeOfTarget() {
var proto = {x:42};
var target = Object.create(proto);
var proxy = createProxy(target);
var getX = function(o) { return o.x; };
noInline(getX);
var sum = 0;
for (var i = 0; i < niters; ++i)
sum += getX(proxy);
if (sum != 42 * niters)
throw new Error("Incorrect result");
};
// base -> proto (proxy) -> target -> x
function dontCacheOnProxyInPrototypeChain() {
var target = {x:42};
var protoProxy = createProxy(target);
var base = Object.create(protoProxy);
var getX = function(o) { return o.x; };
noInline(getX);
var sum = 0;
for (var i = 0; i < niters; ++i)
sum += getX(base);
if (sum != 42 * niters)
throw new Error("Incorrect result");
};
// proxy -> target 1 -> proto (proxy) -> target 2 -> x
function dontCacheOnTargetOfProxyInPrototypeChainOfTarget() {
var target2 = {x:42};
var protoProxy = createProxy(target2);
var target1 = Object.create(protoProxy);
var proxy = createProxy(target1);
var getX = function(o) { return o.x; };
noInline(getX);
var sum = 0;
for (var i = 0; i < niters; ++i)
sum += getX(proxy);
if (sum != 42 * niters)
throw new Error("Incorrect result");
};
cacheOnTarget();
cacheOnPrototypeOfTarget();
dontCacheOnProxyInPrototypeChain();
dontCacheOnTargetOfProxyInPrototypeChainOfTarget();

View File

@ -1,23 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
(function () {
var builtin = createBuiltin(`(function (obj, value) {
return @putByIdDirect(obj, "hello", value);
})`);
noInline(builtin);
var setValue = null;
var object = {
__proto__: {
hello: 30
}
};
builtin(object, 42);
shouldBe(object.hello, 42);
shouldBe(object.hasOwnProperty("hello"), true);
}());

View File

@ -1,26 +0,0 @@
var createBuiltin = $vm.createBuiltin;
function shouldBe(actual, expected) {
if (actual !== expected)
throw new Error('bad value: ' + actual);
}
var testInt32 = createBuiltin(`(function (array, index, value) {
@putByValDirect(array, index, value);
})`);
noInline(testInt32);
Object.defineProperty(Array.prototype, 42, {
get() {
return 30;
},
set(value) {
}
});
for (var i = 0; i < 1e5; ++i) {
var array = [1, 2, 3, 4, 5];
shouldBe(array[42], 30);
testInt32(array, 42, 42);
shouldBe(array[42], 42);
shouldBe(Array.prototype[42], 30);
}

View File

@ -1,28 +0,0 @@
var abort = $vm.abort;
function shouldBe(actual, expected)
{
if (actual !== expected)
throw new Error(`bad value: ${String(actual)}`);
}
(async function () {
{
let errorMessage = null;
try {
await import("./resources/error-module.js");
} catch (error) {
errorMessage = String(error);
}
shouldBe(errorMessage, `SyntaxError: Importing binding name 'x' is not found.`);
}
{
let errorMessage = null;
try {
await import("./resources/error-module.js");
} catch (error) {
errorMessage = String(error);
}
shouldBe(errorMessage, `SyntaxError: Importing binding name 'x' is not found.`);
}
}()).catch(abort);

View File

@ -1,43 +0,0 @@
// Makes sure we don't use base's tag register on 32-bit when an inline cache fails and jumps to the slow path
// because the slow path depends on the base being present.
var createCustomGetterObject = $vm.createCustomGetterObject;
function assert(b) {
if (!b)
throw new Error("baddd");
}
noInline(assert);
let customGetter = createCustomGetterObject();
let otherObj = {
customGetter: 20
};
function randomFunction() {}
noInline(randomFunction);
function foo(o, c) {
let baz = o.customGetter;
if (c) {
o = 42;
}
let jaz = o.foo;
let kaz = jaz + "hey";
let raz = kaz + "hey";
let result = o.customGetter;
randomFunction(!c, baz, jaz, kaz, raz);
return result;
}
noInline(foo);
for (let i = 0; i < 10000; i++) {
switch (i % 2) {
case 0:
assert(foo(customGetter) === 100);
break;
case 1:
assert(foo(otherObj) === 20);
break;
}
}
assert(foo({hello: 20, world:50, customGetter: 40}) === 40); // Make sure we don't trample registers in "o.customGetter" inline cache failure in foo.

View File

@ -1,35 +0,0 @@
// Verify that DFG TryGetById nodes properly save live registers. This test should not crash.
var createBuiltin = $vm.createBuiltin;
function tryMultipleGetByIds() { return '(function (base) { return @tryGetById(base, "value1") + @tryGetById(base, "value2") + @tryGetById(base, "value3"); })'; }
let get = createBuiltin(tryMultipleGetByIds());
noInline(get);
function test() {
let obj1 = {
value1: "Testing, ",
value2: "testing, ",
value3: "123",
expected: "Testing, testing, 123"
};
let obj2 = {
extraFieldToMakeThisObjectDifferentThanObj1: 42,
value1: 20,
value2: 10,
value3: 12,
expected: 42
};
let objects = [obj1, obj2];
for (let i = 0; i < 200000; i++) {
let obj = objects[i % 2];
if (get(obj) !== obj.expected)
throw new Error("wrong on iteration: " + i);
}
}
test();

Some files were not shown because too many files have changed in this diff Show More