Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion JSTests/stress/resources/shadow-realm-example-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ function getCallCount() {
}

var answer = 6;
export { anObject, answer, getCallCount, getFromGlobal, getAnObject, putInGlobal };
var undefinedValue = undefined;
let notYet;

function setNotYet(val) {
notYet = val;
}

export { anObject, answer, getCallCount, getFromGlobal, getAnObject, notYet, putInGlobal, setNotYet, undefinedValue };
12 changes: 12 additions & 0 deletions JSTests/stress/shadow-realm-import-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ async function shouldThrowAsync(func, errorType) {

// importing non-existent ref fails
await shouldThrowAsync(async () => { let x = await realm.importValue(importPath, "nothing"); }, TypeError);
// so does a name that only an ordinary object would inherit: a module namespace has a null prototype
await shouldThrowAsync(async () => { let x = await realm.importValue(importPath, "toString"); }, TypeError);
await shouldThrowAsync(async () => { let x = await realm.importValue(importPath, "__proto__"); }, TypeError);
await shouldThrowAsync(async () => { let x = await realm.importValue(importPath, "__esModule"); }, TypeError);

// an export that exists with the value undefined is not missing
shouldBe(await realm.importValue(importPath, "undefinedValue"), undefined);
// and a live binding that is still undefined reads its current value each time
shouldBe(await realm.importValue(importPath, "notYet"), undefined);
let innerSetNotYet = await realm.importValue(importPath, "setNotYet");
innerSetNotYet("now");
shouldBe(await realm.importValue(importPath, "notYet"), "now");

// importing from non-existent file fails
await shouldThrowAsync(async () => { let x = await realm.importValue("random", "nothing"); }, TypeError);
Expand Down
6 changes: 3 additions & 3 deletions Source/JavaScriptCore/builtins/ShadowRealmPrototype.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ function importValue(specifier, exportName)
if (typeof exportName !== 'string')
@throwTypeError("`%ShadowRealm%.importValue requires that the |exportName| argument be a string");

// https://tc39.es/proposal-shadowrealm/#sec-export-getter-functions
var lookupBinding = (module) => {
var lookup = module[exportName]
if (lookup === @undefined)
if (!@Object.@hasOwn(module, exportName))
@throwTypeError("%ShadowRealm%.importValue requires |exportName| to exist in the |specifier|");

return @wrapRemoteValue(true, this, lookup);
return @wrapRemoteValue(true, this, module[exportName]);
};

return @importInRealm(this, specifierString).@then(lookupBinding, @crossRealmThrow);
Expand Down
Loading