简体   繁体   English

'在JavaScriptCore中执行JavaScript代码时编译内置错误'

[英]'Error compiling builtin' while executing JavaScript code in JavaScriptCore

I execute the following javascript code in iOS using JavaScriptCore framework. 我使用JavaScriptCore框架在iOS中执行以下javascript代码。 The javascript code is browserified. javascript代码是浏览器化的。

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. printFunc是一个在Swift中实现的方法,只是打印一些东西到控制台。 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!" 更奇怪的是,如果我删除印刷品“Callback called!” and "Callback called end!" 和“回叫叫做结束!” the code executes without error and it prints "test". 代码执行时没有错误,并打印“test”。

Did you guys encountered this strange behaviour? 你们有没遇到过这种奇怪的行为? Is it a known bug with Promise implementation? 它是Promise实现的已知错误吗?

This is a bug in the JavascriptCore's Promise implementation. 这是JavascriptCore的Promise实现中的一个错误。 I opened a ticket at Apple and it is confirmed. 我在Apple开了一张票,证实了这一点。

An workaround is to come with your own Promise implementation. 解决方法是使用您自己的Promise实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM