Reviewers: yurys, Alexandra Mikhaylova,

Message:
This CL is dependent on https://codereview.chromium.org/273653007/

What this changes:
- circumvent cross context access checks for PromiseMirror.
- return a mirror object from Promise.prototype.promiseValue instead of the raw
value, to maintain consistency to other mirror object types.

Description:
Use %DebugGetProperty in debug mirror to check for Promise.

Please review this at https://codereview.chromium.org/283373003/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+27, -25 lines):
  M src/mirror-debugger.js
  M src/promise.js
  M test/mjsunit/es6/mirror-promises.js


Index: src/mirror-debugger.js
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js
index b140343f4858086237783e96755c955d1daecfc5..124347b7bd5b72cd7a977750b91a2d608aa951e2 100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -21,10 +21,11 @@ function ClearMirrorCache() {

 // Wrapper to check whether an object is a Promise.  The call may not work
 // if promises are not enabled.
-// TODO(yangguo): remove this wrapper once promises are enabled by default.
+// TODO(yangguo): remove try-catch once promises are enabled by default.
 function ObjectIsPromise(value) {
   try {
-    return %IsPromise(value);
+    return IS_SPEC_OBJECT(value) &&
+           !IS_UNDEFINED(%DebugGetProperty(value, builtins.promiseStatus));
   } catch (e) {
     return false;
   }
@@ -824,13 +825,12 @@ ObjectMirror.GetInternalProperties = function(value) {
     }
     return result;
   } else if (ObjectIsPromise(value)) {
-      var mirror = new PromiseMirror(value);
-      var result = [];
-      result.push(new InternalPropertyMirror("[[PromiseStatus]]",
-                                             mirror.status()));
-      result.push(new InternalPropertyMirror("[[PromiseValue]]",
-                                             mirror.promiseValue()));
-      return result;
+    var result = [];
+    result.push(new InternalPropertyMirror("[[PromiseStatus]]",
+                                           PromiseGetStatus_(value)));
+    result.push(new InternalPropertyMirror("[[PromiseValue]]",
+                                           PromiseGetValue_(value)));
+    return result;
   }
   return [];
 }
@@ -1194,16 +1194,26 @@ function PromiseMirror(value) {
 inherits(PromiseMirror, ObjectMirror);


-PromiseMirror.prototype.status = function() {
-  var status = builtins.GetPromiseStatus(this.value_);
+function PromiseGetStatus_(value) {
+  var status = %DebugGetProperty(value, builtins.promiseStatus);
   if (status == 0) return "pending";
   if (status == 1) return "resolved";
   return "rejected";
+}
+
+
+function PromiseGetValue_(value) {
+  return %DebugGetProperty(value, builtins.promiseValue);
+}
+
+
+PromiseMirror.prototype.status = function() {
+  return PromiseGetStatus_(this.value_);
 };


 PromiseMirror.prototype.promiseValue = function() {
-  return builtins.GetPromiseValue(this.value_);
+  return MakeMirror(PromiseGetValue_(this.value_));
 };


@@ -2524,7 +2534,7 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content,
   if (mirror.isPromise()) {
     // Add promise specific properties.
     content.status = mirror.status();
-    content.promiseValue = mirror.promiseValue();
+    content.promiseValue = this.serializeReference(mirror.promiseValue());
   }

// Add actual properties - named properties followed by indexed properties.
Index: src/promise.js
diff --git a/src/promise.js b/src/promise.js
index f4c60d66cacc9538b8aa7d7133481251b3833b0e..959be51a84faaccedb013d3c68855aa274573351 100644
--- a/src/promise.js
+++ b/src/promise.js
@@ -301,12 +301,3 @@ function SetUpPromise() {
 }

 SetUpPromise();
-
-// Functions to expose promise details to the debugger.
-function GetPromiseStatus(promise) {
-  return GET_PRIVATE(promise, promiseStatus);
-}
-
-function GetPromiseValue(promise) {
-  return GET_PRIVATE(promise, promiseValue);
-}
Index: test/mjsunit/es6/mirror-promises.js
diff --git a/test/mjsunit/es6/mirror-promises.js b/test/mjsunit/es6/mirror-promises.js index a3e4a0d18e4152ccaefbd319f3a19e6c087687b4..bce26f4f92f6393027c84cbcb50e0ff9328becaf 100644
--- a/test/mjsunit/es6/mirror-promises.js
+++ b/test/mjsunit/es6/mirror-promises.js
@@ -39,7 +39,8 @@ function testPromiseMirror(promise, status, value) {
   assertEquals("Object", mirror.className());
   assertEquals("#<Promise>", mirror.toText());
   assertSame(promise, mirror.value());
-  assertEquals(value, mirror.promiseValue());
+  assertTrue(mirror.promiseValue() instanceof debug.Mirror);
+  assertEquals(value, mirror.promiseValue().value());

   // Parse JSON representation and check.
   var fromJSON = eval('(' + json + ')');
@@ -48,7 +49,7 @@ function testPromiseMirror(promise, status, value) {
assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name);
   assertEquals(status, fromJSON.status);
-  assertEquals(value, fromJSON.promiseValue);
+  assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value);
 }

 // Test a number of different promises.
@@ -86,4 +87,4 @@ assertEquals(2, ip[1].value().value());
 var m3 = debug.MakeMirror(new Promise(function(resolve, reject) { }));
 ip = m3.internalProperties();
 assertEquals("pending", ip[0].value().value());
-assertEquals("undefined", typeof(ip[1].value().value()));
\ No newline at end of file
+assertEquals("undefined", typeof(ip[1].value().value()));


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to