diff options
Diffstat (limited to 'Userland')
80 files changed, 245 insertions, 274 deletions
diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 23b16fb21b..5fdbc1d60c 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -896,10 +896,10 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob } auto* prototype = Object::create(global_object, super_constructor_prototype); - prototype->define_property(vm.names.constructor, class_constructor, 0); + prototype->define_direct_property(vm.names.constructor, class_constructor, 0); if (interpreter.exception()) return {}; - class_constructor->define_property(vm.names.prototype, prototype, Attribute::Writable); + class_constructor->define_direct_property(vm.names.prototype, prototype, Attribute::Writable); if (interpreter.exception()) return {}; class_constructor->internal_set_prototype_of(super_constructor.is_null() ? global_object.function_prototype() : &super_constructor.as_object()); @@ -1825,7 +1825,7 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o for (auto& it : obj_to_spread.shape().property_table_ordered()) { if (it.value.attributes.is_enumerable()) { - object->define_property(it.key, obj_to_spread.get(it.key)); + object->define_direct_property(it.key, obj_to_spread.get(it.key), JS::default_attributes); if (interpreter.exception()) return {}; } @@ -1834,7 +1834,7 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o auto& str_to_spread = key.as_string().string(); for (size_t i = 0; i < str_to_spread.length(); i++) { - object->define_property(i, js_string(interpreter.heap(), str_to_spread.substring(i, 1))); + object->define_direct_property(i, js_string(interpreter.heap(), str_to_spread.substring(i, 1)), JS::default_attributes); if (interpreter.exception()) return {}; } @@ -1861,14 +1861,14 @@ Value ObjectExpression::execute(Interpreter& interpreter, GlobalObject& global_o switch (property.type()) { case ObjectProperty::Type::Getter: VERIFY(value.is_function()); - object->define_accessor(PropertyName::from_value(global_object, key), &value.as_function(), nullptr, Attribute::Configurable | Attribute::Enumerable); + object->define_direct_accessor(PropertyName::from_value(global_object, key), &value.as_function(), nullptr, Attribute::Configurable | Attribute::Enumerable); break; case ObjectProperty::Type::Setter: VERIFY(value.is_function()); - object->define_accessor(PropertyName::from_value(global_object, key), nullptr, &value.as_function(), Attribute::Configurable | Attribute::Enumerable); + object->define_direct_accessor(PropertyName::from_value(global_object, key), nullptr, &value.as_function(), Attribute::Configurable | Attribute::Enumerable); break; case ObjectProperty::Type::KeyValue: - object->define_property(PropertyName::from_value(global_object, key), value); + object->define_direct_property(PropertyName::from_value(global_object, key), value, JS::default_attributes); break; case ObjectProperty::Type::Spread: default: @@ -2110,7 +2110,7 @@ Value TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject& glo return {}; raw_strings->indexed_properties().append(value); } - strings->define_property(vm.names.raw, raw_strings, 0); + strings->define_direct_property(vm.names.raw, raw_strings, 0); return vm.call(tag_function, js_undefined(), move(arguments)); } diff --git a/Userland/Libraries/LibJS/Bytecode/Op.cpp b/Userland/Libraries/LibJS/Bytecode/Op.cpp index bfefe55b17..27a072dcec 100644 --- a/Userland/Libraries/LibJS/Bytecode/Op.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Op.cpp @@ -203,7 +203,7 @@ void CopyObjectExcludingProperties::execute_impl(Bytecode::Interpreter& interpre auto property_value = from_object->get(property_name); if (interpreter.vm().exception()) return; - to_object->define_property(property_name, property_value); + to_object->define_direct_property(property_name, property_value, JS::default_attributes); } } diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp index 4ecca4bd46..f9a24a35b6 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorConstructor.cpp @@ -25,9 +25,9 @@ void AggregateErrorConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.5.7.2.1 AggregateError.prototype, https://tc39.es/ecma262/#sec-aggregate-error.prototype - define_property(vm.names.prototype, global_object.aggregate_error_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.aggregate_error_prototype(), 0); - define_property(vm.names.length, Value(2), Attribute::Configurable); + define_direct_property(vm.names.length, Value(2), Attribute::Configurable); } // 20.5.7.1.1 AggregateError ( errors, message ), https://tc39.es/ecma262/#sec-aggregate-error diff --git a/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp index c90390337a..ae37c8bea8 100644 --- a/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/AggregateErrorPrototype.cpp @@ -20,8 +20,8 @@ void AggregateErrorPrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); Object::initialize(global_object); u8 attr = Attribute::Writable | Attribute::Configurable; - define_property(vm.names.name, js_string(vm, "AggregateError"), attr); - define_property(vm.names.message, js_string(vm, ""), attr); + define_direct_property(vm.names.name, js_string(vm, "AggregateError"), attr); + define_direct_property(vm.names.message, js_string(vm, ""), attr); } } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp index b046a05387..d06b0f09d3 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferConstructor.cpp @@ -24,9 +24,9 @@ void ArrayBufferConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 25.1.4.2 ArrayBuffer.prototype, https://tc39.es/ecma262/#sec-arraybuffer.prototype - define_property(vm.names.prototype, global_object.array_buffer_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.array_buffer_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.isView, is_view, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp index 2df5dfb1b4..14b1c12d52 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayBufferPrototype.cpp @@ -28,7 +28,7 @@ void ArrayBufferPrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.byteLength, byte_length_getter, {}, Attribute::Configurable); // 25.1.5.4 ArrayBuffer.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-arraybuffer.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.ArrayBuffer.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.ArrayBuffer.as_string()), Attribute::Configurable); } ArrayBufferPrototype::~ArrayBufferPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp index 1dcf312880..3ca00847df 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayConstructor.cpp @@ -31,9 +31,9 @@ void ArrayConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 23.1.2.4 Array.prototype, https://tc39.es/ecma262/#sec-array.prototype - define_property(vm.names.prototype, global_object.array_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.array_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp index d8238a8f18..697f9a8517 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayIteratorPrototype.cpp @@ -28,7 +28,7 @@ void ArrayIteratorPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); // 23.1.5.2.2 %ArrayIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%arrayiteratorprototype%-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Array Iterator"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Array Iterator"), Attribute::Configurable); } ArrayIteratorPrototype::~ArrayIteratorPrototype() @@ -87,10 +87,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayIteratorPrototype::next) if (iteration_kind == Object::PropertyKind::Value) return create_iterator_result_object(global_object, value, false); - auto* entry_array = Array::create(global_object, 0); - entry_array->define_property(0, Value(static_cast<i32>(index))); - entry_array->define_property(1, value); - return create_iterator_result_object(global_object, entry_array, false); + return create_iterator_result_object(global_object, Array::create_from(global_object, { Value(static_cast<i32>(index)), value }), false); } } diff --git a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp index 2e18cddde6..25b97c5ede 100644 --- a/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ArrayPrototype.cpp @@ -74,7 +74,7 @@ void ArrayPrototype::initialize(GlobalObject& global_object) // Object.is(Array.prototype[Symbol.iterator], Array.prototype.values) // evaluates to true // 23.1.3.33 Array.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-array.prototype-@@iterator - define_property(*vm.well_known_symbol_iterator(), get(vm.names.values), attr); + define_direct_property(*vm.well_known_symbol_iterator(), get(vm.names.values), attr); // 23.1.3.34 Array.prototype [ @@unscopables ], https://tc39.es/ecma262/#sec-array.prototype-@@unscopables auto* unscopable_list = Object::create(global_object, nullptr); @@ -89,7 +89,7 @@ void ArrayPrototype::initialize(GlobalObject& global_object) unscopable_list->create_data_property_or_throw(vm.names.keys, Value(true)); unscopable_list->create_data_property_or_throw(vm.names.values, Value(true)); - define_property(*vm.well_known_symbol_unscopables(), unscopable_list, Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_unscopables(), unscopable_list, Attribute::Configurable); } ArrayPrototype::~ArrayPrototype() @@ -364,7 +364,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::push) return {}; } for (size_t i = 0; i < argument_count; ++i) { - this_object->define_property(length + i, vm.argument(i)); + this_object->set(length + i, vm.argument(i), true); if (vm.exception()) return {}; } @@ -403,7 +403,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) auto from_value = this_object->get(from); if (vm.exception()) return {}; - this_object->define_property(to, from_value); + this_object->set(to, from_value, true); if (vm.exception()) return {}; } else { @@ -414,7 +414,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::unshift) } for (size_t j = 0; j < arg_count; j++) { - this_object->define_property(j, vm.argument(j)); + this_object->set(j, vm.argument(j), true); if (vm.exception()) return {}; } @@ -487,7 +487,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::shift) auto from_value = this_object->get(from); if (vm.exception()) return {}; - this_object->define_property(to, from_value); + this_object->set(to, from_value, true); if (vm.exception()) return {}; } else { @@ -1095,14 +1095,14 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse) } if (lower_exists && upper_exists) { - this_object->define_property(lower, upper_value); + this_object->set(lower, upper_value, true); if (vm.exception()) return {}; - this_object->define_property(upper, lower_value); + this_object->set(upper, lower_value, true); if (vm.exception()) return {}; } else if (!lower_exists && upper_exists) { - this_object->define_property(lower, upper_value); + this_object->set(lower, upper_value, true); if (vm.exception()) return {}; this_object->delete_property_or_throw(upper); @@ -1112,7 +1112,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::reverse) this_object->delete_property_or_throw(lower); if (vm.exception()) return {}; - this_object->define_property(upper, lower_value); + this_object->set(upper, lower_value, true); if (vm.exception()) return {}; } @@ -1688,7 +1688,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) auto to = i + insert_count; if (!from.is_empty()) { - this_object->define_property(to, from); + this_object->set(to, from, true); } else { this_object->delete_property_or_throw(to); } @@ -1710,7 +1710,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) auto to = i + insert_count - 1; if (!from.is_empty()) { - this_object->define_property(to, from); + this_object->set(to, from, true); } else { this_object->delete_property_or_throw(to); } @@ -1720,7 +1720,7 @@ JS_DEFINE_NATIVE_FUNCTION(ArrayPrototype::splice) } for (size_t i = 0; i < insert_count; ++i) { - this_object->define_property(actual_start + i, vm.argument(i + 2)); + this_object->set(actual_start + i, vm.argument(i + 2), true); if (vm.exception()) return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp index 321789a2d5..19e644186c 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntConstructor.cpp @@ -25,9 +25,9 @@ void BigIntConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 21.2.2.3 BigInt.prototype, https://tc39.es/ecma262/#sec-bigint.prototype - define_property(vm.names.prototype, global_object.bigint_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.bigint_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); // TODO: Implement these functions below and uncomment this. // u8 attr = Attribute::Writable | Attribute::Configurable; diff --git a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp index a38c247c35..46556f6bb7 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BigIntPrototype.cpp @@ -27,7 +27,7 @@ void BigIntPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.valueOf, value_of, 0, attr); // 21.2.3.5 BigInt.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-bigint.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.BigInt.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.BigInt.as_string()), Attribute::Configurable); } BigIntPrototype::~BigIntPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp index 3376321bb8..85fd448b07 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanConstructor.cpp @@ -22,9 +22,9 @@ void BooleanConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.3.2.1 Boolean.prototype, https://tc39.es/ecma262/#sec-boolean.prototype - define_property(vm.names.prototype, global_object.boolean_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.boolean_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } BooleanConstructor::~BooleanConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp index 18aadb3448..7b2ba688c4 100644 --- a/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/BoundFunction.cpp @@ -22,7 +22,7 @@ void BoundFunction::initialize(GlobalObject& global_object) { auto& vm = this->vm(); Base::initialize(global_object); - define_property(vm.names.length, Value(m_length), Attribute::Configurable); + define_direct_property(vm.names.length, Value(m_length), Attribute::Configurable); } BoundFunction::~BoundFunction() diff --git a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp index f72408ed5e..9c543b0c7b 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewConstructor.cpp @@ -23,9 +23,9 @@ void DataViewConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 25.3.3.1 DataView.prototype, https://tc39.es/ecma262/#sec-dataview.prototype - define_property(vm.names.prototype, global_object.data_view_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.data_view_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } DataViewConstructor::~DataViewConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp index ce5171016a..8a5cc4313d 100644 --- a/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DataViewPrototype.cpp @@ -45,7 +45,7 @@ void DataViewPrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.byteOffset, byte_offset_getter, {}, Attribute::Configurable); // 25.3.4.25 DataView.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-dataview.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.DataView.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.DataView.as_string()), Attribute::Configurable); } DataViewPrototype::~DataViewPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp index cddd9a8e6c..8299b23751 100644 --- a/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/DateConstructor.cpp @@ -131,9 +131,9 @@ void DateConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 21.4.3.3 Date.prototype, https://tc39.es/ecma262/#sec-date.prototype - define_property(vm.names.prototype, global_object.date_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.date_prototype(), 0); - define_property(vm.names.length, Value(7), Attribute::Configurable); + define_direct_property(vm.names.length, Value(7), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.now, now, 0, attr); diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index 317dbb2f45..d77896f550 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -93,7 +93,7 @@ void DatePrototype::initialize(GlobalObject& global_object) // B.2.4.3 Date.prototype.toGMTString ( ), https://tc39.es/ecma262/#sec-date.prototype.togmtstring // The function object that is the initial value of Date.prototype.toGMTString // is the same function object that is the initial value of Date.prototype.toUTCString. - define_property(vm.names.toGMTString, get(vm.names.toUTCString), attr); + define_direct_property(vm.names.toGMTString, get(vm.names.toUTCString), attr); } DatePrototype::~DatePrototype() diff --git a/Userland/Libraries/LibJS/Runtime/Error.cpp b/Userland/Libraries/LibJS/Runtime/Error.cpp index 8ef82233c8..838cdcec1c 100644 --- a/Userland/Libraries/LibJS/Runtime/Error.cpp +++ b/Userland/Libraries/LibJS/Runtime/Error.cpp @@ -20,7 +20,7 @@ Error* Error::create(GlobalObject& global_object, String const& message) auto& vm = global_object.vm(); auto* error = Error::create(global_object); u8 attr = Attribute::Writable | Attribute::Configurable; - error->define_property(vm.names.message, js_string(vm, message), attr); + error->define_direct_property(vm.names.message, js_string(vm, message), attr); return error; } @@ -55,7 +55,7 @@ void Error::install_error_cause(Value options) auto& vm = global_object.vm(); \ auto* error = ClassName::create(global_object); \ u8 attr = Attribute::Writable | Attribute::Configurable; \ - error->define_property(vm.names.message, js_string(vm, message), attr); \ + error->define_direct_property(vm.names.message, js_string(vm, message), attr); \ return error; \ } \ \ diff --git a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp index 3538ae25de..24e3d4ac1a 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorConstructor.cpp @@ -22,9 +22,9 @@ void ErrorConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.5.2.1 Error.prototype, https://tc39.es/ecma262/#sec-error.prototype - define_property(vm.names.prototype, global_object.error_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.error_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } // 20.5.1.1 Error ( message ), https://tc39.es/ecma262/#sec-error-message @@ -70,9 +70,9 @@ Value ErrorConstructor::construct(FunctionObject& new_target) \ /* 20.5.6.2.1 NativeError.prototype, \ https://tc39.es/ecma262/#sec-nativeerror.prototype */ \ - define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ + define_direct_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ \ - define_property(vm.names.length, Value(1), Attribute::Configurable); \ + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); \ } \ \ ConstructorName::~ConstructorName() { } \ diff --git a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp index 7b16468660..094457bcc4 100644 --- a/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/ErrorPrototype.cpp @@ -24,8 +24,8 @@ void ErrorPrototype::initialize(GlobalObject& global_object) auto& vm = this->vm(); Object::initialize(global_object); u8 attr = Attribute::Writable | Attribute::Configurable; - define_property(vm.names.name, js_string(vm, "Error"), attr); - define_property(vm.names.message, js_string(vm, ""), attr); + define_direct_property(vm.names.name, js_string(vm, "Error"), attr); + define_direct_property(vm.names.message, js_string(vm, ""), attr); define_native_function(vm.names.toString, to_string, 0, attr); } @@ -77,8 +77,8 @@ JS_DEFINE_NATIVE_FUNCTION(ErrorPrototype::to_string) auto& vm = this->vm(); \ Object::initialize(global_object); \ u8 attr = Attribute::Writable | Attribute::Configurable; \ - define_property(vm.names.name, js_string(vm, #ClassName), attr); \ - define_property(vm.names.message, js_string(vm, ""), attr); \ + define_direct_property(vm.names.name, js_string(vm, #ClassName), attr); \ + define_direct_property(vm.names.message, js_string(vm, ""), attr); \ } JS_ENUMERATE_NATIVE_ERRORS diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp index e37ca80d64..c9f73e080b 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryConstructor.cpp @@ -23,9 +23,9 @@ void FinalizationRegistryConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 26.2.2.1 FinalizationRegistry.prototype, https://tc39.es/ecma262/#sec-finalization-registry.prototype - define_property(vm.names.prototype, global_object.finalization_registry_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.finalization_registry_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } FinalizationRegistryConstructor::~FinalizationRegistryConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp index f1afa3863d..494c2cf1c4 100644 --- a/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FinalizationRegistryPrototype.cpp @@ -24,7 +24,7 @@ void FinalizationRegistryPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.unregister, unregister, 1, attr); // 26.2.3.4 FinalizationRegistry.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-finalization-registry.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.FinalizationRegistry.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.FinalizationRegistry.as_string()), Attribute::Configurable); } FinalizationRegistryPrototype::~FinalizationRegistryPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index ad1d743f95..39fe9e2637 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -26,9 +26,9 @@ void FunctionConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.2.2.2 Function.prototype, https://tc39.es/ecma262/#sec-function.prototype - define_property(vm.names.prototype, global_object.function_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.function_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } FunctionConstructor::~FunctionConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 3c62678e04..a19f282333 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -35,8 +35,8 @@ void FunctionPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.call, call, 1, attr); define_native_function(vm.names.toString, to_string, 0, attr); define_native_function(*vm.well_known_symbol_has_instance(), symbol_has_instance, 1, 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); - define_property(vm.names.name, js_string(heap(), ""), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.name, js_string(heap(), ""), Attribute::Configurable); } FunctionPrototype::~FunctionPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp index 1454de0b2d..849ed24317 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp @@ -27,9 +27,9 @@ void GeneratorFunctionConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 27.3.2.1 GeneratorFunction.length, https://tc39.es/ecma262/#sec-generatorfunction.length - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); // 27.3.2.2 GeneratorFunction.prototype, https://tc39.es/ecma262/#sec-generatorfunction.length - define_property(vm.names.prototype, global_object.generator_function_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.generator_function_prototype(), 0); } GeneratorFunctionConstructor::~GeneratorFunctionConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp index df7226ad30..34e5b786ca 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionPrototype.cpp @@ -21,9 +21,9 @@ void GeneratorFunctionPrototype::initialize(GlobalObject& global_object) Object::initialize(global_object); // 27.3.3.2 %GeneratorFunction.prototype% prototype, https://tc39.es/ecma262/#sec-generatorfunction.prototype.prototype - define_property(vm.names.prototype, global_object.generator_object_prototype(), Attribute::Configurable); + define_direct_property(vm.names.prototype, global_object.generator_object_prototype(), Attribute::Configurable); // 27.3.3.3 %GeneratorFunction.prototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-generatorfunction.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "GeneratorFunction"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "GeneratorFunction"), Attribute::Configurable); } GeneratorFunctionPrototype::~GeneratorFunctionPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp index 780950c319..7fa2f90b9e 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorObjectPrototype.cpp @@ -37,7 +37,7 @@ void GeneratorObjectPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.throw_, throw_, 1, attr); // 27.5.1.5 Generator.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-generator.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Generator"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm, "Generator"), Attribute::Configurable); } GeneratorObjectPrototype::~GeneratorObjectPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp index 4c30e70a1f..30afc5f467 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.cpp @@ -126,7 +126,7 @@ void GlobalObject::initialize_global_object() // %GeneratorFunction.prototype.prototype% must be initialized separately as it has no // companion constructor m_generator_object_prototype = heap().allocate<GeneratorObjectPrototype>(*this, *this); - m_generator_object_prototype->define_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); + m_generator_object_prototype->define_direct_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName, ArrayType) \ if (!m_##snake_name##_prototype) \ @@ -148,13 +148,13 @@ void GlobalObject::initialize_global_object() vm.throw_exception<TypeError>(global_object, ErrorType::RestrictedFunctionPropertiesAccess); return Value(); }); - m_throw_type_error_function->define_property_without_transition(vm.names.length, Value(0), 0, false); - m_throw_type_error_function->define_property_without_transition(vm.names.name, js_string(vm, ""), 0, false); + m_throw_type_error_function->define_direct_property(vm.names.length, Value(0), 0); + m_throw_type_error_function->define_direct_property(vm.names.name, js_string(vm, ""), 0); m_throw_type_error_function->internal_prevent_extensions(); // 10.2.4 AddRestrictedFunctionProperties ( F, realm ), https://tc39.es/ecma262/#sec-addrestrictedfunctionproperties - m_function_prototype->define_accessor(vm.names.caller, throw_type_error_function(), throw_type_error_function(), Attribute::Configurable); - m_function_prototype->define_accessor(vm.names.arguments, throw_type_error_function(), throw_type_error_function(), Attribute::Configurable); + m_function_prototype->define_direct_accessor(vm.names.caller, throw_type_error_function(), throw_type_error_function(), Attribute::Configurable); + m_function_prototype->define_direct_accessor(vm.names.arguments, throw_type_error_function(), throw_type_error_function(), Attribute::Configurable); define_native_function(vm.names.encodeURI, encode_uri, 1, attr); define_native_function(vm.names.decodeURI, decode_uri, 1, attr); @@ -163,15 +163,15 @@ void GlobalObject::initialize_global_object() define_native_function(vm.names.escape, escape, 1, attr); define_native_function(vm.names.unescape, unescape, 1, attr); - define_property(vm.names.NaN, js_nan(), 0); - define_property(vm.names.Infinity, js_infinity(), 0); - define_property(vm.names.undefined, js_undefined(), 0); + define_direct_property(vm.names.NaN, js_nan(), 0); + define_direct_property(vm.names.Infinity, js_infinity(), 0); + define_direct_property(vm.names.undefined, js_undefined(), 0); - define_property(vm.names.globalThis, this, attr); - define_property(vm.names.console, heap().allocate<ConsoleObject>(*this, *this), attr); - define_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr); - define_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr); - define_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr); + define_direct_property(vm.names.globalThis, this, attr); + define_direct_property(vm.names.console, heap().allocate<ConsoleObject>(*this, *this), attr); + define_direct_property(vm.names.Math, heap().allocate<MathObject>(*this, *this), attr); + define_direct_property(vm.names.JSON, heap().allocate<JSONObject>(*this, *this), attr); + define_direct_property(vm.names.Reflect, heap().allocate<ReflectObject>(*this, *this), attr); // This must be initialized before allocating AggregateErrorConstructor, which uses ErrorConstructor as its prototype. initialize_constructor(vm.names.Error, m_error_constructor, m_error_prototype); @@ -210,7 +210,7 @@ void GlobalObject::initialize_global_object() // The generator constructor cannot be initialized with add_constructor as it has no global binding m_generator_function_constructor = heap().allocate<GeneratorFunctionConstructor>(*this, *this); // 27.3.3.1 GeneratorFunction.prototype.constructor, https://tc39.es/ecma262/#sec-generatorfunction.prototype.constructor - m_generator_function_prototype->define_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); + m_generator_function_prototype->define_direct_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable); } GlobalObject::~GlobalObject() diff --git a/Userland/Libraries/LibJS/Runtime/GlobalObject.h b/Userland/Libraries/LibJS/Runtime/GlobalObject.h index 6ff199c520..b2b761f533 100644 --- a/Userland/Libraries/LibJS/Runtime/GlobalObject.h +++ b/Userland/Libraries/LibJS/Runtime/GlobalObject.h @@ -109,11 +109,11 @@ inline void GlobalObject::initialize_constructor(PropertyName const& property_na { auto& vm = this->vm(); constructor = heap().allocate<ConstructorType>(*this, *this); - constructor->define_property(vm.names.name, js_string(heap(), property_name.as_string()), Attribute::Configurable); + constructor->define_direct_property(vm.names.name, js_string(heap(), property_name.as_string()), Attribute::Configurable); if (vm.exception()) return; if (prototype) { - prototype->define_property(vm.names.constructor, constructor, Attribute::Writable | Attribute::Configurable); + prototype->define_direct_property(vm.names.constructor, constructor, Attribute::Writable | Attribute::Configurable); if (vm.exception()) return; } @@ -125,7 +125,7 @@ inline void GlobalObject::add_constructor(PropertyName const& property_name, Con // Some constructors are pre-initialized separately. if (!constructor) initialize_constructor(property_name, constructor, prototype); - define_property(property_name, constructor, Attribute::Writable | Attribute::Configurable); + define_direct_property(property_name, constructor, Attribute::Writable | Attribute::Configurable); } inline GlobalObject* Shape::global_object() const diff --git a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp index 1394705c59..4a702daedd 100644 --- a/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp +++ b/Userland/Libraries/LibJS/Runtime/IteratorOperations.cpp @@ -149,8 +149,8 @@ Value create_iterator_result_object(GlobalObject& global_object, Value value, bo { auto& vm = global_object.vm(); auto* object = Object::create(global_object, global_object.object_prototype()); - object->define_property(vm.names.value, value); - object->define_property(vm.names.done, Value(done)); + object->create_data_property_or_throw(vm.names.value, value); + object->create_data_property_or_throw(vm.names.done, Value(done)); return object; } diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index 4213785f51..961cebd862 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -37,7 +37,7 @@ void JSONObject::initialize(GlobalObject& global_object) define_native_function(vm.names.parse, parse, 2, attr); // 25.5.3 JSON [ @@toStringTag ], https://tc39.es/ecma262/#sec-json-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "JSON"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "JSON"), Attribute::Configurable); } JSONObject::~JSONObject() @@ -460,7 +460,7 @@ Object* JSONObject::parse_json_object(GlobalObject& global_object, const JsonObj { auto* object = Object::create(global_object, global_object.object_prototype()); json_object.for_each_member([&](auto& key, auto& value) { - object->define_property(key, parse_json_value(global_object, value)); + object->define_direct_property(key, parse_json_value(global_object, value), JS::default_attributes); }); return object; } @@ -470,7 +470,7 @@ Array* JSONObject::parse_json_array(GlobalObject& global_object, const JsonArray auto* array = Array::create(global_object, 0); size_t index = 0; json_array.for_each([&](auto& value) { - array->define_property(index++, parse_json_value(global_object, value)); + array->define_direct_property(index++, parse_json_value(global_object, value), JS::default_attributes); }); return array; } diff --git a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp index 1653b35840..f5664b01e1 100644 --- a/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapConstructor.cpp @@ -24,9 +24,9 @@ void MapConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 24.1.2.1 Map.prototype, https://tc39.es/ecma262/#sec-map.prototype - define_property(vm.names.prototype, global_object.map_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.map_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); define_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp index ff91e540ae..a446f587b2 100644 --- a/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapIteratorPrototype.cpp @@ -24,7 +24,7 @@ void MapIteratorPrototype::initialize(GlobalObject& global_object) Object::initialize(global_object); define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Map Iterator"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Map Iterator"), Attribute::Configurable); } MapIteratorPrototype::~MapIteratorPrototype() @@ -59,10 +59,7 @@ JS_DEFINE_NATIVE_FUNCTION(MapIteratorPrototype::next) else if (iteration_kind == Object::PropertyKind::Value) return create_iterator_result_object(global_object, entry.value, false); - auto* entry_array = Array::create(global_object, 0); - entry_array->define_property(0, entry.key); - entry_array->define_property(1, entry.value); - return create_iterator_result_object(global_object, entry_array, false); + return create_iterator_result_object(global_object, Array::create_from(global_object, { entry.key, entry.value }), false); } } diff --git a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp index 07760674ec..549c273211 100644 --- a/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/MapPrototype.cpp @@ -33,8 +33,8 @@ void MapPrototype::initialize(GlobalObject& global_object) define_native_accessor(vm.names.size, size_getter, {}, Attribute::Configurable); - define_property(*vm.well_known_symbol_iterator(), Object::get(vm.names.entries), attr); - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.Map.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_iterator(), Object::get(vm.names.entries), attr); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.Map.as_string()), Attribute::Configurable); } MapPrototype::~MapPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/MathObject.cpp b/Userland/Libraries/LibJS/Runtime/MathObject.cpp index 68071f12c5..23bff0b243 100644 --- a/Userland/Libraries/LibJS/Runtime/MathObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/MathObject.cpp @@ -61,17 +61,17 @@ void MathObject::initialize(GlobalObject& global_object) define_native_function(vm.names.tanh, tanh, 1, attr); // 21.3.1 Value Properties of the Math Object, https://tc39.es/ecma262/#sec-value-properties-of-the-math-object - define_property(vm.names.E, Value(M_E), 0); - define_property(vm.names.LN2, Value(M_LN2), 0); - define_property(vm.names.LN10, Value(M_LN10), 0); - define_property(vm.names.LOG2E, Value(::log2(M_E)), 0); - define_property(vm.names.LOG10E, Value(::log10(M_E)), 0); - define_property(vm.names.PI, Value(M_PI), 0); - define_property(vm.names.SQRT1_2, Value(M_SQRT1_2), 0); - define_property(vm.names.SQRT2, Value(M_SQRT2), 0); + define_direct_property(vm.names.E, Value(M_E), 0); + define_direct_property(vm.names.LN2, Value(M_LN2), 0); + define_direct_property(vm.names.LN10, Value(M_LN10), 0); + define_direct_property(vm.names.LOG2E, Value(::log2(M_E)), 0); + define_direct_property(vm.names.LOG10E, Value(::log10(M_E)), 0); + define_direct_property(vm.names.PI, Value(M_PI), 0); + define_direct_property(vm.names.SQRT1_2, Value(M_SQRT1_2), 0); + define_direct_property(vm.names.SQRT2, Value(M_SQRT2), 0); // 21.3.1.9 Math [ @@toStringTag ], https://tc39.es/ecma262/#sec-math-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Math.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Math.as_string()), Attribute::Configurable); } MathObject::~MathObject() diff --git a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp index 977da1b552..72a8b54f78 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberConstructor.cpp @@ -34,25 +34,25 @@ void NumberConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 21.1.2.15 Number.prototype, https://tc39.es/ecma262/#sec-number.prototype - define_property(vm.names.prototype, global_object.number_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.number_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.isFinite, is_finite, 1, attr); define_native_function(vm.names.isInteger, is_integer, 1, attr); define_native_function(vm.names.isNaN, is_nan, 1, attr); define_native_function(vm.names.isSafeInteger, is_safe_integer, 1, attr); - define_property(vm.names.parseInt, global_object.get(vm.names.parseInt), attr); - define_property(vm.names.parseFloat, global_object.get(vm.names.parseFloat), attr); - define_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0); - define_property(vm.names.MAX_VALUE, Value(NumericLimits<double>::max()), 0); - define_property(vm.names.MIN_VALUE, Value(NumericLimits<double>::min()), 0); - define_property(vm.names.MAX_SAFE_INTEGER, Value(MAX_SAFE_INTEGER_VALUE), 0); - define_property(vm.names.MIN_SAFE_INTEGER, Value(MIN_SAFE_INTEGER_VALUE), 0); - define_property(vm.names.NEGATIVE_INFINITY, js_negative_infinity(), 0); - define_property(vm.names.POSITIVE_INFINITY, js_infinity(), 0); - define_property(vm.names.NaN, js_nan(), 0); + define_direct_property(vm.names.parseInt, global_object.get(vm.names.parseInt), attr); + define_direct_property(vm.names.parseFloat, global_object.get(vm.names.parseFloat), attr); + define_direct_property(vm.names.EPSILON, Value(EPSILON_VALUE), 0); + define_direct_property(vm.names.MAX_VALUE, Value(NumericLimits<double>::max()), 0); + define_direct_property(vm.names.MIN_VALUE, Value(NumericLimits<double>::min()), 0); + define_direct_property(vm.names.MAX_SAFE_INTEGER, Value(MAX_SAFE_INTEGER_VALUE), 0); + define_direct_property(vm.names.MIN_SAFE_INTEGER, Value(MIN_SAFE_INTEGER_VALUE), 0); + define_direct_property(vm.names.NEGATIVE_INFINITY, js_negative_infinity(), 0); + define_direct_property(vm.names.POSITIVE_INFINITY, js_infinity(), 0); + define_direct_property(vm.names.NaN, js_nan(), 0); } NumberConstructor::~NumberConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index bc1d0de283..7b11081653 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1032,7 +1032,7 @@ void Object::set_shape(Shape& new_shape) m_shape = &new_shape; } -bool Object::define_native_accessor(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attribute) +void Object::define_native_accessor(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attribute) { auto& vm = this->vm(); String formatted_property_name; @@ -1047,34 +1047,20 @@ bool Object::define_native_accessor(PropertyName const& property_name, Function< if (getter) { auto name = String::formatted("get {}", formatted_property_name); getter_function = NativeFunction::create(global_object(), name, move(getter)); - getter_function->define_property_without_transition(vm.names.length, Value(0), Attribute::Configurable); - if (vm.exception()) - return {}; - getter_function->define_property_without_transition(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable); - if (vm.exception()) - return {}; + getter_function->define_direct_property(vm.names.length, Value(0), Attribute::Configurable); + getter_function->define_direct_property(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable); } FunctionObject* setter_function = nullptr; if (setter) { auto name = String::formatted("set {}", formatted_property_name); setter_function = NativeFunction::create(global_object(), name, move(setter)); - setter_function->define_property_without_transition(vm.names.length, Value(1), Attribute::Configurable); - if (vm.exception()) - return {}; - setter_function->define_property_without_transition(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable); - if (vm.exception()) - return {}; + setter_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable); + setter_function->define_direct_property(vm.names.name, js_string(vm.heap(), name), Attribute::Configurable); } - return define_accessor(property_name, getter_function, setter_function, attribute); -} - -bool Object::define_property_without_transition(PropertyName const& property_name, Value value, PropertyAttributes attributes, bool throw_exceptions) -{ - TemporaryChange change(m_transitions_enabled, false); - return define_property(property_name, value, attributes, throw_exceptions); + return define_direct_accessor(property_name, getter_function, setter_function, attribute); } -bool Object::define_accessor(PropertyName const& property_name, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes, bool throw_exceptions) +void Object::define_direct_accessor(PropertyName const& property_name, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes) { VERIFY(property_name.is_valid()); @@ -1082,18 +1068,13 @@ bool Object::define_accessor(PropertyName const& property_name, FunctionObject* auto* accessor = existing_property.is_accessor() ? &existing_property.as_accessor() : nullptr; if (!accessor) { accessor = Accessor::create(vm(), getter, setter); - bool definition_success = define_property(property_name, accessor, attributes, throw_exceptions); - if (vm().exception()) - return {}; - if (!definition_success) - return false; + define_direct_property(property_name, accessor, attributes); } else { if (getter) accessor->set_getter(getter); if (setter) accessor->set_setter(setter); } - return true; } void Object::ensure_shape_is_unique() @@ -1117,7 +1098,7 @@ Value Object::get_without_side_effects(const PropertyName& property_name) const return {}; } -bool Object::define_native_function(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute) +void Object::define_native_function(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> native_function, i32 length, PropertyAttributes attribute) { auto& vm = this->vm(); String function_name; @@ -1127,18 +1108,14 @@ bool Object::define_native_function(PropertyName const& property_name, Function< function_name = String::formatted("[{}]", property_name.as_symbol()->description()); } auto* function = NativeFunction::create(global_object(), function_name, move(native_function)); - function->define_property_without_transition(vm.names.length, Value(length), Attribute::Configurable); - if (vm.exception()) - return {}; - function->define_property_without_transition(vm.names.name, js_string(vm.heap(), function_name), Attribute::Configurable); - if (vm.exception()) - return {}; - return define_property(property_name, function, attribute); + function->define_direct_property(vm.names.length, Value(length), Attribute::Configurable); + function->define_direct_property(vm.names.name, js_string(vm.heap(), function_name), Attribute::Configurable); + define_direct_property(property_name, function, attribute); } -bool Object::define_native_property(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attribute) +void Object::define_native_property(PropertyName const& property_name, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attribute) { - return define_property(property_name, heap().allocate_without_global_object<NativeProperty>(move(getter), move(setter)), attribute); + define_direct_property(property_name, heap().allocate_without_global_object<NativeProperty>(move(getter), move(setter)), attribute); } // 20.1.2.3.1 ObjectDefineProperties ( O, Properties ), https://tc39.es/ecma262/#sec-objectdefineproperties diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 4fd6daeece..9510e2084c 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -126,19 +126,14 @@ public: // - Helpers using old, non-standard names but wrapping the standard methods. // FIXME: Update all the code relying on these and remove them. bool put(PropertyName const& property_name, Value value, Value receiver = {}) { return internal_set(property_name, value, receiver.value_or(this)); } - bool define_property(PropertyName const& property_name, Value value, PropertyAttributes attributes = default_attributes, bool = true) - { - return internal_define_own_property(property_name, { .value = value, .writable = attributes.is_writable(), .enumerable = attributes.is_enumerable(), .configurable = attributes.is_configurable() }); - }; - Value get_without_side_effects(const PropertyName&) const; - bool define_property_without_transition(const PropertyName&, Value value, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true); - bool define_accessor(const PropertyName&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes = default_attributes, bool throw_exceptions = true); + void define_direct_property(PropertyName const& property_name, Value value, PropertyAttributes attributes) { storage_set(property_name, { value, attributes }); }; + void define_direct_accessor(PropertyName const&, FunctionObject* getter, FunctionObject* setter, PropertyAttributes attributes); - bool define_native_function(PropertyName const&, Function<Value(VM&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes); - bool define_native_property(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attributes = default_attributes); - bool define_native_accessor(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attributes = default_attributes); + void define_native_function(PropertyName const&, Function<Value(VM&, GlobalObject&)>, i32 length = 0, PropertyAttributes attributes = default_attributes); + void define_native_property(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<void(VM&, GlobalObject&, Value)> setter, PropertyAttributes attributes = default_attributes); + void define_native_accessor(PropertyName const&, Function<Value(VM&, GlobalObject&)> getter, Function<Value(VM&, GlobalObject&)> setter, PropertyAttributes attributes = default_attributes); virtual bool is_array() const { return false; } virtual bool is_function() const { return false; } diff --git a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 9412165c9d..760b59680e 100644 --- a/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -28,9 +28,9 @@ void ObjectConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.1.2.19 Object.prototype, https://tc39.es/ecma262/#sec-object.prototype - define_property(vm.names.prototype, global_object.object_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.object_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.defineProperty, define_property_, 3, attr); @@ -263,7 +263,7 @@ JS_DEFINE_NATIVE_FUNCTION(ObjectConstructor::from_entries) auto property_key = key.to_property_key(global_object); if (vm.exception()) return IterationDecision::Break; - object->define_property(property_key, value); + object->create_data_property_or_throw(property_key, value); if (vm.exception()) return IterationDecision::Break; return IterationDecision::Continue; diff --git a/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp index 0ed95fdf9d..ce5f791580 100644 --- a/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/OrdinaryFunctionObject.cpp @@ -78,14 +78,14 @@ void OrdinaryFunctionObject::initialize(GlobalObject& global_object) auto* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_ordinary_function_prototype_object_shape()); switch (m_kind) { case FunctionKind::Regular: - prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable); + prototype->define_property_or_throw(vm.names.constructor, { .value = this, .writable = true, .enumerable = false, .configurable = true }); break; case FunctionKind::Generator: // prototype is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) prototype->internal_set_prototype_of(global_object.generator_object_prototype()); break; } - define_property(vm.names.prototype, prototype, Attribute::Writable); + define_direct_property(vm.names.prototype, prototype, Attribute::Writable); } define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true }); define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index 531eebc1e6..9bbc4ecb2b 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -26,9 +26,9 @@ void PromiseConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 27.2.4.4 Promise.prototype, https://tc39.es/ecma262/#sec-promise.prototype - define_property(vm.names.prototype, global_object.promise_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.promise_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; // TODO: Implement these functions below and uncomment this. diff --git a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp index dc28e1f793..f05f7a9e35 100644 --- a/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromisePrototype.cpp @@ -32,7 +32,7 @@ void PromisePrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.finally, finally, 1, attr); // 27.2.5.5 Promise.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-promise.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Promise.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Promise.as_string()), Attribute::Configurable); } static Promise* promise_from(VM& vm, GlobalObject& global_object) @@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) }); return promise->invoke(vm.names.then.as_string(), value_thunk); }); - then_finally_function->define_property(vm.names.length, Value(1), Attribute::Configurable); + then_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable); // 27.2.5.3.2 Catch Finally Functions, https://tc39.es/ecma262/#sec-catchfinallyfunctions auto* catch_finally_function = NativeFunction::create(global_object, "", [constructor_handle = make_handle(constructor), on_finally_handle = make_handle(&on_finally.as_function())](auto& vm, auto& global_object) -> Value { @@ -125,7 +125,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromisePrototype::finally) }); return promise->invoke(vm.names.then.as_string(), thrower); }); - catch_finally_function->define_property(vm.names.length, Value(1), Attribute::Configurable); + catch_finally_function->define_direct_property(vm.names.length, Value(1), Attribute::Configurable); then_finally = Value(then_finally_function); catch_finally = Value(catch_finally_function); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp index 1105291875..c16b434d68 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseReaction.cpp @@ -42,7 +42,7 @@ PromiseCapability new_promise_capability(GlobalObject& global_object, Value cons promise_capability_functions.reject = reject; return js_undefined(); }); - executor->define_property(vm.names.length, Value(2), Attribute::Configurable); + executor->define_direct_property(vm.names.length, Value(2), Attribute::Configurable); MarkedValueList arguments(vm.heap()); arguments.append(executor); diff --git a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp index 13c9a18357..e6553c92c9 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseResolvingFunction.cpp @@ -27,7 +27,7 @@ PromiseResolvingFunction::PromiseResolvingFunction(Promise& promise, AlreadyReso void PromiseResolvingFunction::initialize(GlobalObject& global_object) { Base::initialize(global_object); - define_property(vm().names.length, Value(1), Attribute::Configurable); + define_direct_property(vm().names.length, Value(1), Attribute::Configurable); } Value PromiseResolvingFunction::call() diff --git a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp index 540a691a21..824b28eb17 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/ProxyConstructor.cpp @@ -37,7 +37,7 @@ void ProxyConstructor::initialize(GlobalObject& global_object) { auto& vm = this->vm(); NativeFunction::initialize(global_object); - define_property(vm.names.length, Value(2), Attribute::Configurable); + define_direct_property(vm.names.length, Value(2), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.revocable, revocable, 2, attr); } @@ -79,7 +79,7 @@ JS_DEFINE_NATIVE_FUNCTION(ProxyConstructor::revocable) proxy.revoke(); return js_undefined(); }); - revoker->define_property(vm.names.length, Value(0), Attribute::Configurable); + revoker->define_direct_property(vm.names.length, Value(0), Attribute::Configurable); auto* result = Object::create(global_object, global_object.object_prototype()); result->create_data_property_or_throw(vm.names.proxy, proxy); diff --git a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp index 0c0d642b68..e074e97760 100644 --- a/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ReflectObject.cpp @@ -40,7 +40,7 @@ void ReflectObject::initialize(GlobalObject& global_object) define_native_function(vm.names.setPrototypeOf, set_prototype_of, 2, attr); // 28.1.14 Reflect [ @@toStringTag ], https://tc39.es/ecma262/#sec-reflect-@@tostringtag - Object::define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Reflect.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Reflect.as_string()), Attribute::Configurable); } ReflectObject::~ReflectObject() diff --git a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp index 9502c0e7df..534bc2227e 100644 --- a/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/RegExpConstructor.cpp @@ -22,9 +22,9 @@ void RegExpConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 22.2.4.1 RegExp.prototype, https://tc39.es/ecma262/#sec-regexp.prototype - define_property(vm.names.prototype, global_object.regexp_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.regexp_prototype(), 0); - define_property(vm.names.length, Value(2), Attribute::Configurable); + define_direct_property(vm.names.length, Value(2), Attribute::Configurable); define_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp index 017fec4dde..2c8d854078 100644 --- a/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetConstructor.cpp @@ -24,9 +24,9 @@ void SetConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 24.2.2.1 Set.prototype, https://tc39.es/ecma262/#sec-set.prototype - define_property(vm.names.prototype, global_object.set_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.set_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); define_native_accessor(*vm.well_known_symbol_species(), symbol_species_getter, {}, Attribute::Configurable); } diff --git a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp index e758e3e742..9d383097e1 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetIteratorPrototype.cpp @@ -27,7 +27,7 @@ void SetIteratorPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); // 24.2.5.2.2 %SetIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%setiteratorprototype%-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Set Iterator"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Set Iterator"), Attribute::Configurable); } SetIteratorPrototype::~SetIteratorPrototype() @@ -61,10 +61,7 @@ JS_DEFINE_NATIVE_FUNCTION(SetIteratorPrototype::next) if (iteration_kind == Object::PropertyKind::Value) return create_iterator_result_object(global_object, value, false); - auto* entry_array = Array::create(global_object, 0); - entry_array->define_property(0, value); - entry_array->define_property(1, value); - return create_iterator_result_object(global_object, entry_array, false); + return create_iterator_result_object(global_object, Array::create_from(global_object, { value, value }), false); } } diff --git a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp index b2d14baf65..d90c631873 100644 --- a/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SetPrototype.cpp @@ -30,13 +30,13 @@ void SetPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.values, values, 0, attr); define_native_accessor(vm.names.size, size_getter, {}, Attribute::Configurable); - define_property(vm.names.keys, get(vm.names.values), attr); + define_direct_property(vm.names.keys, get(vm.names.values), attr); // 24.2.3.11 Set.prototype [ @@iterator ] ( ), https://tc39.es/ecma262/#sec-set.prototype-@@iterator - define_property(*vm.well_known_symbol_iterator(), get(vm.names.values), attr); + define_direct_property(*vm.well_known_symbol_iterator(), get(vm.names.values), attr); // 24.2.3.12 Set.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-set.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Set.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.Set.as_string()), Attribute::Configurable); } SetPrototype::~SetPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp index cc336f4def..a032d80499 100644 --- a/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringConstructor.cpp @@ -26,9 +26,9 @@ void StringConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 22.1.2.3 String.prototype, https://tc39.es/ecma262/#sec-string.prototype - define_property(vm.names.prototype, global_object.string_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.string_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.raw, raw, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp index 080b7f9908..89c2290392 100644 --- a/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringIteratorPrototype.cpp @@ -25,7 +25,7 @@ void StringIteratorPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.next, next, 0, Attribute::Configurable | Attribute::Writable); // 22.1.5.1.2 %StringIteratorPrototype% [ @@toStringTag ], https://tc39.es/ecma262/#sec-%stringiteratorprototype%-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "String Iterator"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "String Iterator"), Attribute::Configurable); } StringIteratorPrototype::~StringIteratorPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.cpp b/Userland/Libraries/LibJS/Runtime/StringObject.cpp index f1f028665d..a1f4186c4c 100644 --- a/Userland/Libraries/LibJS/Runtime/StringObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringObject.cpp @@ -33,7 +33,7 @@ void StringObject::initialize(GlobalObject& global_object) { auto& vm = this->vm(); Object::initialize(global_object); - define_property(vm.names.length, Value(m_string.string().length()), 0); + define_direct_property(vm.names.length, Value(m_string.string().length()), 0); } void StringObject::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp index 2b8f3d3534..9dbe65f48e 100644 --- a/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/StringPrototype.cpp @@ -68,9 +68,9 @@ void StringPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.padEnd, pad_end, 1, attr); define_native_function(vm.names.trim, trim, 0, attr); define_native_function(vm.names.trimStart, trim_start, 0, attr); - define_property(vm.names.trimLeft, get_without_side_effects(vm.names.trimStart), attr); + define_direct_property(vm.names.trimLeft, get_without_side_effects(vm.names.trimStart), attr); define_native_function(vm.names.trimEnd, trim_end, 0, attr); - define_property(vm.names.trimRight, get_without_side_effects(vm.names.trimEnd), attr); + define_direct_property(vm.names.trimRight, get_without_side_effects(vm.names.trimEnd), attr); define_native_function(vm.names.concat, concat, 1, attr); define_native_function(vm.names.substr, substr, 2, attr); define_native_function(vm.names.substring, substring, 2, attr); diff --git a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp index c51dccb4a0..1d12e00507 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolConstructor.cpp @@ -21,16 +21,16 @@ void SymbolConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 20.4.2.9 Symbol.prototype, https://tc39.es/ecma262/#sec-symbol.prototype - define_property(vm.names.prototype, global_object.symbol_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.symbol_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.for_, for_, 1, attr); define_native_function(vm.names.keyFor, key_for, 1, attr); #define __JS_ENUMERATE(SymbolName, snake_name) \ - define_property(vm.names.SymbolName, vm.well_known_symbol_##snake_name(), 0); + define_direct_property(vm.names.SymbolName, vm.well_known_symbol_##snake_name(), 0); JS_ENUMERATE_WELL_KNOWN_SYMBOLS #undef __JS_ENUMERATE } diff --git a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp index 8c21729e04..0f7d4f9cb0 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/SymbolPrototype.cpp @@ -33,7 +33,7 @@ void SymbolPrototype::initialize(GlobalObject& global_object) define_native_function(*vm.well_known_symbol_to_primitive(), symbol_to_primitive, 1, Attribute::Configurable); // 20.4.3.6 Symbol.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Symbol"), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), "Symbol"), Attribute::Configurable); } SymbolPrototype::~SymbolPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp index 24b2491113..e4ef5dca83 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.cpp @@ -236,12 +236,17 @@ void TypedArrayBase::visit_edges(Visitor& visitor) PrototypeName::PrototypeName(GlobalObject& global_object) \ : Object(*global_object.typed_array_prototype()) \ { \ - auto& vm = this->vm(); \ - define_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ } \ \ PrototypeName::~PrototypeName() { } \ \ + void PrototypeName::initialize(GlobalObject& global_object) \ + { \ + auto& vm = this->vm(); \ + Object::initialize(global_object); \ + define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ + } \ + \ ConstructorName::ConstructorName(GlobalObject& global_object) \ : TypedArrayConstructor(vm().names.ClassName.as_string(), *global_object.typed_array_constructor()) \ { \ @@ -255,12 +260,12 @@ void TypedArrayBase::visit_edges(Visitor& visitor) NativeFunction::initialize(global_object); \ \ /* 23.2.6.2 TypedArray.prototype, https://tc39.es/ecma262/#sec-typedarray.prototype */ \ - define_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ + define_direct_property(vm.names.prototype, global_object.snake_name##_prototype(), 0); \ \ - define_property(vm.names.length, Value(3), Attribute::Configurable); \ + define_direct_property(vm.names.length, Value(3), Attribute::Configurable); \ \ /* 23.2.6.1 TypedArray.BYTES_PER_ELEMENT, https://tc39.es/ecma262/#sec-typedarray.bytes_per_element */ \ - define_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ + define_direct_property(vm.names.BYTES_PER_ELEMENT, Value((i32)sizeof(Type)), 0); \ } \ \ /* 23.2.5.1 TypedArray ( ...args ), https://tc39.es/ecma262/#sec-typedarray */ \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArray.h b/Userland/Libraries/LibJS/Runtime/TypedArray.h index dcceb3eaa2..43a3411ef6 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArray.h +++ b/Userland/Libraries/LibJS/Runtime/TypedArray.h @@ -471,6 +471,7 @@ private: \ public: \ PrototypeName(GlobalObject&); \ + virtual void initialize(GlobalObject&) override; \ virtual ~PrototypeName() override; \ }; \ class ConstructorName final : public TypedArrayConstructor { \ diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp index 14a5d8c764..4402529fdb 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayConstructor.cpp @@ -27,9 +27,9 @@ void TypedArrayConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 23.2.2.3 %TypedArray%.prototype, https://tc39.es/ecma262/#sec-%typedarray%.prototype - define_property(vm.names.prototype, global_object.typed_array_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.typed_array_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); u8 attr = Attribute::Writable | Attribute::Configurable; define_native_function(vm.names.from, from, 1, attr); diff --git a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp index 5171706f3e..a9a3563536 100644 --- a/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/TypedArrayPrototype.cpp @@ -44,7 +44,7 @@ void TypedArrayPrototype::initialize(GlobalObject& object) define_native_accessor(*vm.well_known_symbol_to_string_tag(), to_string_tag_getter, nullptr, Attribute::Configurable); // 23.2.3.29 %TypedArray%.prototype.toString ( ), https://tc39.es/ecma262/#sec-%typedarray%.prototype.tostring - define_property(vm.names.toString, global_object().array_prototype()->get_without_side_effects(vm.names.toString), attr); + define_direct_property(vm.names.toString, global_object().array_prototype()->get_without_side_effects(vm.names.toString), attr); } TypedArrayPrototype::~TypedArrayPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp index 726a9096ba..383e01ec6b 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapConstructor.cpp @@ -24,9 +24,9 @@ void WeakMapConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 24.3.2.1 WeakMap.prototype, https://tc39.es/ecma262/#sec-weakmap.prototype - define_property(vm.names.prototype, global_object.weak_map_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.weak_map_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } WeakMapConstructor::~WeakMapConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp index 64476736a8..a317a4cbb3 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakMapPrototype.cpp @@ -26,7 +26,7 @@ void WeakMapPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.set, set, 2, attr); // 24.3.3.6 WeakMap.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakmap.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.WeakMap.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.WeakMap.as_string()), Attribute::Configurable); } WeakMapPrototype::~WeakMapPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp index 857a32c68e..131902bddd 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefConstructor.cpp @@ -23,9 +23,9 @@ void WeakRefConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 26.1.2.1 WeakRef.prototype, https://tc39.es/ecma262/#sec-weak-ref.prototype - define_property(vm.names.prototype, global_object.weak_ref_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.weak_ref_prototype(), 0); - define_property(vm.names.length, Value(1), Attribute::Configurable); + define_direct_property(vm.names.length, Value(1), Attribute::Configurable); } WeakRefConstructor::~WeakRefConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp index 1b4c210d5d..33092b8631 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakRefPrototype.cpp @@ -20,7 +20,7 @@ void WeakRefPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.deref, deref, 0, Attribute::Writable | Attribute::Configurable); - define_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.WeakRef.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), vm.names.WeakRef.as_string()), Attribute::Configurable); } WeakRefPrototype::~WeakRefPrototype() diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp index 4227787fc7..995a13a7a9 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetConstructor.cpp @@ -24,9 +24,9 @@ void WeakSetConstructor::initialize(GlobalObject& global_object) NativeFunction::initialize(global_object); // 24.4.2.1 WeakSet.prototype, https://tc39.es/ecma262/#sec-weakset.prototype - define_property(vm.names.prototype, global_object.weak_set_prototype(), 0); + define_direct_property(vm.names.prototype, global_object.weak_set_prototype(), 0); - define_property(vm.names.length, Value(0), Attribute::Configurable); + define_direct_property(vm.names.length, Value(0), Attribute::Configurable); } WeakSetConstructor::~WeakSetConstructor() diff --git a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp index 96d78b2f21..14bc6eed0c 100644 --- a/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/WeakSetPrototype.cpp @@ -25,7 +25,7 @@ void WeakSetPrototype::initialize(GlobalObject& global_object) define_native_function(vm.names.has, has, 1, attr); // 24.4.3.5 WeakSet.prototype [ @@toStringTag ], https://tc39.es/ecma262/#sec-weakset.prototype-@@tostringtag - define_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakSet.as_string()), Attribute::Configurable); + define_direct_property(*vm.well_known_symbol_to_string_tag(), js_string(global_object.heap(), vm.names.WeakSet.as_string()), Attribute::Configurable); } WeakSetPrototype::~WeakSetPrototype() diff --git a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js index 7b2a27e45e..152f782596 100644 --- a/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js +++ b/Userland/Libraries/LibJS/Tests/builtins/Array/Array.prototype.shift.js @@ -26,7 +26,7 @@ test("Issue #5884, GenericIndexedPropertyStorage::take_first() loses elements", const a = []; for (let i = 0; i < 300; i++) { // NOTE: We use defineProperty to prevent the array from using SimpleIndexedPropertyStorage - Object.defineProperty(a, i, { value: i, configurable: true }); + Object.defineProperty(a, i, { value: i, configurable: true, writable: true }); } expect(a.length).toBe(300); for (let i = 0; i < 300; i++) { diff --git a/Userland/Libraries/LibTest/JavaScriptTestRunner.h b/Userland/Libraries/LibTest/JavaScriptTestRunner.h index 0c04276d7b..24aa57c23f 100644 --- a/Userland/Libraries/LibTest/JavaScriptTestRunner.h +++ b/Userland/Libraries/LibTest/JavaScriptTestRunner.h @@ -180,13 +180,13 @@ public: inline void TestRunnerGlobalObject::initialize_global_object() { Base::initialize_global_object(); - define_property("global", this, JS::Attribute::Enumerable); + define_direct_property("global", this, JS::Attribute::Enumerable); for (auto& entry : s_exposed_global_functions) { define_native_function( entry.key, [fn = entry.value.function](auto& vm, auto& global_object) { return fn(vm, global_object); }, - entry.value.length); + entry.value.length, JS::default_attributes); } } diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index e18fcb0b60..adf4deba97 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -25,8 +25,8 @@ void ImageConstructor::initialize(JS::GlobalObject& global_object) auto& window = static_cast<WindowObject&>(global_object); NativeFunction::initialize(global_object); - define_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0); - define_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype<HTMLImageElementPrototype>("HTMLImageElement"), 0); + define_direct_property(vm.names.length, JS::Value(0), JS::Attribute::Configurable); } ImageConstructor::~ImageConstructor() diff --git a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp index 02b4861687..a7269eae65 100644 --- a/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NavigatorObject.cpp @@ -24,13 +24,14 @@ void NavigatorObject::initialize(JS::GlobalObject& global_object) languages->indexed_properties().append(js_string(heap, "en-US")); // FIXME: All of these should be in Navigator's prototype and be native accessors - define_property("appCodeName", js_string(heap, "Mozilla")); - define_property("appName", js_string(heap, "Netscape")); - define_property("appVersion", js_string(heap, "4.0")); - define_property("language", languages->get(0)); - define_property("languages", languages); - define_property("platform", js_string(heap, "SerenityOS")); - define_property("product", js_string(heap, "Gecko")); + u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable; + define_direct_property("appCodeName", js_string(heap, "Mozilla"), attr); + define_direct_property("appName", js_string(heap, "Netscape"), attr); + define_direct_property("appVersion", js_string(heap, "4.0"), attr); + define_direct_property("language", languages->get(0), attr); + define_direct_property("languages", languages, attr); + define_direct_property("platform", js_string(heap, "SerenityOS"), attr); + define_direct_property("product", js_string(heap, "Gecko"), attr); define_native_accessor("userAgent", user_agent_getter, {}); } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index fc772e2c82..8fef8a4eca 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -47,9 +47,9 @@ void WindowObject::initialize_global_object() VERIFY(success); // FIXME: These should be native accessors, not properties - define_property("window", this, JS::Attribute::Enumerable); - define_property("frames", this, JS::Attribute::Enumerable); - define_property("self", this, JS::Attribute::Enumerable); + define_direct_property("window", this, JS::Attribute::Enumerable); + define_direct_property("frames", this, JS::Attribute::Enumerable); + define_direct_property("self", this, JS::Attribute::Enumerable); define_native_accessor("top", top_getter, nullptr, JS::Attribute::Enumerable); define_native_accessor("parent", parent_getter, {}, JS::Attribute::Enumerable); define_native_accessor("document", document_getter, {}, JS::Attribute::Enumerable); @@ -72,11 +72,11 @@ void WindowObject::initialize_global_object() // Legacy define_native_accessor("event", event_getter, {}, JS::Attribute::Enumerable); - define_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); - define_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_direct_property("navigator", heap().allocate<NavigatorObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_direct_property("location", heap().allocate<LocationObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); // WebAssembly "namespace" - define_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); + define_direct_property("WebAssembly", heap().allocate<WebAssemblyObject>(*this, *this), JS::Attribute::Enumerable | JS::Attribute::Configurable); ADD_WINDOW_OBJECT_INTERFACES; } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.h b/Userland/Libraries/LibWeb/Bindings/WindowObject.h index 62db566d91..36d88aff8f 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.h @@ -51,7 +51,7 @@ public: return *it->value; auto* constructor = heap().allocate<T>(*this, *this); m_constructors.set(class_name, constructor); - define_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable); + define_direct_property(class_name, JS::Value(constructor), JS::Attribute::Writable | JS::Attribute::Configurable); return *constructor; } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index cdc01843be..d39375510e 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -226,12 +226,12 @@ #include <LibWeb/Bindings/XMLHttpRequestEventTargetPrototype.h> #include <LibWeb/Bindings/XMLHttpRequestPrototype.h> -#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \ - { \ - auto& constructor = ensure_web_constructor<constructor_name>(#interface_name); \ - constructor.define_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \ - auto& prototype = ensure_web_prototype<prototype_name>(#interface_name); \ - prototype.define_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \ +#define ADD_WINDOW_OBJECT_CONSTRUCTOR_AND_PROTOTYPE(interface_name, constructor_name, prototype_name) \ + { \ + auto& constructor = ensure_web_constructor<constructor_name>(#interface_name); \ + constructor.define_direct_property(vm.names.name, js_string(vm, #interface_name), JS::Attribute::Configurable); \ + auto& prototype = ensure_web_prototype<prototype_name>(#interface_name); \ + prototype.define_direct_property(vm.names.constructor, &constructor, JS::Attribute::Writable | JS::Attribute::Configurable); \ } #define ADD_WINDOW_OBJECT_INTERFACE(interface_name) \ diff --git a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp index de238ece47..395fc351f4 100644 --- a/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp +++ b/Userland/Libraries/LibWeb/CodeGenerators/WrapperGenerator.cpp @@ -1113,8 +1113,8 @@ void @constructor_class@::initialize(JS::GlobalObject& global_object) [[maybe_unused]] u8 default_attributes = JS::Attribute::Enumerable; NativeFunction::initialize(global_object); - define_property(vm.names.prototype, &window.ensure_web_prototype<@prototype_class@>("@name@"), 0); - define_property(vm.names.length, JS::Value(@constructor.length@), JS::Attribute::Configurable); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype<@prototype_class@>("@name@"), 0); + define_direct_property(vm.names.length, JS::Value(@constructor.length@), JS::Attribute::Configurable); )~~~"); @@ -1124,7 +1124,7 @@ void @constructor_class@::initialize(JS::GlobalObject& global_object) constant_generator.set("constant.value", constant.value); constant_generator.append(R"~~~( -define_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable); +define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable); )~~~"); } @@ -1336,7 +1336,7 @@ void @prototype_class@::initialize(JS::GlobalObject& global_object) constant_generator.set("constant.value", constant.value); constant_generator.append(R"~~~( - define_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable); + define_direct_property("@constant.name@", JS::Value((i32)@constant.value@), JS::Attribute::Enumerable); )~~~"); } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp index b74870e368..8b2e990e68 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp @@ -59,8 +59,8 @@ void WebAssemblyInstanceConstructor::initialize(JS::GlobalObject& global_object) auto& window = static_cast<WindowObject&>(global_object); NativeFunction::initialize(global_object); - define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype")); - define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"), 0); + define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp index 96d42f3f41..a9931a6f23 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObject.cpp @@ -39,7 +39,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object) object = create_native_function(address, export_.name(), global_object); cache.function_instances.set(address, *object); } - m_exports_object->define_property(export_.name(), *object); + m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes); }, [&](const Wasm::MemoryAddress& address) { auto object = cache.memory_instances.get(address); @@ -47,7 +47,7 @@ void WebAssemblyInstanceObject::initialize(JS::GlobalObject& global_object) object = heap().allocate<Web::Bindings::WebAssemblyMemoryObject>(global_object, global_object, address); cache.memory_instances.set(address, *object); } - m_exports_object->define_property(export_.name(), *object); + m_exports_object->define_direct_property(export_.name(), *object, JS::default_attributes); }, [&](const auto&) { // FIXME: Implement other exports! diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp index 625a76ee35..111993a5de 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp @@ -72,8 +72,8 @@ void WebAssemblyMemoryConstructor::initialize(JS::GlobalObject& global_object) auto& window = static_cast<WindowObject&>(global_object); NativeFunction::initialize(global_object); - define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype")); - define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"), 0); + define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp index 59c7532910..b998fce270 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp @@ -54,8 +54,8 @@ void WebAssemblyModuleConstructor::initialize(JS::GlobalObject& global_object) auto& window = static_cast<WindowObject&>(global_object); NativeFunction::initialize(global_object); - define_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype")); - define_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); + define_direct_property(vm.names.prototype, &window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"), 0); + define_direct_property(vm.names.length, JS::Value(1), JS::Attribute::Configurable); } } diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp index 1c298bdbad..2dee5ffe2d 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp @@ -31,30 +31,31 @@ void WebAssemblyObject::initialize(JS::GlobalObject& global_object) { Object::initialize(global_object); - define_native_function("validate", validate, 1); - define_native_function("compile", compile, 1); - define_native_function("instantiate", instantiate, 1); + u8 attr = JS::Attribute::Configurable | JS::Attribute::Writable | JS::Attribute::Enumerable; + define_native_function("validate", validate, 1, attr); + define_native_function("compile", compile, 1, attr); + define_native_function("instantiate", instantiate, 1, attr); auto& vm = global_object.vm(); auto& window = static_cast<WindowObject&>(global_object); auto& memory_constructor = window.ensure_web_constructor<WebAssemblyMemoryConstructor>("WebAssembly.Memory"); - memory_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Memory"), JS::Attribute::Configurable); + memory_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Memory"), JS::Attribute::Configurable); auto& memory_prototype = window.ensure_web_prototype<WebAssemblyMemoryPrototype>("WebAssemblyMemoryPrototype"); - memory_prototype.define_property(vm.names.constructor, &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - define_property("Memory", &memory_constructor); + memory_prototype.define_direct_property(vm.names.constructor, &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); + define_direct_property("Memory", &memory_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); auto& instance_constructor = window.ensure_web_constructor<WebAssemblyInstanceConstructor>("WebAssembly.Instance"); - instance_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Instance"), JS::Attribute::Configurable); + instance_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Instance"), JS::Attribute::Configurable); auto& instance_prototype = window.ensure_web_prototype<WebAssemblyInstancePrototype>("WebAssemblyInstancePrototype"); - instance_prototype.define_property(vm.names.constructor, &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - define_property("Instance", &instance_constructor); + instance_prototype.define_direct_property(vm.names.constructor, &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); + define_direct_property("Instance", &instance_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); auto& module_constructor = window.ensure_web_constructor<WebAssemblyModuleConstructor>("WebAssembly.Module"); - module_constructor.define_property(vm.names.name, js_string(vm, "WebAssembly.Module"), JS::Attribute::Configurable); + module_constructor.define_direct_property(vm.names.name, js_string(vm, "WebAssembly.Module"), JS::Attribute::Configurable); auto& module_prototype = window.ensure_web_prototype<WebAssemblyModulePrototype>("WebAssemblyModulePrototype"); - module_prototype.define_property(vm.names.constructor, &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); - define_property("Module", &module_constructor); + module_prototype.define_direct_property(vm.names.constructor, &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); + define_direct_property("Module", &module_constructor, JS::Attribute::Writable | JS::Attribute::Configurable); } NonnullOwnPtrVector<WebAssemblyObject::CompiledWebAssemblyModule> WebAssemblyObject::s_compiled_modules; diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 730e2cf12b..65d99bc6c3 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -653,7 +653,7 @@ static JS::Value load_file_impl(JS::VM& vm, JS::GlobalObject& global_object) void ReplObject::initialize_global_object() { Base::initialize_global_object(); - define_property("global", this, JS::Attribute::Enumerable); + define_direct_property("global", this, JS::Attribute::Enumerable); define_native_function("exit", exit_interpreter); define_native_function("help", repl_help); define_native_function("load", load_file, 1); @@ -700,7 +700,7 @@ JS_DEFINE_NATIVE_FUNCTION(ReplObject::load_file) void ScriptObject::initialize_global_object() { Base::initialize_global_object(); - define_property("global", this, JS::Attribute::Enumerable); + define_direct_property("global", this, JS::Attribute::Enumerable); define_native_function("load", load_file, 1); } |