Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  function-call-bind.js

  Sprache: JAVA
 

// See "Wasm Function.prototype.call.bind optimization" in WasmInstance.cpp
// for more information.

function wrapFunc(params, func) {
    let funcCallBind = Function.prototype.call.bind(func);

    return wasmEvalText(`(module
        (func (import "" "f") (param ${params.join(" ")}))
        (func (export "f") (param ${params.join(" ")})
            ${params.map((x, i) => `local.get ${i}`).join("\n")}
            call 0
        )
    )`, {"": {"f": funcCallBind}}).exports.f;
}

// Test passing all kinds of externref values to func through the 'this'
// parameter.
{
    let func = function (expected) {
        "use strict";
        assertEq(this, expected);
    };
    let test = wrapFunc(["externref""externref"], func);
    for (let val of WasmExternrefValues) {
        test(val, val);
    }
}

// Same as above but with two non-this params.
{
    let func = function (a, b) {
        "use strict";
        assertEq(this, a);
        assertEq(a, b);
    };
    let test = wrapFunc(["externref""externref""externref"], func);
    for (let val of WasmExternrefValues) {
        test(val, val, val);
    }
}

// Test passing primitives as the 'this' value.
{
    let func = function (expected) {
        "use strict";
        assertEq(this, expected);
    };
    let vals = [012345];
    for (let valType of ["i32""i64""f32""f64"]) {
        let test = wrapFunc([valType, valType], func);
        for (let val of vals) {
            if (valType === "i64") {
                val = BigInt(val);
            }
            test(val, val);
        }
    }
}

// Function.prototype.call on a non-strict function will coerce null/undefined
// to the global object.
{
    let func = function (expected) {
        assertEq(this, expected);
    };
    let test = wrapFunc(["externref""externref"], func);
    test(null, globalThis);
    test(undefined, globalThis);
}

// Test binding extra JS arguments still works (this should skip the
// optimization)
{
    function func(x) {
        "use strict";
        assertEq(this1);
        assertEq(x, 2);
    }

    // Bind '2' to be the first normal arg to 'call', which will then become
    // the 'this' parameter always.
    let funcCallBind = Function.prototype.call.bind(func, 1);

    let {test} = wasmEvalText(`(module
        (func (import "" "f") (param i32))
        (export "test" (func 0))
    )`, {"": {"f": funcCallBind}}).exports;

    test(2);
}

// Test a missing this parameter.
{
    let test = wrapFunc([], function () {
        "use strict";
        assertEq(this, undefined);
    });
    test();
}

Messung V0.5 in Prozent
C=89 H=92 G=90

¤ Dauer der Verarbeitung: 0.3 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002