refactor(js)!: split js/object reflection into glendix/js/reflect (#19) - #29
Merged
Merged
Conversation
`glendix/js/object` bundled two concerns behind one FFI file: plain data-object construction and arbitrary JavaScript reflection. This separates them so the data boundary no longer depends on interop. - `glendix/js/object` is now data-only: `JsValue`/`JsObject`/`JsBoolean`, the scalar coercions, `from_entries`, and `empty`. `object_ffi.mjs` is trimmed to `create_object`/`empty_object`/`identity`. - New `glendix/js/reflect` (+ `reflect_ffi.mjs`) owns the minimized, explicitly named reflection surface: `get`/`set`/`delete`/`has`, `call_method`, `call_method_without_arguments`, `new_instance`, and the `JsConstructor` type. Function names, labels, and behavior are preserved; only the module changes. Data construction keeps its bespoke `Object.fromEntries` FFI on purpose: no ecosystem package builds a live, prototype-pollution-safe plain object (`gleam/javascript` only covers arrays/promises/symbols, and a `gleam/json` round-trip is indirect and lossy for live handles). The `__proto__`-as-own-data guarantee is retained and documented. Tests cover creation (including a `__proto__` key), property get/set/delete/has, method calls with and without arguments, and construction. Module docs and the README document the split, the migration, and the unsafe/dynamic reflection boundary. The `glendix -> mendraw` dependency source form is unchanged. Closes #19
Move the object and reflection contracts into source-matched test modules, cover all value coercions, empty construction, missing and inherited properties, handle identity, receiver binding, and constructor arguments, and assert that __proto__ remains own data without changing the prototype. Clarify the reflection setter risk and has-property semantics, document the ecosystem retention rationale, and keep the English, Korean, and Japanese migration guidance synchronized.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #19.
glendix/js/objectpreviously bundled two distinct concerns behind one FFI file:plain data-object construction and arbitrary JavaScript reflection. This
splits them so the data boundary no longer depends on interop.
glendix/js/objectis now data-only:JsValue,JsObject,JsBoolean,the scalar coercions (
string/int/float/bool/from_object),from_entries, andempty.object_ffi.mjsis trimmed tocreate_object/empty_object/identity.glendix/js/reflect(+reflect_ffi.mjs) owns the minimized, explicitlynamed reflection surface:
get,set,delete,has,call_method,call_method_without_arguments,new_instance, and theJsConstructortype.Function names, labels, and behavior are preserved; only the owning module
changes.
Ecosystem evaluation (data-object construction)
No safe ecosystem equivalent exists for building a live, prototype-pollution-safe
plain object: the public
gleam/javascriptAPI only covers arrays/promises/symbols, Plinth has no general plain-object builder, and a
gleam/jsonround-trip is indirect and lossy for live handles. The minimal
Object.fromEntriesFFI is therefore retained with a documented justification,and its
__proto__-as-own-data guarantee is preserved.Tests
Source-matched test modules cover object creation (all value coercions, empty
construction, duplicate-key last-wins, ordering, and
__proto__remaining owndata without changing the prototype) and reflection (get present/missing,
set overwrite + same-handle identity, delete present/missing,
hasprototype-chain semantics, method calls with/without arguments and receiver
binding, and constructor argument forwarding).
Compatibility / migration
Documented as a versioned migration in the English, Korean, and Japanese READMEs.
The
glendix -> mendrawdependency source form is unchanged.Verification
gleam format --check,gleam check,gleam build --warnings-as-errors,gleam docs build— passedgleam test --runtime bun— 85 passed, 0 failuresno stale declarations/exports), and repository boundaries — passed
This is a pure FFI module-split refactor with identical runtime behavior; no
Mendix/Lustre end-to-end path is exercised or claimed.