Giter VIP home page Giter VIP logo

Comments (4)

j-f1 avatar j-f1 commented on July 30, 2024 1

The problem is here:

let promise = file.text.function!.callAsFunction().object!

The use of callAsFunction is unnecessary and causes the text method to not get the proper this value internally. Here’s the standard way to do this in JSKit:

let promise = file.text().object!

from javascriptkit.

j-f1 avatar j-f1 commented on July 30, 2024 1

I think that’s the best we can do for now. There isn’t currently a cross-browser supported way for us to keep an object alive on the Swift side as long as its corresponding JS object remains alive. So you have to keep a strong reference to the JSObjectRef inside Swift if you want JS to be able to call into it. Once Safari gains support for FinalizationRegistry, it should be possible for us to automatically hold onto Swift objects until they’re no longer reachable from either Swift or JS.

from javascriptkit.

revolter avatar revolter commented on July 30, 2024

Indeed, though I actually had to change it to:

let promise = file.text!().object!

But now I'm getting:

[Error] Fatal error: The function was already released: file JavaScriptKit/JSFunction.swift, line 292
[Error] Unhandled Promise Rejection: RuntimeError: Unreachable code should not be executed (evaluating 'exports.swjs_call_host_function(host_func_id, argv, argc, callback_func_ref)')

from javascriptkit.

revolter avatar revolter commented on July 30, 2024

I fixed it by changing it to:

let jsPromise = JSPromise<JSValue, Error>(promise)!

jsPromise.then { value in
    let console = JSObject.global.console.object!
    let log = console.log.function!

    log(value)

    // Without this, `jsPromise` gets released before this
    // closure gets called.
    print(jsPromise)
}

but I feel like it's not the best solution.

from javascriptkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.