2021.2.0b6 .jslib ES6+ Support Survey

.jslib ES6+ support test

Object function Literal: NG[Build Error]

// NG: [Build Error]
mergeInto(LibraryManager.library, {
    fnc() {
    }
});

Object Arrow Function: NG[Runtime Error]

// NG: [Runtime Error]
mergeInto(LibraryManager.library, {
    fnc:() => {
    }
});

Async Function: OK

// OK
mergeInto(LibraryManager.library, {
    $asyncFnc: async function(a, b, c) {
        return new Promise(resolve => {
            setTimeout(() => {
                console.log(Date.now());
                resolve();
            }, 1000);
        });
    },

    fnc__deps: ['$asyncFnc'],
    fnc: async function(){
        await asyncFnc();
        await asyncFnc();
        await asyncFnc();
    }
});

Default Parameters: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(a = 3, b = 4) {
        console.log(a, b);
    }
});

Rest parameters: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(a, ...args) {
        console.log(a);
        args.forEach(x => console.log(x));
    }
});

Arrow Function: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(...args) {
        args.forEach(x => console.log(x));
    }
});

let / const: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(a, b, c) {
        let d = a;
        const e = b;
        console.log(d, e);
    }
});

New Object Literal: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(a, b, c) {
        let obj = {a, b, c};
        console.log(JSON.stringify(obj));
    }
});

Template Literal: OK

// OK
mergeInto(LibraryManager.library, {
    fnc: function(a, b, c) {
        console.log(`Template Literal test:${a}, ${b}, ${c}`);
    }
});

Destructuring assignment: OK and NG

// OK
mergeInto(LibraryManager.library, {
    fnc: function() {
        let a, b, c;
        [a, b, c] = [1, 2, 3];
        console.log(`${a}, ${b}, ${c}`);
    }
});
// NG: [Runtime Error]
mergeInto(LibraryManager.library, {
    fnc: function() {
        let [a, b, c] = [1, 2, 3];
        console.log(`${a}, ${b}, ${c}`);
    }
});
// NG: [Runtime Error]
mergeInto(LibraryManager.library, {
    fnc: function(a, b, c) {
        let {d, e, f} = {d:a, e:b, f:c};
        console.log(`${a}, ${b}, ${c}`);
    }
});

Object Function Literal was a very strong hope, but I’m very sorry that it wasn’t supported.

3 Likes

Can you help me to resolve this issue ?

I am working on webgl unity 2021.2. But Build time i am getting this error .

You’re trying to copy to D:/wamp64/www/vv10/Build/vv10.framework.js more than once. Previously from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.framework.js and now from Library/Bee/artifacts/WebGL/build/debug_WebGL_wasm/build.worker.framework.js

@lyflike

Maybe it’s because you have multithreading enabled somewhere in your code.
Unity WebGL does not yet officially support multithreading.
So you need to disable multithreading.

PlayerSettings.WebGL.threadsSupport = false;