From b785aeda446f77aaaa39b93c9bc144f04b0ee408 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 12 May 2014 12:42:35 +0000 Subject: [PATCH] Read internal properties [[PromiseStatus]] and [[PromiseValue]] of the promise. BUG=v8:3093 LOG=N R=aandrey@chromium.org, yangguo@chromium.org Review URL: https://codereview.chromium.org/273653007 Patch from Alexandra Mikhaylova . git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21266 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/mirror-debugger.js | 11 ++++++++++- test/mjsunit/es6/mirror-promises.js | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js index fde3f10..71b2992 100644 --- a/src/mirror-debugger.js +++ b/src/mirror-debugger.js @@ -798,7 +798,8 @@ ObjectMirror.prototype.toText = function() { /** * Return the internal properties of the value, such as [[PrimitiveValue]] of - * scalar wrapper objects and properties of the bound function. + * scalar wrapper objects, properties of the bound function and properties of + * the promise. * This method is done static to be accessible from Debug API with the bare * values without mirrors. * @return {Array} array (possibly empty) of InternalProperty instances @@ -822,6 +823,14 @@ ObjectMirror.GetInternalProperties = function(value) { result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs)); } 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; } return []; } diff --git a/test/mjsunit/es6/mirror-promises.js b/test/mjsunit/es6/mirror-promises.js index 5a21a6b..105b91d 100644 --- a/test/mjsunit/es6/mirror-promises.js +++ b/test/mjsunit/es6/mirror-promises.js @@ -67,3 +67,23 @@ var thrownv = new Promise(function(resolve, reject) { throw 'throw' }); testPromiseMirror(resolvedv, "resolved", 'resolve'); testPromiseMirror(rejectedv, "rejected", 'reject'); testPromiseMirror(thrownv, "rejected", 'throw'); + +// Test internal properties of different promises. +var m1 = debug.MakeMirror(new Promise( + function(resolve, reject) { resolve(1) })); +var ip = m1.internalProperties(); +assertEquals(2, ip.length); +assertEquals("[[PromiseStatus]]", ip[0].name()); +assertEquals("[[PromiseValue]]", ip[1].name()); +assertEquals("resolved", ip[0].value().value()); +assertEquals(1, ip[1].value().value()); + +var m2 = debug.MakeMirror(new Promise(function(resolve, reject) { reject(2) })); +ip = m2.internalProperties(); +assertEquals("rejected", ip[0].value().value()); +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())); -- 2.7.4