packages/compiler/src/code-generation/per-file/get-wasm-module-function.ts
Function __moduleLoader
has 373 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function __moduleLoader(this: any, wasmUri: string, options: Options): ModuleLoader {
const PTR_SIZE = 4;
const PTR_SHIFT = Math.log2(PTR_SIZE);
function sizeOf(type: string): int {
Function __moduleLoader
has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring. Open
Open
function __moduleLoader(this: any, wasmUri: string, options: Options): ModuleLoader {
const PTR_SIZE = 4;
const PTR_SHIFT = Math.log2(PTR_SIZE);
function sizeOf(type: string): int {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
File get-wasm-module-function.ts
has 400 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
/**
* This file includes a single statement, the function declaration of the getWasmModuleFactory. This function is used in the
* speedyjs-transformer to generate the code to load the wasm module.
* The code is inspired by https://github.com/kripken/emscripten/blob/incoming/src/runtime.js
*/
Function loadInstance
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function loadInstance(): Promise<WebAssemblyInstance> {
let instance: WebAssemblyInstance;
let wasmLoaded: Promise<ArrayBuffer>;
// browser
Function jsToWasm
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function jsToWasm(jsValue: any, typeName: string, types: Types, objectReferences: Map<object, int>): any {
const type = types[typeName];
if (!type) { throw new Error("Unknown type " + typeName); }
Function wasmToJs
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
function wasmToJs(wasmValue: any, typeName: string, types: Types, returnedObjects: Map<int, object>) {
const type = types[typeName];
if (!type) { throw new Error("Unknown type " + typeName); }
if (type.primitive) {
Function from
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static from(native: any[], elementType: string, types: Types, objectReferences: Map<object, int>): RuntimeArray {
// begin, back, capacity
const size = PTR_SIZE * 2 + sizeOf("i32");
const arrayPtr = malloc(size);
const elementSize = sizeOf(elementType);
Function invoke_iiiii
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
invoke_iiiii(index: number, a1: number, a2: number, a3: number, a4: number) {
Avoid too many return
statements within this function. Open
Open
return objectReference;