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
1 change: 1 addition & 0 deletions scripts/emitted-baseline-runtime.txt
Original file line number Diff line number Diff line change
Expand Up @@ -926,6 +926,7 @@ object-integrity-uses-physical-index-protocol.runtime.ts.cpp 23551c4185ed
object-is-over-union-and-optional-carriers.runtime.ts.cpp 199c1035ac10
object-key-enumeration-requires-native-object.runtime.ts.cpp ca35c32c1e8b
object-keyed-map-index-matches-node.runtime.ts.cpp ab5c357ecdd6
object-keys-over-recursive-dictionary-or-array-union.runtime.ts.cpp 061e846e55a7
object-literal-beside-class-in-or-keeps-its-own-layout.runtime.ts.cpp d86094099c83
object-literal-es5-method-receiver.runtime.js.cpp e93b403533f4
object-literal-getter-capture.ts.cpp f63f14f03eef
Expand Down
29 changes: 29 additions & 0 deletions src/targets/cpp/runtime/gea_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15956,6 +15956,15 @@ struct ArrayObjectElementOf<ArrayObject<Element>> {
using type = Element;
};

namespace detail {
template <typename Element>
ArrayObject<Element> arrayObjectBaseProbe(const ArrayObject<Element>&);
template <typename T>
using ArrayObjectBaseOf = decltype(arrayObjectBaseProbe(std::declval<const T&>()));
template <typename T>
concept DerivedArrayObject = !IsArrayObjectStruct<T>::value && requires { typename ArrayObjectBaseOf<T>; };
}

namespace detail {
template <typename T>
struct DynamicCarrier;
Expand Down Expand Up @@ -32569,6 +32578,26 @@ bool assignOwnPropertiesUnorderedWith(const gea::Ref<T>& source, const gea::Ref<
}

/** Array exotic own enumerable string keys, followed by enumerable expandos. */
template <typename Element>
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<ArrayObject<Element>>& array);
template <typename Element>
bool arrayHasOwnEnumerableKey(const gea::Ref<ArrayObject<Element>>& array, const std::string& key);
template <typename Element>
std::vector<std::string> arrayOwnPropertyNames(const gea::Ref<ArrayObject<Element>>& array);

template <detail::DerivedArrayObject Array>
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<Array>& array) {
return arrayOwnEnumerableKeys(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array));
}
template <detail::DerivedArrayObject Array>
bool arrayHasOwnEnumerableKey(const gea::Ref<Array>& array, const std::string& key) {
return arrayHasOwnEnumerableKey(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array), key);
}
template <detail::DerivedArrayObject Array>
std::vector<std::string> arrayOwnPropertyNames(const gea::Ref<Array>& array) {
return arrayOwnPropertyNames(gea::Ref<detail::ArrayObjectBaseOf<Array>>(array));
}

template <typename Element>
std::vector<std::string> arrayOwnEnumerableKeys(const gea::Ref<ArrayObject<Element>>& array) {
std::vector<std::string> keys;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type Leaf = string
type Tree = { [key: string]: Leaf | Tree | Branch }
type Branch = (Leaf | Tree | Branch | undefined)[]
type Container = Tree | Branch

const keysOf = (container: Container): string => Object.keys(container).join(',')

const tree: Tree = { a: 'x', b: ['y', { c: 'z' }] }
const branch: Branch = ['p', tree, undefined, 'q']
tree['self'] = branch

console.log(keysOf(tree))
console.log(keysOf(branch))

//! expect: a,b,self
//! expect: 0,1,2,3
Loading