Upgrade V8 to version 4.9.385.28

https://chromium.googlesource.com/v8/v8/+/4.9.385.28

FPIIM-449

Change-Id: I4b2e74289d4bf3667f2f3dc8aa2e541f63e26eb4
diff --git a/test/mjsunit/es6/debug-promises/events.js b/test/mjsunit/es6/debug-promises/events.js
index a9f9454..3fcb22f 100644
--- a/test/mjsunit/es6/debug-promises/events.js
+++ b/test/mjsunit/es6/debug-promises/events.js
@@ -116,9 +116,7 @@
   }
 
   var iteration = iteration || 0;
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone();
diff --git a/test/mjsunit/es6/debug-promises/promise-all-caught.js b/test/mjsunit/es6/debug-promises/promise-all-caught.js
new file mode 100644
index 0000000..2c940ce
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/promise-all-caught.js
@@ -0,0 +1,40 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we only listen to uncaught exceptions and a
+// Promise p3 created by Promise.all has a catch handler, and is rejected
+// because one of the Promises p2 passed to Promise.all is rejected. We
+// expect no Exception debug event to be triggered, since p3 and by
+// extension p2 have a catch handler.
+
+var Debug = debug.Debug;
+
+var expected_events = 2;
+
+var p1 = Promise.resolve();
+p1.name = "p1";
+
+var p2 = p1.then(function() {
+  throw new Error("caught");
+});
+
+p2.name = "p2";
+
+var p3 = Promise.all([p2]);
+p3.name = "p3";
+
+p3.catch(function(e) {});
+
+function listener(event, exec_state, event_data, data) {
+  try {
+    assertTrue(event != Debug.DebugEvent.Exception)
+  } catch (e) {
+    %AbortJS(e + "\n" + e.stack);
+  }
+}
+
+Debug.setBreakOnUncaughtException();
+Debug.setListener(listener);
diff --git a/test/mjsunit/es6/debug-promises/promise-all-uncaught.js b/test/mjsunit/es6/debug-promises/promise-all-uncaught.js
new file mode 100644
index 0000000..d183c5c
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/promise-all-uncaught.js
@@ -0,0 +1,73 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we only listen to uncaught exceptions and a
+// Promise p3 created by Promise.all has no catch handler, and is rejected
+// because one of the Promises p2 passed to Promise.all is rejected. We
+// expect two Exception debug events to be triggered, for p2 and p3 each,
+// because neither has an user-defined catch handler.
+
+var Debug = debug.Debug;
+
+var expected_events = 2;
+var log = [];
+
+var p1 = Promise.resolve();
+p1.name = "p1";
+
+var p2 = p1.then(function() {
+  log.push("throw");
+  throw new Error("uncaught");  // event
+});
+
+p2.name = "p2";
+
+var p3 = Promise.all([p2]);
+p3.name = "p3";
+
+function listener(event, exec_state, event_data, data) {
+  if (event != Debug.DebugEvent.Exception) return;
+  try {
+    expected_events--;
+    assertTrue(expected_events >= 0);
+    assertEquals("uncaught", event_data.exception().message);
+    assertTrue(event_data.promise() instanceof Promise);
+    if (expected_events === 1) {
+      // Assert that the debug event is triggered at the throw site.
+      assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
+      assertEquals("p2", event_data.promise().name);
+    } else {
+      assertEquals("p3", event_data.promise().name);
+    }
+    assertTrue(event_data.uncaught());
+  } catch (e) {
+    %AbortJS(e + "\n" + e.stack);
+  }
+}
+
+Debug.setBreakOnUncaughtException();
+Debug.setListener(listener);
+
+log.push("end main");
+
+function testDone(iteration) {
+  function checkResult() {
+    try {
+      assertTrue(iteration < 10);
+      if (expected_events === 0) {
+        assertEquals(["end main", "throw"], log);
+      } else {
+        testDone(iteration + 1);
+      }
+    } catch (e) {
+      %AbortJS(e + "\n" + e.stack);
+    }
+  }
+
+  %EnqueueMicrotask(checkResult);
+}
+
+testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/promise-race-caught.js b/test/mjsunit/es6/debug-promises/promise-race-caught.js
new file mode 100644
index 0000000..dd3ca83
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/promise-race-caught.js
@@ -0,0 +1,40 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we only listen to uncaught exceptions and a
+// Promise p3 created by Promise.race has a catch handler, and is rejected
+// because one of the Promises p2 passed to Promise.all is rejected. We
+// expect no Exception debug event to be triggered, since p3 and by
+// extension p2 have a catch handler.
+
+var Debug = debug.Debug;
+
+var expected_events = 2;
+
+var p1 = Promise.resolve();
+p1.name = "p1";
+
+var p2 = p1.then(function() {
+  throw new Error("caught");
+});
+
+p2.name = "p2";
+
+var p3 = Promise.all([p2]);
+p3.name = "p3";
+
+p3.catch(function(e) {});
+
+function listener(event, exec_state, event_data, data) {
+  try {
+    assertTrue(event != Debug.DebugEvent.Exception)
+  } catch (e) {
+    %AbortJS(e + "\n" + e.stack);
+  }
+}
+
+Debug.setBreakOnUncaughtException();
+Debug.setListener(listener);
diff --git a/test/mjsunit/es6/debug-promises/promise-race-uncaught.js b/test/mjsunit/es6/debug-promises/promise-race-uncaught.js
new file mode 100644
index 0000000..57955c0
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/promise-race-uncaught.js
@@ -0,0 +1,73 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we only listen to uncaught exceptions and a
+// Promise p3 created by Promise.race has no catch handler, and is rejected
+// because one of the Promises p2 passed to Promise.all is rejected. We
+// expect two Exception debug events to be triggered, for p2 and p3 each,
+// because neither has an user-defined catch handler.
+
+var Debug = debug.Debug;
+
+var expected_events = 2;
+var log = [];
+
+var p1 = Promise.resolve();
+p1.name = "p1";
+
+var p2 = p1.then(function() {
+  log.push("throw");
+  throw new Error("uncaught");  // event
+});
+
+p2.name = "p2";
+
+var p3 = Promise.race([p2]);
+p3.name = "p3";
+
+function listener(event, exec_state, event_data, data) {
+  if (event != Debug.DebugEvent.Exception) return;
+  try {
+    expected_events--;
+    assertTrue(expected_events >= 0);
+    assertEquals("uncaught", event_data.exception().message);
+    assertTrue(event_data.promise() instanceof Promise);
+    if (expected_events === 1) {
+      // Assert that the debug event is triggered at the throw site.
+      assertTrue(exec_state.frame(0).sourceLineText().indexOf("// event") > 0);
+      assertEquals("p2", event_data.promise().name);
+    } else {
+      assertEquals("p3", event_data.promise().name);
+    }
+    assertTrue(event_data.uncaught());
+  } catch (e) {
+    %AbortJS(e + "\n" + e.stack);
+  }
+}
+
+Debug.setBreakOnUncaughtException();
+Debug.setListener(listener);
+
+log.push("end main");
+
+function testDone(iteration) {
+  function checkResult() {
+    try {
+      assertTrue(iteration < 10);
+      if (expected_events === 0) {
+        assertEquals(["end main", "throw"], log);
+      } else {
+        testDone(iteration + 1);
+      }
+    } catch (e) {
+      %AbortJS(e + "\n" + e.stack);
+    }
+  }
+
+  %EnqueueMicrotask(checkResult);
+}
+
+testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reentry.js b/test/mjsunit/es6/debug-promises/reentry.js
index fbe5424..a97ce81 100644
--- a/test/mjsunit/es6/debug-promises/reentry.js
+++ b/test/mjsunit/es6/debug-promises/reentry.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug
+// Flags: --expose-debug-as debug --promise-extra
 
 // Test reentry of special try catch for Promises.
 
diff --git a/test/mjsunit/es6/debug-promises/reject-after-resolve.js b/test/mjsunit/es6/debug-promises/reject-after-resolve.js
index a0036cf..ed4b2c4 100644
--- a/test/mjsunit/es6/debug-promises/reject-after-resolve.js
+++ b/test/mjsunit/es6/debug-promises/reject-after-resolve.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we listen to uncaught exceptions and
 // the Promise is rejected in a chained closure after it has been resolved.
diff --git a/test/mjsunit/es6/debug-promises/reject-caught-all.js b/test/mjsunit/es6/debug-promises/reject-caught-all.js
index 0fca577..e1a6538 100644
--- a/test/mjsunit/es6/debug-promises/reject-caught-all.js
+++ b/test/mjsunit/es6/debug-promises/reject-caught-all.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we listen to all exceptions and
 // there is a catch handler for the to-be-rejected Promise.
@@ -63,10 +63,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js b/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js
index 63151df..b7c5861 100644
--- a/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js
+++ b/test/mjsunit/es6/debug-promises/reject-caught-by-default-reject-handler.js
@@ -77,10 +77,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-caught-late.js b/test/mjsunit/es6/debug-promises/reject-caught-late.js
index 2ff13d5..9224492 100644
--- a/test/mjsunit/es6/debug-promises/reject-caught-late.js
+++ b/test/mjsunit/es6/debug-promises/reject-caught-late.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions, the Promise
 // is rejected, and a catch handler is installed right before the rejection.
