Skip to content

Conversation

@nex3
Copy link
Member

@nex3 nex3 commented Dec 10, 2025

This doesn't include JSObject extensions that require types that
aren't defined yet, like JSSymbolicRecord.

This doesn't include JSObject extensions that require types that
aren't defined yet, like JSSymbolicRecord.
@kevmoo
Copy link
Member

kevmoo commented Dec 10, 2025

We should do better on those JS failures in Wasm: dart-lang/sdk#62218

/// The operation is equivalent to doing `this[key] = value` for each key and
/// associated value in [other]. It iterates over [other], which must therefore
/// not change during the iteration.
void addAllRecord(JSRecord<V> other) => addPairs(other.pairs);
Copy link
Contributor

Choose a reason for hiding this comment

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

tiny nit: maybe addAllFromRecord instead?

@JS('Object.values')
external JSArray<JSAny?> _values(JSObject object);

/// Additional instance methods for the `dart:js_interop` [interop.JSObject]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove interop.

/// See [`Object.entries()`].
///
/// [`Object.entries()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
List<(String, JSAny?)> get entries => [
Copy link
Contributor

Choose a reason for hiding this comment

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

Thoughts on making this a generic method instead so that the second tuple member can be a generic (and therefore avoid the need for a cast list)?

/// The [name] must be a [JSString] or a [JSSymbol].
///
/// [`Reflect.get()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get
R getPropertyWithThis<R extends JSAny?>(JSAny name, JSAny? thisArg) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this and setPropertyWithThis are sufficiently different in name that we may want a Reflect type instead, especially if we're planning to add more Reflect members. Thoughts?

);
});

test("addPairs()", () {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: did you mean to name this as clear()?

expect(record.containsKey("foo"), isTrue);
expect(record.containsKey("baz"), isFalse);
});

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: test for containsValue

() =>
expect(object.getPropertyWithThis("foo".toJS, object), equals(1.toJS)),
);

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: test for getOwnProperty

@kevmoo
Copy link
Member

kevmoo commented Dec 11, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces JSRecord as a map-like wrapper for JS objects and adds several unsafe extensions for JSObject. The implementation is generally good, but I've found a few areas for improvement, mainly related to performance in JSRecord and some minor issues in documentation and tests. My review includes suggestions to optimize method implementations and fix typos.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants