Title: [287109] trunk
Revision
287109
Author
[email protected]
Date
2021-12-15 14:34:30 -0800 (Wed, 15 Dec 2021)

Log Message

[Shadow Realms] Wrapped functions must only throw TypeError from calling realm
https://bugs.webkit.org/show_bug.cgi?id=234357

JSTests:

Test the cases when the exception would be thrown by a function
originating from both the shadow realm and the incubating realm.

Patch by Joseph Griego <[email protected]> on 2021-12-15
Reviewed by Yusuke Suzuki.

* stress/shadow-realm-evaluate.js:
(shouldBe):
(let.f.realm.evaluate):
(shouldBe.f):

Source/_javascript_Core:

Patch by Joseph Griego <[email protected]> on 2021-12-15
Reviewed by Yusuke Suzuki.

This wrapping logic already exists for ShadowRealm.prototype.evaluate
but not for calls to wrapped functions. at present, this requires some
awkward manouvering to actually throw a typeerror from the shadow realm,
since the wrapper code always runs in the incubating realm.

Hopefully we can make this less messy soon by replacing this
implementation with one more integrated with the runtime.

This case wasn't covered by existing JSC or test262 tests; added
coverage both upstream in t262 and in this patch.

* builtins/ShadowRealmPrototype.js:
(wrapped):
(globalPrivate.wrap):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (287108 => 287109)


--- trunk/JSTests/ChangeLog	2021-12-15 21:54:53 UTC (rev 287108)
+++ trunk/JSTests/ChangeLog	2021-12-15 22:34:30 UTC (rev 287109)
@@ -1,3 +1,18 @@
+2021-12-15  Joseph Griego  <[email protected]>
+
+        [Shadow Realms] Wrapped functions must only throw TypeError from calling realm
+        https://bugs.webkit.org/show_bug.cgi?id=234357
+
+        Test the cases when the exception would be thrown by a function
+        originating from both the shadow realm and the incubating realm.
+
+        Reviewed by Yusuke Suzuki.
+
+        * stress/shadow-realm-evaluate.js:
+        (shouldBe):
+        (let.f.realm.evaluate):
+        (shouldBe.f):
+
 2021-12-13  Yusuke Suzuki  <[email protected]>
 
         [JSC] Update Intl tests based on ICU 69~

Modified: trunk/JSTests/stress/shadow-realm-evaluate.js (287108 => 287109)


--- trunk/JSTests/stress/shadow-realm-evaluate.js	2021-12-15 21:54:53 UTC (rev 287108)
+++ trunk/JSTests/stress/shadow-realm-evaluate.js	2021-12-15 22:34:30 UTC (rev 287109)
@@ -174,3 +174,35 @@
     shouldBe(retrievedFoo, false);
     shouldBe(anotherFoo, 42);
 }
+
+// wrapped functions throw TypeError from the calling realm whenever the
+// implementing function throws:
+
+// (1) when the calling realm is the incubating realm
+{
+    let realm = new ShadowRealm();
+    let f = realm.evaluate("() => {throw new Error('ahh');}");
+    shouldThrow(f, TypeError, (e) => {});
+}
+
+// (2) when the calling realm is the shadow realm
+{
+    let realm = new ShadowRealm();
+    let f = realm.evaluate(`
+      (f) => {
+        try {
+          f();
+        } catch(e) {
+          if (e instanceof TypeError)
+            return 'ok';
+          else
+            return e.toString();
+        }
+        return 'fail: normal exit';
+      }
+    `);
+    shouldBe(
+        f(() => {throw new Error('ahhh');}),
+        'ok'
+    );
+}

Modified: trunk/Source/_javascript_Core/ChangeLog (287108 => 287109)


--- trunk/Source/_javascript_Core/ChangeLog	2021-12-15 21:54:53 UTC (rev 287108)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-12-15 22:34:30 UTC (rev 287109)
@@ -1,3 +1,25 @@
+2021-12-15  Joseph Griego  <[email protected]>
+
+        [Shadow Realms] Wrapped functions must only throw TypeError from calling realm
+        https://bugs.webkit.org/show_bug.cgi?id=234357
+
+        Reviewed by Yusuke Suzuki.
+
+        This wrapping logic already exists for ShadowRealm.prototype.evaluate
+        but not for calls to wrapped functions. at present, this requires some
+        awkward manouvering to actually throw a typeerror from the shadow realm,
+        since the wrapper code always runs in the incubating realm.
+
+        Hopefully we can make this less messy soon by replacing this
+        implementation with one more integrated with the runtime.
+
+        This case wasn't covered by existing JSC or test262 tests; added
+        coverage both upstream in t262 and in this patch.
+
+        * builtins/ShadowRealmPrototype.js:
+        (wrapped):
+        (globalPrivate.wrap):
+
 2021-12-14  Ross Kirsling  <[email protected]>
 
         [JSC] OpInstanceofCustom should be in CommonSlowPaths

Modified: trunk/Source/_javascript_Core/builtins/ShadowRealmPrototype.js (287108 => 287109)


--- trunk/Source/_javascript_Core/builtins/ShadowRealmPrototype.js	2021-12-15 21:54:53 UTC (rev 287108)
+++ trunk/Source/_javascript_Core/builtins/ShadowRealmPrototype.js	2021-12-15 22:34:30 UTC (rev 287109)
@@ -42,7 +42,18 @@
                 // calling the wrapped function
                 @putByValDirect(wrappedArgs, index, @wrap(!fromShadowRealm, shadowRealm, arguments[index]));
 
-            var result = target.@apply(@undefined, wrappedArgs);
+            try {
+                var result = target.@apply(@undefined, wrappedArgs);
+            } catch (e) {
+                const msg = "wrapped function threw: " + e.toString();
+                if (fromShadowRealm)
+                    @throwTypeError(msg);
+                else {
+                    const mkTypeError = @evalInRealm(shadowRealm, "(msg) => new TypeError(msg)");
+                    const err = mkTypeError.@apply(msg);
+                    throw err;
+                }
+            }
             return @wrap(fromShadowRealm, shadowRealm, result);
         };
         delete wrapped['name'];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to