Skip to content

Truly independent web browser

LibJS: Find lazy function properties in get_without_side_effects

Shannon Booth5fcc859c3a00
diff --git a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
index 78d3e38368d..30b78bf87ca 100644
--- a/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/ecmascript_function_object.rs
@@ -494,6 +494,20 @@ impl EcmascriptFunctionObject {
);
}
+ pub(crate) fn reify_lazy_property(&self, vm: &Vm, property_key: &PropertyKey) {
+ if self.has_flag(ecmascript_function_flags::HAS_LAZY_LENGTH_AND_NAME)
+ && (*property_key == vm.names.length || *property_key == vm.names.name)
+ {
+ self.reify_lazy_length_and_name(vm);
+ }
+
+ if self.has_flag(ecmascript_function_flags::MAY_NEED_LAZY_PROTOTYPE_INSTANTIATION)
+ && *property_key == vm.names.prototype
+ {
+ self.instantiate_lazy_prototype(vm);
+ }
+ }
+
/// Gives the function all of the properties it makes lazily. This must happen before its shape changes in a way that
/// insert_properties() cannot rebuild.
pub(crate) fn reify_lazy_properties(&self, vm: &Vm) {
@@ -1383,20 +1397,7 @@ impl EcmascriptFunctionObject {
vm: &Vm,
property_key: &PropertyKey,
) -> ThrowCompletionOr<Option<PropertyDescriptor>> {
- let function = as_ecmascript_function(object);
-
- if function.has_flag(ecmascript_function_flags::HAS_LAZY_LENGTH_AND_NAME)
- && (*property_key == vm.names.length || *property_key == vm.names.name)
- {
- function.reify_length_and_name(vm);
- }
-
- if function.has_flag(ecmascript_function_flags::MAY_NEED_LAZY_PROTOTYPE_INSTANTIATION)
- && *property_key == vm.names.prototype
- {
- function.instantiate_lazy_prototype(vm);
- }
-
+ as_ecmascript_function(object).reify_lazy_property(vm, property_key);
object.ordinary_get_own_property(vm, property_key)
}
diff --git a/Libraries/LibJS/Rust/src/runtime/object.rs b/Libraries/LibJS/Rust/src/runtime/object.rs
index 079ec675c8a..651bf3ce469 100644
--- a/Libraries/LibJS/Rust/src/runtime/object.rs
+++ b/Libraries/LibJS/Rust/src/runtime/object.rs
@@ -3067,6 +3067,9 @@ impl Object {
pub fn get_without_side_effects(&self, vm: &Vm, property_key: &PropertyKey) -> Value {
let mut object = Some(self.as_gc());
while let Some(current) = object {
+ if current.is_ecmascript_function_object() {
+ cast_ref::<Object, EcmascriptFunctionObject>(&current).reify_lazy_property(vm, property_key);
+ }
if let Some(value_and_attributes) = current.storage_get(vm, property_key) {
return value_and_attributes.value;
}
diff --git a/Tests/LibWeb/Text/expected/HTML/reportError-name-from-function-prototype.txt b/Tests/LibWeb/Text/expected/HTML/reportError-name-from-function-prototype.txt
new file mode 100644
index 00000000000..2a47c18c8d0
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/reportError-name-from-function-prototype.txt
@@ -0,0 +1 @@
+message = CustomError: boom
diff --git a/Tests/LibWeb/Text/input/HTML/reportError-name-from-function-prototype.html b/Tests/LibWeb/Text/input/HTML/reportError-name-from-function-prototype.html
new file mode 100644
index 00000000000..f93b54bdfff
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/reportError-name-from-function-prototype.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ removeTestErrorHandler();
+
+ window.onerror = message => {
+ println(`message = ${message}`);
+ return true;
+ };
+
+ function CustomError() {}
+ const error = new Error("boom");
+ Object.setPrototypeOf(error, CustomError);
+ window.reportError(error);
+ });
+</script>