Skip to content

Commit

Permalink
v8: handle proxy objects in MakeMirror(), v2
Browse files Browse the repository at this point in the history
  • Loading branch information
bnoordhuis authored and MylesBorins committed Aug 15, 2017
1 parent 199af21 commit cebce8b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 5
#define V8_MINOR_VERSION 1
#define V8_BUILD_NUMBER 281
#define V8_PATCH_LEVEL 106
#define V8_PATCH_LEVEL 107

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/debug/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ Debug.debuggerFlags = function() {
};

Debug.MakeMirror = MakeMirror;
Debug.MakeMirrorSerializer = MakeMirrorSerializer;

function MakeExecutionState(break_id) {
return new ExecutionState(break_id);
Expand Down
36 changes: 36 additions & 0 deletions deps/v8/src/debug/mirrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ utils.Import(function(from) {
// - FrameMirror
// - ScriptMirror
// - ScopeMirror
// - ProxyMirror

// Type names of the different mirrors.
var MirrorType = {
Expand All @@ -84,6 +85,7 @@ var MirrorType = {
SET_TYPE : 'set',
ITERATOR_TYPE : 'iterator',
GENERATOR_TYPE : 'generator',
PROXY_TYPE : 'proxy',
}


Expand Down Expand Up @@ -157,6 +159,8 @@ function MakeMirror(value, opt_transient) {
mirror = new StringMirror(value);
} else if (IS_SYMBOL(value)) {
mirror = new SymbolMirror(value);
} else if (IS_PROXY(value)) {
mirror = new ProxyMirror(value);
} else if (IS_ARRAY(value)) {
mirror = new ArrayMirror(value);
} else if (IS_DATE(value)) {
Expand Down Expand Up @@ -342,6 +346,15 @@ Mirror.prototype.isSymbol = function() {
};


/**
* Check whether the mirror reflects a proxy object.
* @returns {boolean} True if the mirror reflects a proxy object.
*/
Mirror.prototype.isProxy = function() {
return this instanceof ProxyMirror;
};


/**
* Check whether the mirror reflects an object.
* @returns {boolean} True if the mirror reflects an object
Expand Down Expand Up @@ -2439,6 +2452,29 @@ ContextMirror.prototype.data = function() {
};


/**
* Mirror object for proxies.
* @param {value} value The value reflected by this mirror.
* @constructor
* @extends Mirror
*/
function ProxyMirror(value) {
%_Call(Mirror, this, MirrorType.PROXY_TYPE);
this.value_ = value;
}
inherits(ProxyMirror, Mirror);


ProxyMirror.prototype.value = function() {
return this.value_;
};


ProxyMirror.prototype.toText = function() {
return '#<Proxy>';
};


/**
* Returns a mirror serializer
*
Expand Down
4 changes: 0 additions & 4 deletions deps/v8/src/runtime/runtime-debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) {

DCHECK(args.length() == 2);

if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value();
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);

Expand Down Expand Up @@ -383,7 +382,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetProperty) {

DCHECK(args.length() == 2);

if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value();
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
CONVERT_ARG_HANDLE_CHECKED(Name, name, 1);

Expand Down Expand Up @@ -1320,7 +1318,6 @@ static bool HasInPrototypeChainIgnoringProxies(Isolate* isolate,
RUNTIME_FUNCTION(Runtime_DebugReferencedBy) {
HandleScope scope(isolate);
DCHECK(args.length() == 3);
if (!args[0]->IsJSObject()) return *isolate->factory()->NewJSArray(0);
CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
CONVERT_ARG_HANDLE_CHECKED(Object, filter, 1);
RUNTIME_ASSERT(filter->IsUndefined() || filter->IsJSObject());
Expand Down Expand Up @@ -1411,7 +1408,6 @@ RUNTIME_FUNCTION(Runtime_DebugConstructedBy) {
RUNTIME_FUNCTION(Runtime_DebugGetPrototype) {
HandleScope shs(isolate);
DCHECK(args.length() == 1);
if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value();
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
Handle<Object> prototype;
// TODO(1543): Come up with a solution for clients to handle potential errors
Expand Down
29 changes: 9 additions & 20 deletions test/parallel/test-debug-mirror-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,16 @@ require('../common');
const assert = require('assert');
const vm = require('vm');

const { MakeMirror } = vm.runInDebugContext('Debug');
const { MakeMirror, MakeMirrorSerializer } = vm.runInDebugContext('Debug');
const proxy = new Proxy({ x: 1, y: 2 }, { get: Reflect.get });
const mirror = MakeMirror(proxy, /* transient */ true);

assert.strictEqual(mirror.protoObject().value(), undefined);
assert.strictEqual(mirror.className(), 'Object');
assert.strictEqual(mirror.constructorFunction().value(), undefined);
assert.strictEqual(mirror.prototypeObject().value(), undefined);
assert.strictEqual(mirror.hasNamedInterceptor(), false);
assert.strictEqual(mirror.hasIndexedInterceptor(), false);
assert.strictEqual(mirror.referencedBy(1).length, 0);
assert.strictEqual(mirror.toText(), '#<Object>');
assert.strictEqual(mirror.isProxy(), true);
assert.strictEqual(mirror.toText(), '#<Proxy>');
assert.strictEqual(mirror.value(), proxy);

const propertyNames = mirror.propertyNames();
const DebugContextArray = propertyNames.constructor;
assert.deepStrictEqual(propertyNames, DebugContextArray.from(['x', 'y']));

const properties = mirror.properties();
assert.strictEqual(properties.length, 2);
// UndefinedMirror because V8 cannot retrieve the values without invoking
// the handler. Could be turned a PropertyMirror but mirror.value() would
// still be an UndefinedMirror. This seems Good Enough for now.
assert(properties[0].isUndefined());
assert(properties[1].isUndefined());
const serializer = MakeMirrorSerializer(/* details */ true);
const serialized = serializer.serializeValue(mirror);
assert.deepStrictEqual(Object.keys(serialized).sort(), ['text', 'type']);
assert.strictEqual(serialized.type, 'proxy');
assert.strictEqual(serialized.text, '#<Proxy>');

0 comments on commit cebce8b

Please sign in to comment.