Revision: 13049
Author:   [email protected]
Date:     Fri Nov 23 07:47:58 2012
Log:      Censor .caller if it is a strict function instead of throwing.

For details, see:

http://www.mail-archive.com/[email protected]/msg19322.html
https://bugs.ecmascript.org/show_bug.cgi?id=310

[email protected]
BUG=

Review URL: https://codereview.chromium.org/11417140
http://code.google.com/p/v8/source/detail?r=13049

Modified:
 /branches/bleeding_edge/src/accessors.cc
 /branches/bleeding_edge/test/mjsunit/strict-mode.js

=======================================
--- /branches/bleeding_edge/src/accessors.cc    Wed Nov 14 08:51:21 2012
+++ /branches/bleeding_edge/src/accessors.cc    Fri Nov 23 07:47:58 2012
@@ -647,19 +647,6 @@
 //
 // Accessors::FunctionCaller
 //
-
-
-static MaybeObject* CheckNonStrictCallerOrThrow(
-    Isolate* isolate,
-    JSFunction* caller) {
-  DisableAssertNoAllocation enable_allocation;
-  if (!caller->shared()->is_classic_mode()) {
-    return isolate->Throw(
-        *isolate->factory()->NewTypeError("strict_caller",
-                                          HandleVector<Object>(NULL, 0)));
-  }
-  return caller;
-}


 class FrameFunctionIterator {
@@ -748,7 +735,14 @@
   if (caller->shared()->bound()) {
     return isolate->heap()->null_value();
   }
-  return CheckNonStrictCallerOrThrow(isolate, caller);
+  // Censor if the caller is not a classic mode function.
+  // Change from ES5, which used to throw, see:
+  // https://bugs.ecmascript.org/show_bug.cgi?id=310
+  if (!caller->shared()->is_classic_mode()) {
+    return isolate->heap()->null_value();
+  }
+
+  return caller;
 }


=======================================
--- /branches/bleeding_edge/test/mjsunit/strict-mode.js Fri Nov 23 07:45:03 2012 +++ /branches/bleeding_edge/test/mjsunit/strict-mode.js Fri Nov 23 07:47:58 2012
@@ -1141,9 +1141,9 @@

   function strict() {
     "use strict";
-    return_my_caller();
+    return return_my_caller();
   }
-  assertThrows(strict, TypeError);
+  assertSame(null, strict());

   function non_strict() {
     return return_my_caller();
@@ -1155,32 +1155,57 @@
 (function TestNonStrictFunctionCallerPill() {
   function strict(n) {
     "use strict";
-    non_strict(n);
+    return non_strict(n);
   }

   function recurse(n, then) {
     if (n > 0) {
-      recurse(n - 1, then);
+      return recurse(n - 1, then);
     } else {
       return then();
     }
   }

   function non_strict(n) {
-    recurse(n, function() { non_strict.caller; });
+    return recurse(n, function() { return non_strict.caller; });
   }

   function test(n) {
-    try {
-      recurse(n, function() { strict(n); });
-    } catch(e) {
-      return e instanceof TypeError;
+    return recurse(n, function() { return strict(n); });
+  }
+
+  for (var i = 0; i < 10; i ++) {
+    assertSame(null, test(i));
+  }
+})();
+
+
+(function TestNonStrictFunctionCallerDescriptorPill() {
+  function strict(n) {
+    "use strict";
+    return non_strict(n);
+  }
+
+  function recurse(n, then) {
+    if (n > 0) {
+      return recurse(n - 1, then);
+    } else {
+      return then();
     }
-    return false;
+  }
+
+  function non_strict(n) {
+    return recurse(n, function() {
+      return Object.getOwnPropertyDescriptor(non_strict, "caller").value;
+    });
+  }
+
+  function test(n) {
+    return recurse(n, function() { return strict(n); });
   }

   for (var i = 0; i < 10; i ++) {
-    assertEquals(test(i), true);
+    assertSame(null, test(i));
   }
 })();

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to