Skip to content

Commit 9e2d85e

Browse files
bnoordhuisMylesBorins
authored andcommitted
v8: handle proxy objects in MakeMirror(), v2
PR-URL: #14343 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bccd2f5 commit 9e2d85e

File tree

5 files changed

+47
-25
lines changed

5 files changed

+47
-25
lines changed

deps/v8/include/v8-version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define V8_MAJOR_VERSION 5
1212
#define V8_MINOR_VERSION 1
1313
#define V8_BUILD_NUMBER 281
14-
#define V8_PATCH_LEVEL 106
14+
#define V8_PATCH_LEVEL 107
1515

1616
// Use 1 for candidates and 0 otherwise.
1717
// (Boolean macro values are not supported by all preprocessors.)

deps/v8/src/debug/debug.js

+1
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ Debug.debuggerFlags = function() {
864864
};
865865

866866
Debug.MakeMirror = MakeMirror;
867+
Debug.MakeMirrorSerializer = MakeMirrorSerializer;
867868

868869
function MakeExecutionState(break_id) {
869870
return new ExecutionState(break_id);

deps/v8/src/debug/mirrors.js

+36
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ utils.Import(function(from) {
6060
// - FrameMirror
6161
// - ScriptMirror
6262
// - ScopeMirror
63+
// - ProxyMirror
6364

6465
// Type names of the different mirrors.
6566
var MirrorType = {
@@ -84,6 +85,7 @@ var MirrorType = {
8485
SET_TYPE : 'set',
8586
ITERATOR_TYPE : 'iterator',
8687
GENERATOR_TYPE : 'generator',
88+
PROXY_TYPE : 'proxy',
8789
}
8890

8991

@@ -157,6 +159,8 @@ function MakeMirror(value, opt_transient) {
157159
mirror = new StringMirror(value);
158160
} else if (IS_SYMBOL(value)) {
159161
mirror = new SymbolMirror(value);
162+
} else if (IS_PROXY(value)) {
163+
mirror = new ProxyMirror(value);
160164
} else if (IS_ARRAY(value)) {
161165
mirror = new ArrayMirror(value);
162166
} else if (IS_DATE(value)) {
@@ -342,6 +346,15 @@ Mirror.prototype.isSymbol = function() {
342346
};
343347

344348

349+
/**
350+
* Check whether the mirror reflects a proxy object.
351+
* @returns {boolean} True if the mirror reflects a proxy object.
352+
*/
353+
Mirror.prototype.isProxy = function() {
354+
return this instanceof ProxyMirror;
355+
};
356+
357+
345358
/**
346359
* Check whether the mirror reflects an object.
347360
* @returns {boolean} True if the mirror reflects an object
@@ -2439,6 +2452,29 @@ ContextMirror.prototype.data = function() {
24392452
};
24402453

24412454

2455+
/**
2456+
* Mirror object for proxies.
2457+
* @param {value} value The value reflected by this mirror.
2458+
* @constructor
2459+
* @extends Mirror
2460+
*/
2461+
function ProxyMirror(value) {
2462+
%_Call(Mirror, this, MirrorType.PROXY_TYPE);
2463+
this.value_ = value;
2464+
}
2465+
inherits(ProxyMirror, Mirror);
2466+
2467+
2468+
ProxyMirror.prototype.value = function() {
2469+
return this.value_;
2470+
};
2471+
2472+
2473+
ProxyMirror.prototype.toText = function() {
2474+
return '#<Proxy>';
2475+
};
2476+
2477+
24422478
/**
24432479
* Returns a mirror serializer
24442480
*

deps/v8/src/runtime/runtime-debug.cc

-4
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetPropertyDetails) {
310310

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

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

@@ -383,7 +382,6 @@ RUNTIME_FUNCTION(Runtime_DebugGetProperty) {
383382

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

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

@@ -1320,7 +1318,6 @@ static bool HasInPrototypeChainIgnoringProxies(Isolate* isolate,
13201318
RUNTIME_FUNCTION(Runtime_DebugReferencedBy) {
13211319
HandleScope scope(isolate);
13221320
DCHECK(args.length() == 3);
1323-
if (!args[0]->IsJSObject()) return *isolate->factory()->NewJSArray(0);
13241321
CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
13251322
CONVERT_ARG_HANDLE_CHECKED(Object, filter, 1);
13261323
RUNTIME_ASSERT(filter->IsUndefined() || filter->IsJSObject());
@@ -1411,7 +1408,6 @@ RUNTIME_FUNCTION(Runtime_DebugConstructedBy) {
14111408
RUNTIME_FUNCTION(Runtime_DebugGetPrototype) {
14121409
HandleScope shs(isolate);
14131410
DCHECK(args.length() == 1);
1414-
if (args[0]->IsJSProxy()) return isolate->heap()->undefined_value();
14151411
CONVERT_ARG_HANDLE_CHECKED(JSObject, obj, 0);
14161412
Handle<Object> prototype;
14171413
// TODO(1543): Come up with a solution for clients to handle potential errors

test/parallel/test-debug-mirror-proxy.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,16 @@ require('../common');
44
const assert = require('assert');
55
const vm = require('vm');
66

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

11-
assert.strictEqual(mirror.protoObject().value(), undefined);
12-
assert.strictEqual(mirror.className(), 'Object');
13-
assert.strictEqual(mirror.constructorFunction().value(), undefined);
14-
assert.strictEqual(mirror.prototypeObject().value(), undefined);
15-
assert.strictEqual(mirror.hasNamedInterceptor(), false);
16-
assert.strictEqual(mirror.hasIndexedInterceptor(), false);
17-
assert.strictEqual(mirror.referencedBy(1).length, 0);
18-
assert.strictEqual(mirror.toText(), '#<Object>');
11+
assert.strictEqual(mirror.isProxy(), true);
12+
assert.strictEqual(mirror.toText(), '#<Proxy>');
13+
assert.strictEqual(mirror.value(), proxy);
1914

20-
const propertyNames = mirror.propertyNames();
21-
const DebugContextArray = propertyNames.constructor;
22-
assert.deepStrictEqual(propertyNames, DebugContextArray.from(['x', 'y']));
23-
24-
const properties = mirror.properties();
25-
assert.strictEqual(properties.length, 2);
26-
// UndefinedMirror because V8 cannot retrieve the values without invoking
27-
// the handler. Could be turned a PropertyMirror but mirror.value() would
28-
// still be an UndefinedMirror. This seems Good Enough for now.
29-
assert(properties[0].isUndefined());
30-
assert(properties[1].isUndefined());
15+
const serializer = MakeMirrorSerializer(/* details */ true);
16+
const serialized = serializer.serializeValue(mirror);
17+
assert.deepStrictEqual(Object.keys(serialized).sort(), ['text', 'type']);
18+
assert.strictEqual(serialized.type, 'proxy');
19+
assert.strictEqual(serialized.text, '#<Proxy>');

0 commit comments

Comments
 (0)