зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset dd50da0646a4
This commit is contained in:
Родитель
19a25cd0a3
Коммит
9ca5509b31
|
@ -0,0 +1,74 @@
|
|||
JS Trace Test Suite
|
||||
|
||||
* PURPOSE
|
||||
|
||||
This is a test suite for testing TraceMonkey. All tests are run in the JS shell
|
||||
with tracing enabled (-j).
|
||||
|
||||
* REQUIREMENTS
|
||||
|
||||
Python 2.5. This is already a standard requirement for building our tree.
|
||||
|
||||
* RUNNING THE TESTS
|
||||
|
||||
Basic usage:
|
||||
|
||||
python jit_test.py <path-to-js-shell>
|
||||
|
||||
The progress bar shows [#tests passed, #tests failed, #tests run] at the left.
|
||||
If all tests pass, the output is 'PASSED ALL'. The test suite can be interrupted
|
||||
at any time with Ctrl+C and partial results will be printed.
|
||||
|
||||
To run only the basic tests, not including the slow tests:
|
||||
|
||||
python jit_test.py <path-to-js-shell> basic
|
||||
|
||||
For more options:
|
||||
|
||||
python jit_test.py -h
|
||||
|
||||
* CREATING NEW TESTS
|
||||
|
||||
Simply create a JS file under the 'tests/' directory. Most tests should go in
|
||||
'tests/basic/'.
|
||||
|
||||
All tests are run with 'lib/prolog.js' included first on the command line. The
|
||||
command line also creates a global variable 'libdir' that is set to the path
|
||||
of the 'lib' directory. To include a file 'foo.js' from the lib directory in a
|
||||
test case:
|
||||
|
||||
load(libdir + 'foo.js')
|
||||
|
||||
* TEST METALINES
|
||||
|
||||
The first line of a test case can contain a special comment controlling how the
|
||||
test is run. For example:
|
||||
|
||||
// |jit-test| allow-oom;
|
||||
|
||||
The general format in EBNF is:
|
||||
|
||||
metaline ::= cookie { item ";" }
|
||||
cookie ::= "|jit-test|"
|
||||
item ::= flag | attribute
|
||||
|
||||
flag ::= "slow" | "allow-oom"
|
||||
|
||||
attribute ::= name ":" value
|
||||
name ::= "TMFLAGS" | "error"
|
||||
value ::= <string>
|
||||
|
||||
The metaline may appear anywhere in the first line of the file: this allows it
|
||||
to be placed inside any kind of comment.
|
||||
|
||||
The meaning of the items:
|
||||
|
||||
slow Test runs slowly. Do not run if the --no-slow option is given.
|
||||
allow-oom If the test runs out of memory, it counts as passing.
|
||||
valgrind Run test under valgrind.
|
||||
|
||||
error The test should be considered to pass iff it throws the
|
||||
given JS exception.
|
||||
TMFLAGS Set the environment variable TMFLAGS to the given value.
|
||||
|
||||
* END
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
|
||||
const HAVE_TM = 'tracemonkey' in this;
|
||||
|
||||
const HOTLOOP = HAVE_TM ? tracemonkey.HOTLOOP : 8;
|
||||
const RECORDLOOP = HOTLOOP;
|
||||
const RUNLOOP = HOTLOOP + 1;
|
||||
|
||||
var checkStats;
|
||||
if (HAVE_TM) {
|
||||
checkStats = function(stats)
|
||||
{
|
||||
// Temporarily disabled while we work on heuristics.
|
||||
return;
|
||||
function jit(on)
|
||||
{
|
||||
if (on && !options().match(/tracejit/))
|
||||
{
|
||||
options('tracejit');
|
||||
}
|
||||
else if (!on && options().match(/tracejit/))
|
||||
{
|
||||
options('tracejit');
|
||||
}
|
||||
}
|
||||
|
||||
jit(false);
|
||||
for (var name in stats) {
|
||||
var expected = stats[name];
|
||||
var actual = tracemonkey[name];
|
||||
if (expected != actual) {
|
||||
print('Trace stats check failed: got ' + actual + ', expected ' + expected + ' for ' + name);
|
||||
}
|
||||
}
|
||||
jit(true);
|
||||
};
|
||||
} else {
|
||||
checkStats = function() {};
|
||||
}
|
||||
|
||||
var appendToActual = function(s) {
|
||||
actual += s + ',';
|
||||
}
|
||||
|
||||
if (!("gczeal" in this)) {
|
||||
gczeal = function() { }
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
actual = '';
|
||||
expected = '6,';
|
||||
|
||||
// tracing length
|
||||
|
||||
var g = 0;
|
||||
|
||||
function h(args) {
|
||||
g = args.length;
|
||||
}
|
||||
|
||||
function f() {
|
||||
h(arguments);
|
||||
}
|
||||
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
f(10, 20, 30, 40, 50, 60);
|
||||
}
|
||||
appendToActual(g);
|
||||
|
||||
|
||||
assertEq(actual, expected)
|
|
@ -0,0 +1,14 @@
|
|||
actual = '';
|
||||
expected = '[object Arguments],[object Arguments],[object Arguments],[object Arguments],[object Arguments],';
|
||||
|
||||
function h() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
for (var i = 0; i < 5; ++i) {
|
||||
var p = h(i, i*2);
|
||||
appendToActual(p);
|
||||
}
|
||||
|
||||
|
||||
assertEq(actual, expected)
|
|
@ -0,0 +1,23 @@
|
|||
actual = '';
|
||||
expected = '[object Arguments] undefined undefined,[object Arguments] undefined undefined,';
|
||||
|
||||
function f() {
|
||||
g(arguments);
|
||||
}
|
||||
|
||||
function g(a, b, c) {
|
||||
h(arguments);
|
||||
a = 1;
|
||||
b = 2;
|
||||
c = 3;
|
||||
h(arguments);
|
||||
}
|
||||
|
||||
function h(a, b, c) {
|
||||
appendToActual(a + ' ' + b + ' ' + c);
|
||||
}
|
||||
|
||||
f(4, 5, 6);
|
||||
|
||||
|
||||
assertEq(actual, expected)
|
|
@ -0,0 +1,11 @@
|
|||
// |jit-test| TMFLAGS: full,fragprofile,treevis
|
||||
|
||||
function arith()
|
||||
{
|
||||
var accum = 0;
|
||||
for (var i = 0; i < 100; i++) {
|
||||
accum += (i * 2) - 1;
|
||||
}
|
||||
return accum;
|
||||
}
|
||||
assertEq(arith(), 9800);
|
|
@ -0,0 +1,9 @@
|
|||
var Q = 0;
|
||||
try {
|
||||
(function f(i) { Q = i; if (i == 100000) return; f(i+1); })(1)
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
if (Q == 100000)
|
||||
assertEq(Q, "fail");
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
var Q = 0;
|
||||
try {
|
||||
(function f(i) { Q = i; if (i == 100000) return; f(i+1); })(1)
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
// Exact behavior of recursion check depends on which JIT we use.
|
||||
var ok = (Q == 3000 || Q == 3001);
|
||||
assertEq(ok, true);
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
// Don't crash
|
||||
|
||||
function g(foo) {
|
||||
for (a in foo) {
|
||||
}
|
||||
}
|
||||
|
||||
var makegen = eval("\n\
|
||||
(function(b) {\n\
|
||||
var h = \n\
|
||||
eval(\"new function() { yield print(b) }\" ); \n\
|
||||
return h\n\
|
||||
})\n\
|
||||
");
|
||||
|
||||
g(makegen());
|
|
@ -0,0 +1 @@
|
|||
eval("for(a = 0; a < 4; a++) x = 1;", []);
|
|
@ -0,0 +1,3 @@
|
|||
__defineGetter__('x', Float32Array);
|
||||
with(this)
|
||||
x;
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
for (a = 0; a < 4; a++) {
|
||||
new Math.round(0).t
|
||||
}
|
||||
|
||||
/* Don't assert. */
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
// |jit-test| error: TypeError
|
||||
var s = "12345";
|
||||
for(var i=0; i<7; i++) {
|
||||
print(s[i].length);
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
function f(x) {
|
||||
var s = "a";
|
||||
var last = "";
|
||||
for (var i = 0; i < HOTLOOP + 2; i++) {
|
||||
last = s[x];
|
||||
}
|
||||
return last;
|
||||
}
|
||||
|
||||
f(0);
|
||||
|
||||
assertEq(f(1), undefined);
|
|
@ -0,0 +1,10 @@
|
|||
// Any copyright is dedicated to the Public Domain.
|
||||
// http://creativecommons.org/licenses/publicdomain/
|
||||
// Contributor: Luke Wagner <lw@mozilla.com>
|
||||
|
||||
var x, f;
|
||||
for (var i = 0; i < 100; i++) {
|
||||
f = function() {};
|
||||
f.foo;
|
||||
x = f.length;
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
function g(x) {
|
||||
if ((x & 1) == 1) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
function f(n) {
|
||||
var q = 0;
|
||||
for (var i = 0; i < n; i++)
|
||||
q += g(i);
|
||||
return q;
|
||||
}
|
||||
|
||||
assertEq(f(1000), 1500);
|
|
@ -0,0 +1,17 @@
|
|||
var a = ['p', 'q', 'r', 's', 't'];
|
||||
var o = {p:1, q:2, r:3, s:4, t:5};
|
||||
for (var i in o) {
|
||||
delete o.p;
|
||||
delete o.q;
|
||||
delete o.r;
|
||||
delete o.s;
|
||||
delete o.t;
|
||||
}
|
||||
for each (var i in a)
|
||||
assertEq(o.hasOwnProperty(i), false);
|
||||
|
||||
checkStats({
|
||||
recorderAborted:0,
|
||||
traceCompleted:1,
|
||||
sideExitIntoInterpreter:1
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
// Make sure the arch flags are valid on startup, even if nothing has
|
||||
// been traced yet. We don't know what arch the user is building on,
|
||||
// but presumably we want at least 1 flag to be set on all supported
|
||||
// platforms.
|
||||
|
||||
if (HAVE_TM) {
|
||||
assertEq(jitstats.archIsIA32 ||
|
||||
jitstats.archIs64BIT ||
|
||||
jitstats.archIsARM ||
|
||||
jitstats.archIsSPARC ||
|
||||
jitstats.archIsPPC ||
|
||||
jitstats.archIsAMD64,
|
||||
1);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
function parseIntHelper(n) {
|
||||
var a;
|
||||
for (var i = 0; i < 5; i++)
|
||||
a = parseInt(n);
|
||||
return a;
|
||||
}
|
||||
function doParseIntTests() {
|
||||
var inputs = [0, -0, .1, -.1, .7, -.7, 1.3, -1.3];
|
||||
var outputs = new Array(8);
|
||||
//avoid jit, unrolled
|
||||
outputs[0] = outputs[1] = outputs[2] = outputs[4] = 0;
|
||||
outputs[3] = outputs[5] = -0;
|
||||
outputs[6] = 1;
|
||||
outputs[7] = -1;
|
||||
for (var i = 0; i < 8; i++) {
|
||||
var testfn = new Function('return parseIntHelper(' + uneval(inputs[i]) + ');');
|
||||
assertEq(testfn(), outputs[i]);
|
||||
}
|
||||
}
|
||||
doParseIntTests();
|
||||
|
||||
assertEq(parseInt("08"), 0);
|
||||
assertEq(parseInt("09"), 0);
|
|
@ -0,0 +1,16 @@
|
|||
"use strict";
|
||||
|
||||
assertEq(parseInt("08"), 0);
|
||||
assertEq(parseInt("09"), 0);
|
||||
assertEq(parseInt("014"), 12);
|
||||
assertEq(parseInt("0xA"), 10);
|
||||
assertEq(parseInt("00123"), 83);
|
||||
|
||||
for (var i = 0; i < 5; i++)
|
||||
{
|
||||
assertEq(parseInt("08"), 0);
|
||||
assertEq(parseInt("09"), 0);
|
||||
assertEq(parseInt("014"), 12);
|
||||
assertEq(parseInt("0xA"), 10);
|
||||
assertEq(parseInt("00123"), 83);
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
var o = {
|
||||
set x(v) {
|
||||
return 42;
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
var z = o.x = "choose me";
|
||||
assertEq(z, "choose me");
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
var escape;
|
||||
function testBug458838() {
|
||||
var a = 1;
|
||||
function g() {
|
||||
var b = 0
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
b += a;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
return g();
|
||||
}
|
||||
assertEq(testBug458838(), 10);
|
||||
checkStats({
|
||||
recorderStarted: 1,
|
||||
recorderAborted: 0,
|
||||
traceCompleted: 1
|
||||
});
|
|
@ -0,0 +1,11 @@
|
|||
function testBug504520() {
|
||||
// A bug involving comparisons.
|
||||
var arr = [1/0, 1/0, 1/0, 1/0, 1/0, 1/0, 1/0, 1/0, 1/0, 0];
|
||||
assertEq(arr.length > RUNLOOP, true);
|
||||
|
||||
var s = '';
|
||||
for (var i = 0; i < arr.length; i++)
|
||||
arr[i] >= 1/0 ? null : (s += i);
|
||||
assertEq(s, '9');
|
||||
}
|
||||
testBug504520();
|
|
@ -0,0 +1,33 @@
|
|||
function testBug504520Harder() {
|
||||
// test 1024 similar cases
|
||||
var vals = [1/0, -1/0, 0, 0/0];
|
||||
var ops = ["===", "!==", "==", "!=", "<", ">", "<=", ">="];
|
||||
for each (var x in vals) {
|
||||
for each (var y in vals) {
|
||||
for each (var op in ops) {
|
||||
for each (var z in vals) {
|
||||
// Assume eval is correct. This depends on the global
|
||||
// Infinity property not having been reassigned.
|
||||
var xz = eval(x + op + z);
|
||||
var yz = eval(y + op + z);
|
||||
|
||||
var arr = [x, x, x, x, x, x, x, x, x, y];
|
||||
assertEq(arr.length > RUNLOOP, true);
|
||||
var expected = [xz, xz, xz, xz, xz, xz, xz, xz, xz, yz];
|
||||
|
||||
// ?: looks superfluous but that's what we're testing here
|
||||
var fun = eval(
|
||||
'(function (arr, results) {\n' +
|
||||
' for (let i = 0; i < arr.length; i++)\n' +
|
||||
' results.push(arr[i]' + op + z + ' ? "true" : "false");\n' +
|
||||
'});\n');
|
||||
var actual = [];
|
||||
fun(arr, actual);
|
||||
print(x, y, op, z);
|
||||
assertEq("" + actual, "" + expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
testBug504520Harder();
|
|
@ -0,0 +1,36 @@
|
|||
setDebug(true);
|
||||
var a = new Array();
|
||||
|
||||
function i(save) {
|
||||
var x = 9;
|
||||
evalInFrame(0, "a.push(x)", save);
|
||||
evalInFrame(1, "a.push(z)", save);
|
||||
evalInFrame(2, "a.push(z)", save);
|
||||
evalInFrame(3, "a.push(y)", save);
|
||||
evalInFrame(4, "a.push(x)", save);
|
||||
}
|
||||
|
||||
function h() {
|
||||
var z = 5;
|
||||
evalInFrame(0, "a.push(z)");
|
||||
evalInFrame(1, "a.push(y)");
|
||||
evalInFrame(2, "a.push(x)");
|
||||
evalInFrame(0, "i(false)");
|
||||
evalInFrame(0, "a.push(z)", true);
|
||||
evalInFrame(1, "a.push(y)", true);
|
||||
evalInFrame(2, "a.push(x)", true);
|
||||
evalInFrame(0, "i(true)", true);
|
||||
}
|
||||
|
||||
function g() {
|
||||
var y = 4;
|
||||
h();
|
||||
}
|
||||
|
||||
function f() {
|
||||
var x = 3;
|
||||
g();
|
||||
}
|
||||
|
||||
f();
|
||||
assertEq(a+'', [5, 4, 3, 9, 5, 5, 4, 3, 5, 4, 3, 9, 5, 5, 4, 3]+'');
|
|
@ -0,0 +1,21 @@
|
|||
// don't panic
|
||||
|
||||
f = function() {
|
||||
x = yield
|
||||
}
|
||||
rv = f()
|
||||
for (a in rv) (function() {})
|
||||
x = Proxy.create((function() {
|
||||
return {
|
||||
defineProperty: gc
|
||||
}
|
||||
})(), x)
|
||||
with({
|
||||
d: (({
|
||||
x: Object.defineProperty(x, "", ({
|
||||
set: Array.e
|
||||
}))
|
||||
}))
|
||||
}) {}
|
||||
|
||||
// don't crash
|
|
@ -0,0 +1,22 @@
|
|||
if (typeof gczeal != "function")
|
||||
gczeal = function() {}
|
||||
|
||||
for (a = 0; a < 9; a++)
|
||||
for (b = 0; b < 1; b++)
|
||||
for (c = 0; c < 2; c++)
|
||||
gczeal();
|
||||
|
||||
for each(e in [NaN])
|
||||
for (d = 0; d < 1; d++)
|
||||
z = 0;
|
||||
|
||||
for (w in [0, 0])
|
||||
{}
|
||||
|
||||
x = 0;
|
||||
|
||||
for (e = 0; e < 3; e++)
|
||||
for (f = 0; f < 4; f++)
|
||||
x = -x
|
||||
|
||||
// don't crash
|
|
@ -0,0 +1,9 @@
|
|||
if (typeof gczeal != "function")
|
||||
gczeal = function() {}
|
||||
|
||||
// don't crash
|
||||
x = (evalcx('lazy'))
|
||||
x.watch("", function () {})
|
||||
gczeal(1)
|
||||
for (w in x) {}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
function leak_test() {
|
||||
// Create a reference loop function->script->traceFragment->object->function
|
||||
// that GC must be able to break. To embedd object into the fragment the
|
||||
// code use prototype chain of depth 2 which caches obj.__proto__.__proto__
|
||||
// into the fragment.
|
||||
|
||||
// To make sure that we have no references to the function f after this
|
||||
// function returns due via the conservative scan of the native stack we
|
||||
// loop here multiple times overwriting the stack and registers with new garabge.
|
||||
for (var j = 0; j != 8; ++j) {
|
||||
var f = Function("a", "var s = 0; for (var i = 0; i != 100; ++i) s += a.b; return s;");
|
||||
var c = {b: 1, f: f, leakDetection: makeFinalizeObserver()};
|
||||
f({ __proto__: { __proto__: c}});
|
||||
f = c = a = null;
|
||||
gc();
|
||||
}
|
||||
}
|
||||
|
||||
function test()
|
||||
{
|
||||
if (typeof finalizeCount != "function")
|
||||
return;
|
||||
|
||||
var base = finalizeCount();
|
||||
leak_test();
|
||||
gc();
|
||||
gc();
|
||||
var n = finalizeCount();
|
||||
assertEq(base + 4 < finalizeCount(), true, "Some finalizations must happen");
|
||||
}
|
||||
|
||||
test();
|
|
@ -0,0 +1,12 @@
|
|||
function testEliminatedGuardWithinAnchor() {
|
||||
for (let i = 0; i < 5; ++i) { i / (i * i); }
|
||||
return "ok";
|
||||
}
|
||||
|
||||
assertEq(testEliminatedGuardWithinAnchor(), "ok");
|
||||
|
||||
if (HAVE_TM) {
|
||||
checkStats({
|
||||
sideExitIntoInterpreter: (jitstats.archIsARM ? 1 : 3)
|
||||
});
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
var s;
|
||||
|
||||
function f(i) {
|
||||
if (i > 4) /* side exit when arr[i] changes from bool to undefined (via a hole) */
|
||||
assertEq(s, undefined);
|
||||
else
|
||||
assertEq(s, false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* trailing 'true' ensures array has capacity >= 10 */
|
||||
var arr = [ false, false, false, false, false, , , , , , true ];
|
||||
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
(s = arr[i]) + f(i);
|
||||
}
|
||||
|
||||
checkStats({ traceTriggered: 2, sideExitIntoInterpreter: 2 })
|
|
@ -0,0 +1,15 @@
|
|||
function testIntOverflow() {
|
||||
// int32_max - 7
|
||||
var ival = 2147483647 - 7;
|
||||
for (var i = 0; i < 30; i++) {
|
||||
ival += 30;
|
||||
}
|
||||
return (ival < 2147483647);
|
||||
}
|
||||
assertEq(testIntOverflow(), false);
|
||||
checkStats({
|
||||
recorderStarted: 1,
|
||||
recorderAborted: 0,
|
||||
traceCompleted: 1,
|
||||
traceTriggered: 1,
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
function testMethodInitSafety() {
|
||||
function f() { return 'fail'; }
|
||||
function g() { return 'ok'; }
|
||||
|
||||
var s;
|
||||
var arr = [f, f, f, f, g];
|
||||
//assertEq(arr.length > RUNLOOP, true);
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var x = {m: arr[i]};
|
||||
s = x.m();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
assertEq(testMethodInitSafety(), "ok");
|
|
@ -0,0 +1,14 @@
|
|||
if ('gczeal' in this)
|
||||
(function () {
|
||||
(eval("\
|
||||
(function () {\
|
||||
for (var y = 0; y < 16; ++y) {\
|
||||
if (y % 3 == 2) {\
|
||||
gczeal(1);\
|
||||
} else {\
|
||||
print(0 / 0);\
|
||||
}\
|
||||
}\
|
||||
});\
|
||||
"))()
|
||||
})();
|
|
@ -0,0 +1,20 @@
|
|||
var _quit;
|
||||
function testNestedDeepBail()
|
||||
{
|
||||
_quit = false;
|
||||
function loop() {
|
||||
for (var i = 0; i < 4; i++)
|
||||
;
|
||||
}
|
||||
loop();
|
||||
|
||||
function f() {
|
||||
loop();
|
||||
_quit = true;
|
||||
}
|
||||
|
||||
var stk = [[1], [], [], [], []];
|
||||
while (!_quit)
|
||||
stk.pop().forEach(f);
|
||||
}
|
||||
testNestedDeepBail();
|
|
@ -0,0 +1,29 @@
|
|||
// Test stack reconstruction after a nested exit
|
||||
function testNestedExitStackInner(j, counter) {
|
||||
++counter;
|
||||
var b = 0;
|
||||
for (var i = 1; i <= RUNLOOP; i++) {
|
||||
++b;
|
||||
var a;
|
||||
// Make sure that once everything has been traced we suddenly switch to
|
||||
// a different control flow the first time we run the outermost tree,
|
||||
// triggering a side exit.
|
||||
if (j < RUNLOOP)
|
||||
a = 1;
|
||||
else
|
||||
a = 0;
|
||||
++b;
|
||||
b += a;
|
||||
}
|
||||
return counter + b;
|
||||
}
|
||||
function testNestedExitStackOuter() {
|
||||
var counter = 0;
|
||||
for (var j = 1; j <= RUNLOOP; ++j) {
|
||||
for (var k = 1; k <= RUNLOOP; ++k) {
|
||||
counter = testNestedExitStackInner(j, counter);
|
||||
}
|
||||
}
|
||||
return counter;
|
||||
}
|
||||
//assertEq(testNestedExitStackOuter(), 81);
|
|
@ -0,0 +1,12 @@
|
|||
function testNewArrayCount()
|
||||
{
|
||||
function count(a) { var n = 0; for (var p in a) n++; return n; }
|
||||
var a = [];
|
||||
for (var i = 0; i < 5; i++)
|
||||
a = [0];
|
||||
assertEq(count(a), 1);
|
||||
for (var i = 0; i < 5; i++)
|
||||
a = [0, , 2];
|
||||
assertEq(count(a), 2);
|
||||
}
|
||||
testNewArrayCount();
|
|
@ -0,0 +1,8 @@
|
|||
function testNewArrayCount2() {
|
||||
function count(a) { var n = 0; for (var p in a) n++; return n; }
|
||||
var x = 0;
|
||||
for (var i = 0; i < 10; ++i)
|
||||
x = count(new Array(1,2,3));
|
||||
return x;
|
||||
}
|
||||
assertEq(testNewArrayCount2(), 3);
|
|
@ -0,0 +1,9 @@
|
|||
// proxies can return primitives
|
||||
assertEq(new (Proxy.createFunction({}, function(){}, function(){})), undefined);
|
||||
|
||||
x = Proxy.createFunction((function () {}), Uint16Array, wrap)
|
||||
new(wrap(x))
|
||||
|
||||
// proxies can return the callee
|
||||
var x = Proxy.createFunction({}, function (q) { return q; });
|
||||
new x(x);
|
|
@ -0,0 +1,16 @@
|
|||
var g;
|
||||
|
||||
function h() {
|
||||
return arguments.length;
|
||||
}
|
||||
|
||||
function f() {
|
||||
var args = arguments;
|
||||
g = function() { return h.apply(this, args); }
|
||||
}
|
||||
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
f();
|
||||
}
|
||||
|
||||
assertEq(g(), 0);
|
|
@ -0,0 +1,21 @@
|
|||
delete q;
|
||||
delete g;
|
||||
delete h;
|
||||
delete a;
|
||||
delete f;
|
||||
|
||||
function testRebranding2() {
|
||||
// Same as testRebranding, but the object to be rebranded isn't the global.
|
||||
var x = "FAIL";
|
||||
function g(){}
|
||||
function h(){ x = "ok"; }
|
||||
var obj = {m: g};
|
||||
var arr = [g, g, g, g, h];
|
||||
//assertEq(arr.length > RUNLOOP, true);
|
||||
for (var i = 0; i < 5; i++) {
|
||||
obj.m = arr[i];
|
||||
obj.m();
|
||||
}
|
||||
return x;
|
||||
}
|
||||
assertEq(testRebranding2(), "ok");
|
|
@ -0,0 +1,28 @@
|
|||
x = Proxy.create((function () {
|
||||
return {
|
||||
get: function () {}
|
||||
}
|
||||
}()), Object.e)
|
||||
|
||||
var hit = false;
|
||||
|
||||
try {
|
||||
Function("\
|
||||
for(var a = 0; a < 2; ++a) {\
|
||||
if (a == 0) {}\
|
||||
else {\
|
||||
x > x\
|
||||
}\
|
||||
}\
|
||||
")()
|
||||
} catch (e) {
|
||||
hit = true;
|
||||
|
||||
var str = String(e);
|
||||
var match = (str == "TypeError: x is not a function" ||
|
||||
str == "TypeError: can't convert x to number");
|
||||
|
||||
assertEq(match, true);
|
||||
}
|
||||
|
||||
assertEq(hit, true);
|
|
@ -0,0 +1,10 @@
|
|||
// |jit-test| TMFLAGS: full,fragprofile,treevis; valgrind
|
||||
|
||||
function testRegExpTest() {
|
||||
var r = /abc/;
|
||||
var flag = false;
|
||||
for (var i = 0; i < 10; ++i)
|
||||
flag = r.test("abc");
|
||||
return flag;
|
||||
}
|
||||
assertEq(testRegExpTest(), true);
|
|
@ -0,0 +1,11 @@
|
|||
var a = {_val: 'q',
|
||||
get p() { return f; }};
|
||||
|
||||
function f() { return this._val; }
|
||||
|
||||
var g = '';
|
||||
for (var i = 0; i < 9; i++)
|
||||
g += a.p();
|
||||
assertEq(g, 'qqqqqqqqq');
|
||||
|
||||
checkStats({recorderStarted: 1, recorderAborted: 0, traceCompleted: 1, traceTriggered: 1});
|
|
@ -0,0 +1,38 @@
|
|||
// |jit-test| TMFLAGS: full,fragprofile,treevis; valgrind
|
||||
|
||||
/* Test the proper operation of the left shift operator. This is especially
|
||||
* important on ARM as an explicit mask is required at the native instruction
|
||||
* level. */
|
||||
|
||||
load(libdir + 'range.js');
|
||||
|
||||
function testShiftLeft()
|
||||
{
|
||||
var r = [];
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
|
||||
var shifts = [0,1,7,8,15,16,23,24,31];
|
||||
|
||||
/* Samples from the simple shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = 1 << shifts[i];
|
||||
|
||||
/* Samples outside the normal shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = 1 << (shifts[i] + 32);
|
||||
|
||||
/* Samples far outside the normal shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = 1 << (shifts[i] + 224);
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = 1 << (shifts[i] + 256);
|
||||
|
||||
return r.join(",");
|
||||
}
|
||||
|
||||
assertEq(testShiftLeft(),
|
||||
"1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
|
||||
"1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
|
||||
"1,2,128,256,32768,65536,8388608,16777216,-2147483648,"+
|
||||
"1,2,128,256,32768,65536,8388608,16777216,-2147483648");
|
|
@ -0,0 +1,44 @@
|
|||
/* Test the proper operation of the arithmetic right shift operator. This is
|
||||
* especially important on ARM as an explicit mask is required at the native
|
||||
* instruction level. */
|
||||
|
||||
load(libdir + 'range.js');
|
||||
|
||||
/* Test different combinations of literals/variables. */
|
||||
var s = 4;
|
||||
var t = 100;
|
||||
assertEq(42 >> s, 2);
|
||||
assertEq(s >> 1, 2);
|
||||
assertEq(23 >> 3, 2);
|
||||
assertEq(t >> s, 6);
|
||||
|
||||
|
||||
function testShiftRightArithmetic()
|
||||
{
|
||||
var r = [];
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
|
||||
var shifts = [0,1,7,8,15,16,23,24,31];
|
||||
|
||||
/* Samples from the simple shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = -2147483648 >> shifts[i];
|
||||
|
||||
/* Samples outside the normal shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = -2147483648 >> (shifts[i] + 32);
|
||||
|
||||
/* Samples far outside the normal shift range. */
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = -2147483648 >> (shifts[i] + 224);
|
||||
for (i = 0; i < shifts.length; i++)
|
||||
r[j++] = -2147483648 >> (shifts[i] + 256);
|
||||
|
||||
return r.join(",");
|
||||
}
|
||||
assertEq(testShiftRightArithmetic(),
|
||||
"-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
|
||||
"-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
|
||||
"-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+
|
||||
"-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1");
|
|
@ -0,0 +1,39 @@
|
|||
// |jit-test| TMFLAGS: full,fragprofile,treevis; valgrind
|
||||
|
||||
function testSideExitInConstructor() {
|
||||
var FCKConfig = {};
|
||||
FCKConfig.CoreStyles =
|
||||
{
|
||||
'Bold': { },
|
||||
'Italic': { },
|
||||
'FontFace': { },
|
||||
'Size' :
|
||||
{
|
||||
Overrides: [ ]
|
||||
},
|
||||
|
||||
'Color' :
|
||||
{
|
||||
Element: '',
|
||||
Styles: { },
|
||||
Overrides: [ ]
|
||||
},
|
||||
'BackColor': {
|
||||
Element : '',
|
||||
Styles : { 'background-color' : '' }
|
||||
},
|
||||
|
||||
};
|
||||
var FCKStyle = function(A) {
|
||||
A.Element;
|
||||
};
|
||||
|
||||
var pass = true;
|
||||
for (var s in FCKConfig.CoreStyles) {
|
||||
var x = new FCKStyle(FCKConfig.CoreStyles[s]);
|
||||
if (!x)
|
||||
pass = false;
|
||||
}
|
||||
return pass;
|
||||
}
|
||||
assertEq(testSideExitInConstructor(), true);
|
|
@ -0,0 +1,10 @@
|
|||
function testSlowNativeBail() {
|
||||
var a = ['0', '1', '2', '3', '+'];
|
||||
try {
|
||||
for (var i = 0; i < a.length; i++)
|
||||
new RegExp(a[i]);
|
||||
} catch (exc) {
|
||||
assertEq(""+exc, "SyntaxError: invalid quantifier");
|
||||
}
|
||||
}
|
||||
testSlowNativeBail();
|
|
@ -0,0 +1,29 @@
|
|||
const numFatArgs = Math.pow(2,19) - 1024;
|
||||
|
||||
function fun(x) {
|
||||
if (x <= 0)
|
||||
return 0;
|
||||
return fun(x-1);
|
||||
}
|
||||
|
||||
function fatStack() {
|
||||
return fun(10000);
|
||||
}
|
||||
|
||||
function assertRightFailure(e) {
|
||||
assertEq(e.toString() == "InternalError: script stack space quota is exhausted" ||
|
||||
e.toString() == "InternalError: too much recursion",
|
||||
true);
|
||||
}
|
||||
|
||||
exception = false;
|
||||
try {
|
||||
fatStack.apply(null, new Array(numFatArgs));
|
||||
} catch (e) {
|
||||
assertRightFailure(e);
|
||||
exception = true;
|
||||
}
|
||||
assertEq(exception, true);
|
||||
|
||||
// No more trace recursion w/ JM
|
||||
checkStats({traceCompleted:0});
|
|
@ -0,0 +1,17 @@
|
|||
// |jit-test| error: TypeError
|
||||
|
||||
(eval("\
|
||||
(function () {\
|
||||
for (var[x] = function(){} in \
|
||||
(function m(a) {\
|
||||
if (a < 1) {\
|
||||
x;\
|
||||
return\
|
||||
}\
|
||||
return m(a - 1) + m(a - 2)\
|
||||
})(7)\
|
||||
(eval(\"\"))\
|
||||
)\
|
||||
([])\
|
||||
})\
|
||||
"))()
|
|
@ -0,0 +1,17 @@
|
|||
for (j = 0; j < 1; j++) {
|
||||
var f = eval("\
|
||||
(function() {\
|
||||
for (var a = 0; a < 8; ++a) {\
|
||||
if (a % 3 == 2) {\
|
||||
eval(\"\
|
||||
for(b in[0,0,0,0]) {\
|
||||
print()\
|
||||
}\
|
||||
\")\
|
||||
}\
|
||||
gc()\
|
||||
}\
|
||||
})\
|
||||
");
|
||||
f()
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
for (a in (eval("\
|
||||
(function() {\
|
||||
return function() {\
|
||||
yield ((function() {\
|
||||
return d\
|
||||
})())\
|
||||
} ();\
|
||||
var d = []\
|
||||
})\
|
||||
"))());
|
|
@ -0,0 +1,16 @@
|
|||
function m() {
|
||||
var d = 73;
|
||||
|
||||
return (eval("\n\
|
||||
(function() {\n\
|
||||
return function() {\n\
|
||||
yield ((function() {\n\
|
||||
print(d);\n\
|
||||
return d\n\
|
||||
})())\n\
|
||||
} ();\n\
|
||||
})\n\
|
||||
"))();
|
||||
}
|
||||
|
||||
m().next();
|
|
@ -0,0 +1,27 @@
|
|||
function f() {
|
||||
var k = 0;
|
||||
|
||||
var g = function() {
|
||||
return ++k;
|
||||
}
|
||||
|
||||
return g;
|
||||
}
|
||||
|
||||
function h() {
|
||||
for (var i = 0; i < 10; ++i) {
|
||||
var vf = f();
|
||||
assertEq(vf(), 1);
|
||||
assertEq(vf(), 2);
|
||||
for (var j = 0; j < 10; ++j) {
|
||||
assertEq(vf(), j + 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
h();
|
||||
|
||||
checkStats({
|
||||
recorderAborted: 8, // Inner tree is trying to grow
|
||||
});
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
actual = '';
|
||||
expected = 'undefined,';
|
||||
|
||||
function f() {
|
||||
(eval("\
|
||||
(function () {\
|
||||
for (var z = 0; z < 2; ++z) {\
|
||||
x = ''\
|
||||
}\
|
||||
})\
|
||||
"))();
|
||||
}
|
||||
__defineSetter__("x", eval)
|
||||
f()
|
||||
appendToActual(x);
|
||||
|
||||
|
||||
assertEq(actual, expected)
|
|
@ -0,0 +1,20 @@
|
|||
(function() {
|
||||
(function g(m, n) {
|
||||
if (m = n) {
|
||||
return eval("x=this")
|
||||
}
|
||||
g(m, 1)[[]]
|
||||
})()
|
||||
})()
|
||||
Function("\
|
||||
for (let b in [0]) {\
|
||||
for (var k = 0; k < 6; ++k) {\
|
||||
if (k == 1) {\
|
||||
print(x)\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
")()
|
||||
|
||||
/* Don't crash/assert. */
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
// |jit-test| error: undefined
|
||||
(function() {
|
||||
throw (function f(a, b) {
|
||||
if (a.h == b) {
|
||||
return eval("((function(){return 1})())!=this")
|
||||
}
|
||||
f(b)
|
||||
})([], 0)
|
||||
})()
|
||||
|
||||
/* Don't assert/crash. */
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(function() {
|
||||
for each(let z in [new String(''), new String('q'), new String('')]) {
|
||||
if (uneval() < z) (function(){})
|
||||
}
|
||||
})()
|
||||
|
||||
/* Don't assert/crash. */
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
for each(x in [new Number])
|
||||
x.__proto__ = []
|
||||
++x[x]
|
||||
|
||||
// don't assert
|
|
@ -0,0 +1,9 @@
|
|||
setDebug(true);
|
||||
|
||||
function nop(){}
|
||||
function caller(obj) {
|
||||
assertJit();
|
||||
return x;
|
||||
}
|
||||
trap(caller, 7, "var x = 'success'; nop()");
|
||||
assertEq(caller(this), "success");
|
|
@ -0,0 +1,10 @@
|
|||
setDebug(true);
|
||||
|
||||
function nop(){}
|
||||
function caller(obj) {
|
||||
assertJit();
|
||||
var x = ({ dana : "zuul" });
|
||||
return x;
|
||||
}
|
||||
trap(caller, 23, "x = 'success'; nop()");
|
||||
assertEq(caller(this), "success");
|
|
@ -0,0 +1,10 @@
|
|||
setDebug(true);
|
||||
|
||||
function nop(){}
|
||||
function caller(obj) {
|
||||
assertJit();
|
||||
var x = "failure";
|
||||
return x;
|
||||
}
|
||||
trap(caller, 14, "x = 'success'; nop()");
|
||||
assertEq(caller(this), "success");
|
|
@ -0,0 +1,9 @@
|
|||
setDebug(true);
|
||||
var x = "failure";
|
||||
function main() { x = "success"; }
|
||||
|
||||
/* The JSOP_STOP in a. */
|
||||
trap(main, 8, "");
|
||||
main();
|
||||
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,10 @@
|
|||
setDebug(true);
|
||||
var x = "notset";
|
||||
function main() { x = "failure"; }
|
||||
function success() { x = "success"; }
|
||||
|
||||
/* The JSOP_STOP in a. */
|
||||
trap(main, 7, "success()");
|
||||
main();
|
||||
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,11 @@
|
|||
setDebug(true);
|
||||
var x = "notset";
|
||||
function main() { x = "success"; }
|
||||
function failure() { x = "failure"; }
|
||||
|
||||
/* The JSOP_STOP in a. */
|
||||
trap(main, 8, "failure()");
|
||||
untrap(main, 8);
|
||||
main();
|
||||
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,7 @@
|
|||
setDebug(true);
|
||||
function main() {
|
||||
return "failure";
|
||||
}
|
||||
/* JSOP_RETURN in main. */
|
||||
trap(main, 3, "'success'");
|
||||
assertEq(main(), "success");
|
|
@ -0,0 +1,7 @@
|
|||
setDebug(true);
|
||||
function main() {
|
||||
return 1;
|
||||
}
|
||||
/* JSOP_RETURN in main. */
|
||||
trap(main, 1, "0");
|
||||
assertEq(main(), 0);
|
|
@ -0,0 +1,15 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
function myparent(nested) {
|
||||
if (nested) {
|
||||
/* myparent call in myparent. */
|
||||
trap(myparent, 39, "failure()");
|
||||
} else {
|
||||
x = "success";
|
||||
myparent(true);
|
||||
}
|
||||
}
|
||||
function failure() { x = "failure"; }
|
||||
|
||||
myparent(false);
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,21 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
|
||||
function child() {
|
||||
x = "failure1";
|
||||
/* JSOP_STOP in parent. */
|
||||
trap(parent, 10, "success()");
|
||||
}
|
||||
|
||||
function parent() {
|
||||
x = "failure2";
|
||||
}
|
||||
/* First op in parent. */
|
||||
trap(parent, 0, "child()");
|
||||
|
||||
function success() {
|
||||
x = "success";
|
||||
}
|
||||
|
||||
parent();
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,16 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
function child() {
|
||||
/* JSOP_STOP in parent. */
|
||||
trap(parent, 17, "success()");
|
||||
}
|
||||
function parent() {
|
||||
child();
|
||||
x = "failure";
|
||||
}
|
||||
function success() {
|
||||
x = "success";
|
||||
}
|
||||
|
||||
parent()
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,18 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
|
||||
function myparent(nested) {
|
||||
if (nested) {
|
||||
/* noop call in myparent */
|
||||
trap(myparent, 50, "success()");
|
||||
} else {
|
||||
myparent(true);
|
||||
x = "failure";
|
||||
noop();
|
||||
}
|
||||
}
|
||||
function noop() { }
|
||||
function success() { x = "success"; }
|
||||
|
||||
myparent();
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,23 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
|
||||
function doNothing() { }
|
||||
|
||||
function myparent(nested) {
|
||||
if (nested) {
|
||||
/* JSOP_CALL to doNothing in myparent with nested = true. */
|
||||
trap(myparent, 24, "success()");
|
||||
doNothing();
|
||||
} else {
|
||||
doNothing();
|
||||
}
|
||||
}
|
||||
/* JSOP_CALL to doNothing in myparent with nested = false. */
|
||||
trap(myparent, 35, "myparent(true)");
|
||||
|
||||
function success() {
|
||||
x = "success";
|
||||
}
|
||||
|
||||
myparent(false);
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,11 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
function main() {
|
||||
/* The JSOP_STOP in a. */
|
||||
trap(main, 25, "success()");
|
||||
x = "failure";
|
||||
}
|
||||
function success() { x = "success"; }
|
||||
|
||||
main();
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,15 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
function child() {
|
||||
/* JSOP_STOP in parent */
|
||||
untrap(parent, 10);
|
||||
x = "success";
|
||||
}
|
||||
function parent() {
|
||||
x = "failure";
|
||||
}
|
||||
/* JSOP_STOP in parent */
|
||||
trap(parent, 10, "child()");
|
||||
|
||||
parent();
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,13 @@
|
|||
setDebug(true);
|
||||
x = "notset";
|
||||
function main() {
|
||||
/* JSOP_STOP in main. */
|
||||
untrap(main, 23);
|
||||
x = "success";
|
||||
}
|
||||
function failure() { x = "failure"; }
|
||||
|
||||
/* JSOP_STOP in main. */
|
||||
trap(main, 23, "failure()");
|
||||
main();
|
||||
assertEq(x, "success");
|
|
@ -0,0 +1,7 @@
|
|||
// |jit-test| error: TypeError
|
||||
function f() {
|
||||
eval("(function() \n{\nfor(x in[])\n{}\n})");
|
||||
("")()
|
||||
}
|
||||
f()
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// |jit-test| error: ReferenceError
|
||||
for (let a in [0])
|
||||
a = e
|
||||
for (let a in [0])
|
||||
(function () {
|
||||
a
|
||||
})
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
evalcx("function s(){}",evalcx('lazy'))
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
// |jit-test| error: ReferenceError
|
||||
function g() {
|
||||
var rv = (function() {
|
||||
this << 1
|
||||
})()
|
||||
if (a) (function() {})
|
||||
}
|
||||
g()
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
__defineGetter__("x", Float64Array)
|
||||
Function("\
|
||||
with(this) {\
|
||||
eval(\"x\")\
|
||||
}\
|
||||
")()
|
|
@ -0,0 +1,14 @@
|
|||
// |jit-test| error: <x/> is not a function
|
||||
function f() { (e)
|
||||
} (x = Proxy.createFunction((function(x) {
|
||||
return {
|
||||
get: function(r, b) {
|
||||
return x[b]
|
||||
}
|
||||
}
|
||||
})(/x/), wrap))
|
||||
for (z = 0; z < 100; x.unwatch(), z++)
|
||||
for (e in [0]) {
|
||||
gczeal(2)
|
||||
} ( <x/>)("")
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
with(evalcx('')) {
|
||||
delete eval;
|
||||
eval("x", this.__defineGetter__("x", Function));
|
||||
}
|
||||
|
||||
/* Don't assert or crash. */
|
||||
|
|
@ -0,0 +1 @@
|
|||
assertEq(Infinity >= Infinity ? true : false, true);
|
|
@ -0,0 +1,6 @@
|
|||
function ack(m,n){
|
||||
if (m==0) { return n+1; }
|
||||
if (n==0) { return ack(m-1,1); }
|
||||
return ack(m-1, ack(m,n-1) );
|
||||
}
|
||||
assertEq(ack(3, 3), 61);
|
|
@ -0,0 +1,60 @@
|
|||
(function()[function() function() function() function() function() function() {}]);
|
||||
foo = [{
|
||||
text: "(function(){if(d){(1)}})",
|
||||
s: function() {},
|
||||
test: function() {
|
||||
try {
|
||||
f
|
||||
} catch(e) {}
|
||||
}
|
||||
},
|
||||
{
|
||||
text: "(function(){t})",
|
||||
s: function() {},
|
||||
test: function() {}
|
||||
},
|
||||
{
|
||||
text: "(function(){if(0){}})",
|
||||
s: function() {},
|
||||
test: function() {}
|
||||
},
|
||||
{
|
||||
text: "(function(){if(1){}(2)})",
|
||||
s: function() {},
|
||||
test: function() {}
|
||||
},
|
||||
{
|
||||
text: "(function(){g})",
|
||||
b: function() {},
|
||||
test: function() {}
|
||||
},
|
||||
{
|
||||
text: "(function(){})",
|
||||
s: function() {},
|
||||
test: function() {}
|
||||
},
|
||||
{
|
||||
text: "(function(){1})",
|
||||
s: function() {},
|
||||
test: function() {}
|
||||
}]; (function() {
|
||||
for (i = 0; i < foo.length; ++i) {
|
||||
a = foo[i]
|
||||
text = a.text
|
||||
eval(text.replace(/@/, ""));
|
||||
if (a.test()) {}
|
||||
}
|
||||
} ());
|
||||
s = [function() function() function() function() function() function() {}]
|
||||
[function() function() function() function() {}];
|
||||
(function() { [function() function() {}] });
|
||||
(function() {});
|
||||
(eval("\
|
||||
(function(){\
|
||||
for each(d in[\
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,null,NaN,1,Boolean(false),Boolean(false)\
|
||||
]){\
|
||||
[].filter(new Function,gczeal(2))\
|
||||
}\
|
||||
})\
|
||||
"))();
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (C) 2007 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
var loops = 15
|
||||
var nx = 120
|
||||
var nz = 120
|
||||
|
||||
function morph(a, f) {
|
||||
var PI2nx = Math.PI * 8/nx
|
||||
var sin = Math.sin
|
||||
var f30 = -(50 * sin(f*Math.PI*2))
|
||||
|
||||
for (var i = 0; i < nz; ++i) {
|
||||
for (var j = 0; j < nx; ++j) {
|
||||
a[3*(i*nx+j)+1] = sin((j-1) * PI2nx ) * -f30
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var a = Array()
|
||||
for (var i=0; i < nx*nz*3; ++i)
|
||||
a[i] = 0
|
||||
|
||||
for (var i = 0; i < loops; ++i) {
|
||||
morph(a, i/loops)
|
||||
}
|
||||
|
||||
testOutput = 0;
|
||||
for (var i = 0; i < nx; i++)
|
||||
testOutput += a[3*(i*nx+i)+1];
|
||||
a = null;
|
||||
|
||||
/* not based on any mathematical error calculation.*/
|
||||
acceptableDelta = 4e-15
|
||||
|
||||
assertEq((testOutput - 6.394884621840902e-14) < acceptableDelta, true);
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -0,0 +1,52 @@
|
|||
/* The Great Computer Language Shootout
|
||||
http://shootout.alioth.debian.org/
|
||||
contributed by Isaac Gouy */
|
||||
|
||||
function TreeNode(left,right,item){
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
TreeNode.prototype.itemCheck = function(){
|
||||
if (this.left==null) return this.item;
|
||||
else return this.item + this.left.itemCheck() - this.right.itemCheck();
|
||||
}
|
||||
|
||||
function bottomUpTree(item,depth){
|
||||
if (depth>0){
|
||||
return new TreeNode(
|
||||
bottomUpTree(2*item-1, depth-1)
|
||||
,bottomUpTree(2*item, depth-1)
|
||||
,item
|
||||
);
|
||||
}
|
||||
else {
|
||||
return new TreeNode(null,null,item);
|
||||
}
|
||||
}
|
||||
|
||||
var ret;
|
||||
|
||||
for ( var n = 4; n <= 7; n += 1 ) {
|
||||
var minDepth = 4;
|
||||
var maxDepth = Math.max(minDepth + 2, n);
|
||||
var stretchDepth = maxDepth + 1;
|
||||
|
||||
var check = bottomUpTree(0,stretchDepth).itemCheck();
|
||||
|
||||
var longLivedTree = bottomUpTree(0,maxDepth);
|
||||
for (var depth=minDepth; depth<=maxDepth; depth+=2){
|
||||
var iterations = 1 << (maxDepth - depth + minDepth);
|
||||
|
||||
check = 0;
|
||||
for (var i=1; i<=iterations; i++){
|
||||
check += bottomUpTree(i,depth).itemCheck();
|
||||
check += bottomUpTree(-i,depth).itemCheck();
|
||||
}
|
||||
}
|
||||
|
||||
ret = longLivedTree.itemCheck();
|
||||
}
|
||||
|
||||
assertEq(ret, -1)
|
|
@ -0,0 +1,66 @@
|
|||
/* The Great Computer Language Shootout
|
||||
http://shootout.alioth.debian.org/
|
||||
contributed by Isaac Gouy */
|
||||
|
||||
function fannkuch(n) {
|
||||
var check = 0;
|
||||
var perm = Array(n);
|
||||
var perm1 = Array(n);
|
||||
var count = Array(n);
|
||||
var maxPerm = Array(n);
|
||||
var maxFlipsCount = 0;
|
||||
var m = n - 1;
|
||||
|
||||
for (var i = 0; i < n; i++) perm1[i] = i;
|
||||
var r = n;
|
||||
|
||||
while (true) {
|
||||
// write-out the first 30 permutations
|
||||
if (check < 30){
|
||||
var s = "";
|
||||
for(var i=0; i<n; i++) s += (perm1[i]+1).toString();
|
||||
check++;
|
||||
}
|
||||
|
||||
while (r != 1) { count[r - 1] = r; r--; }
|
||||
if (!(perm1[0] == 0 || perm1[m] == m)) {
|
||||
for (var i = 0; i < n; i++) perm[i] = perm1[i];
|
||||
|
||||
var flipsCount = 0;
|
||||
var k;
|
||||
|
||||
while (!((k = perm[0]) == 0)) {
|
||||
var k2 = (k + 1) >> 1;
|
||||
for (var i = 0; i < k2; i++) {
|
||||
var temp = perm[i]; perm[i] = perm[k - i]; perm[k - i] = temp;
|
||||
}
|
||||
flipsCount++;
|
||||
}
|
||||
|
||||
if (flipsCount > maxFlipsCount) {
|
||||
maxFlipsCount = flipsCount;
|
||||
for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (r == n) return maxFlipsCount;
|
||||
var perm0 = perm1[0];
|
||||
var i = 0;
|
||||
while (i < r) {
|
||||
var j = i + 1;
|
||||
perm1[i] = perm1[j];
|
||||
i = j;
|
||||
}
|
||||
perm1[r] = perm0;
|
||||
|
||||
count[r] = count[r] - 1;
|
||||
if (count[r] > 0) break;
|
||||
r++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var n = 8;
|
||||
var ret = fannkuch(n);
|
||||
assertEq(ret, 22)
|
|
@ -0,0 +1,171 @@
|
|||
/* The Great Computer Language Shootout
|
||||
http://shootout.alioth.debian.org/
|
||||
contributed by Isaac Gouy */
|
||||
|
||||
var PI = 3.141592653589793;
|
||||
var SOLAR_MASS = 4 * PI * PI;
|
||||
var DAYS_PER_YEAR = 365.24;
|
||||
|
||||
function Body(x,y,z,vx,vy,vz,mass){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.vx = vx;
|
||||
this.vy = vy;
|
||||
this.vz = vz;
|
||||
this.mass = mass;
|
||||
}
|
||||
|
||||
Body.prototype.offsetMomentum = function(px,py,pz) {
|
||||
this.vx = -px / SOLAR_MASS;
|
||||
this.vy = -py / SOLAR_MASS;
|
||||
this.vz = -pz / SOLAR_MASS;
|
||||
return this;
|
||||
}
|
||||
|
||||
function Jupiter(){
|
||||
return new Body(
|
||||
4.84143144246472090e+00,
|
||||
-1.16032004402742839e+00,
|
||||
-1.03622044471123109e-01,
|
||||
1.66007664274403694e-03 * DAYS_PER_YEAR,
|
||||
7.69901118419740425e-03 * DAYS_PER_YEAR,
|
||||
-6.90460016972063023e-05 * DAYS_PER_YEAR,
|
||||
9.54791938424326609e-04 * SOLAR_MASS
|
||||
);
|
||||
}
|
||||
|
||||
function Saturn(){
|
||||
return new Body(
|
||||
8.34336671824457987e+00,
|
||||
4.12479856412430479e+00,
|
||||
-4.03523417114321381e-01,
|
||||
-2.76742510726862411e-03 * DAYS_PER_YEAR,
|
||||
4.99852801234917238e-03 * DAYS_PER_YEAR,
|
||||
2.30417297573763929e-05 * DAYS_PER_YEAR,
|
||||
2.85885980666130812e-04 * SOLAR_MASS
|
||||
);
|
||||
}
|
||||
|
||||
function Uranus(){
|
||||
return new Body(
|
||||
1.28943695621391310e+01,
|
||||
-1.51111514016986312e+01,
|
||||
-2.23307578892655734e-01,
|
||||
2.96460137564761618e-03 * DAYS_PER_YEAR,
|
||||
2.37847173959480950e-03 * DAYS_PER_YEAR,
|
||||
-2.96589568540237556e-05 * DAYS_PER_YEAR,
|
||||
4.36624404335156298e-05 * SOLAR_MASS
|
||||
);
|
||||
}
|
||||
|
||||
function Neptune(){
|
||||
return new Body(
|
||||
1.53796971148509165e+01,
|
||||
-2.59193146099879641e+01,
|
||||
1.79258772950371181e-01,
|
||||
2.68067772490389322e-03 * DAYS_PER_YEAR,
|
||||
1.62824170038242295e-03 * DAYS_PER_YEAR,
|
||||
-9.51592254519715870e-05 * DAYS_PER_YEAR,
|
||||
5.15138902046611451e-05 * SOLAR_MASS
|
||||
);
|
||||
}
|
||||
|
||||
function Sun(){
|
||||
return new Body(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, SOLAR_MASS);
|
||||
}
|
||||
|
||||
|
||||
function NBodySystem(bodies){
|
||||
this.bodies = bodies;
|
||||
var px = 0.0;
|
||||
var py = 0.0;
|
||||
var pz = 0.0;
|
||||
var size = this.bodies.length;
|
||||
for (var i=0; i<size; i++){
|
||||
var b = this.bodies[i];
|
||||
var m = b.mass;
|
||||
px += b.vx * m;
|
||||
py += b.vy * m;
|
||||
pz += b.vz * m;
|
||||
}
|
||||
this.bodies[0].offsetMomentum(px,py,pz);
|
||||
}
|
||||
|
||||
NBodySystem.prototype.advance = function(dt){
|
||||
var dx, dy, dz, distance, mag;
|
||||
var size = this.bodies.length;
|
||||
|
||||
for (var i=0; i<size; i++) {
|
||||
var bodyi = this.bodies[i];
|
||||
for (var j=i+1; j<size; j++) {
|
||||
var bodyj = this.bodies[j];
|
||||
dx = bodyi.x - bodyj.x;
|
||||
dy = bodyi.y - bodyj.y;
|
||||
dz = bodyi.z - bodyj.z;
|
||||
|
||||
distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
mag = dt / (distance * distance * distance);
|
||||
|
||||
bodyi.vx -= dx * bodyj.mass * mag;
|
||||
bodyi.vy -= dy * bodyj.mass * mag;
|
||||
bodyi.vz -= dz * bodyj.mass * mag;
|
||||
|
||||
bodyj.vx += dx * bodyi.mass * mag;
|
||||
bodyj.vy += dy * bodyi.mass * mag;
|
||||
bodyj.vz += dz * bodyi.mass * mag;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i=0; i<size; i++) {
|
||||
var body = this.bodies[i];
|
||||
body.x += dt * body.vx;
|
||||
body.y += dt * body.vy;
|
||||
body.z += dt * body.vz;
|
||||
}
|
||||
}
|
||||
|
||||
NBodySystem.prototype.energy = function(){
|
||||
var dx, dy, dz, distance;
|
||||
var e = 0.0;
|
||||
var size = this.bodies.length;
|
||||
|
||||
for (var i=0; i<size; i++) {
|
||||
var bodyi = this.bodies[i];
|
||||
|
||||
e += 0.5 * bodyi.mass *
|
||||
( bodyi.vx * bodyi.vx
|
||||
+ bodyi.vy * bodyi.vy
|
||||
+ bodyi.vz * bodyi.vz );
|
||||
|
||||
for (var j=i+1; j<size; j++) {
|
||||
var bodyj = this.bodies[j];
|
||||
dx = bodyi.x - bodyj.x;
|
||||
dy = bodyi.y - bodyj.y;
|
||||
dz = bodyi.z - bodyj.z;
|
||||
|
||||
distance = Math.sqrt(dx*dx + dy*dy + dz*dz);
|
||||
e -= (bodyi.mass * bodyj.mass) / distance;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
var ret;
|
||||
|
||||
for ( var n = 3; n <= 24; n *= 2 ) {
|
||||
(function(){
|
||||
var bodies = new NBodySystem( Array(
|
||||
Sun(),Jupiter(),Saturn(),Uranus(),Neptune()
|
||||
));
|
||||
var max = n * 100;
|
||||
|
||||
ret = bodies.energy();
|
||||
for (var i=0; i<max; i++){
|
||||
bodies.advance(0.01);
|
||||
}
|
||||
ret = bodies.energy();
|
||||
})();
|
||||
}
|
||||
|
||||
assertEq(ret, -0.16906933525822856)
|
|
@ -0,0 +1,40 @@
|
|||
// The Great Computer Language Shootout
|
||||
// http://shootout.alioth.debian.org/
|
||||
//
|
||||
// modified by Isaac Gouy
|
||||
|
||||
function pad(number,width){
|
||||
var s = number.toString();
|
||||
var prefixWidth = width - s.length;
|
||||
if (prefixWidth>0){
|
||||
for (var i=1; i<=prefixWidth; i++) s = " " + s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
function nsieve(m, isPrime){
|
||||
var i, k, count;
|
||||
|
||||
for (i=2; i<=m; i++) { isPrime[i] = true; }
|
||||
count = 0;
|
||||
|
||||
for (i=2; i<=m; i++){
|
||||
if (isPrime[i]) {
|
||||
for (k=i+i; k<=m; k+=i) isPrime[k] = false;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
var ret = 0;
|
||||
function sieve() {
|
||||
for (var i = 1; i <= 3; i++ ) {
|
||||
var m = (1<<i)*10000;
|
||||
var flags = Array(m+1);
|
||||
ret += nsieve(m, flags);
|
||||
}
|
||||
}
|
||||
|
||||
sieve();
|
||||
assertEq(ret, 14302)
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com
|
||||
|
||||
// 1 op = 6 ANDs, 3 SHRs, 3 SHLs, 4 assigns, 2 ADDs
|
||||
// O(1)
|
||||
function fast3bitlookup(b) {
|
||||
var c, bi3b = 0xE994; // 0b1110 1001 1001 0100; // 3 2 2 1 2 1 1 0
|
||||
c = 3 & (bi3b >> ((b << 1) & 14));
|
||||
c += 3 & (bi3b >> ((b >> 2) & 14));
|
||||
c += 3 & (bi3b >> ((b >> 5) & 6));
|
||||
return c;
|
||||
|
||||
/*
|
||||
lir4,0xE994; 9 instructions, no memory access, minimal register dependence, 6 shifts, 2 adds, 1 inline assign
|
||||
rlwinmr5,r3,1,28,30
|
||||
rlwinmr6,r3,30,28,30
|
||||
rlwinmr7,r3,27,29,30
|
||||
rlwnmr8,r4,r5,30,31
|
||||
rlwnmr9,r4,r6,30,31
|
||||
rlwnmr10,r4,r7,30,31
|
||||
addr3,r8,r9
|
||||
addr3,r3,r10
|
||||
*/
|
||||
}
|
||||
|
||||
var ret = 0;
|
||||
function TimeFunc(func) {
|
||||
var x, y, t;
|
||||
for(var x=0; x<500; x++)
|
||||
for(var y=0; y<256; y++) {
|
||||
ret += func(y);
|
||||
}
|
||||
}
|
||||
|
||||
TimeFunc(fast3bitlookup);
|
||||
assertEq(ret, 512000)
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright (c) 2004 by Arthur Langereis (arthur_ext at domain xfinitegames, tld com)
|
||||
|
||||
|
||||
// 1 op = 2 assigns, 16 compare/branches, 8 ANDs, (0-8) ADDs, 8 SHLs
|
||||
// O(n)
|
||||
function bitsinbyte(b) {
|
||||
var m = 1, c = 0;
|
||||
while(m<0x100) {
|
||||
if(b & m) c++;
|
||||
m <<= 1;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
var ret = 0;
|
||||
function TimeFunc(func) {
|
||||
var x, y, t;
|
||||
for(var x=0; x<350; x++)
|
||||
for(var y=0; y<256; y++)
|
||||
ret += func(y);
|
||||
}
|
||||
|
||||
TimeFunc(bitsinbyte);
|
||||
assertEq(ret, 358400)
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (C) 2007 Apple Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
bitwiseAndValue = 4294967296;
|
||||
for (var i = 0; i < 60; i++)
|
||||
bitwiseAndValue = bitwiseAndValue & i;
|
||||
assertEq(bitwiseAndValue, 0)
|
|
@ -0,0 +1,40 @@
|
|||
// The Great Computer Language Shootout
|
||||
// http://shootout.alioth.debian.org
|
||||
//
|
||||
// Contributed by Ian Osgood
|
||||
|
||||
var result = [];
|
||||
|
||||
function pad(n,width) {
|
||||
var s = n.toString();
|
||||
while (s.length < width) s = ' ' + s;
|
||||
return s;
|
||||
}
|
||||
|
||||
function primes(isPrime, n) {
|
||||
var i, count = 0, m = 10000<<n, size = m+31>>5;
|
||||
|
||||
for (i=0; i<size; i++) isPrime[i] = 0xffffffff;
|
||||
|
||||
for (i=2; i<m; i++)
|
||||
if (isPrime[i>>5] & 1<<(i&31)) {
|
||||
for (var j=i+i; j<m; j+=i)
|
||||
result.push(isPrime[j>>5] &= ~(1<<(j&31)));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
function sieve() {
|
||||
for (var i = 4; i <= 4; i++) {
|
||||
var isPrime = new Array((10000<<i)+31>>5);
|
||||
primes(isPrime, i);
|
||||
}
|
||||
}
|
||||
|
||||
sieve();
|
||||
|
||||
var ret = 0;
|
||||
for (var i = 0; i < result.length; ++i)
|
||||
ret += result[i];
|
||||
|
||||
assertEq(ret, -211235557404919)
|
|
@ -0,0 +1,27 @@
|
|||
// The Computer Language Shootout
|
||||
// http://shootout.alioth.debian.org/
|
||||
// contributed by Isaac Gouy
|
||||
|
||||
function ack(m,n){
|
||||
if (m==0) { return n+1; }
|
||||
if (n==0) { return ack(m-1,1); }
|
||||
return ack(m-1, ack(m,n-1) );
|
||||
}
|
||||
|
||||
function fib(n) {
|
||||
if (n < 2){ return 1; }
|
||||
return fib(n-2) + fib(n-1);
|
||||
}
|
||||
|
||||
function tak(x,y,z) {
|
||||
if (y >= x) return z;
|
||||
return tak(tak(x-1,y,z), tak(y-1,z,x), tak(z-1,x,y));
|
||||
}
|
||||
|
||||
var ret = 0;
|
||||
for ( var i = 3; i <= 5; i++ ) {
|
||||
ret += ack(3,i);
|
||||
ret += fib(17.0+i);
|
||||
ret += tak(3*i+3,2*i+2,i+1);
|
||||
}
|
||||
assertEq(ret, 57775);
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -0,0 +1,422 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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");
|
||||
|
||||
var ret;
|
||||
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");
|
||||
ret = shortFormat + longFormat;
|
||||
date.setTime(date.getTime() + 84266956);
|
||||
}
|
||||
|
||||
// No exact match because the output depends on the locale's time zone. See bug 524490.
|
||||
assertEq(/^2017-09-05Tuesday, September 05, 2017 [0-9:]* AM$/.exec(ret) != null, true);
|
|
@ -0,0 +1,41 @@
|
|||
// The Computer Language Shootout
|
||||
// http://shootout.alioth.debian.org/
|
||||
// contributed by Isaac Gouy
|
||||
|
||||
function partial(n){
|
||||
var a1 = a2 = a3 = a4 = a5 = a6 = a7 = a8 = a9 = 0.0;
|
||||
var twothirds = 2.0/3.0;
|
||||
var alt = -1.0;
|
||||
var k2 = k3 = sk = ck = 0.0;
|
||||
|
||||
for (var k = 1; k <= n; k++){
|
||||
k2 = k*k;
|
||||
k3 = k2*k;
|
||||
sk = Math.sin(k);
|
||||
ck = Math.cos(k);
|
||||
alt = -alt;
|
||||
|
||||
a1 += Math.pow(twothirds,k-1);
|
||||
a2 += Math.pow(k,-0.5);
|
||||
a3 += 1.0/(k*(k+1.0));
|
||||
a4 += 1.0/(k3 * sk*sk);
|
||||
a5 += 1.0/(k3 * ck*ck);
|
||||
a6 += 1.0/k;
|
||||
a7 += 1.0/k2;
|
||||
a8 += alt/k;
|
||||
a9 += alt/(2*k -1);
|
||||
}
|
||||
|
||||
return [ a1, a2, a3, a4, a5, a6, a7, a8, a9 ];
|
||||
}
|
||||
|
||||
var actual = [];
|
||||
for (var i = 1024; i <= 16384; i *= 2)
|
||||
Array.prototype.push.apply(actual, partial(i));
|
||||
|
||||
var eps = 1e-12;
|
||||
var expect = [2.9999999999999987,62.555269219624684,0.9990243902439033,30.174793391263677,42.99468748637077,7.509175672278132,1.6439579810301654,0.6926591377284127,0.785154022830656,2.9999999999999987,89.06036157695789,0.9995119570522216,30.30796333494624,42.99485339033617,8.202078771817716,1.6444459047881168,0.6929030995395857,0.7852760930922243,2.9999999999999987,126.54745783224483,0.999755918965097,30.314167756318135,42.994888939123,8.89510389696629,1.6446899560231332,0.6930251251486118,0.7853371282421086,2.9999999999999987,179.56450569047874,0.9998779445868421,30.314499725429847,42.99489723774016,9.588190046095265,1.644812003986005,0.693086149128997,0.785367645819433,2.9999999999999987,254.54355172132264,0.9999389685688135,30.31451920492601,42.99489939769195,10.281306710008463,1.6448730335545856,0.6931166639131536,0.7853829046083998];
|
||||
|
||||
assertEq(actual.length, expect.length);
|
||||
for (var i = 0; i < expect.length; ++i)
|
||||
assertEq(Math.abs(actual[i] - expect[i]) < eps, true);
|
|
@ -0,0 +1,119 @@
|
|||
// regression test for Bug 452008 - TM: SRP in Clipperz crypto library fails when JIT (TraceMonkey) is enabled.
|
||||
|
||||
var x = [9385, 32112, 25383, 16317, 30138, 14565, 17812, 24500, 2719, 30174, 3546, 9096, 15352, 19120, 20648, 14334, 7426, 0, 0, 0];
|
||||
var n = [27875, 25925, 30422, 12227, 27798, 32170, 10873, 21748, 30629, 26296, 20697, 5125, 4815, 2221, 14392, 23369, 5560, 2, 0, 0];
|
||||
var np = 18229;
|
||||
var expected = [18770, 31456, 17999, 32635, 27508, 29131, 2856, 16233, 5439, 27580, 7093, 18192, 30804, 5472, 8529, 28649, 14852, 0, 0, 0];
|
||||
|
||||
//globals
|
||||
bpe=0; //bits stored per array element
|
||||
mask=0; //AND this with an array element to chop it down to bpe bits
|
||||
|
||||
//initialize the global variables
|
||||
for (bpe=0; (1<<(bpe+1)) > (1<<bpe); bpe++); //bpe=number of bits in the mantissa on this platform
|
||||
bpe>>=1; //bpe=number of bits in one element of the array representing the bigInt
|
||||
mask=(1<<bpe)-1; //AND the mask with an integer to get its bpe least significant bits
|
||||
|
||||
|
||||
//the following global variables are scratchpad memory to
|
||||
//reduce dynamic memory allocation in the inner loop
|
||||
sa = new Array(0); //used in mont_()
|
||||
|
||||
//do x=y on bigInts x and y. x must be an array at least as big as y (not counting the leading zeros in y).
|
||||
function copy_(x,y) {
|
||||
var i;
|
||||
var k=x.length<y.length ? x.length : y.length;
|
||||
for (i=0;i<k;i++)
|
||||
x[i]=y[i];
|
||||
for (i=k;i<x.length;i++)
|
||||
x[i]=0;
|
||||
}
|
||||
|
||||
//do x=y on bigInt x and integer y.
|
||||
function copyInt_(x,n) {
|
||||
var i,c;
|
||||
for (c=n,i=0;i<x.length;i++) {
|
||||
x[i]=c & mask;
|
||||
c>>=bpe;
|
||||
}
|
||||
}
|
||||
|
||||
//is x > y? (x and y both nonnegative)
|
||||
function greater(x,y) {
|
||||
var i;
|
||||
var k=(x.length<y.length) ? x.length : y.length;
|
||||
|
||||
for (i=x.length;i<y.length;i++)
|
||||
if (y[i])
|
||||
return 0; //y has more digits
|
||||
|
||||
for (i=y.length;i<x.length;i++)
|
||||
if (x[i])
|
||||
return 1; //x has more digits
|
||||
|
||||
for (i=k-1;i>=0;i--)
|
||||
if (x[i]>y[i])
|
||||
return 1;
|
||||
else if (x[i]<y[i])
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//do x=x*y*Ri mod n for bigInts x,y,n,
|
||||
// where Ri = 2**(-kn*bpe) mod n, and kn is the
|
||||
// number of elements in the n array, not
|
||||
// counting leading zeros.
|
||||
//x must be large enough to hold the answer.
|
||||
//It's OK if x and y are the same variable.
|
||||
//must have:
|
||||
// x,y < n
|
||||
// n is odd
|
||||
// np = -(n^(-1)) mod radix
|
||||
function mont_(x,y,n,np) {
|
||||
var i,j,c,ui,t;
|
||||
var kn=n.length;
|
||||
var ky=y.length;
|
||||
|
||||
if (sa.length!=kn)
|
||||
sa=new Array(kn);
|
||||
|
||||
for (;kn>0 && n[kn-1]==0;kn--); //ignore leading zeros of n
|
||||
for (;ky>0 && y[ky-1]==0;ky--); //ignore leading zeros of y
|
||||
|
||||
copyInt_(sa,0);
|
||||
|
||||
//the following loop consumes 95% of the runtime for randTruePrime_() and powMod_() for large keys
|
||||
for (i=0; i<kn; i++) {
|
||||
t=sa[0]+x[i]*y[0];
|
||||
ui=((t & mask) * np) & mask; //the inner "& mask" is needed on Macintosh MSIE, but not windows MSIE
|
||||
c=(t+ui*n[0]) >> bpe;
|
||||
t=x[i];
|
||||
|
||||
//do sa=(sa+x[i]*y+ui*n)/b where b=2**bpe
|
||||
for (j=1;j<ky;j++) {
|
||||
c+=sa[j]+t*y[j]+ui*n[j];
|
||||
sa[j-1]=c & mask;
|
||||
c>>=bpe;
|
||||
}
|
||||
for (;j<kn;j++) {
|
||||
c+=sa[j]+ui*n[j];
|
||||
sa[j-1]=c & mask;
|
||||
c>>=bpe;
|
||||
}
|
||||
sa[j-1]=c & mask;
|
||||
}
|
||||
|
||||
if (!greater(n,sa))
|
||||
sub_(sa,n);
|
||||
copy_(x,sa);
|
||||
}
|
||||
|
||||
mont_(x, x, n, np);
|
||||
|
||||
var passed = expected.length == x.length;
|
||||
for (var i = 0; i < expected.length; i++) {
|
||||
if (passed)
|
||||
passed = expected[i] == x[i];
|
||||
}
|
||||
assertEq(passed, true);
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче