Socket
Socket
Sign inDemoInstall

asm.js

Package Overview
Dependencies
8
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    asm.js

Tools for the asm.js subset of JavaScript


Version published
Weekly downloads
4
increased by33.33%
Maintainers
1
Install size
2.37 MB
Created
Weekly downloads
 

Readme

Source

asm.js

A Mozilla Research project to specify and develop the extremely optimizable subset of JS targeted by compilers like Emscripten, Mandreel, and LLJS.

Example

function mymodule(stdlib, foreign, heap) {
    "use asm";

    // -------------------------------------------------------------------------
    // SECTION 1: globals

    var H32 = new stdlib.Int32Array(heap);
    var HU32 = new stdlib.Uint32Array(heap);
    var log = foreign.consoleDotLog;

    var g_i = 0;   // int global
    var g_f = 0.0; // double global

    // -------------------------------------------------------------------------
    // SECTION 2: functions

    function f(x, y) {
        // SECTION A: parameter type declarations
        x = x|0;      // int parameter
        y = +y;       // double parameter

        // SECTION B: function body
        log(x|0);     // call into FFI -- must force the sign
        log(y);       // call into FFI -- already know it's a double
        x = (x+3)|0;  // signed addition

        // SECTION C: unconditional return
        return ((((x+1)|0)>>>0)/(x|0))>>>0; // compound expression
    }

    function g() {
        g_f = +g_i; // read/write globals
        return;
    }
    
    function g2() {
        return;
    }

    function h(i, x) {
        i = i|0;
        x = x|0;
        H32[i>>2] = x;       // shifted by log2(byte count)
        ftable_2[(x-2)&2](); // dynamic call of functions in table 2

        // no return necessary when return type is void
    }
    
    // -------------------------------------------------------------------------
    // SECTION 3: function tables

    var ftable_1 = [f];
    var ftable_2 = [g, g2]; // all of the same type

    // -------------------------------------------------------------------------
    // SECTION 4: exports

    return { f_export: f, goop: g };
}

Keywords

FAQs

Last updated on 01 Nov 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc