Chromium Code Reviews| Index: src/mirror-debugger.js |
| diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js |
| index d413b090b71a86e587329a410ae7bce46c2ae730..17bd1456abc9942dd01ad13cc658620a336884bb 100644 |
| --- a/src/mirror-debugger.js |
| +++ b/src/mirror-debugger.js |
| @@ -42,6 +42,18 @@ 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. |
| +function ObjectIsPromise(value) { |
| + try { |
| + return %IsPromise(value); |
| + } catch (e) { |
| + return false; |
| + } |
| +} |
| + |
| + |
| /** |
| * Returns the mirror for a specified value or object. |
| * |
| @@ -90,6 +102,8 @@ function MakeMirror(value, opt_transient) { |
| mirror = new ErrorMirror(value); |
| } else if (IS_SCRIPT(value)) { |
| mirror = new ScriptMirror(value); |
| + } else if (ObjectIsPromise(value)) { |
| + mirror = new PromiseMirror(value); |
| } else { |
| mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient); |
| } |
| @@ -159,6 +173,7 @@ var FRAME_TYPE = 'frame'; |
| var SCRIPT_TYPE = 'script'; |
| var CONTEXT_TYPE = 'context'; |
| var SCOPE_TYPE = 'scope'; |
| +var PROMISE_TYPE = 'promise'; |
| // Maximum length when sending strings through the JSON protocol. |
| var kMaxProtocolStringLength = 80; |
| @@ -212,6 +227,7 @@ var ScopeType = { Global: 0, |
| // - DateMirror |
| // - RegExpMirror |
| // - ErrorMirror |
| +// - PromiseMirror |
| // - PropertyMirror |
| // - InternalPropertyMirror |
| // - FrameMirror |
| @@ -351,6 +367,15 @@ Mirror.prototype.isError = function() { |
| /** |
| + * Check whether the mirror reflects a promise. |
| + * @returns {boolean} True if the mirror reflects a promise |
| + */ |
| +Mirror.prototype.isPromise = function() { |
| + return this instanceof PromiseMirror; |
| +}; |
| + |
| + |
| +/** |
| * Check whether the mirror reflects a property. |
| * @returns {boolean} True if the mirror reflects a property |
| */ |
| @@ -637,9 +662,9 @@ ObjectMirror.prototype.propertyNames = function(kind, limit) { |
| // Find all the named properties. |
| if (kind & PropertyKind.Named) { |
| - // Get all the local property names. |
| + // Get all the local property names except for private symbols. |
| propertyNames = |
| - %GetLocalPropertyNames(this.value_, PROPERTY_ATTRIBUTES_NONE); |
| + %GetLocalPropertyNames(this.value_, PROPERTY_ATTRIBUTES_PRIVATE_SYMBOL); |
| total += propertyNames.length; |
| // Get names for named interceptor properties if any. |
| @@ -1172,6 +1197,33 @@ ErrorMirror.prototype.toText = function() { |
| /** |
| + * Mirror object for a Promise object. |
| + * @param {Object} data The Promise object |
| + * @constructor |
| + * @extends Mirror |
| + */ |
| +function PromiseMirror(value) { |
| + %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror); |
| +} |
| +inherits(PromiseMirror, ObjectMirror); |
| + |
| + |
| +PromiseMirror.prototype.promise = function() { |
| + return this.promise_; |
|
aandrey
2014/04/25 13:38:25
did you mean this.value_ ?
Yang
2014/04/25 13:42:51
Nice catch. I removed this so that .value() return
|
| +}; |
| + |
| + |
| +PromiseMirror.Pending = 0; |
|
rossberg
2014/04/25 13:29:45
Instead of defining these constants, the status fu
Yang
2014/04/25 13:42:51
Done.
|
| +PromiseMirror.Rejected = -1; |
| +PromiseMirror.Resolved = +1; |
| + |
| + |
| +PromiseMirror.prototype.status = function() { |
| + return %GetPromiseStatus(this.value_); |
| +}; |
| + |
| + |
| +/** |
| * Base mirror object for properties. |
| * @param {ObjectMirror} mirror The mirror object having this property |
| * @param {string} name The name of the property |
| @@ -2350,6 +2402,7 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference, |
| case FUNCTION_TYPE: |
| case ERROR_TYPE: |
| case REGEXP_TYPE: |
| + case PROMISE_TYPE: |
| // Add object representation. |
| this.serializeObject_(mirror, content, details); |
| break; |
| @@ -2452,7 +2505,6 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, |
| content.indexedInterceptor = true; |
| } |
| - // Add function specific properties. |
| if (mirror.isFunction()) { |
| // Add function specific properties. |
| content.name = mirror.name(); |
| @@ -2480,12 +2532,16 @@ JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content, |
| } |
| } |
| - // Add date specific properties. |
| if (mirror.isDate()) { |
| // Add date specific properties. |
| content.value = mirror.value(); |
| } |
| + if (mirror.isPromise()) { |
| + // Add promise specific properties. |
| + content.status = mirror.status(); |
| + } |
| + |
| // Add actual properties - named properties followed by indexed properties. |
| var propertyNames = mirror.propertyNames(PropertyKind.Named); |
| var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed); |