Agoric / realms-shim

Spec-compliant shim for Realms TC39 Proposal
Other
345 stars 19 forks source link

Realm is not a constructor #441

Open dy opened 2 years ago

dy commented 2 years ago

Using latest realms-shim.min.js in code as:

  import Realm from "./lib/realms.js"
  const realm = Realm();

Getting

(index):75 Uncaught TypeError: Class constructor j cannot be invoked without 'new'
    at (index):75

But if calling it as constructor realm = new Realm(), getting:

realms.js:1 Uncaught TypeError: Realm is not a constructor
    at new j (realms.js:1)
    at (index):75

I'm confused. I guess will try partytown for now.

KonghaYao commented 2 years ago

I had the same problem.But I use const sandbox = Realm.makeRootRealm(); // root realm , and it worked.

import Realm from "https://cdn.jsdelivr.net/npm/realms-shim@1.2.2/dist/realms-shim.esm.min.js";
console.log(Realm);
const sandbox = Realm.makeRootRealm(); // root realm
const unsafeCode = "function main(){return 1000};main();";
let result;
try {
    result = sandbox.evaluate(unsafeCode);
} catch (e) {
    result = `Error: ${e}`;
}
console.log(result);