Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes of Errors are not preserved across realms #18

Open
antocuni opened this issue May 16, 2023 · 1 comment
Open

Attributes of Errors are not preserved across realms #18

antocuni opened this issue May 16, 2023 · 1 comment

Comments

@antocuni
Copy link
Collaborator

Consider the following example:

// worker.js
importScripts("./iife/synclink.js");

function raiseFromWorker(){
    const err = new Error("hi!");
    err.xxx = 42;
    throw err;
}

Synclink.expose(raiseFromWorker);
<!-- index.html >
<html>
  <head>
    <script>
      async function main() {
          const Synclink = await import("./esm/synclink.mjs");
          let raiseFromWorker = Synclink.wrap(new Worker("worker.js"))
          try {
              await raiseFromWorker();
          }
          catch(err) {
              //console.log(err);
              console.log(err.message);
              console.log(err.xxx);
          }
      }
      main();
    </script>
  </head>
</html>

The attribute xxx is not preserved across the boundary.
I think it would be nice/useful/expected that it is.
For example, this would remove the need for this ugly hack in pyscript:
https://github.com/pyscript/pyscript/blob/b247864414ae813b6ff73792d10a344bc4d477f9/pyscriptjs/src/main.ts#L30-L41

If I understand correctly, the relevant code is here:
https://github.com/hoodmane/synclink/blob/cc08aab7d28f5b5573c80a3766714944bf666160/src/transfer_handlers.ts#L156-L164

would it be possible to iterate over all attributes and transfer them?

@hoodmane
Copy link
Member

Yes, this should be a simple patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants