Add overall code reformatting

This commit is contained in:
Christoph Diehl 2017-04-22 23:07:29 +03:00
parent 93d5fec51a
commit 6654cf857e
12 changed files with 248 additions and 212 deletions

View file

@ -1,14 +1,14 @@
var Logger = (function () { var Logger = (function () {
let color = { let color = {
red: "\033[1;31m", red: "\033[1;31m",
green: "\033[1;32m", green: "\033[1;32m",
clear: "\033[0m" clear: "\033[0m"
}; };
if (platform.isWindows) { if (platform.isWindows) {
color = { color = {
red: "", red: "",
green: "", green: "",
clear: "" clear: ""
}; };
} }
@ -30,31 +30,31 @@ var Logger = (function () {
} }
function dump(msg) { function dump(msg) {
console(msg); console(msg);
} }
function testcase(msg) { function testcase(msg) {
dump("/*L*/ " + JSON.stringify(msg) + "\n"); dump("/*L*/ " + JSON.stringify(msg) + "\n");
} }
function dumpln(msg) { function dumpln(msg) {
dump(msg + "\n"); dump(msg + "\n");
} }
function error(msg) { function error(msg) {
dumpln(color.red + msg + color.clear); dumpln(color.red + msg + color.clear);
} }
function JSError(msg) { function JSError(msg) {
error(comment(msg)) error(comment(msg))
} }
function comment(msg) { function comment(msg) {
return "/* " + msg + " */"; return "/* " + msg + " */";
} }
function separator() { function separator() {
dumpln(color.green + sep + color.clear); dumpln(color.green + sep + color.clear);
} }
return { return {

View file

@ -1,5 +1,5 @@
make.colors = { make.colors = {
colors: function() { colors: function () {
return random.pick([ return random.pick([
make.colors.colorRGB, make.colors.colorRGB,
make.colors.colorHSL, make.colors.colorHSL,
@ -7,9 +7,9 @@ make.colors = {
]); ]);
}, },
colorRGB: function() { colorRGB: function () {
let values; let values;
switch (random.number(4)) { switch (random.number(4)) {
case 0: case 0:
// Rgb functional notation // Rgb functional notation
@ -34,10 +34,10 @@ make.colors = {
} }
}, },
colorHSL: function() { colorHSL: function () {
let values, opt; let values, opt;
switch(random.number(4)) { switch (random.number(4)) {
case 0: case 0:
values = [random.number(255), "%" + random.number(255), "%" + random.number(255)]; values = [random.number(255), "%" + random.number(255), "%" + random.number(255)];
return "hsl(" + values.join(',') + ")"; return "hsl(" + values.join(',') + ")";
@ -54,7 +54,7 @@ make.colors = {
} }
}, },
colorKeywords: function() { colorKeywords: function () {
return random.pick([ return random.pick([
"lime", "red", "blue", "invert", "currentColor", "ActiveBorder", "ActiveCaption", "lime", "red", "blue", "invert", "currentColor", "ActiveBorder", "ActiveCaption",
"AppWorkspace", "Background", "ButtonFace", "ButtonHighlight", "ButtonShadow", "AppWorkspace", "Background", "ButtonFace", "ButtonHighlight", "ButtonShadow",

View file

@ -1,20 +1,20 @@
make.fonts = { make.fonts = {
fontStyles: function() { fontStyles: function () {
return ["italic", "normal", "oblique", "inherit"]; return ["italic", "normal", "oblique", "inherit"];
}, },
fontVariants: function() { fontVariants: function () {
return ["normal", "small-caps", "inherit"]; return ["normal", "small-caps", "inherit"];
}, },
fontWeights: function() { fontWeights: function () {
return ["normal", "bold", "bolder", "lighter"]; return ["normal", "bold", "bolder", "lighter"];
}, },
fontSizeAbsolute: function() { fontSizeAbsolute: function () {
return ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"]; return ["xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large"];
}, },
fontFamiliesGeneric: function() { fontFamiliesGeneric: function () {
return ["serif", "sans-serif", "cursive", "fantasy", "monospace"]; return ["serif", "sans-serif", "cursive", "fantasy", "monospace"];
}, },
fontFamilies: function() { fontFamilies: function () {
return ["'Times New Roman'", "Arial", "Courier", "Helvetica"]; return ["'Times New Roman'", "Arial", "Courier", "Helvetica"];
}, },
fontFamily: function () { fontFamily: function () {

View file

@ -1,5 +1,5 @@
make.network = { make.network = {
sdp: function() { sdp: function () {
// session description protocol template // session description protocol template
return [ return [
"v=0", "v=0",
@ -34,36 +34,42 @@ make.network = {
"a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host", "a=candidate:0 2 UDP 2113601790 192.168.129.33 62658 typ host",
].join("\n"); ].join("\n");
}, },
PeerConnectionProtocols: function() { PeerConnectionProtocols: function () {
return ["turn", "turns", "stun", "stuns"] return ["turn", "turns", "stun", "stuns"]
}, },
randomIPv4: function() { randomIPv4: function () {
return random.pick([random.number(255), make.numbers.number]) + "." + return random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." + random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]) + "." + random.pick([random.number(255), make.numbers.number]) + "." +
random.pick([random.number(255), make.numbers.number]); random.pick([random.number(255), make.numbers.number]);
}, },
randomIPv6: function() { randomIPv6: function () {
return "[" + make.stringFromBlocks([":", function() { return make.strings.digitsHex(random.range(1, 4)) }]) + "]" return "[" + make.stringFromBlocks([":", function () {
return make.strings.digitsHex(random.range(1, 4))
}]) + "]"
}, },
goodHostnames: function() { return [ goodHostnames: function () {
"0.0.0.0", return [
"127.0.0.1:8080", "0.0.0.0",
]}, "127.0.0.1:8080",
badHostnames: function() { return [ ]
"google.org:8080", },
"::1", badHostnames: function () {
"[::192.9.5.5]:42", return [
"2001:db8:85a3::8a2e:370:3478", "google.org:8080",
"2001:db8:85a3:0:0:8a2e:370:3478", "::1",
"::ffff:192.0.2.1", "[::192.9.5.5]:42",
"0000:0000:0000:0000:0000:0000:0000:0001", "2001:db8:85a3::8a2e:370:3478",
"::192.0.2.128", "2001:db8:85a3:0:0:8a2e:370:3478",
"::ffff:192.0.2.128", "::ffff:192.0.2.1",
"2001:db8::1:2", "0000:0000:0000:0000:0000:0000:0000:0001",
"2001:db8::1:1:1:1:1" "::192.0.2.128",
]}, "::ffff:192.0.2.128",
randomBitmask: function(list) { "2001:db8::1:2",
"2001:db8::1:1:1:1:1"
]
},
randomBitmask: function (list) {
if (list.length <= 1) { if (list.length <= 1) {
return list.join(""); return list.join("");
} }

View file

@ -5,16 +5,25 @@ make.numbers = {
float: function () { float: function () {
let n; let n;
if (random.chance(32)) { if (random.chance(32)) {
switch(random.number(4)) { switch (random.number(4)) {
case 0: n = random.range(Number.MAX_VALUE, Number.MIN_VALUE); break; case 0:
case 1: n = Math.pow(10, 1) / Math.pow(10, random.number(307)); break; n = random.range(Number.MAX_VALUE, Number.MIN_VALUE);
case 2: n = Math.pow(2, random.float() * random.float() * 64); break; break;
case 3: n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9)); break; case 1:
n = Math.pow(10, 1) / Math.pow(10, random.number(307));
break;
case 2:
n = Math.pow(2, random.float() * random.float() * 64);
break;
case 3:
n = Math.pow(10, random.range(1, 9)) / Math.pow(10, random.range(1, 9));
break;
} }
return n; return n;
} }
switch (random.number(6)) { switch (random.number(6)) {
default: n = random.float(); default:
n = random.float();
} }
return n; return n;
}, },
@ -37,7 +46,7 @@ make.numbers = {
let value = random.choose([ let value = random.choose([
[10, make.numbers.float], [10, make.numbers.float],
[10, [make.numbers.rangeNumber, make.numbers.tinyNumber]], [10, [make.numbers.rangeNumber, make.numbers.tinyNumber]],
[ 1, Make.numbers.unsignedNumber] [1, Make.numbers.unsignedNumber]
]); ]);
return random.chance(10) ? -value : value; return random.chance(10) ? -value : value;
} }

View file

@ -1,5 +1,5 @@
make.shaders = { make.shaders = {
fragment1: function() { fragment1: function () {
return [ return [
[ [
"#ifdef GL_ES", "#ifdef GL_ES",
@ -7,7 +7,7 @@ make.shaders = {
"#endif", "#endif",
"varying vec4 vColor;", "varying vec4 vColor;",
"void main() {", "void main() {",
"gl_FragColor=vColor;", "gl_FragColor=vColor;",
"}", "}",
], ],
[ [
@ -15,8 +15,8 @@ make.shaders = {
"varying highp vec3 vLighting;", "varying highp vec3 vLighting;",
"uniform sampler2D uSampler;", "uniform sampler2D uSampler;",
"void main(void) {", "void main(void) {",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));", "highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);", "gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"}" "}"
] ]
] ]
@ -28,8 +28,8 @@ make.shaders = {
"attribute vec4 aColor;", "attribute vec4 aColor;",
"varying vec4 vColor;", "varying vec4 vColor;",
"void main(){", "void main(){",
"vColor=aColor;", "vColor=aColor;",
"gl_Position=aVertex;", "gl_Position=aVertex;",
"}", "}",
], ],
[ [
@ -42,27 +42,27 @@ make.shaders = {
"varying highp vec2 vTextureCoord;", "varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;", "varying highp vec3 vLighting;",
"void main(void) {", "void main(void) {",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);", "gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;", "vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);", "highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);", "highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);", "highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);", "highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);", "highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);", "vLighting = ambientLight + (directionalLightColor * directional);",
"}" "}"
] ]
] ]
}, },
fragment2: function() { fragment2: function () {
return [ return [
[ [
"varying highp vec2 vTextureCoord;", "varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;", "varying highp vec3 vLighting;",
"uniform sampler2D uSampler;", "uniform sampler2D uSampler;",
"void main(void) {", "void main(void) {",
"highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));", "highp vec4 texelColor = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t));",
"gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);", "gl_FragColor = vec4(texelColor.rgb * vLighting, texelColor.a);",
"}" "}"
], ],
[ [
@ -74,19 +74,19 @@ make.shaders = {
"varying vec3 varyingNormal;", "varying vec3 varyingNormal;",
"varying vec2 varyingUV;", "varying vec2 varyingUV;",
"void main(void) {", "void main(void) {",
"vec3 albedo=texture2D(albedoMap,varyingUV).rgb;", "vec3 albedo=texture2D(albedoMap,varyingUV).rgb;",
"vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;", "vec3 normal=texture2D(normalMap,varyingUV).rgb*2.0-1.0;",
"float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);", "float specularFactor=pow((albedo.r+albedo.g+albedo.b)*0.33,2.0);",
"float specularHardness=2.0;", "float specularHardness=2.0;",
"vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;", "vec3 spaceNormal=varyingTangent*normal.x+varyingBitangent*normal.y+varyingNormal*normal.z;",
"gl_FragData[0]=vec4(albedo,1.0);", "gl_FragData[0]=vec4(albedo,1.0);",
"gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);", "gl_FragData[1]=vec4(spaceNormal*0.5 +0.5,1.0);",
"gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);", "gl_FragData[2]=vec4(specularFactor,specularHardness*0.1,0.0,1.0);",
"}" "}"
] ]
] ]
}, },
vertex2: function() { vertex2: function () {
return [ return [
[ [
"attribute highp vec3 aVertexNormal;", "attribute highp vec3 aVertexNormal;",
@ -98,14 +98,14 @@ make.shaders = {
"varying highp vec2 vTextureCoord;", "varying highp vec2 vTextureCoord;",
"varying highp vec3 vLighting;", "varying highp vec3 vLighting;",
"void main(void) {", "void main(void) {",
"gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);", "gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);",
"vTextureCoord = aTextureCoord;", "vTextureCoord = aTextureCoord;",
"highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);", "highp vec3 ambientLight = vec3(0.6, 0.6, 0.6);",
"highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);", "highp vec3 directionalLightColor = vec3(0.5, 0.5, 0.75);",
"highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);", "highp vec3 directionalVector = vec3(0.85, 0.8, 0.75);",
"highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);", "highp vec4 transformedNormal = uNormalMatrix * vec4(aVertexNormal, 1.0);",
"highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);", "highp float directional = max(dot(transformedNormal.xyz, directionalVector), 0.0);",
"vLighting = ambientLight + (directionalLightColor * directional);", "vLighting = ambientLight + (directionalLightColor * directional);",
"}" "}"
], ],
[ [
@ -122,17 +122,17 @@ make.shaders = {
"varying vec3 varyingNormal;", "varying vec3 varyingNormal;",
"varying vec2 varyingUV;", "varying vec2 varyingUV;",
"void main(void){", "void main(void){",
"gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));", "gl_Position=viewMatrix*(modelMatrix*vec4(vertexPosition,1.0));",
"gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);", "gl_Position.xy=gl_Position.xy*0.5+(float(gl_InstanceID)-0.5);",
"varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;", "varyingTangent=(modelMatrix*vec4(vertexTangent,0.0)).xyz;",
"varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;", "varyingBitangent=(modelMatrix*vec4(vertexBitangent,0.0)).xyz;",
"varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;", "varyingNormal=(modelMatrix*vec4(vertexNormal,0.0)).xyz;",
"varyingUV = vertexUV;", "varyingUV = vertexUV;",
"}" "}"
] ]
] ]
}, },
shaderPair: function(v, f) { shaderPair: function (v, f) {
let i = random.number(v.length); let i = random.number(v.length);
return { return {
vertex: utils.common.quote(v[i].join("\n")), vertex: utils.common.quote(v[i].join("\n")),

View file

@ -26,7 +26,7 @@ make.text = {
"en-US", "en", "de" "en-US", "en", "de"
]); ]);
}, },
layoutCharCodes: function() { layoutCharCodes: function () {
return random.pick([ return random.pick([
0, // null 0, // null
160, // non-breaking space 160, // non-breaking space
@ -96,73 +96,91 @@ make.text = {
}, },
// http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt // http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt
unicodeCombiningCharacters: function() { return random.item([ unicodeCombiningCharacters: function () {
[0x0300, 0x036F], // Combining Diacritical Marks return random.item([
[0x0483, 0x0489], [0x0300, 0x036F], // Combining Diacritical Marks
[0x07EB, 0x07F3], [0x0483, 0x0489],
[0x135D, 0x135F], [0x07EB, 0x07F3],
[0x1A7F, 0x1A7F], [0x135D, 0x135F],
[0x1B6B, 0x1B73], [0x1A7F, 0x1A7F],
[0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement [0x1B6B, 0x1B73],
[0x20D0, 0x2DFF], [0x1DC0, 0x1DFF], // Combining Diacritical Marks Supplement
[0x3099, 0x309A], [0x20D0, 0x2DFF],
[0xA66F, 0xA6F1], [0x3099, 0x309A],
[0xA8E0, 0xA8F1], [0xA66F, 0xA6F1],
[0xFE20, 0xFE26], // Combining Half Marks [0xA8E0, 0xA8F1],
[0x101FD, 0x101FD], [0xFE20, 0xFE26], // Combining Half Marks
[0x1D165, 0x1D169], [0x101FD, 0x101FD],
[0x1D16D, 0x1D172], [0x1D165, 0x1D169],
[0x1D17B, 0x1D18B], [0x1D16D, 0x1D172],
[0x1D1AA, 0x1D1AD], [0x1D17B, 0x1D18B],
[0x1D242, 0x1D244] [0x1D1AA, 0x1D1AD],
])}, [0x1D242, 0x1D244]
unicodeBMP: function() { return random.item([ ])
// BMP = Basic Multilingual Plane },
[0x0000, 0xFFFF] unicodeBMP: function () {
])}, return random.item([
unicodeSMP: function() { return random.item([ // BMP = Basic Multilingual Plane
// SMP = Supplementary Multilingual Plane [0x0000, 0xFFFF]
[0x10000, 0x13FFF], ])
[0x16000, 0x16FFF], },
[0x1B000, 0x1BFFF], unicodeSMP: function () {
[0x1D000, 0x1DFFF], return random.item([
[0x1F000, 0x1FFFF] // SMP = Supplementary Multilingual Plane
])}, [0x10000, 0x13FFF],
unicodeSIP: function() { return random.item([ [0x16000, 0x16FFF],
// SIP = Supplementary Ideographic Plane [0x1B000, 0x1BFFF],
[0x20000, 0x2BFFF], [0x1D000, 0x1DFFF],
[0x2F000, 0x2FFFF] [0x1F000, 0x1FFFF]
])}, ])
unicodeSSP: function() { return random.item([ },
// SSP = Supplementary Special-purpose Plane unicodeSIP: function () {
[0xE0000, 0xE0FFF] return random.item([
])}, // SIP = Supplementary Ideographic Plane
registeredFontFeatures: function() { return random.pick([ [0x20000, 0x2BFFF],
'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws', [0x2F000, 0x2FFFF]
'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh', ])
'curs', 'cv01-cv99', 'c2pc', 'c2sc', 'dist', 'dlig', 'dnom', 'expt', },
'falt', 'fin2', 'fin3', 'fina', 'frac', 'fwid', 'half', 'haln', 'halt', unicodeSSP: function () {
'hist', 'hkna', 'hlig', 'hngl', 'hojo', 'hwid', 'init', 'isol', 'ital', return random.item([
'jalt', 'jp78', 'jp83', 'jp90', 'jp04', 'kern', 'lfbd', 'liga', 'ljmo', // SSP = Supplementary Special-purpose Plane
'lnum', 'locl', 'ltra', 'ltrm', 'mark', 'med2', 'medi', 'mgrk', 'mkmk', [0xE0000, 0xE0FFF]
'mset', 'nalt', 'nlck', 'nukt', 'numr', 'onum', 'opbd', 'ordn', 'ornm', ])
'palt', 'pcap', 'pkna', 'pnum', 'pref', 'pres', 'pstf', 'psts', 'pwid', },
'qwid', 'rand', 'rkrf', 'rlig', 'rphf', 'rtbd', 'rtla', 'rtlm', 'ruby', registeredFontFeatures: function () {
'salt', 'sinf', 'size', 'smcp', 'smpl', 'ss01', 'ss02', 'ss03', 'ss04', return random.pick([
'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10', 'ss11', 'ss12', 'ss13', 'aalt', 'abvf', 'abvm', 'abvs', 'afrc', 'akhn', 'blwf', 'blwm', 'blws',
'ss14', 'ss15', 'ss16', 'ss17', 'ss18', 'ss19', 'ss20', 'subs', 'sups', 'calt', 'case', 'ccmp', 'cfar', 'cjct', 'clig', 'cpct', 'cpsp', 'cswh',
'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt', 'curs', 'cv01-cv99', 'c2pc', 'c2sc', 'dist', 'dlig', 'dnom', 'expt',
'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero' 'falt', 'fin2', 'fin3', 'fina', 'frac', 'fwid', 'half', 'haln', 'halt',
])}, 'hist', 'hkna', 'hlig', 'hngl', 'hojo', 'hwid', 'init', 'isol', 'ital',
assignmentOperator: function() { return random.pick([ 'jalt', 'jp78', 'jp83', 'jp90', 'jp04', 'kern', 'lfbd', 'liga', 'ljmo',
"=", "-=", "+=", "*=", "/=" 'lnum', 'locl', 'ltra', 'ltrm', 'mark', 'med2', 'medi', 'mgrk', 'mkmk',
])}, 'mset', 'nalt', 'nlck', 'nukt', 'numr', 'onum', 'opbd', 'ordn', 'ornm',
arithmeticOperator: function() { return random.pick([ 'palt', 'pcap', 'pkna', 'pnum', 'pref', 'pres', 'pstf', 'psts', 'pwid',
"%", "-", "+", "*", "/" 'qwid', 'rand', 'rkrf', 'rlig', 'rphf', 'rtbd', 'rtla', 'rtlm', 'ruby',
])}, 'salt', 'sinf', 'size', 'smcp', 'smpl', 'ss01', 'ss02', 'ss03', 'ss04',
currency: function() { return random.pick([ 'ss05', 'ss06', 'ss07', 'ss08', 'ss09', 'ss10', 'ss11', 'ss12', 'ss13',
// https://en.wikipedia.org/wiki/ISO_4217 'ss14', 'ss15', 'ss16', 'ss17', 'ss18', 'ss19', 'ss20', 'subs', 'sups',
"USD", "USS", "USN", "EUR", "CHF", "GBP", "XAG", "XBA", "XBB", "XBC", 'swsh', 'titl', 'tjmo', 'tnam', 'tnum', 'trad', 'twid', 'unic', 'valt',
"XBD", "XSU", "XTS", "XXX", 'vatu', 'vert', 'vhal', 'vjmo', 'vkna', 'vkrn', 'vpal', 'vrt2', 'zero'
])}, ])
},
assignmentOperator: function () {
return random.pick([
"=", "-=", "+=", "*=", "/="
])
},
arithmeticOperator: function () {
return random.pick([
"%", "-", "+", "*", "/"
])
},
currency: function () {
return random.pick([
// https://en.wikipedia.org/wiki/ISO_4217
"USD", "USS", "USN", "EUR", "CHF", "GBP", "XAG", "XBA", "XBB", "XBC",
"XBD", "XSU", "XTS", "XXX",
])
},
}; };

View file

@ -1,5 +1,5 @@
make.types = { make.types = {
random: function() { random: function () {
return random.item([ return random.item([
"true", "true",
"null", "null",

View file

@ -9,15 +9,15 @@
* *
*/ */
function MersenneTwister() function MersenneTwister() {
{
const N = 624; const N = 624;
const M = 397; const M = 397;
const UPPER_MASK = 0x80000000; const UPPER_MASK = 0x80000000;
const LOWER_MASK = 0x7fffffff; const LOWER_MASK = 0x7fffffff;
const MAG01 = new Int32Array([0, 0x9908b0df]); const MAG01 = new Int32Array([0, 0x9908b0df]);
let mt = new Int32Array(N); /* the array for the state vector */ let mt = new Int32Array(N);
/* the array for the state vector */
let mti = 625; let mti = 625;
this.seed = function (s) { this.seed = function (s) {
@ -27,28 +27,28 @@ function MersenneTwister()
} }
}; };
this.export_state = function() { this.export_state = function () {
return [mt, mti]; return [mt, mti];
}; };
this.import_state = function(s) { this.import_state = function (s) {
mt = s[0]; mt = s[0];
mti = s[1]; mti = s[1];
}; };
this.export_mta = function() { this.export_mta = function () {
return mt; return mt;
}; };
this.import_mta = function(_mta) { this.import_mta = function (_mta) {
mt = _mta; mt = _mta;
}; };
this.export_mti = function() { this.export_mti = function () {
return mti; return mti;
}; };
this.import_mti = function(_mti) { this.import_mti = function (_mti) {
mti = _mti; mti = _mti;
}; };
@ -56,16 +56,16 @@ function MersenneTwister()
let y, kk; let y, kk;
if (mti >= N) { /* generate N words at one time */ if (mti >= N) { /* generate N words at one time */
for (kk = 0; kk < N-M; kk++) { for (kk = 0; kk < N - M; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK)); y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK));
mt[kk] = (mt[kk+M] ^ (y >>> 1) ^ MAG01[y & 0x1]); mt[kk] = (mt[kk + M] ^ (y >>> 1) ^ MAG01[y & 0x1]);
} }
for (; kk < N-1; kk++) { for (; kk < N - 1; kk++) {
y = ((mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK)); y = ((mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK));
mt[kk] = (mt[kk+(M-N)] ^ (y >>> 1) ^ MAG01[y & 0x1]); mt[kk] = (mt[kk + (M - N)] ^ (y >>> 1) ^ MAG01[y & 0x1]);
} }
y = ((mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK)); y = ((mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK));
mt[N-1] = (mt[M-1] ^ (y >>> 1) ^ MAG01[y & 0x1]); mt[N - 1] = (mt[M - 1] ^ (y >>> 1) ^ MAG01[y & 0x1]);
mti = 0; mti = 0;
} }

View file

@ -2,9 +2,9 @@ var random = {
twister: null, twister: null,
/** /**
* Must be called before any other methods can be called to initialize MersenneTwister. * Must be called before any other methods can be called to initialize MersenneTwister.
* @param {number|null|undefined} seed Value to initialize MersenneTwister. * @param {number|null|undefined} seed Value to initialize MersenneTwister.
*/ */
init: function (seed) { init: function (seed) {
if (seed == null || seed === undefined) { if (seed == null || seed === undefined) {
seed = new Date().getTime(); seed = new Date().getTime();
@ -21,10 +21,10 @@ var random = {
limit = 0xffffffff; limit = 0xffffffff;
} }
let x = (0x100000000 / limit) >>> 0, let x = (0x100000000 / limit) >>> 0,
y = (x * limit) >>> 0, r; y = (x * limit) >>> 0, r;
do { do {
r = this.twister.int32(); r = this.twister.int32();
} while(y && r >= y); } while (y && r >= y);
return (r / x) >>> 0; return (r / x) >>> 0;
}, },
float: function () { float: function () {
@ -39,7 +39,7 @@ var random = {
} }
return this.number(limit - start + 1) + start; return this.number(limit - start + 1) + start;
}, },
ludOneTo: function(limit) { ludOneTo: function (limit) {
// Returns a float in [1, limit]. The logarithm has uniform distribution. // Returns a float in [1, limit]. The logarithm has uniform distribution.
return Math.exp(this.float() * Math.log(limit)); return Math.exp(this.float() * Math.log(limit));
}, },

View file

@ -1,5 +1,5 @@
utils.block = { utils.block = {
block: function(list, optional) { block: function (list, optional) {
if (optional == true) { if (optional == true) {
if (random.chance(6)) { if (random.chance(6)) {
return ''; return '';
@ -16,7 +16,7 @@ utils.block = {
if (typeof(item) == "string") { if (typeof(item) == "string") {
return item; return item;
} }
if (item instanceof(Array)) { if (item instanceof (Array)) {
let s = ""; let s = "";
for (let i = 0; i < item.length; i++) { for (let i = 0; i < item.length; i++) {
s += go_deeper(item[i]); s += go_deeper(item[i]);

View file

@ -11,7 +11,7 @@ utils.script = {
return "(" + params.join(", ") + ")"; return "(" + params.join(", ") + ")";
}, },
methodCall: function (objectName, methodHash) { methodCall: function (objectName, methodHash) {
if(!utils.common.getKeysFromHash(methodHash).length || !objectName) { if (!utils.common.getKeysFromHash(methodHash).length || !objectName) {
return ""; return "";
} }
var methodName = random.key(methodHash); var methodName = random.key(methodHash);
@ -22,20 +22,20 @@ utils.script = {
return objectName + "." + methodName + utils.script..methodHead(methodArgs); return objectName + "." + methodName + utils.script..methodHead(methodArgs);
}, },
setAttribute: function (objectName, attributeHash) { setAttribute: function (objectName, attributeHash) {
if(!utils.common.getKeysFromHash(attributeHash).length || !objectName) { if (!utils.common.getKeysFromHash(attributeHash).length || !objectName) {
return ""; return "";
} }
var attributeName = random.key(attributeHash); var attributeName = random.key(attributeHash);
var attributeValue = random.pick(attributeHash[attributeName]); var attributeValue = random.pick(attributeHash[attributeName]);
var operator = " = "; var operator = " = ";
/* /*
if (typeof(attributeValue) == "number" && Random.chance(8)) { if (typeof(attributeValue) == "number" && Random.chance(8)) {
operator = " " + Make.randomAssignmentOperator() + " "; operator = " " + Make.randomAssignmentOperator() + " ";
} }
if (typeof(attributeValue) == "string") { if (typeof(attributeValue) == "string") {
attributeValue = "'" + attributeValue + "'"; attributeValue = "'" + attributeValue + "'";
} }
*/ */
return objectName + "." + attributeName + operator + attributeValue + ";"; return objectName + "." + attributeName + operator + attributeValue + ";";
}, },
makeConstraint: function (keys, values) { makeConstraint: function (keys, values) {
@ -85,15 +85,18 @@ utils.script = {
return "(document.body || document.documentElement).appendChild" + utils.script..methodHead([name]); return "(document.body || document.documentElement).appendChild" + utils.script..methodHead([name]);
}, },
forceGC: function () { forceGC: function () {
if (platform.isMozilla) {} if (platform.isMozilla) {
if (platform.isChrome) { }
if (window.GCController) if (platform.isChrome) {
return GCController.collect(); if (window.GCController)
return GCController.collect();
}
if (platform.isSafari) {
}
if (platform.isIE) {
} }
if (platform.isSafari) {}
if (platform.isIE) {}
}, },
getRandomElement: function() { getRandomElement: function () {
return "document.getElementsByTagName('*')[" + random.number(document.getElementsByTagName("*").length) + "]"; return "document.getElementsByTagName('*')[" + random.number(document.getElementsByTagName("*").length) + "]";
} }
}; };