Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Can't read from a file using JSPromise #121

Copy link
Copy link
@revolter

Description

@revolter
Issue body actions

I know that this is more of a support issue than a bug report, but I really don't know what else to try, and didn't find another help channel.

Here is the entire script using Tokamak:

import JavaScriptKit
import TokamakDOM

struct TokamakApp: App {
    var body: some Scene {
        WindowGroup("Tokamak App") {
            ContentView()
        }
    }
}

struct ContentView: View {
    var body: some View {
        VStack {
            HTML("input", [
                "id": "file",
                "type": "file"
            ])
            Button("Convert") {
                let document = JSObject.global.document
                let input = document.getElementById("file")
                let file = input.files.item(0).object!

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

                JSPromise<JSValue, Error>(promise)!.then { value in
                    let console = JSObject.global.console.object!
                    let log = console.log.function!

                    log(value)
                }
            }
        }
    }
}

// @main attribute is not supported in SwiftPM apps.
// See https://bugs.swift.org/browse/SR-12683 for more details.
TokamakApp.main()

which is throwing this error:

Unhandled Promise Rejection: TypeError: Can only call Blob.text on instances of Blob

Running

document.getElementById("file").files.item(0).text().then(text => console.log(text))

works though.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.