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

LibJS: Make define_property always throw if specified

Now put uses is_strict_mode to determine define_property should throw
This commit is contained in:
davidot 2021-06-21 16:32:07 +02:00 committed by Linus Groh
parent e10219a293
commit 15edad8202
2 changed files with 4 additions and 5 deletions

View file

@ -621,7 +621,7 @@ bool Object::put_own_property(const StringOrSymbol& property_name, Value value,
if (!is_extensible() && new_property) { if (!is_extensible() && new_property) {
dbgln_if(OBJECT_DEBUG, "Disallow define_property of non-extensible object"); dbgln_if(OBJECT_DEBUG, "Disallow define_property of non-extensible object");
if (throw_exceptions && vm().in_strict_mode()) if (throw_exceptions)
vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_name.to_display_string()); vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_name.to_display_string());
return false; return false;
} }
@ -729,7 +729,7 @@ bool Object::put_own_property_by_index(u32 property_index, Value value, Property
if (!is_extensible() && new_property) { if (!is_extensible() && new_property) {
dbgln_if(OBJECT_DEBUG, "Disallow define_property of non-extensible object"); dbgln_if(OBJECT_DEBUG, "Disallow define_property of non-extensible object");
if (throw_exceptions && vm().in_strict_mode()) if (throw_exceptions)
vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_index); vm().throw_exception<TypeError>(global_object(), ErrorType::NonExtensibleDefine, property_index);
return false; return false;
} }
@ -781,7 +781,6 @@ bool Object::delete_property(PropertyName const& property_name, bool force_throw
return true; return true;
} }
auto metadata = shape().lookup(property_name.to_string_or_symbol()); auto metadata = shape().lookup(property_name.to_string_or_symbol());
if (!metadata.has_value()) if (!metadata.has_value())
return true; return true;
@ -923,7 +922,7 @@ bool Object::put(const PropertyName& property_name, Value value, Value receiver)
if (vm().exception()) if (vm().exception())
return false; return false;
} }
return put_own_property(string_or_symbol, value, default_attributes, PutOwnPropertyMode::Put); return put_own_property(string_or_symbol, value, default_attributes, PutOwnPropertyMode::Put, vm().in_strict_mode());
} }
bool Object::define_native_function(PropertyName const& property_name, AK::Function<Value(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute) bool Object::define_native_function(PropertyName const& property_name, AK::Function<Value(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute)

View file

@ -26,7 +26,7 @@ test("Issue #5884, GenericIndexedPropertyStorage::take_first() loses elements",
const a = []; const a = [];
for (let i = 0; i < 300; i++) { for (let i = 0; i < 300; i++) {
// NOTE: We use defineProperty to prevent the array from using SimpleIndexedPropertyStorage // NOTE: We use defineProperty to prevent the array from using SimpleIndexedPropertyStorage
Object.defineProperty(a, i, { value: i, writable: false }); Object.defineProperty(a, i, { value: i, configurable: true });
} }
expect(a.length).toBe(300); expect(a.length).toBe(300);
for (let i = 0; i < 300; i++) { for (let i = 0; i < 300; i++) {