Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test the Detailed Calc with Jest #292

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
11 changes: 10 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
* See: https://www.gatsbyjs.org/docs/node-apis/
*/

// You can delete this file if you're not using it
// You can delete this file if you're not using it

exports.onCreateWebpackConfig = ({ stage, actions }) => {
actions.setWebpackConfig({

//allow us to not use ENVIRONMENT=web when compiling anypia-js, test it
// https://stackoverflow.com/questions/59487224/webpack-throws-error-with-emscripten-cant-resolve-fs
"node": { "fs": "empty" }
})
}
28,445 changes: 28,433 additions & 12 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/react-helmet": "^6.1.0",
"@types/use-persisted-state": "^0.3.0",
"babel-preset-gatsby": "^0.5.6",
"caniuse-lite": "^1.0.30001198",
"core-js": "3.6.5",
"d3": "^6.2.0",
"d3-format": "^1.4.3",
Expand Down
167 changes: 152 additions & 15 deletions src/library/anypiajs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import 'core-js/modules/es6.typed-array.uint8-clamped-array'
// See: https://stackoverflow.com/questions/63592691/core-js-cannot-resolve-core-js-modules-es6-typed-uint32-array/63592692#63592692

var Module = (function() {
var _scriptDir = '/anypiajs.wasm';
var _scriptDir = '/anypiajs-20211-versioned.wasm';

return (
function(Module) {
Module = Module || {};



// The Module object: Our interface to the outside world. We import
// and export values on it. There are various ways Module can be used:
// 1. Not defined. We create it here
Expand Down Expand Up @@ -193,10 +192,16 @@ var quit_ = function(status, toThrow) {
// Determine the runtime environment we are in. You can customize this by
// setting the ENVIRONMENT setting at compile time (see settings.js).

var ENVIRONMENT_IS_WEB = true;
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
ENVIRONMENT_IS_WEB = typeof window === 'object';
ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
// N.b. Electron.js environment is simultaneously a NODE-environment, but
// also a web environment.
ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;

if (Module['ENVIRONMENT']) {
throw new Error('Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)');
Expand All @@ -219,6 +224,104 @@ var read_,
readBinary,
setWindowTitle;

var nodeFS;
var nodePath;

if (ENVIRONMENT_IS_NODE) {
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/';
} else {
scriptDirectory = __dirname + '/';
}




read_ = function shell_read(filename, binary) {
if (!nodeFS) nodeFS = require('fs');
if (!nodePath) nodePath = require('path');
filename = nodePath['normalize'](filename);
return nodeFS['readFileSync'](filename, binary ? null : 'utf8');
};

readBinary = function readBinary(filename) {
var ret = read_(filename, true);
if (!ret.buffer) {
ret = new Uint8Array(ret);
}
assert(ret.buffer);
return ret;
};




if (process['argv'].length > 1) {
thisProgram = process['argv'][1].replace(/\\/g, '/');
}

arguments_ = process['argv'].slice(2);

// MODULARIZE will export the module in the proper place outside, we don't need to export here

process['on']('uncaughtException', function(ex) {
// suppress ExitStatus exceptions from showing an error
if (!(ex instanceof ExitStatus)) {
throw ex;
}
});

process['on']('unhandledRejection', abort);

quit_ = function(status) {
process['exit'](status);
};

Module['inspect'] = function () { return '[Emscripten Module object]'; };



} else
if (ENVIRONMENT_IS_SHELL) {


if (typeof read != 'undefined') {
read_ = function shell_read(f) {
return read(f);
};
}

readBinary = function readBinary(f) {
var data;
if (typeof readbuffer === 'function') {
return new Uint8Array(readbuffer(f));
}
data = read(f, 'binary');
assert(typeof data === 'object');
return data;
};

if (typeof scriptArgs != 'undefined') {
arguments_ = scriptArgs;
} else if (typeof arguments != 'undefined') {
arguments_ = arguments;
}

if (typeof quit === 'function') {
quit_ = function(status) {
quit(status);
};
}

if (typeof print !== 'undefined') {
// Prefer to use print/printErr where they exist, as they usually work better.
if (typeof console === 'undefined') console = /** @type{!Console} */({});
console.log = /** @type{!function(this:Console, ...*): undefined} */ (print);
console.warn = console.error = /** @type{!function(this:Console, ...*): undefined} */ (typeof printErr !== 'undefined' ? printErr : print);
}


} else

// Note that this includes Node.js workers when relevant (pthreads is enabled).
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
Expand All @@ -244,7 +347,6 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
scriptDirectory = '';
}

if (!(typeof window === 'object' || typeof importScripts === 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');

// Differentiate the Web Worker from the Node Worker case, as reading must
// be done differently.
Expand Down Expand Up @@ -1359,11 +1461,11 @@ function updateGlobalBufferAndViews(buf) {
}

var STATIC_BASE = 1024,
STACK_BASE = 74208,
STACK_BASE = 74512,
STACKTOP = STACK_BASE,
STACK_MAX = 5317088,
DYNAMIC_BASE = 5317088,
DYNAMICTOP_PTR = 74000;
STACK_MAX = 5317392,
DYNAMIC_BASE = 5317392,
DYNAMICTOP_PTR = 74304;

assert(STACK_BASE % 16 === 0, 'stack must start aligned');
assert(DYNAMIC_BASE % 16 === 0, 'heap must start aligned');
Expand Down Expand Up @@ -1787,7 +1889,7 @@ function createExportWrapper(name, fixedasm) {
};
}

var wasmBinaryFile = 'anypiajs.wasm';
var wasmBinaryFile = 'anypiajs20211-versioned.wasm';
if (!isDataURI(wasmBinaryFile)) {
wasmBinaryFile = locateFile(wasmBinaryFile);
}
Expand All @@ -1813,6 +1915,8 @@ function getBinaryPromise() {
// If we don't have the binary yet, and have the Fetch api, use that;
// in some environments, like Electron's render process, Fetch api may be present, but have a different context than expected, let's only use it on the Web
if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === 'function'
// Let's not use fetch to get objects over file:// as it's most likely Cordova which doesn't support fetch for file://
&& !isFileURI(wasmBinaryFile)
) {
return fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function(response) {
if (!response['ok']) {
Expand Down Expand Up @@ -1890,6 +1994,8 @@ function createWasm() {
if (!wasmBinary &&
typeof WebAssembly.instantiateStreaming === 'function' &&
!isDataURI(wasmBinaryFile) &&
// Don't use streaming for file:// delivered objects in a webview, fetch them synchronously.
!isFileURI(wasmBinaryFile) &&
typeof fetch === 'function') {
fetch(wasmBinaryFile, { credentials: 'same-origin' }).then(function (response) {
var result = WebAssembly.instantiateStreaming(response, info);
Expand Down Expand Up @@ -1936,7 +2042,7 @@ var ASM_CONSTS = [];



// STATICTOP = STATIC_BASE + 73184;
// STATICTOP = STATIC_BASE + 73488;
/* global initializers */ __ATINIT__.push({ func: function() { globalCtors() } });


Expand All @@ -1947,7 +2053,7 @@ var ASM_CONSTS = [];


/* no memory initializer */
var tempDoublePtr = 74192;
var tempDoublePtr = 74496;

function copyTempFloat(ptr) { // functions, because inlining this code increases code size too much
HEAP8[tempDoublePtr] = HEAP8[ptr];
Expand Down Expand Up @@ -2290,6 +2396,27 @@ function copyTempDouble(ptr) {
}},default_tty_ops:{get_char:function(tty) {
if (!tty.input.length) {
var result = null;
if (ENVIRONMENT_IS_NODE) {
// we will read data by chunks of BUFSIZE
var BUFSIZE = 256;
var buf = Buffer.alloc ? Buffer.alloc(BUFSIZE) : new Buffer(BUFSIZE);
var bytesRead = 0;

try {
bytesRead = nodeFS.readSync(process.stdin.fd, buf, 0, BUFSIZE, null);
} catch(e) {
// Cross-platform differences: on Windows, reading EOF throws an exception, but on other OSes,
// reading EOF returns 0. Uniformize behavior by treating the EOF exception to return 0.
if (e.toString().indexOf('EOF') != -1) bytesRead = 0;
else throw e;
}

if (bytesRead > 0) {
result = buf.slice(0, bytesRead).toString('utf-8');
} else {
result = null;
}
} else
if (typeof window != 'undefined' &&
typeof window.prompt == 'function') {
// Browser.
Expand Down Expand Up @@ -3735,6 +3862,16 @@ function copyTempDouble(ptr) {
var randomBuffer = new Uint8Array(1);
random_device = function() { crypto.getRandomValues(randomBuffer); return randomBuffer[0]; };
} else
if (ENVIRONMENT_IS_NODE) {
// for nodejs with or without crypto support included
try {
var crypto_module = require('crypto');
// nodejs has crypto support
random_device = function() { return crypto_module['randomBytes'](1)[0]; };
} catch (e) {
// nodejs doesn't have crypto support
}
} else
{}
if (!random_device) {
// we couldn't find a proper implementation, as Math.random() is not suitable for /dev/random, see emscripten-core/emscripten/pull/7096
Expand Down Expand Up @@ -6206,7 +6343,7 @@ function copyTempDouble(ptr) {
}


var ___tm_timezone=(stringToUTF8("GMT", 74096, 4), 74096);
var ___tm_timezone=(stringToUTF8("GMT", 74400, 4), 74400);

function _tzset() {
// TODO: Use (malleable) environment variables instead of system settings.
Expand Down Expand Up @@ -6947,8 +7084,8 @@ var dynCall_viiiiii = Module["dynCall_viiiiii"] = createExportWrapper("dynCall_v

/** @type {function(...*):?} */
var dynCall_viijii = Module["dynCall_viijii"] = createExportWrapper("dynCall_viijii");
Module['__ZZNKSt3__27num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEE6do_putES4_RNS_8ios_baseEwPKvE5__fmt'] = 62561;
Module['__ZZNKSt3__27num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEE6do_putES4_RNS_8ios_baseEwmE5__fmt'] = 62572;;
Module['__ZZNKSt3__27num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEE6do_putES4_RNS_8ios_baseEwPKvE5__fmt'] = 62863;
Module['__ZZNKSt3__27num_putIwNS_19ostreambuf_iteratorIwNS_11char_traitsIwEEEEE6do_putES4_RNS_8ios_baseEwmE5__fmt'] = 62874;;



Expand All @@ -6974,7 +7111,7 @@ if (!Object.getOwnPropertyDescriptor(Module, "addOnPreRun")) Module["addOnPreRun
if (!Object.getOwnPropertyDescriptor(Module, "addOnInit")) Module["addOnInit"] = function() { abort("'addOnInit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
if (!Object.getOwnPropertyDescriptor(Module, "addOnPreMain")) Module["addOnPreMain"] = function() { abort("'addOnPreMain' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
if (!Object.getOwnPropertyDescriptor(Module, "addOnExit")) Module["addOnExit"] = function() { abort("'addOnExit' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
if (!Object.getOwnPropertyDescriptor(Module, "addOnPostRun")) Module["addOnPostRun"] = function() { abort("'addOnPostRun' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
Module["addOnPostRun"] = addOnPostRun;
if (!Object.getOwnPropertyDescriptor(Module, "writeStringToMemory")) Module["writeStringToMemory"] = function() { abort("'writeStringToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
if (!Object.getOwnPropertyDescriptor(Module, "writeArrayToMemory")) Module["writeArrayToMemory"] = function() { abort("'writeArrayToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
if (!Object.getOwnPropertyDescriptor(Module, "writeAsciiToMemory")) Module["writeAsciiToMemory"] = function() { abort("'writeAsciiToMemory' was not exported. add it to EXTRA_EXPORTED_RUNTIME_METHODS (see the FAQ)") };
Expand Down
Loading