Revision: 21339
Author: [email protected]
Date: Fri May 16 13:06:20 2014 UTC
Log: Use %DebugGetProperty in debug mirror to check for Promise.
[email protected], [email protected]
Review URL: https://codereview.chromium.org/283373003
http://code.google.com/p/v8/source/detail?r=21339
Modified:
/branches/bleeding_edge/src/mirror-debugger.js
/branches/bleeding_edge/src/promise.js
/branches/bleeding_edge/test/mjsunit/es6/mirror-promises.js
=======================================
--- /branches/bleeding_edge/src/mirror-debugger.js Mon May 12 13:38:39 2014
UTC
+++ /branches/bleeding_edge/src/mirror-debugger.js Fri May 16 13:06:20 2014
UTC
@@ -21,10 +21,11 @@
// 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;
}
@@ -798,7 +799,8 @@
/**
* 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
@@ -821,6 +823,13 @@
}
result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs));
}
+ return result;
+ } else if (ObjectIsPromise(value)) {
+ var result = [];
+ result.push(new InternalPropertyMirror("[[PromiseStatus]]",
+ PromiseGetStatus_(value)));
+ result.push(new InternalPropertyMirror("[[PromiseValue]]",
+ PromiseGetValue_(value)));
return result;
}
return [];
@@ -1185,16 +1194,26 @@
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_));
};
@@ -2515,7 +2534,7 @@
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.
=======================================
--- /branches/bleeding_edge/src/promise.js Wed May 14 10:44:34 2014 UTC
+++ /branches/bleeding_edge/src/promise.js Fri May 16 13:06:20 2014 UTC
@@ -301,12 +301,3 @@
}
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);
-}
=======================================
--- /branches/bleeding_edge/test/mjsunit/es6/mirror-promises.js Mon May 12
13:38:39 2014 UTC
+++ /branches/bleeding_edge/test/mjsunit/es6/mirror-promises.js Fri May 16
13:06:20 2014 UTC
@@ -39,7 +39,8 @@
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 @@
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.
@@ -67,3 +68,23 @@
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()));
--
--
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.