Skip to content

fix(schema): recognize cross-realm arrays with Array.isArray - #1646

Open
edenbuilds wants to merge 3 commits into
arktypeio:mainfrom
edenbuilds:fix/cross-realm-array-isarray
Open

fix(schema): recognize cross-realm arrays with Array.isArray#1646
edenbuilds wants to merge 3 commits into
arktypeio:mainfrom
edenbuilds:fix/cross-realm-array-isarray

Conversation

@edenbuilds

Copy link
Copy Markdown

Summary

  • ProtoNode validated arrays with instanceof Array (and the same in the JIT compiledCondition), which fails for arrays from another window/vm realm.
  • Use Array.isArray for the Array proto; early-return "Array" from objectKindOf the same way so error text stays accurate.

Fixes #1597

Test plan

  • Runtime probe: vm foreign [1,2,3]allows false on main, true with fix; T(foreign) returns [1,2,3]
  • Mocha: accepts arrays from another realm in ark/type/__tests__/arrays/array.test.ts
  • Confirmed the new test fails when proto.ts / objectKinds.ts are stashed

Made with Cursor

ProtoNode and objectKindOf used instanceof Array, which rejects arrays
from other windows/vm contexts. Use Array.isArray (and the compiled
equivalent) so number[] accepts foreign-realm arrays (fixes arktypeio#1597).

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The fix itself is correct, but the newly-added test fails as written, so the suite is red. attest(T(foreign)).equals([1, 2, 3]) at array.test.ts:294 throws Objects did not have the same constructor because attest's equals rejects mismatched constructors, and a cross-realm array's constructor differs from a local [1, 2, 3] literal.

Reviewed changes

  • proto.tsProtoNode now routes the Array proto through Array.isArray in both traverseAllows and compiledCondition, so arrays from other realms validate.
  • objectKinds.tsobjectKindOf early-returns "Array" for any Array.isArray value, keeping kind/error descriptions accurate across realms.
  • array.test.ts — adds a vm-realm cross-realm array test.

I verified the runtime behavior directly: with the fix, type("number[]").allows returns true for a vm-realm [1, 2, 3] (and reverting proto.ts to instanceof Array breaks it), so the fix is sound. The only problem is the test's final assertion, which fails regardless of the fix and must be corrected before this can merge.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Comment thread ark/type/__tests__/arrays/array.test.ts Outdated
attest().equals treats foreign-realm arrays as unequal to literals
because their constructors differ. Assert identity + element values.
Unblocks arktype CI prChecks (prettier --check on proto.ts).
@edenbuilds

Copy link
Copy Markdown
Author

@pullfrog addressed: the test no longer uses `attest(...).equals` against a foreign-realm array (constructor identity fails). It asserts identity + element values instead. CI `core` / `prChecks` / compatibility are green on the latest head.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Confirmed the fix: array.test.ts no longer calls attest(...).equals against the foreign-realm array (whose constructor differs, which attest treats as unequal). It now asserts realm-safe facts — Array.isArray(foreign) is true, T.allows(foreign) is true, T(foreign) returns the same object (result === foreign) — and compares element values via a local spread [...(result as number[])].

pnpm mocha ark/type/__tests__/arrays/array.test.ts passes accepts arrays from another realm. (The benchTemplate/snapTemplate module-not-found output in that run comes from the ark/attest dev build not being present locally and is unrelated to this PR.) The earlier review blocker is resolved.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To do

Development

Successfully merging this pull request may close these issues.

Array from a different window object not recognized as array

1 participant