Skip to content

Commit

Permalink
Merge pull request #57 from oven-sh/dylan/object-values
Browse files Browse the repository at this point in the history
add `objectValues` for bun test matchers
  • Loading branch information
Jarred-Sumner authored Jun 9, 2024
2 parents 54dac57 + 9408c6b commit 7dea1bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Source/JavaScriptCore/runtime/ObjectConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,10 @@ JSC_DEFINE_HOST_FUNCTION(objectConstructorEntries, (JSGlobalObject* globalObject
return JSValue::encode(entries);
}

JSC_DEFINE_HOST_FUNCTION(objectConstructorValues, (JSGlobalObject* globalObject, CallFrame* callFrame))
JSValue objectValues(VM& vm, JSGlobalObject* globalObject, JSValue targetValue)
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

JSValue targetValue = callFrame->argument(0);
if (targetValue.isUndefinedOrNull())
return throwVMTypeError(globalObject, scope, "Object.values requires that input parameter not be null or undefined"_s);
JSObject* target = targetValue.toObject(globalObject);
RETURN_IF_EXCEPTION(scope, { });

Expand Down Expand Up @@ -609,7 +605,7 @@ JSC_DEFINE_HOST_FUNCTION(objectConstructorValues, (JSGlobalObject* globalObject,
result->initializeIndex(initializationScope, i, indexedPropertyValues.at(i));
for (unsigned i = 0; i < namedPropertyValues.size(); ++i)
result->initializeIndex(initializationScope, indexedPropertyValues.size() + i, namedPropertyValues.at(i));
return JSValue::encode(result);
return result;
}
}
throwOutOfMemoryError(globalObject, scope);
Expand Down Expand Up @@ -649,7 +645,19 @@ JSC_DEFINE_HOST_FUNCTION(objectConstructorValues, (JSGlobalObject* globalObject,
RETURN_IF_EXCEPTION(scope, { });
}

return JSValue::encode(values);
return values;
}

JSC_DEFINE_HOST_FUNCTION(objectConstructorValues, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);

JSValue targetValue = callFrame->argument(0);
if (targetValue.isUndefinedOrNull())
return throwVMTypeError(globalObject, scope, "Object.values requires that input parameter not be null or undefined"_s);

return JSValue::encode(objectValues(vm, globalObject, targetValue));
}

// https://tc39.github.io/ecma262/#sec-topropertydescriptor
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/ObjectConstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ JSValue objectConstructorGetOwnPropertyDescriptors(JSGlobalObject*, JSObject*);
JSArray* ownPropertyKeys(JSGlobalObject*, JSObject*, PropertyNameMode, DontEnumPropertiesMode);
bool toPropertyDescriptor(JSGlobalObject*, JSValue, PropertyDescriptor&);
void objectAssignGeneric(JSGlobalObject*, VM&, JSObject* target, JSObject* source);
JSValue objectValues(VM&, JSGlobalObject*, JSValue);

JSC_DECLARE_HOST_FUNCTION(objectConstructorIs);

Expand Down

0 comments on commit 7dea1bd

Please sign in to comment.