Truly independent web browser
LibWeb: Throw Location define and delete errors in the current realm
Tim Ledbetter9824bef808d2
diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cppindex 89a86805534..3b1e857ebe6 100644--- a/Libraries/LibWeb/HTML/Location.cpp+++ b/Libraries/LibWeb/HTML/Location.cpp@@ -213,8 +213,7 @@ struct LocationWrapperTraits {}// 2. Throw a "SecurityError" DOMException.- auto& realm = HTML::relevant_realm(wrapper);- return throw_completion(realm, WebIDL::SecurityError::create(realm, Utf16String::formatted("Can't define property '{}' on cross-origin object", property_key)));+ return throw_completion(*wrapper.vm().current_realm(), WebIDL::SecurityError::create(Utf16String::formatted("Can't define property '{}' on cross-origin object", property_key)));}// 7.10.5.7 [[Get]] ( P, Receiver ), https://html.spec.whatwg.org/multipage/history.html#location-get@@ -247,8 +246,7 @@ struct LocationWrapperTraits {return wrapper.ordinary_delete(property_key);// 2. Throw a "SecurityError" DOMException.- auto& realm = HTML::relevant_realm(wrapper);- return throw_completion(realm, WebIDL::SecurityError::create(realm, Utf16String::formatted("Can't delete property '{}' on cross-origin object", property_key)));+ return throw_completion(*wrapper.vm().current_realm(), WebIDL::SecurityError::create(Utf16String::formatted("Can't delete property '{}' on cross-origin object", property_key)));}// 7.10.5.10 [[OwnPropertyKeys]] ( ), https://html.spec.whatwg.org/multipage/history.html#location-ownpropertykeysdiff --git a/Tests/LibWeb/Text/expected/HTML/cross-origin-Location-define-and-delete-realm.txt b/Tests/LibWeb/Text/expected/HTML/cross-origin-Location-define-and-delete-realm.txtnew file mode 100644index 00000000000..a6e9577e22d--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/cross-origin-Location-define-and-delete-realm.txt@@ -0,0 +1,2 @@+Define property: SecurityError, current realm: true+Delete property: SecurityError, current realm: truediff --git a/Tests/LibWeb/Text/input/HTML/cross-origin-Location-define-and-delete-realm.html b/Tests/LibWeb/Text/input/HTML/cross-origin-Location-define-and-delete-realm.htmlnew file mode 100644index 00000000000..412677ce4a9--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/cross-origin-Location-define-and-delete-realm.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ function report(description, callback) {+ try {+ callback();+ println(`${description}: no exception`);+ } catch (e) {+ println(`${description}: ${e.name}, current realm: ${e instanceof DOMException}`);+ }+ }++ asyncTest(done => {+ const iframe = document.createElement("iframe");+ iframe.sandbox = "";+ iframe.srcdoc = "<!DOCTYPE html>";+ iframe.onload = () => {+ const crossOriginLocation = iframe.contentWindow.location;++ report("Define property", () => Object.defineProperty(crossOriginLocation, "x", { value: 1 }));+ report("Delete property", () => Reflect.deleteProperty(crossOriginLocation, "x"));++ done();+ };+ document.body.appendChild(iframe);+ });+</script>