diff --git a/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js b/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js
index d3fd9f3..afb46fe 100644
--- a/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js
+++ b/test/mjsunit/es6/debug-promises/reject-caught-uncaught.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions and
 // there is a catch handler for the to-be-rejected Promise.
diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-all.js b/test/mjsunit/es6/debug-promises/reject-uncaught-all.js
index beaf187..63e3b86 100644
--- a/test/mjsunit/es6/debug-promises/reject-uncaught-all.js
+++ b/test/mjsunit/es6/debug-promises/reject-uncaught-all.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we listen to all exceptions and
 // there is a catch handler for the to-be-rejected Promise.
@@ -60,10 +60,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-late.js b/test/mjsunit/es6/debug-promises/reject-uncaught-late.js
index 4a883da..db58790 100644
--- a/test/mjsunit/es6/debug-promises/reject-uncaught-late.js
+++ b/test/mjsunit/es6/debug-promises/reject-uncaught-late.js
@@ -67,10 +67,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js b/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js
index 86e2a81..b542bc6 100644
--- a/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js
+++ b/test/mjsunit/es6/debug-promises/reject-uncaught-uncaught.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions and
 // there is no catch handler for the to-be-rejected Promise.
@@ -60,10 +60,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js b/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js
index fc6233d..8775df6 100644
--- a/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js
+++ b/test/mjsunit/es6/debug-promises/reject-with-invalid-reject.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when a Promise is rejected, which is caught by a custom
 // promise, which has a number for reject closure.  We expect an Exception debug
@@ -66,10 +66,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js b/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js
index 15e464e..b6c06df 100644
--- a/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js
+++ b/test/mjsunit/es6/debug-promises/reject-with-throw-in-reject.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when a Promise is rejected, which is caught by a
 // custom promise, which throws a new exception in its reject handler.
@@ -78,10 +78,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js b/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js
index d11c01f..d058d41 100644
--- a/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js
+++ b/test/mjsunit/es6/debug-promises/reject-with-undefined-reject.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when a Promise is rejected, which is caught by a custom
 // promise, which has undefined for reject closure.  We expect an Exception
@@ -66,10 +66,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js b/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js
new file mode 100644
index 0000000..918ae2a
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/resolve-after-aborted-try-finally.js
@@ -0,0 +1,32 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we listen to all exceptions and
+// there is a catch handler for the exception thrown in a Promise.
+// We expect a normal Exception debug event to be triggered.
+
+Debug = debug.Debug;
+
+var events = [];
+
+function listener(event, exec_state, event_data, data) {
+  if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
+}
+
+Debug.setListener(listener);
+
+var p = new Promise(function(resolve, reject) {
+  do {
+    try {
+      throw new Error("reject");
+    } finally {
+      break;  // No rethrow.
+    }
+  } while (false);
+  resolve();
+});
+
+assertEquals([0 /* create */, 1 /* resolve */], events);
diff --git a/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js b/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js
new file mode 100644
index 0000000..298201f
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/resolve-after-try-catch.js
@@ -0,0 +1,29 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we listen to all exceptions and
+// there is a catch handler for the exception thrown in a Promise.
+// We expect a normal Exception debug event to be triggered.
+
+Debug = debug.Debug;
+
+var events = [];
+
+function listener(event, exec_state, event_data, data) {
+  if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
+}
+
+Debug.setListener(listener);
+
+var p = new Promise(function (resolve, reject) {
+  try {
+    throw new Error("reject");
+  } catch (e) {
+  }
+  resolve();
+});
+
+assertEquals([0 /* create */, 1 /* resolve */], events);
diff --git a/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js b/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js
new file mode 100644
index 0000000..b1e2ff9
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/rethrow-in-try-finally.js
@@ -0,0 +1,30 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax
+
+// Test debug events when we listen to all exceptions and
+// there is a catch handler for the exception thrown in a Promise.
+// We expect a normal Exception debug event to be triggered.
+
+Debug = debug.Debug;
+
+var events = [];
+
+function listener(event, exec_state, event_data, data) {
+  if (event == Debug.DebugEvent.PromiseEvent) events.push(event_data.status());
+}
+
+Debug.setListener(listener);
+
+var p = new Promise(function(resolve, reject) {
+  try {
+    throw new Error("reject");
+  } finally {
+    // Implicit rethrow.
+  }
+  resolve();
+});
+
+assertEquals([0 /* create */, -1 /* rethrown */], events);
diff --git a/test/mjsunit/es6/debug-promises/stepin-constructor.js b/test/mjsunit/es6/debug-promises/stepin-constructor.js
new file mode 100644
index 0000000..906969e
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/stepin-constructor.js
@@ -0,0 +1,47 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug
+
+var Debug = debug.Debug;
+var exception = null;
+var breaks = [];
+
+function listener(event, exec_state, event_data, data) {
+  if (event != Debug.DebugEvent.Break) return;
+  try {
+    breaks.push(exec_state.frame(0).sourceLineText().trimLeft());
+    exec_state.prepareStep(Debug.StepAction.StepIn);
+  } catch (e) {
+    exception = e;
+  }
+}
+
+Debug.setListener(listener);
+
+function resolver(resolve, reject) {
+  1;
+  2;
+  3;
+  resolve();
+}
+
+debugger;
+var p = new Promise(resolver);
+
+Debug.setListener(null);
+
+var expected_breaks = [
+  "debugger;",
+  "var p = new Promise(resolver);",
+  "1;",
+  "2;",
+  "3;",
+  "resolve();",
+  "}",
+  "Debug.setListener(null);"
+];
+
+assertEquals(expected_breaks, breaks);
+assertNull(exception);
diff --git a/test/mjsunit/es6/debug-promises/stepin-handler.js b/test/mjsunit/es6/debug-promises/stepin-handler.js
new file mode 100644
index 0000000..8083c17
--- /dev/null
+++ b/test/mjsunit/es6/debug-promises/stepin-handler.js
@@ -0,0 +1,65 @@
+// Copyright 2015 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --allow-natives-syntax --noalways-opt
+// Tests stepping into through Promises.
+
+Debug = debug.Debug
+var exception = null;
+var break_count = 0;
+var expected_breaks = -1;
+
+function listener(event, exec_state, event_data, data) {
+  try {
+    if (event == Debug.DebugEvent.Break) {
+      assertTrue(exec_state.frameCount() != 0, "FAIL: Empty stack trace");
+      if (!break_count) {
+        // Count number of expected breakpoints in this source file.
+        var source_text = exec_state.frame(0).func().script().source();
+        expected_breaks = source_text.match(/\/\/\s*Break\s+\d+\./g).length;
+        print("Expected breaks: " + expected_breaks);
+      }
+      var source = exec_state.frame(0).sourceLineText();
+      print("paused at: " + source);
+      assertTrue(source.indexOf("// Break " + break_count + ".") > 0,
+                 "Unexpected pause at: " + source + "\n" +
+                 "Expected: // Break " + break_count + ".");
+      ++break_count;
+      if (break_count !== expected_breaks) {
+        exec_state.prepareStep(Debug.StepAction.StepIn);
+      }
+    }
+  } catch(e) {
+    exception = e;
+    print(e, e.stack);
+  }
+};
+
+Debug.setListener(listener);
+
+Promise.resolve(42)
+  .then(
+    function f0() {
+      debugger;  // Break 0.
+    } // Break 1.
+  )
+  .then(callback)
+  .then(callback.bind(null))
+  .then(Object)
+  .then(callback.bind(null).bind(null))
+  .then(finalize)
+  .catch(function(err) {
+    %AbortJS("FAIL: " + err);
+  });
+
+function callback(x) {
+  return x; // Break 2. // Break 4. // Break 6.
+} // Break 3. // Break 5. // Break 7.
+
+function finalize() {
+  assertNull(exception); // Break 8.
+  assertEquals(expected_breaks, break_count);
+
+  Debug.setListener(null);
+}
diff --git a/test/mjsunit/es6/debug-promises/throw-caught-all.js b/test/mjsunit/es6/debug-promises/throw-caught-all.js
index 2fbf051..3b7c48c 100644
--- a/test/mjsunit/es6/debug-promises/throw-caught-all.js
+++ b/test/mjsunit/es6/debug-promises/throw-caught-all.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we listen to all exceptions and
 // there is a catch handler for the exception thrown in a Promise.
@@ -62,10 +62,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js b/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js
index 36b5565..3c30ad3 100644
--- a/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js
+++ b/test/mjsunit/es6/debug-promises/throw-caught-by-default-reject-handler.js
@@ -78,10 +78,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/throw-caught-late.js b/test/mjsunit/es6/debug-promises/throw-caught-late.js
index ac79aba..aa7e584 100644
--- a/test/mjsunit/es6/debug-promises/throw-caught-late.js
+++ b/test/mjsunit/es6/debug-promises/throw-caught-late.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions, the Promise
 // throws, and a catch handler is installed right before throwing.
diff --git a/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js b/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js
index 0ad9ce4..a424ccc 100644
--- a/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js
+++ b/test/mjsunit/es6/debug-promises/throw-caught-uncaught.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions and
 // there is a catch handler for the exception thrown in a Promise.
diff --git a/test/mjsunit/es6/debug-promises/throw-uncaught-all.js b/test/mjsunit/es6/debug-promises/throw-uncaught-all.js
index 72f800b..bfe0bed 100644
--- a/test/mjsunit/es6/debug-promises/throw-uncaught-all.js
+++ b/test/mjsunit/es6/debug-promises/throw-uncaught-all.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we listen to all exceptions and
 // there is no catch handler for the exception thrown in a Promise.
@@ -61,10 +61,7 @@
     }
   }
 
-  // Rerun testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js b/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js
index 69aa8eb..8dff592 100644
--- a/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js
+++ b/test/mjsunit/es6/debug-promises/throw-uncaught-uncaught.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when we only listen to uncaught exceptions and
 // there is a catch handler for the exception thrown in a Promise.
@@ -61,10 +61,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js b/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js
index 1ea1c7f..349d014 100644
--- a/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js
+++ b/test/mjsunit/es6/debug-promises/throw-with-throw-in-reject.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when an exception is thrown inside a Promise, which is
 // caught by a custom promise, which throws a new exception in its reject
@@ -81,10 +81,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);
diff --git a/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js b/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js
index 94dcdff..69ee01e 100644
--- a/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js
+++ b/test/mjsunit/es6/debug-promises/throw-with-undefined-reject.js
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-// Flags: --expose-debug-as debug --allow-natives-syntax
+// Flags: --expose-debug-as debug --allow-natives-syntax --promise-extra
 
 // Test debug events when an exception is thrown inside a Promise, which is
 // caught by a custom promise, which has no reject handler.
@@ -48,7 +48,7 @@
       } else if (expected_events == 0) {
         // All of the frames on the stack are from native Javascript.
         assertEquals(0, exec_state.frameCount());
-        assertEquals("undefined is not a function",
+        assertEquals("(var).reject is not a function",
                      event_data.exception().message);
       } else {
         assertUnreachable();
@@ -79,10 +79,7 @@
     }
   }
 
-  // Run testDone through the Object.observe processing loop.
-  var dummy = {};
-  Object.observe(dummy, checkResult);
-  dummy.dummy = dummy;
+  %EnqueueMicrotask(checkResult);
 }
 
 testDone(0);