test(javascript): share unknown loader fixture rows (#17409)

This commit is contained in:
Vincent Koc
2026-12-06 14:06:37 +08:00
committed by GitHub
parent cf30c499be
commit c5aefe38fd
@@ -46,13 +46,16 @@ const caseWithoutUnknowns = <Name extends string, Source extends string>(
source: Source,
) => ({ name, source, unknownOwner: false, unknownLoad: false }) as const;
const caseWithUnknowns = <Name extends string, Source extends string>(
name: Name,
source: Source,
) => ({ name, source, unknownOwner: true, unknownLoad: true }) as const;
const loaderCases = [
{
name: "returned module",
source: 'const get=()=>module;get().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"returned module",
'const get=()=>module;get().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"returned local",
'const get=()=>({require(){}});get().require("../shared/window.cjs");',
@@ -120,24 +123,18 @@ const loaderCases = [
"inactive callable default",
'function host(){return module;}const {make=host}={make(){return {};}};make().require=()=>{};require("./local.cjs");',
),
{
name: "active callable default",
source:
'function host(){return module;}const {make=host}={};make().require=()=>{};require("./local.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"active callable default",
'function host(){return module;}const {make=host}={};make().require=()=>{};require("./local.cjs");',
),
caseWithoutUnknowns(
"inactive array callable default",
'function host(){return module;}const [make=host]=[()=>({})];make().require=()=>{};require("./local.cjs");',
),
{
name: "iterator callable default",
source:
'function host(){return module;}const values=[()=>({})];values[Symbol.iterator]=function*(){yield undefined;};const [make=host]=values;make().require=()=>{};require("./local.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"iterator callable default",
'function host(){return module;}const values=[()=>({})];values[Symbol.iterator]=function*(){yield undefined;};const [make=host]=values;make().require=()=>{};require("./local.cjs");',
),
caseWithoutUnknowns(
"generator local result",
'function* get(){yield module;}const api=get();api.require=()=>{};api.require("../shared/window.cjs");',
@@ -146,20 +143,14 @@ const loaderCases = [
"async local result",
'async function get(){return module;}const api=get();api.require=()=>{};api.require("../shared/window.cjs");',
),
{
name: "awaited module result",
source:
'(async()=>{const get=async()=>module;(await get()).require("../shared/window.cjs");})();',
unknownOwner: true,
unknownLoad: true,
},
{
name: "awaited pending alias",
source:
'(async()=>{const get=async()=>module;const pending=get();const api=await pending;api.require("../shared/window.cjs");})();',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"awaited module result",
'(async()=>{const get=async()=>module;(await get()).require("../shared/window.cjs");})();',
),
caseWithUnknowns(
"awaited pending alias",
'(async()=>{const get=async()=>module;const pending=get();const api=await pending;api.require("../shared/window.cjs");})();',
),
caseWithoutUnknowns(
"awaited generator local",
'(async()=>{function* get(){yield module;}const api=await get();api.require=()=>{};api.require("../shared/window.cjs");})();',
@@ -168,92 +159,62 @@ const loaderCases = [
"awaited async local",
'(async()=>{const get=async()=>({require(){}});const api=await get();api.require("../shared/window.cjs");})();',
),
{
name: "prototype extra host write",
source:
'const [api]=[module];Array.prototype.extra=1;api.require=replacement;require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"prototype extra host write",
'const [api]=[module];Array.prototype.extra=1;api.require=replacement;require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"prototype extra local write",
'const [api]=[{}];Array.prototype.extra=1;api.require=()=>{};api.require("../shared/window.cjs");',
),
{
name: "custom iterator host write",
source:
'const values={*[Symbol.iterator](){yield module;}};const [api]=values;api.require=replacement;require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "constructor cycle iterator",
source:
'Array.prototype.constructor.prototype[Symbol.iterator]=function*(){yield module;};const [api]=[];api.require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "inherited array hole",
source:
'Array.prototype[0]=module;const [api]=[,];api.require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "Object prototype array hole",
source:
'Object.prototype[0]=module;const [api]=[,];api.require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"custom iterator host write",
'const values={*[Symbol.iterator](){yield module;}};const [api]=values;api.require=replacement;require("../shared/window.cjs");',
),
caseWithUnknowns(
"constructor cycle iterator",
'Array.prototype.constructor.prototype[Symbol.iterator]=function*(){yield module;};const [api]=[];api.require("../shared/window.cjs");',
),
caseWithUnknowns(
"inherited array hole",
'Array.prototype[0]=module;const [api]=[,];api.require("../shared/window.cjs");',
),
caseWithUnknowns(
"Object prototype array hole",
'Object.prototype[0]=module;const [api]=[,];api.require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"Object prototype extra local",
'Object.prototype.extra=module;const [api]=[{require(){}}];api.require("../shared/window.cjs");',
),
{
name: "replaced host method",
source:
'const box={make(){return {};}};box.make=()=>module;box.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"replaced host method",
'const box={make(){return {};}};box.make=()=>module;box.make().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"replaced local method",
'const box={make(){return module;}};box.make=()=>({require(){}});box.make().require("../shared/window.cjs");',
),
{
name: "captured factory host",
source:
'let make=()=>module;const box={make};make=()=>({});box.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"captured factory host",
'let make=()=>module;const box={make};make=()=>({});box.make().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"captured factory local",
'let make=()=>({require(){}});const box={make};make=()=>module;box.make().require("../shared/window.cjs");',
),
{
name: "captured array factory",
source:
'let make=()=>module;const values=[make];make=()=>({});values[0]().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "captured stored factory",
source:
'let make=()=>module;const box={};box.make=make;make=()=>({});box.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "copied host factory",
source:
'const old={make:()=>module};const box={...old};old.make=()=>({});box.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"captured array factory",
'let make=()=>module;const values=[make];make=()=>({});values[0]().require("../shared/window.cjs");',
),
caseWithUnknowns(
"captured stored factory",
'let make=()=>module;const box={};box.make=make;make=()=>({});box.make().require("../shared/window.cjs");',
),
caseWithUnknowns(
"copied host factory",
'const old={make:()=>module};const box={...old};old.make=()=>({});box.make().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"copied local factory",
'const old={make:()=>({require(){}})};const box={...old};old.make=()=>module;box.make().require("../shared/window.cjs");',
@@ -295,53 +256,38 @@ const loaderCases = [
"fresh deep child local capture",
'const old={child:{inner:{make:()=>({require(){}})}}};const box={...old};old.child={inner:{make:()=>module}};old.child.inner.make=()=>module;box.child.inner.make().require("../shared/window.cjs");',
),
{
name: "fresh deep child host capture",
source:
'const old={child:{inner:{make:()=>module}}};const box={...old};old.child={inner:{make:()=>({})}};old.child.inner.make=()=>({});box.child.inner.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
{
name: "twice copied host factory",
source:
'const old={make:()=>module};const middle={...old};old.make=()=>({});const box={...middle};middle.make=()=>({});box.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"fresh deep child host capture",
'const old={child:{inner:{make:()=>module}}};const box={...old};old.child={inner:{make:()=>({})}};old.child.inner.make=()=>({});box.child.inner.make().require("../shared/window.cjs");',
),
caseWithUnknowns(
"twice copied host factory",
'const old={make:()=>module};const middle={...old};old.make=()=>({});const box={...middle};middle.make=()=>({});box.make().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"twice copied local factory",
'const old={make:()=>({require(){}})};const middle={...old};old.make=()=>module;const box={...middle};middle.make=()=>module;box.make().require("../shared/window.cjs");',
),
{
name: "assigned rest captured module",
source:
'const holder={};const old={loader:module};({...holder.box}=old);old.loader={};holder.box.loader.require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"assigned rest captured module",
'const holder={};const old={loader:module};({...holder.box}=old);old.loader={};holder.box.loader.require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"assigned rest captured local",
'const holder={};const old={loader:{require(){}}};({...holder.box}=old);old.loader=module;holder.box.loader.require("../shared/window.cjs");',
),
{
name: "copied child later host factory",
source:
'const old={child:{make:()=>({})}};const box={...old};old.child.make=()=>module;box.child.make().require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"copied child later host factory",
'const old={child:{make:()=>({})}};const box={...old};old.child.make=()=>module;box.child.make().require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"copied child later local factory",
'const old={child:{make:()=>module}};const box={...old};old.child.make=()=>({require(){}});box.child.make().require("../shared/window.cjs");',
),
{
name: "captured child later module",
source:
'const inner={loader:{}};const box={inner};inner.loader=module;box.inner.loader.require("../shared/window.cjs");',
unknownOwner: true,
unknownLoad: true,
},
caseWithUnknowns(
"captured child later module",
'const inner={loader:{}};const box={inner};inner.loader=module;box.inner.loader.require("../shared/window.cjs");',
),
caseWithoutUnknowns(
"captured child later local",
'const inner={loader:module};const box={inner};inner.loader={require(){}};box.inner.loader.require("../shared/window.cjs");',