1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:27:44 +00:00

LibJS: Remove argument count checks in Object.* methods

These are inconsistent with the specification.
This commit is contained in:
Idan Horowitz 2021-06-12 20:03:10 +03:00 committed by Linus Groh
parent b9d4dd6850
commit a2da3f97ef
3 changed files with 0 additions and 33 deletions

View file

@ -21,7 +21,6 @@
M(ClassIsAbstract, "Abstract class {} cannot be constructed directly") \ M(ClassIsAbstract, "Abstract class {} cannot be constructed directly") \
M(ConstructorWithoutNew, "{} constructor must be called with 'new'") \ M(ConstructorWithoutNew, "{} constructor must be called with 'new'") \
M(Convert, "Cannot convert {} to {}") \ M(Convert, "Cannot convert {} to {}") \
M(ConvertUndefinedToObject, "Cannot convert undefined to object") \
M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \ M(DescChangeNonConfigurable, "Cannot change attributes of non-configurable property '{}'") \
M(DescWriteNonWritable, "Cannot write to non-writable property '{}'") \ M(DescWriteNonWritable, "Cannot write to non-writable property '{}'") \
M(DetachedArrayBuffer, "ArrayBuffer is detached") \ M(DetachedArrayBuffer, "ArrayBuffer is detached") \
@ -59,7 +58,6 @@
M(ObjectFreezeFailed, "Could not freeze object") \ M(ObjectFreezeFailed, "Could not freeze object") \
M(ObjectSealFailed, "Could not seal object") \ M(ObjectSealFailed, "Could not seal object") \
M(ObjectSetPrototypeOfReturnedFalse, "Object's [[SetPrototypeOf]] method returned false") \ M(ObjectSetPrototypeOfReturnedFalse, "Object's [[SetPrototypeOf]] method returned false") \
M(ObjectSetPrototypeOfTwoArgs, "Object.setPrototypeOf requires at least two arguments") \
M(ObjectPreventExtensionsReturnedFalse, "Object's [[PreventExtensions]] method returned false") \ M(ObjectPreventExtensionsReturnedFalse, "Object's [[PreventExtensions]] method returned false") \
M(ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, \ M(ObjectPrototypeNullOrUndefinedOnSuperPropertyAccess, \
"Object prototype must not be {} on a super property access") \ "Object prototype must not be {} on a super property access") \

View file

@ -68,8 +68,6 @@ Value ObjectConstructor::construct(Function&)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
{ {
if (!vm.argument_count())
return {};
auto* object = vm.argument(0).to_object(global_object); auto* object = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
@ -78,8 +76,6 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_own_property_names)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of)
{ {
if (!vm.argument_count())
return {};
auto* object = vm.argument(0).to_object(global_object); auto* object = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
@ -88,10 +84,6 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::get_prototype_of)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::set_prototype_of)
{ {
if (vm.argument_count() < 2) {
vm.throw_exception<TypeError>(global_object, ErrorType::ObjectSetPrototypeOfTwoArgs);
return {};
}
auto* object = vm.argument(0).to_object(global_object); auto* object = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
@ -247,11 +239,6 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::is)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
{ {
if (!vm.argument_count()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ConvertUndefinedToObject);
return {};
}
auto* obj_arg = vm.argument(0).to_object(global_object); auto* obj_arg = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
@ -261,10 +248,6 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::keys)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
{ {
if (!vm.argument_count()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ConvertUndefinedToObject);
return {};
}
auto* obj_arg = vm.argument(0).to_object(global_object); auto* obj_arg = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};
@ -274,10 +257,6 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::values)
JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries) JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::entries)
{ {
if (!vm.argument_count()) {
vm.throw_exception<TypeError>(global_object, ErrorType::ConvertUndefinedToObject);
return {};
}
auto* obj_arg = vm.argument(0).to_object(global_object); auto* obj_arg = vm.argument(0).to_object(global_object);
if (vm.exception()) if (vm.exception())
return {}; return {};

View file

@ -12,16 +12,6 @@ describe("correct behavior", () => {
}); });
describe("errors", () => { describe("errors", () => {
test("requires two arguments", () => {
expect(() => {
Object.setPrototypeOf();
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
expect(() => {
Object.setPrototypeOf({});
}).toThrowWithMessage(TypeError, "Object.setPrototypeOf requires at least two arguments");
});
test("prototype must be an object", () => { test("prototype must be an object", () => {
expect(() => { expect(() => {
Object.setPrototypeOf({}, "foo"); Object.setPrototypeOf({}, "foo");