Search code examples
javascriptiosjavascriptcore

'Error compiling builtin' while executing JavaScript code in JavaScriptCore


I execute the following javascript code in iOS using JavaScriptCore framework. The javascript code is browserified.

var myCallback = undefined;

*browserify logic*
{
 1: [function(require, module, exports) {

     var q = require('./user');

     var p = new Promise(function(resolved, reject) {
                            myCallback = function() {
                                resolved('test');
                            }
                         });

     p.then(function(x) {printFunc('test');}).catch(function(e){printFunc('test2');});

     q();

     }, {
     "./user": 2
     }],
 2: [function(require, module, exports) {
     function q() {
        printFunc("Callback called!");
        myCallback();
        printFunc("Callback called end!");
     }
     module.exports = q;
     }, {}]
 }, {}, [1]);

printFunc is a method implemented in Swift that just prints something to console. Here is the implementation:

    let printFunction : @convention(block) (String) -> String = {input in
        print("|\(input)|")
        return ""
    }

The problem is that I am receiving the following error:

|Callback called!|
Error compiling builtin: Invalid private name '@capabilities'
|Callback called end!|

Even more strange is that if I remove the prints "Callback called!" and "Callback called end!" the code executes without error and it prints "test".

Did you guys encountered this strange behaviour? Is it a known bug with Promise implementation?


Solution

  • This is a bug in the JavascriptCore's Promise implementation. I opened a ticket at Apple and it is confirmed.

    An workaround is to come with your own Promise implementation.