mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:17:44 +00:00
LibJS: Implement ShadowRealm.prototype.importValue()
Well... sort of. This adds the function itself and all the scaffolding from the ShadowRealm API (and basically completes its implementation). However, we do not nearly have enough support for modules and imports, so we currently pretend whatever was attempted to be imported failed - once we have HostImportModuleDynamically it should be relatively easy to complete the implementation.
This commit is contained in:
parent
2ffb30a996
commit
5910a41adb
6 changed files with 177 additions and 0 deletions
|
@ -0,0 +1,27 @@
|
|||
describe("normal behavior", () => {
|
||||
test("length is 2", () => {
|
||||
expect(ShadowRealm.prototype.importValue).toHaveLength(2);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
// NOTE: The actual import is currently not implemented and always pretends to fail for now.
|
||||
const shadowRealm = new ShadowRealm();
|
||||
const promise = shadowRealm.importValue("./myModule.js", "foo");
|
||||
let error;
|
||||
promise.catch(value => {
|
||||
error = value;
|
||||
});
|
||||
expect(promise).toBeInstanceOf(Promise);
|
||||
runQueuedPromiseJobs();
|
||||
expect(error).toBeInstanceOf(TypeError);
|
||||
expect(error.message).toBe("Import of 'foo' from './myModule.js' failed");
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("this value must be a ShadowRealm object", () => {
|
||||
expect(() => {
|
||||
ShadowRealm.prototype.importValue.call("foo");
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type ShadowRealm");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue