Title: [208410] trunk
Revision
208410
Author
[email protected]
Date
2016-11-04 17:48:01 -0700 (Fri, 04 Nov 2016)

Log Message

Error description code should be able to handle Symbol values.
https://bugs.webkit.org/show_bug.cgi?id=164436
<rdar://problem/29115583>

Reviewed by Filip Pizlo and Saam Barati.

JSTests:

* stress/error-description-on-symbols-should-not-crash.js: Added.

Source/_javascript_Core:

Previously, we try to toString() the Symbol value, resulting in it throwing an
exception in errorDescriptionForValue() which breaks the invariant that
errorDescriptionForValue() should not throw.

We fixed this by making errorDescriptionForValue() aware of the Symbol type, and
not so a toString() on Symbol values.  Also fixed notAFunctionSourceAppender()
to build a nicer message for Symbol values.

* runtime/ExceptionHelpers.cpp:
(JSC::errorDescriptionForValue):
(JSC::notAFunctionSourceAppender):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (208409 => 208410)


--- trunk/JSTests/ChangeLog	2016-11-05 00:41:50 UTC (rev 208409)
+++ trunk/JSTests/ChangeLog	2016-11-05 00:48:01 UTC (rev 208410)
@@ -1,3 +1,13 @@
+2016-11-04  Mark Lam  <[email protected]>
+
+        Error description code should be able to handle Symbol values.
+        https://bugs.webkit.org/show_bug.cgi?id=164436
+        <rdar://problem/29115583>
+
+        Reviewed by Filip Pizlo and Saam Barati.
+
+        * stress/error-description-on-symbols-should-not-crash.js: Added.
+
 2016-11-03  Geoffrey Garen  <[email protected]>
 
         EvalCodeCache should not give up in strict mode and other cases

Added: trunk/JSTests/stress/error-description-on-symbols-should-not-crash.js (0 => 208410)


--- trunk/JSTests/stress/error-description-on-symbols-should-not-crash.js	                        (rev 0)
+++ trunk/JSTests/stress/error-description-on-symbols-should-not-crash.js	2016-11-05 00:48:01 UTC (rev 208410)
@@ -0,0 +1,17 @@
+//@ runFTLNoCJIT
+
+function shouldEqual(actual, expected) {
+    if (actual != expected) {
+        throw "ERROR: expect " + expected + ", actual " + actual;
+    }
+}
+
+var exception;
+
+try {
+    Symbol(1)();
+} catch (e) {
+    exception = e;
+}
+
+shouldEqual(exception, "TypeError: Symbol(1) is not a function. (In 'Symbol(1)()', 'Symbol(1)' is a Symbol)");

Modified: trunk/Source/_javascript_Core/ChangeLog (208409 => 208410)


--- trunk/Source/_javascript_Core/ChangeLog	2016-11-05 00:41:50 UTC (rev 208409)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-11-05 00:48:01 UTC (rev 208410)
@@ -1,3 +1,23 @@
+2016-11-04  Mark Lam  <[email protected]>
+
+        Error description code should be able to handle Symbol values.
+        https://bugs.webkit.org/show_bug.cgi?id=164436
+        <rdar://problem/29115583>
+
+        Reviewed by Filip Pizlo and Saam Barati.
+
+        Previously, we try to toString() the Symbol value, resulting in it throwing an
+        exception in errorDescriptionForValue() which breaks the invariant that
+        errorDescriptionForValue() should not throw.
+
+        We fixed this by making errorDescriptionForValue() aware of the Symbol type, and
+        not so a toString() on Symbol values.  Also fixed notAFunctionSourceAppender()
+        to build a nicer message for Symbol values.
+
+        * runtime/ExceptionHelpers.cpp:
+        (JSC::errorDescriptionForValue):
+        (JSC::notAFunctionSourceAppender):
+
 2016-11-02  Geoffrey Garen  <[email protected]>
 
         EvalCodeCache should not give up in strict mode and other cases

Modified: trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp (208409 => 208410)


--- trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2016-11-05 00:41:50 UTC (rev 208409)
+++ trunk/Source/_javascript_Core/runtime/ExceptionHelpers.cpp	2016-11-05 00:48:01 UTC (rev 208410)
@@ -86,6 +86,8 @@
 {
     if (v.isString())
         return jsNontrivialString(exec, makeString('"',  asString(v)->value(exec), '"'));
+    if (v.isSymbol())
+        return jsNontrivialString(exec, asSymbol(v)->descriptiveString());
     if (v.isObject()) {
         CallData callData;
         JSObject* object = asObject(v);
@@ -182,9 +184,13 @@
     builder.appendLiteral("', '");
     builder.append(base);
     builder.appendLiteral("' is ");
-    if (type == TypeObject)
-        builder.appendLiteral("an instance of ");
-    builder.append(displayValue);
+    if (type == TypeSymbol)
+        builder.appendLiteral("a Symbol");
+    else {
+        if (type == TypeObject)
+            builder.appendLiteral("an instance of ");
+        builder.append(displayValue);
+    }
     builder.append(')');
 
     return builder.toString();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to